Saturday, January 30, 2016

partitioning - How to grow LVM partition to include newly released partition (now unallocated space)


I had a Windows partition and I nuked it in favor of a VirtualBox VM. Now I could use the extra space it was occupying. LVM2 is in use on the Linux side but the Windows partition which has since been removed pre-dates the LVM setup. The space in question is to be added to the /home partition. I've created an admin user who has a home dir that is not in /home so that I can log in as him and get this done. Procedure? Do I need to mess with the volume group? Do I need to use fdisk first or can I use a pv* command? This situation seems more complicated than gparted or lvm (the GUI tool) can manage.


Additional info:


dude@machine:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
home ubuntu-vg -wi-ao--- 214.87g
root ubuntu-vg -wi-ao--- 191.39g
swap_1 ubuntu-vg -wi-a---- 31.94g
dude@machine:~$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 500.1 GB, 500106780160 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976771055 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xca18e148
Note: Below sdb3 is physical and sdb5 logical but it's the same space.
Device Boot Start End Blocks Id System
/dev/sdb3 526147582 976769023 225310721 5 Extended
/dev/sdb5 526147584 976769023 225310720 8e Linux LVM
dude@machine:~$ df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/ubuntu--vg-root ext4 197401876 13355496 173995820 8% /
none tmpfs 4 0 4 0% /sys/fs/cgroup
udev devtmpfs 16428232 4 16428228 1% /dev
tmpfs tmpfs 3288660 1580 3287080 1% /run
none tmpfs 5120 0 5120 0% /run/lock
none tmpfs 16443284 19692 16423592 1% /run/shm
none tmpfs 102400 44 102356 1% /run/user
/dev/sda1 ext2 240972 51593 176938 23% /boot
/dev/mapper/ubuntu--vg-home ext4 221638340 24327232 186029496 12% /home
/home/dude/.Private ecryptfs 221638340 24327232 186029496 12% /home/dude


You need to:



  1. Use fdisk/parted/etc. to create a partition in the currently empty space

  2. Use pvcreate to create a physical volume on the new partition.

  3. Use vgextend to add the new physical volume to you current volume group, or vgcreate create a new volume group

  4. Use lvextend to extend the logical volume of /home (with -r, so that the filesystem gets extended too). You'll want to unmount the partition before doing this.


You can do both 1 and 2 in a single step using GParted (right click free space, format as lvm2 pv). The third and fourth step needs to be run using the respective commands.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...