Custom Stage4

Introduction
This article will demonstrate how to create a custom stage4 archive. A stage4 archive is an image of your entire root partition. The primary reason to create a stage4 archive is to provide for quick recovery in the event of disk failure. A stage4 archive is the same as a stage3, only you can select the CFLAGS you want to use and what other software you want installed. You can adapt this method to suit your personal uses.

If you want a generic stage4 that you can install on multiple systems, use Genkernel to set up your kernel. This will ensure that on boot, the kernel will work like the one on the livecd. You may also want to use less restrictive CFLAGS (i.e., MCPU instead of MARCH). You may still have to modify and the USE flags after extracting the stage4, to suit the user.

This article assumes you have already installed Gentoo, if not go to the handbook and do the install first.

This article also assumes that you have already setup any other software you may want to have on your system. For example, on a desktop system you may want X, Xfce4, Sun's JDK, CVS, Emacs, Thunderbird, and Firefox.

Optional Tar /boot
make a copy of your partition:

Alternatively, you can just mount before you tar everything up. However, there may be problems with this alternate method if you use the stage4 on systems with different hardware configurations.

Optional Clean up
(If you use an exclude file like the one shown in the next paragraph, this step can be omitted.)

If you are cloning machines make sure you use different

You can follow the Running out of disk space FAQ to free more space.

The TAR system
Create an exclusion file that tells tar what not to pack into your stage 4 archive. Ending listed directories with /* instead of / will include the directory itself in the tar, but nothing inside the directory, thereby saving you the hassle of recreating them once you've restored.

After everything is set up correctly from the previous sections, we will create the archive:

tar options we used: c - create archive v - verbosely list files processed j - use bzip2 compression f - specify file name X - use the specified exclusion file tar option we DIDN'T use: p - preserve file attributes (necessary only during extraction of the tar, not during creation)

Be sure to look at the tar manpage

It will probably take a long time to create the archive depending on how much you have installed. I usually save the archive on a spare disk I have in my system that I use for backups. You can also burn it to a cd or dvd.

If it is too large to fit on a cd you will have to split it up. Large tar files can be split up with 'split'. The parts can be joined later with 'cat'. Read the manpages for these tools before you use them.

Here are some scripts to make this step a little easier.

Installing from Stage4

 * Boot live CD
 * Set the system date to UTC and set the BIOS clock
 * Create partitions, make filesystems and mount filesystems
 * Copy your stage4 archive(s) to disk (if it is on another CD type "gentoo docache" at the boot prompt. Then you'll be able to umount/mount other CDs.)
 * If you used the option to copy over your to, then restore  from
 * Make a few basic device nodes needed for booting
 * Mount /proc and /dev into the chroot
 * Get the latest portage snapshot
 * Chroot into
 * Make sure the following files are correct for your system
 * Make sure to install your boot loader into the mbr with either grub or lilo
 * Make sure to install your boot loader into the mbr with either grub or lilo
 * Make sure to install your boot loader into the mbr with either grub or lilo
 * Make sure to install your boot loader into the mbr with either grub or lilo
 * Make sure to install your boot loader into the mbr with either grub or lilo
 * Make sure to install your boot loader into the mbr with either grub or lilo

Partition table tip
To store partition table info:

The first of those saves the mbr and the second will store all partition info (including logical partitions, which aren't part of the mbr).

To restore partition info:

Grub Tip
After chrooting:

(hd may need to be changed depending on your setup)

Udev tip
If your eth0 controller doesn't come up after recovery, take a look at. The issue is that when migrating to a new system, the MAC address for eth0 will probably change if using an embedded NIC, so you need to update eth0 with the correct MAC, which is probably automatically setup as eth1.

backupHome.sh
Small script which is used to make backups of. (The corresponds to the  directory in .)

backupHome.sh

Changes to above script:
 * lazy_bum removed from, this is used with EXTRACT only.

mkstage4.sh
mkstage4.sh

Changes to above script:
 * Milos Ivanovic
 * Removed from tarOptions. This is used with EXTRACT only!
 * odessit
 * Added and  encryption methods using GnuPG
 * Added instructions how to merge split files
 * Added changelog-like comments to the top of the script.
 * BrianW
 * Cleaned up the script a bit.
 * Made it so the for the archive doesn't have to be edited if you modify
 * Added
 * Added to the tar options
 * Added code to remove
 * Moved the out of  into their own variable's (thanks kamilian)

installstage4.sh
Here is a little script to install from a stage4 created by either of the and. (Limited testing reported by rpcyan thanks please continue testing) should work though. A few changes were made by rpcyan to get the install script working correctly Please contact me with comments or improvements. nianderson

installstage4.sh

makestage4.sh
For explanation and further information refer to the Gentoo Forums Post. A howto (Wiki) and the latest version of the script can be found here. mkstage4.sh

/sbin/mkstage4
Here an alternative mkstage4 shell script /sbin/mkstage4

Credits
Original Forum Post by allucid.

Up-to-Date Forum Thread link you to Blinkeye's Wiki by Blinkeye

Feedback
For feedback/comments, please use the Discussion page.

Stage4