In the last week I've had some need to setup some new PCs to control some of our machines in the lab. The problem being that the control interface between machine and PC is quite complicated and uses some pretty niche software, on the openSUSE OS (which is one of the most difficult linux OS's IMHO).
So rather than having to install openSUSE from scratch using repositories that are no longer supported (because the software isn't supported by the new SUSE distros) and then try to install the software and configure it, I thought it perhaps best to take a PC that is working and clone it onto a new PC.
So on the currently working machine I took the case apart, found a spare SATA cable and took the new PCs hard drive and attached to a SATA port (of higher number, so it would have secondary boot priority). I then used a Clonezilla live disk burned to a DVD as a boot device and started the clone. Clonezilla has some nice screenshots and youtube some videos that can take you through the process.
But loosely, because I was cloning an entire hard drive to an equal sized hard drive that was attached locally to the same machine it was as easy as selecting disk one to copy to disk two and waiting for 10 minutes for it to copy, on this screen select “device-device”:
Just make sure you select the right one to copy from and to otherwise you'll have 2 blank disks.
Now foolishly I thought that I'd be up and running at this point. So, I stuck the hard drive back into the new PC and powered it on. I got the initial openSUSE logo and the GRUB bootloader and I allowed a small celebration only to be slapped in the face with failure to boot messages.
As it turns out SUSE (including openSUSE, and most RedHat derivatives) use device IDs to boot past the initial GRUB options. In lay-man's terms, the start of boot is just from whatever drive is available, but the higher levels of booting the OS require a reference to a drive and rather than using the standard linux device labels like /dev/sda as the first hard drive GRUB uses the device ID, in my case /dev/disk/by-id/ata_WDC_WD5000 AAKS-00YGA0_WD_WDCA580752928
Now obviously the hard drive between PCs had changed and this was causing the GRUB boot procedure to fall over. What was required then was to modify the GRUB files to account for the new hard drive.
So I grabbed a Kubuntu live disk (10.04 LTS) (it was the first one I had to hand) and booted into the live disk environment. From here I could then mount the hard drive and edit it's files without all those troublesome error messages and permissions for system files.
In a terminal window, cd to the new disk (usually /media/disk), then
Take note of the drive label, it should look something like “ata-[manufacturer]_[model number]_[serial number]” with multiple entries for -part1, -part2 for each partition on the drive.
Now we know the drive ID we can change GRUB accordingly.
sudo nano menu.lst
You dont have to use nano, you can use any text editor, nano is my preference. This now is the GRUB option file, and you should be able to see an option for something like
### Dont change this comment – …
title Desktop — openSUSE 11.x …
root (hd 0,1)
kernel /boot/vmlinux-[version number]-desktop root = /dev/disk/by-id/ [hard disk]-part2 resume = /dev/disk/by-id/[hard disk]-part1 splash = silent quiet showopts vga = 0x31a
initrd /boot/initrd-[version number]-desktop
Obviously the [hard drive] from the old PC needs to be replaced with the new hard drive version number. Save the file, and close (in nano this is Ctrl-X to close, then Y to save changes then Enter).
So we've now got GRUB to recognize the new drive and address the boot procedure to the correct drive. We now need to get the OS to automatically mount the drive so that we can actually use it within the OS.
sudo nano /media/disk/etc/fstab
fstab is the file that mounts drives when linux boots, in this file we need to change the hard drive addresses again so that we mount the new hard drive and not the old one that isnt connected anymore.
One of the first lines should read something like:
/dev/disk/by-id/ata-[manufacturer]_[model number]_[serial number]-part1 swap swap defaults 0 0
So once again swap the old hard drive details for the new one, and repeat for each partition. Save and close.
Now we can restart the machine and check if it boots (remember to take out the live disk).
In my case this did the trick and I got to the SUSE log in screen, where the log-in details from the old machine were still valid.