Moving existing Fedora17 install into LVM (including /boot)

Fedora 17 has a GRUB2 version that supports booting from a boot partition in a LVM logical volume. That means you can have a full LVM layout of your disk(s) without a separate physical partition for /boot. I want that! Now, I’m rather pleased with my current Fedora setup, so I did not want to do a full re-install. What to do? Would it be possible to lite:rary “move” my existing partitions into LV’s, including /boot? Turn’s out this can be done and it’s fairly (..) easy. You need to have at least the same amount of free disk space available as the separate partitions combined , either in an existing Volume Group or in unused disk space.

I had my Fedora 17 installed on 3 partition’s: swap, boot and root. This is not a default install. A default install has a separate boot partition and the rest lives in a volume group. This procedure also works in that case. Simply apply it then to the boot partition only.

  • Create a fourth partition from the remaining space
  • Make a LVM Physical device out of it
  • Make a Volume Group from the Physical device or grow your existing volume Group if you have that.
The above three steps are not necessary if you already have a Volume Group with enough free space in it.

  • Make a Logical Volume for each to-be-migrated existing partition. Give it a descriptive name and make it exactly the same size as the partition it needs to hold. You could also make them slightly larger. When your done you can then resize the LV’s to a smaller size if you like. There are procedures for that. So, in my case, I created a lv_swap, lv_boot and lv_root Logical volume in my Volume Group called vg00.
  • Make a swap for lv_swap:
  • Now use dd to make an exact block-by-block copy of the running system from each to-be-migrated partition to each corresponding Logical Volume. In my case this looks like this:
The block-size in my case is 4k, but you should check this for each filesystem you want to move this way. You can check this by dumping the file system header using the statement dumpe2fs /dev/<partition>. For ext2/3/4 it usually is 4k. Also, the dd command does not take partition boundaries into consideration when doing its thing, so when the target partition is too small, it will just write on into the next and you’ll get all kinds of nice surprises..
When this is done you have exact copies of your partitions. Too exact! Even the UUID’s are the same and that is not good. This means we need to change the UUID’s of the newly created filesystems. You can generate a new uuid with the command uuidgen and use it’s output as the uuid for a partition:

Do this for each Logical Volume that is involved.
  • Next is do adjust the fstab in the etc directory on the involved Logical Volume. Mount this Logical Volume onto /mnt and edit the /mnt/etc/fstab file. I like to use the UUID as a unique device descriptor, so my new fstab like looks like this after editing:

BTW, You can get a list of the UUID’s from all you’re devices using the “blkid” command.

You can also use traditional device names in you’re fstab, although that is no longer the preferred method:
  • Next up is the bootloader. We need to add an extra menu entry in the boot loader to boot from the new location. With GRUB2, this is very ease, because there is a script available to do just that. It will search your system for installed operating systems. The statement to do this is:
This changes the GRUB2 configuration on the existing boot partition (we need to do it again later on).
  • Now reboot. You will see a new entry in the boot menu. Choose that and boot into your Fedora17 OS in the new location. Hooray! We are however NOT finished. We need to change the GRUB config on the new installation also. Because we are now running in this new location, we can simply to the previous statement again:
  • If this enough? No, because the stage 1 GRUB in the MBR is still looking at the old /boot partition to find it’s GRUB config. So we also need to change that, by installing GRUB2 again:
  • Reboot and choose the new installation again to see if it still works.
  • Now we can clean up the old installation by removing the partitions. It depends on your specific partition layout what to do with them. I just turned them into LVM Physical Volumes and added them to my Volume Group vg00.
  • Edit the file /etc/default/grub. There is an entry that starts with GRUB_CMDLINE_LINUX. Check if in that line there is a text like “rd.lvm-0″. If there is, remove it and save the file.
  • The old Fedora 17 install is still in the boot menu. Remove it by simply generating a new GRUB2 config:
  • Reboot to test and your done!

Comments are closed.