2

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
  • A note about terminology: In your case, /home (and / and swap) are not partitions; they're logical volumes. Given the other information you presented, it's clear what you meant, but in another context it might not have been, and you might have gotten an incorrect answer as a result of using the terms incorrectly. – Rod Smith Apr 20 '15 at 00:26

1 Answers1

3

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.

muru
  • 197,895
  • 55
  • 485
  • 740
  • 1
    It's also possible to do the LVM management (steps 2, 3, and 4) with a GUI, such as system-config-lvm. Note that it is possible to expand the size of an ext2/3/4 filesystem even if it's mounted, so it's actually not necessary to umount it first. (Backing up first is always advisable when doing low-level disk maintenance, though.) – Rod Smith Apr 20 '15 at 00:24
  • 1
    @RodSmith lvextend runs an fsck, which is why I recommended unmounting. I suppose skipping -r and using resize2fs might be better. – muru Apr 20 '15 at 00:26
  • What I actually did was to move all data off of /home after switching to a user with a home directory that wasn't in /home, and then I removed the logical and physical volume using lvm gui. Then I used fcdisk to remove/recreate partition. I recreated physical and logical partition using lvm again. – user447607 Apr 20 '15 at 00:57
  • Question: Did I miss a trick? I note that I don't have a phase where I create a file system but I think that was done by one of the UI's. How can I verify? – user447607 Apr 20 '15 at 00:59
  • @user447607 try sudo parted -l, or use the Disks program. Though, I do think you missed a bunch of tricks when you recreated the lvm volumes instead of extending them, sort of defeating the purpose of lvm there. – muru Apr 20 '15 at 01:01
  • @muro Well, I didn't like the idea of having two underlying partitions on the same drive if I was just going to chop them up anyway. Thought it might be problematic later on. – user447607 Apr 21 '15 at 22:28