LVM volume resizing jots

This post was written by eli on November 17, 2015
Posted Under: Linux,Software

These are my jots as I resized a partition containing an encrypted LVM physical volume, and then took advantage of that extra space by extending a logic volume containing an ext4 file system. The system is an Ubuntu 14.04.1 with a 3.13.0-35-generic kernel.

There are several HOWTOs on this, but somehow I struggled a bit before I got it working. Since I’ll do this again sometime in the future (there’s still some space left on the physical volume) I wrote it down. I mainly followed some of the answers to this question.

The overall setting:

$ ls -lR /dev/mapper
/dev/mapper:
total 0
crw------- 1 root root 10, 236 Nov 17 16:35 control
lrwxrwxrwx 1 root root       7 Nov 17 16:35 cryptdisk -> ../dm-0
lrwxrwxrwx 1 root root       7 Nov 17 16:35 vg_main-lv_home -> ../dm-3
lrwxrwxrwx 1 root root       7 Nov 17 16:35 vg_main-lv_root -> ../dm-2
lrwxrwxrwx 1 root root       7 Nov 17 16:35 vg_main-lv_swap -> ../dm-1

$ ls -lR /dev/vg_main/
/dev/vg_main/:
total 0
lrwxrwxrwx 1 root root 7 Nov 17 16:35 lv_home -> ../dm-3
lrwxrwxrwx 1 root root 7 Nov 17 16:35 lv_root -> ../dm-2
lrwxrwxrwx 1 root root 7 Nov 17 16:35 lv_swap -> ../dm-1

And the LVM players after the operation described below:

lvm> pvs
 PV                    VG      Fmt  Attr PSize   PFree 
 /dev/mapper/cryptdisk vg_main lvm2 a--  465.56g 121.56g
lvm> vgs
 VG      #PV #LV #SN Attr   VSize   VFree 
 vg_main   1   3   0 wz--n- 465.56g 121.56g
lvm> lvs
 LV      VG      Attr      LSize   Pool Origin Data%  Move Log Copy%  Convert
 lv_home vg_main -wi-ao--- 300.00g                                          
 lv_root vg_main -wi-ao---  40.00g                                          
 lv_swap vg_main -wi-ao---   4.00g

Invoke “lvm” in order to run LVM related commands (probably not really required)

Make LVM detect that I’ve resized the underlying partition (mapped as cryptdisk):

lvm> pvresize -t /dev/mapper/cryptdisk

Now to resizing the logical volume. Unfortunately, the Logical Volume Management GUI tool refused that, saying that the volume is not mounted, but in use (actually, I think it *was* mounted). So I went for the low-level way.

Under “Advanced Options” I went for a rescue boot, and chose a root shell.

Check the filesystem in question

fsck -f /dev/mapper/vg_main-lv_home

Back to the “lvm” shell. A little test, not the -t flag (making lv_home, under vg_main 200 GiB larger):

lvm> lvextend -t -L +200g /dev/vg_main/lv_home

It should write out the desired final size (e.g. 300 GiB)

Then for real:

lvm> lvextend -L +200g /dev/vg_main/lv_home

Oops, I got “Command failed with status code 5″. The reason was that the root filesystem was mount read-only. Fixing that I got “Logical volume successfully resized”.

But wait! There is no device file /dev/vg_main/lv_home

Now resize the ext4 filesystem

resize2fs /dev/mapper/vg_main-lv_home

And run a final check again:

fsck -f /dev/mapper/vg_main-lv_home

And rebooted the computer normally.

Add a Comment

required, use real name
required, will not be published
optional, your blog address

Previose Post: