This post isn’t designed to be a “how to” merely an overview of how I achieved the subject. It is possible to do this without any physical intervention but in practice I have had to visit site at least once to fix a boot error on every one I have done.
Disclaimer:- When attempting this having some sort of remote access solution that will give access to the server even when it won’t boot is desirable i.e. BMC, DRAC or KVM over IP. Obviously resizing and deleting partitions and file systems is very dangerous so you need to be ultra careful and ultra sure you understand the process and exactly what you are doing at each step. It may also be helpful to draw the partition layout at each stage so you have a clear view of what is happening. Don’t come crying to me when it all blows up in your face. You have been warned!
The steps to achieve this are:-
- Create a minimal 64 bit ubuntu install to fit inside 512MB (I used KVM and the Ubuntu alternate installer CD as I don’t have hardware virtualisation extensions in my CPU and purged un-needed packages and the apt cache). Resize the filesystem and partition as small as possible i.e. circa 480 MB to make sure it will fit inside the target swap partition space.
- Replace the swap partition on the target server with the disk image you have just created using dd. Use rsync with compression to upload the disk image file to the target server and save time.
- Copy the kernel from the created partition into the boot partition of the target server and update Grub accordingly. Don’t forget to put the correct root option onto the kernel command line.
- Boot from the new kernel and what was swap partition. Normally something goes wrong after changing Grub that involves a site visit.
- Resize the system partition of the target server to make room for a new partition. Not forgetting to make the filesystem and partition size as small as possible to speed copying with dd.
- Create a new partition and use dd to copy the existing system partition to the new partition.
- Erase the original system partition, resize the created partition (the one that was swap) reboot and do an online resize of the file system to take advantage of the extra space.
- Copy data and config files from copied system partition to the new (the one that was swap).
- Copy users and groups from /etc/passwd /etc/group and /etc/shadow, http://www.cyberciti.biz/faq/howto-move-migrate-user-accounts-old-to-new-server/ is very useful in that regard. Manually check the files created to delete any unnecessary groups and accounts.
- Install needed services checking each one works correctly. Most config files should migrate directly even if from a different distro.
- At some stage, when you’ve established everything is working, and you don’t need any data from the old install, delete the partition the original system partition was copied to in step 6 and create a new swap partition (preferably a big one in case you need to do something like this again in future).
Any questions? No? Good!