Søren Lund (slu) wrote,
Søren Lund

Adding more disk space using LVM

I had an old build server that was running low on disk space.

The server was virtual and it was running Ubuntu 10.10 configured with LVM.

LVM means Logical Volume Managment, and it's a virtual layer upon the physical disks (or virtual disks in this case). LVM makes it easy to expand the disk space without the need to move files.

I started by adding an extra disk, which was easy, as this is a virtual machine.

Then I logged on to the machine and issued the following to see what disks were available:

# sudo lshw -short -c disk
H/W path             Device      Class      Description
/0/100/7.1/0.0.0     /dev/cdrom  disk       DVD-RAM writer
/0/100/10/0.0.0      /dev/sda    disk       100GB SCSI Disk
/0/100/10/0.1.0      /dev/sdb    disk       100GB SCSI Disk

The disk I just added is /dev/sdb, which needs formatting:

# sudo fdisk /dev/sdb

(Then select 'm', 'n', 'p', '1', <enter>, <enter>, 't', '8e', 'w')

The command issued to fdisk means: show menu, create new primary partition number 1. Use the complete disk (i.e. just use the suggested values for start and end sectors = 2 x <enter>). Set type to "Linux LVM" (8e) and write changes to disk.

Create the partition as a Physical Volume (PV) in LVM:

# sudo pvcreate /dev/sdb1

Add the PV to the Virtual Group (VG) called 'build' (yours will be another name, probably the hostname of the server):

# vgextend build /dev/sdb1

Extend the Logical Volume (LV) which is available at '/dev/build/root' and is mounted on '/':

# lvextend -L+99G /dev/build/root

Resize the filesystem to use all available space:

# resize2fs /dev/build/root

All the above operations was done while the server was running, i.e. no downtime. I did however reboot to make sure that the server found the new disk, but I'm not sure that was necessary. Anyway the downtime was very short, and there was no need to move or copy files to the new disk.

I other words: LVM FTW.

Finally, you can see the LVM configuration by calling pvdisplay, vgdisplay and lvdisplay.
Tags: lvm, ubuntu
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded