From the course: Linux System Engineer: Advanced Disk Systems and System Backup

Manage LVM volumes and volume groups

From the course: Linux System Engineer: Advanced Disk Systems and System Backup

Start my 1-month free trial

Manage LVM volumes and volume groups

- [Narrator] There are limitations to standard partitions. For instance, they have to be continuous on the disk. If you want to resize a partition in the middle of a disk, you're out of luck. There are tools such as G parted that can manage this through shear brilliance, but you should always back up your drives before attempting a resize. Logical volume management provides tools to avoid this situation by design. If there's room in a volume group, you can resize the logical volume, even if the empty space is somewhere else on the disk. If there is no room in the volume group, you can just add more drives to it on the fly. Then the logical volume can be expanded across all drives. To use a driver partition with LVM, we need to make it a physical volume or PV using the PV create command. Note that you should do this on empty, unmounted, partioner drive. Any data on the drive will be destroyed. Let's make sure that slash, dev, slash, sdb1 is not mounted. In a terminal type in, sudo, space, umount, space, slash, dev, slash, sdb1 and hit enter. Type in your password if prompted. In newer versions of LVM, devices will be automatically made into physical volumes when added to volume groups. For educational purposes and trouble shooting reasons, I like to do this step manually. Type in sudo, space, pvcreate, space, slash, dev, shash, sdb1, and hit enter. It may notice that there's a file system on it already. Press y to proceed. Now let's verify this by typing in sudo, space, pvs, and hit enter. Here we can see slash, dev, slash, sbd1. If you're using an entire raw device, such as, slash, dev, slash, sdb, and that drive is physically on a solid state disk, you will want to add additional arguments to align the data. Now, let's create a volume group, or a VG, including a new PV, we'll use VG create for this. Type in clear, and then type in sudo, space, vgcreate, space, the volume group name, which I'm going to call it, vgdata, space, and then the pvs you want to include. In our case, it's just slash, dev, slash, sdb1. If we had more than one, we could put a space and add it at the end. Hit enter, and we're going to verify this with, sudo, space, vgs, or vg summary. Now that we have a volume group, let's create a logical volume or LV in it. We'll use LV create for this, type in clear, and then type in sudo, space, lvcreate, space, dash, dash, name, space, lvdata, space, dash, dash, size, 500, capital M, for megabytes, space, vgdata, vgdata being the volume group, and hit enter. We'll verify this by typing in sudo, space, lvs. Here we can see our logical volume, in our volume group, and the size. There are two different paths that you can use to refer to the logical volumes, slash, dev, slash, volume group name, slash, logical volume name, or we can also use, slash, dev, slash, mapper, slash, volume group name, hyphen, logical volume name. Either work fine, but I prefer the former. You can even place hyphens in the name of a volume group, or a logical volume, however, LVM will insert two hyphens, one escapes the other. If the name was vg dash data, some tools will print out the path as, slash, dev, slash, mapper, slash, vg, hyphen, hyphen, data, hyphen, lvdata. It doesn't hurt anything, but it may be confusing. We'll need to format our logical volume with a file system, we have several choices for file systems. The historic Linux file system is ext2, which supports permissions in ownership but is not journalized. Ext3 is ext2 but with a journal. The newest in this series is ext4, which supports much larger drives than the ext3, about 32,000 times larger at one million terabytes. Ext4 is more robust than ext3 and supports solid-state drives as well. Ext4 is a good default file system for Linux. Ext2 and three drives should be migrated to ext4. However, the new default in Enterprise Linux 7 is XFS, a file system created by Silicone Graphics for it's version of UNIX. It supports much larger drives than even ext4, and larger maximum file sizes. It supports snap shots as well. Even though it's easy to resize an XFS file system larger, it's very very difficult to resize it smaller. The last one is Btrfs, or Butter File System. Butter File System is the most capable, but currently should be considered a technology preview. It's not as fast as the others, nor is it as mature. It, however, has some amazing features that largely replaced the Linux Rate Subsystem, LVM and file systems all in one. Now to get your LVM path to show up, we may on occasion have to active it using VG change. Type in sudo, space, vgchange, space, dash, ay, and hit enter. You don't always have to do this, but it doesn't hurt anything to do it. Let's format our logical volume as exd4. Type in clear, and then type in sudo, space, mkfs, space, dash, t, space, ext4, space, slash, dev, and the path would be, vgdata, slash, lvdata, so the whole pass would be, slash, dev, slash, vgdata, slash, lvdata, and hit enter. We can verify the file system with blkid. Type in sudo, space, blkid, and hit enter. And there we have it at the end. We have our logical volume and at the end it says type equals exd4. Now let's mount it on a new mount point. First let's create the mount point, using the mkdir. Type in clear, type in sudo, space, mkdir, spash, slash, media, slash, lvdata, and hit enter. And then we'll mount it with, sudo, space, mount, space, slash, dev, slash, vgdata, slash, lvdata, space, slash, media, slash, lvdata and hit enter. And we can verify this with df, type in df, space, dash, h. We'll see the size of it and that it's mounted. A quick lsblk will also show the physical volume and logical volume names as well as the mount point. Type in lsblk and hit enter.

Contents