HPR3727: Expanding your filesystem with LVM




Hacker Public Radio show

Summary: Synopis I installed a new 1TB Crucial MX500 SSD into my work computer. While we are mostly a Windows based business, as the IT guy I do get a bit of discretion when updating my own machine (i.e. I get to solve all the problems I create). Last year, I decided to run the Pop!_OS distribution of Linux on my work computer and run Windows in a VM on it. Recently the Windows image had grown and was causing disk space notifications. This prompted the additional hard drive. During the initial installation of Pop!_OS, I remember deciding not to bother with installing Linux Volume Management (LVM). I have used it in the past, but I am still much more comfortable with the old style device mapping and mounting disk partitions to directories. I even rationalized that if I needed to add more space, I will just add a new disk with one big partition and map it to the home directory. Now a year later I am adding a new HD and thinking, I really hate all the space that is most likely going to be wasted once I move the Windows image to the new drive. Ok, I guess I should figure out how to install LVM, and use it to manage the space on both drives. Luckily there a number of good blogs to be found on adding LVM to an existing system. The following are the steps and commands I used to accomplish my goal. Commands Most of the following commands need to be run as root. I decided to change to root user instead of typing sudo before every command. The basic steps to creating a single filesystem sharing the storage space between two physical disk partitions are: Let LVM know about the new disk. In my case, create a volume group and add the new disk and its full storage space to it. Copy the disk partition with the root filesystem from the origin disk to the new volume group Expand the root filesystem on the volume group to the full size of the volume group. Update system configuration to boot with the root filesystem on the new volume group. Let LVM know about the old root disk partition. Add the old root partition to the volume group. Expand the root filesystem on the volume group to include the new space in the volume group. root@work# pvcreate /dev/sdb root@work# pvdisplay "/dev/sdb" is a new physical volume of "931.51 GiB" --- NEW Physical volume --- PV Name /dev/sdb VG Name PV Size 931.51 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID wRBz38-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx root@work# vgcreate workvg /dev/dsb No device found for /dev/dsb. root@work# vgcreate workvg /dev/sdb Volume group "workvg" successfully created root@work# vgdisplay --- Volume group --- VG Name workvg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 931.51 GiB PE Size 4.00 MiB Total PE 238467 Alloc PE / Size 0 / 0 Free PE / Size 238467 / 931.51 GiB VG UUID 67DSwP-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx root@work# pvdisplay --- Physical volume --- PV Name /dev/sdb VG Name workvg PV Size 931.51 GiB / not usable 1.71 MiB Allocatable yes PE Size 4.00 MiB Total PE 238467 Free PE 238467 Allocated PE 0 PV UUID wRBz38-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx root@work# lvcreate -n root -L 931.51 workvg Rounding up size to full physical extent 9