Linux cross installation

From Devpit
Jump to: navigation, search

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
    • 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.
    • 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.
  2. reboot This will ensure that your machine sees the new partitions.
  3. mkfs
    • 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.
    • 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.
  4. mount
    • Mount your new root filesystem somewhere. Just about anywhere you want. For simplicity's sake, you can just use /mnt.
    • Mount the other new filesystems underneath it. For instance, mkdir /mnt/usr and mount the new /usr there.
  5. untar
    • 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.
    • Be sure to use the -p option to tar. This will ensure that files are created with the proper permissions.
  6. chroot into new system with a command like chroot /mnt.
  7. Configure the new system.
    • Network
    • Kernel modules
    • Hostname
    • sshd startup on boot
    • Anything else necessary to access your machine once it boots back up.
  8. Kernel
    • Verify that the kernel is intact. This includes modules.
    • Verify initrd.img if you are using it.
    • Verify that /dev is populated
    • 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.
  10. grub
    • Install grub to boot sector of your drive.
    • Configure /boot/grub/menu.lst to point accurately to your new system's partition, kernel, and initrd.img if necessary.
    • Include a fallback entry for the old system's partition, kernel, initrd.img, etc.
    • Set the new system boot entry as the default.
    • 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.
  11. Verify
    • Double-check everything.
    • 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.)
  12. Un-chroot by typing exit.
  13. reboot