Linux cross installation

This article describes one process by which you can cross-install one Linux distribution over the top of a running one. It does not require physical access to the machine, which is useful in the event that, for instance, you lease a server from a company which does not offer your preferred distribution of Linux. It has been successfully used for exactly that purpose, to convert from a Red Hat installation to a Debian "sarge" installation.

Note that some steps are particularly sensitive and can require physical access (or a networked KVM) to resolve errors. It is therefore critical that you take the utmost care in each step.

It is also possible to cross-install from a host operating system other than Linux. For instance, FreeBSD could be used. However, the partitioning step will be much trickier from FreeBSD, because it handles partition tables differently from Linux.

Without further ado, here are the steps of the process:


 * 1) fdisk
 * 2) * Create your cross-install partitions. You will need to find a way to organize your partitions so that you have enough room to install the target distribution.  This will also affect how the partition table looks when you are done.  One way to do this is, if you have equal-sized /home and /usr partitions and equal-sized swap and / partitions, to wipe out /home and turn of swap and make those the new /usr and / partitions, respectively.  Note that you can leave out /home or even /var, if you intend to move it to another partition later on, since these will initially be small enough to keep on the / partition.  It is best to plan to use your host system's running partitions for this purpose later on.
 * 3) * Leave the partitions your host system needs to run intact. Make sure not to wipe out /, /usr, /var, and so forth from the host system.  If space allows, you can try to consolidate them all onto the / partition to make more room for your destination partitions.
 * 4) reboot  This will ensure that your machine sees the new partitions.
 * 5) mkfs
 * 6) * Create the filesystems on your cross-install target partitions. This is done just as if you were installing from a CD or any other source.
 * 7) * Make certain that your new kernel will support the filesystems you use. It does you no good to get done installing a new Linux distribution only to find that the kernel it comes with cannot mount the filesystem you installed it on.
 * 8) mount
 * 9) * Mount your new root filesystem somewhere. Just about anywhere you want.  For simplicity's sake, you can just use /mnt.
 * 10) * Mount the other new filesystems underneath it. For instance, mkdir /mnt/usr and mount the new /usr there.
 * 11) untar
 * 12) * Unpack the new system into the cross-install target. You can also use some distribution-specific utilities to populate the cross-install target filesystem.  See your distribution's documentation for details on this.
 * 13) * Be sure to use the -p option to tar. This will ensure that files are created with the proper permissions.
 * 14) chroot into new system with a command like chroot /mnt.
 * 15) Configure the new system.
 * 16) * Network
 * 17) * Kernel modules
 * 18) * Hostname
 * 19) * sshd startup on boot
 * 20) * Anything else necessary to access your machine once it boots back up.
 * 21) Kernel
 * 22) * Verify that the kernel is intact. This includes modules.
 * 23) * Verify initrd.img if you are using it.
 * 24) MAKEDEV
 * 25) * Verify that /dev is populated
 * 26) * Verify that /dev/{random,urandom,null,tty*,pty*} etc. are actual devices with the correct permissions. Essentially, make sure enough devices exist and are in working order to boot up and start the daemons you need to access the machine.
 * 27) grub
 * 28) * Install grub to boot sector of your drive.
 * 29) * Configure /boot/grub/menu.lst to point accurately to your new system's partition, kernel, and initrd.img if necessary.
 * 30) * Include a fallback entry for the old system's partition, kernel, initrd.img, etc.
 * 31) * Set the new system boot entry as the default.
 * 32) * Set up the default entry to install grub with a pointer to the old system's /boot/grub/menu.lst. This way, if the machine is remotely rebooted after a failed attempt to boot into the new system, it should return to the old one.
 * 33) Verify
 * 34) * Double-check everything.
 * 35) * Particularly critical things to check include /etc/fstab, where typos can prevent a working system. (For instance, misspelling "defaults" in /etc/fstab will cause that filesystem not to be mounted at bootup.)
 * 36) Un-chroot by typing exit.
 * 37) reboot