Dealing with hard drives in Ubuntu

·

When the computer starts up, it looks in the BIOS settings to see which drive to start from (which can usually be overridden temporarily by pressing one of the F keys). The chosen drive has a Master Boot Record, which contains software that decides which partition on which drive should be used to boot the operating system.

Hard drives in Linux are found at /dev/hda, /dev/hdb, etc if they're PATA (aka IDE) drives and /dev/sda, /dev/sdb etc if they're SATA drives. To see all the drives you have installed, use sudo fdisk -l. When you install Ubuntu, it detects which drive is set as the primary boot drive and installs GRUB on the MBR.

GRUB uses a different system for identifying drives: hd0, hd1, etc. The file /boot/grub/device.map contains mappings between /dev/hda-style names and hd0-style names. GRUB also uses the file /boot/grub/menu.lst which says where the root of each operating system is found: Ubuntu, for example, might be at (hd0,0) - the first partition on the drive mapped to hd0 in device.map.

The trouble with this is that if you move hard drives around, or even boot from a different drive, the ordering of the /dev/hd naming can often change, so the drive that was once /dev/hda is now /dev/hdb.

Once Ubuntu is booting, it gets around this by using the UUID that is stored on the drive for each partition. The file /etc/fstab controls which partitions are mounted for use, and uses UUIDs to identify them, so this is stable even when the drives are moved around. To see the UUID for a particular partition, use sudo vol_id /dev/hda1, for example.

Because GRUB doesn't use UUIDs, it has problems when partitions and drives move around. For example, if you install Ubuntu on the first partition on a drive, then use a GParted Live CD to move that partition along and create another partition on front of it for installing Windows (a process that works remarkably well in fact, as long as you have a Super GRUB Disk handy to reinstall GRUB to the MBR after Windows' installer wipes it out), GRUB still thinks Ubuntu is at (hd0,0), and any Linux kernel upgrade that recreates the list of operating systems available in /boot/grub/menu.lst will stop the system from being able to boot. To fix this, edit the groot=(hd0,0) line to point to the right partition for Ubuntu's root, then re-run update-grub.

The other thing that can go wrong is Ubuntu's installer will get the drive mappings wrong when installing GRUB, because it's only working from /dev/hda-style identifiers. If that happens, you need to boot from the installer/Live CD again, and edit the installed /boot/grub/device.map manually.