Debian/Ubuntu Tips and Tricks

Debuntu

Debian/Ubuntu Tips and Tricks

How-To: Install Ubuntu on LVM partitions

Posted by chantra on July 28th, 2007

LVM (Logical Volume Manager) is a great piece of software which allow you to deal with Logical Volumes. Using LVM along with ext3 filesystem, you are allowed to extend the size of your logical drives which is pretty handy when running out of space.

Distributions like Fedora, Suse and Debian have a LVM aware installer. Unfortunately, at the time this article was written, Ubuntu does not offer such settings with the Desktop Install CD.

This article will cover how to create LVM partitions and how-to generate your partitions from this LVM volume.

LVM offer better flexibility when it comes to storage management. Using traditional partitioning system, when a partition becomes too small, the only solution left is to:

  • create a bigger partition
  • Copy the datas from the previous partition to the newly created one
  • Change the mounting information of the partition
  • Umount the old one, and mount the new one

LVM allow you to have better control of your storage. Excerpt from http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux):

The LVM can:

* Resize volume groups online by absorbing new physical volumes (PV) or ejecting existing ones.
* Resize logical volumes online by concatenating extents onto them or truncating extents from them.
* Create read-only snapshots of logical volumes (LVM1).
* Create read-write snapshots of logical volumes (LVM2).
* Stripe whole or parts of logical volumes across multiple PVs, in a fashion similar to RAID0.
* Move online logical volumes between PVs.
* Split or merge volume groups in situ (as long as no logical volumes span the split). This can be useful when migrating whole logical volumes to or from offline storage.

It cannot:

* Mirror whole or parts of logical volumes, in a fashion similar to RAID1 or RAID5 mirroring of logical volumes. For this, it is recommended, that one use the Linux software RAID driver to mirror the underlying PVs to achieve redundancy.

In this tutorial, we will install Ubuntu on an LVM filesystem. Because Ubuntu does not support this out of the box, we will have to create and format our partitions using fdisk. Once the partitions will be created, we will start the installer and point it to the right partition.

Because we are going to modify the hard-drive layout, be aware that you might delete datas. Please make sure you have backed-up all important datas.

1. Requirements:

In order to be able to do this tutorial, you will need the following:

  • Ubuntu Desktop install liveCD
  • An internet connection or lvm2 package
  • Free disk space on your hard-drive

2. Preparing the environment:

2.1. Installing LVM

Boot up your computer using Ubuntu liveCD. Once logged in, open a terminal and install LVM:

$ sudo apt-get install lvm2

If you have a lvm package copy on a removeable device, type:

$ sudo dpkg -i /path/to/lvm2.deb

Finally, lod the kernel module dm-mod.

$ sudo modprobe dm-mod

Now, we need to set up our Hard drive.

2.2. Partitioning the disk:

One of the requirements of Linux on LVM is that /boot has to be on a traditional partition. Because of this requirement, we will set up a separate /boot partition and a big LVM partition covering the rest of the hard drive. This LVM partition will then be splitted in a /, /home and swap partitions. Some extra space might be left on the LVM partition allowing you to grow your existing partitions if needed be.

At this stage, I consider that you have space available on your disk, if not, please use fdisk or gparted and delete some partitions, when done, refresh the kernel partition table by typing:

$ sudo partprobe

Well, let's create a boot partition of 100M and all the available space into a LVM partition:

$ sudo fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1033-9729, default 1033):
Using default value 1033
Last cylinder or +size or +sizeM or +sizeK (1033-9729, default 9729): +100M

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1058-9729, default 1058):
Using default value 1058
Last cylinder or +size or +sizeM or +sizeK (1058-9729, default 9729):
Using default value 9729

Command (m for help):t
Partition number (1-4): 3
Hex code (type L to list codes): 8e

Command (m for help):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

$ sudo partprobe

OK, now we have our boot partition and our big LVM partition. We need to format /boot to ext3 filesystem, create our physical volume on /dev/sda3, create a Volume Group and Logical Volumes for /, /home and the swap partition. Finally format those logical volumes and install Ubuntu over those volumes.

$ sudo mke2fs -j /dev/sda2
$ sudo pvcreate /dev/sda3 #create a physical volume on /dev/sda3
Physical volume "/dev/sda3" successfully created
$ sudo vgcreate lvmvolume /dev/sda3 #create a volume group named lvmvolume using /dev/sda3 physical volume
Volume group "lvmvolume" successfully created
$ sudo lvcreate -n root -L 5G lvmvolume #create a logical volume of 5G named "root" in lvmvolume
Logical volume "root" created
$ sudo lvcreate -n home -L 10G lvmvolume #create a logical volume of 10G named "home" in lvmvolume
Logical volume "home" created
$ sudo lvcreate -n swap -L 2G lvmvolume #create a logical volume of 2G named "swap" in lvmvolume
Logical volume "swap" created
$ sudo mkfs -j /dev/lvmvolume/root -L root #format root as ext3
$ sudo mkfs -j /dev/lvmvolume/home -L home #format home as ext3
$ sudo mkswap -L swap /dev/lvmvolume/swap #format swap as swap filesystem, labelled swap

Here we are, no start the installer and when it comes to partitioning, select "manual" and choose the partitions /dev/sda1 (change this according to your layout) , /dev/lvmvolume/{root,home,swap} for /boot, /, /home and swap.

If the partitions are presented like: /dev/dm-X, type ls -l /dev/mapper/, this will help you tracking your volumes.

3. Finalizing the install

Before you reboot your computer, you need to install lvm2 package into your newly created system. To do this, you will chroot into you new ubuntu sytem and install the package in that environment.

As per wayupnorth comment, make sure all your future partition are mounted under /target, for example, you will need to issue:
# mount /dev/sdaX /target/boot
# mount /dev/lvmvolume/usr /target/usr
...

Open a terminal and type:

$ sudo chroot /target
# apt-get update
# apt-get install lvm2

That's it, you can now reboot your system and boot on your Ubuntu system using LVM.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>