Saturday, September 20, 2008

Installing Ubuntu Linux on existing LVM partition.

I wanted to install Ubuntu on a computer that already housed Fedora Linux. It seems that Fedora defaults to installing /root and /swap on an LVM partition -- something that Ubuntu does not recognize out of the box. After poking about online, here is the process I followed (compiled from here, here, and here.):


Warning: As always, any time you are messing about with drive partitions, you risk something tragic happening to your data. Backup critical bits before continuing.

First deal with reducing the existing logical volume:

# Boot Ubuntu from live-CD.

# Install lvm2:
$ sudo apt-get install lvm2

# Load the necessary module(s):
$ sudo modprobe dm-mod

# Scan your system for LVM volumes and identify in the output the volume group name that has your Fedora volume (mine proved to be VolGroup00):
$ sudo vgscan

# Activate the volume:
$ sudo vgchange -ay VolGroup00

# Find the logical volume that has your Fedora root filesystem (mine proved to be LogVol00):
$ sudo lvs

# Determine how much space is used on the volume:
$ sudo vgdisplay

# Check the filesystem
sudo e2fsck -f /dev/VolGroup00/LogVol00

# Resize the filesystem to desired size (CRITICAL before proceeding to next step!)
$ resize2fs -f /dev/VolGroup00/LogVol00 16G

# Reduce the size of the logical volume
$ lvreduce -L10G /dev/VolGroup00/LogVol00


Create new logical volumes for /root and /home (in my case /swap already existed):

# First make sure how much free space remains in the volume group
$ sudo vgdisplay

# Create \UbuntuRoot and \home
$ sudo lvcreate -n UbuntuRoot -L10G VolGroup00
$ sudo lvcreate -n home -L18.28G VolGroup00


# Now format the new logical volumes:
$ sudo mkfs -j /dev/VolGroup00/UbuntuRoot -L root
$ sudo mkfs -j /dev/VolGroup00/home -L home



Then run the installer, choosing the appropriate volumes. Note that I had already created a hard partition to serve as /boot --- this is the only way a lvm install will work.

Finally, make sure that the newly installed system has lvm2 included (otherwise it will not start). The following is adapted from here.


# Create a mountpoint for the newly installed system:
$ sudo mkdir /target
$ sudo mkdir /target


# Mount the newly installed system:
$ sudo mount /dev/VolGroup00/UbuntuRoot /target
$ sudo mount /dev/sda6 /target/boot


# Activate those directories and install lvm2
$ sudo chroot /target
$ sudo apt-get update
$ sudo apt-get install lvm2



Now you can restart into the new system!



No comments: