“A nearly impenetrable thicket of geekitude…”

Moving a FC5 Root Partition to LVM

Posted on November 19, 2006 at 20:10

One of my servers is pretty old, dating back to the dawn of recorded history — or Red Hat 7 as we now call it. Most of its storage has been migrated onto a new hard disk and the Logical Volume Manager some time ago. Finally removing the original hard drive requires a few tricky operations: moving the root partition, moving the boot partition, and moving the boot loader.

These operations are turning out to be tricky enough to make it worth writing down the procedure in case I ever need to use it again. So, here’s an aide-mémoire on moving a Fedora Core 5 root partition onto LVM.

All of this needs to be done after rebooting the system in single-user mode. To do this, type ‘a’ at the GRUB screen and add the parameter ‘1’ to the end of the kernel parameters line.

  • Create a new 1GB partition in an existing LVM volume group (in my case, ops):

      # lvcreate -L1G -n root ops
    
  • Make an ext3 file system on that partition:

      # mke2fs -j /dev/ops/root
    
  • Copy the existing root partition over there:

      # mkdir /mnt/new
      # mount /dev/ops/root /mnt/new
      # cd /mnt/new
      # dump 0af - / | restore xf -
    
  • Change the new fstab to point to the new partition:

      # emacs /mnt/new/etc/fstab
      /dev/ops/root / ext3 defaults 1 1
    
  • Make a new initial RAM disk image:

      # mkinitrd -v -fstab /mnt/new/etc/fstab \
          /boot/new.img 2.6.18-1.2200.fc5
    
  • Add a new GRUB configuration using the new image:

      # emacs /boot/grub/grub.conf
      title Fedora Core (2.6.18-1.2200.fc5 migrated)
         root (hd0,0)
         kernel /vmlinuz-2.6.18-1.2200.fc5 ro root=/dev/ops/root
         initrd /new.img
    

Reboot on the new configuration, and you should be done.

The messing around with initrd is the least obvious part of the above. The good news is that it is a one-off operation; the next time you use yum update to install a new kernel, the new initial RAM disk built as part of the kernel install will take the now current configuration into account.

Tags: