Monday, May 24, 2010

Lucid desktop install with lvm2

As I recently "reorganized" the partitioning scheme on my desktop system to gain some space for my flac music files I also changed the linux partitions to further run from logical volumes. To install Ubuntu on logical volumes you need to run the alternate installer - which in my case pretty much failed. I don't know why, but half the way of copying the new system the installer insisted on putting in the CD medium (which of course was still in the drive) and no matter what option I chose - "Continue" or "Cancel" - the request wouldn't go away. This was the first time an Ubuntu installer didn't work out for me. Still wanting to install Ubuntu's latest release I came across a post in Linux Mint's (another Ubuntu offspring) forum, describing how to install Linux Mint with lvm2. See the original post by piratesmack (thanks!) here. I more or less followed this howto.

So, this is how it worked for me, but: PLEASE KEEP IN MIND THAT MESSING WITH PARTITIONS MAY CAUSE DATA LOSS!!! SO BACK UP YOUR DATA!!!

OK, having that said, let's begin by getting the default Ubuntu Lucid Lynx desktop live iso from here, burn it to CD and boot from it. When you're being asked to either try it out or install Ubuntu, go for the first option. Once the desktop is loaded, open a terminal from the "Applications" menu and install lvm2:
# sudo apt-get update
# sudo apt-get install lvm2

As I already created logical volumes with the alternate installer, all I had to do is make them active:
# sudo vgchange -ay

If you don't have your logical volumes created already, do so now. I guess if you want/need logical volumes you know what you're doing, but this is roughly how it works:

  1. Prepare the harddrive(s) with "sudo fdisk /dev/sdX", you need at least one partition with type set to "e8"

  2. Create a physical volume: sudo pvcreate /dev/sdXY (do that for every partition you've created in step 1 with type set to "e8").

  3. Create a volume group: sudo vgcreate <VOLGROUPNAME> /dev/sdXY /dev/sdZY (if you want to have multiple disks in the group)

  4. Create the logical volumes within the volume group: sudo lvcreate -L <SIZE, i.e. 25G> -n <VOLNAME> <VOLGROUPNAME>

  5. Activate the newly created volumes: sudo vgscan --mknodes && sudo vgchange -ay

  6. Format the volumes: sudo mkfs.ext4 /dev/mapper/<VOLGROUPNAME>-<VOLNAME>

Now close the terminal, start the Ubuntu installer and go on as usual. Remember to choose the "Custom partitioning" option when the installer asks for the disk layout. From here you can choose your logical volumes and assign mount points. Once the install is finished DO NOT REBOOT, but click "Continue testing". As the newly installed system lacks lvm2 we need to add it now by setting up a chroot environment.

First, open a terminal again and mount your root partition (please adjust the devices accordingly):
# sudo mount /dev/mapper/volgrp0-rootlv /mnt

Once done, mount all other devices including the virtual filesystems:
# sudo mount /dev/mapper/volgrp0-homelv /mnt/home
# sudo mount /dev/sda2 /mnt/boot
(/boot is extremely crucial!)
# sudo mount --bind /dev /mnt/dev
# sudo mount --bind /dev/pts /mnt/dev/pts
# sudo mount --bind /proc /mnt/proc

Now install lvm2:
# sudo chroot /mnt apt-get update
# sudo chroot /mnt apt-get install lvm2

Umount everything:
# sudo umount /mnt/proc /mnt/dev/pts /mnt/dev /mnt/boot /mnt/home /mnt

And now choose to reboot from the applet at the upper right corner. If everything went well you should then be running Lucid Lynx with lvm support!

3 comments:

  1. One minor mistake: You need to execute "exit" after "Now install lvm2" and before "Unmount everything", to leave the chroot.

    A tip for the unwary: The thing that makes this whole process work is running mkfs.ext4 on the LV before running the installer. If you don't do this, the installer will try to force you to create a partition table within the LV, so in this example, the root filesystem would end up on "/dev/mapper/volgrp0-rootlvp1". The kernel can be made to recognize this, but the Ubuntu initrd/initramfs scripts won't take the necessary steps to make the kernel process the partition table, so your system won't boot. If you create the filesystem first, the installer behaves differently, and allow you to install directly into the whole LV, like you want.

    ReplyDelete
  2. Actually, I think you don't need to "exit" as the chroot is only for the command given.

    ReplyDelete