Standard partitions require all data to be contiguous. This causes some problems when you want to resize a partition in the middle of a drive. Logical volume management gives us the power to get around such problems. In this video you add a partition to a volume group and then create a logical volume from it.
- [Instructor] There are limitations to standard partitions. They have to be contiguous on the disk. If you want to resize a partition in the middle of a disk, you're out of luck. Logical volume management provides tools to avoid this situation. If there's room in a volume group, you can resize a 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 another drive to it on the fly, and then the logical volume can be expanded across both drives. To create a LVM system, we need to add a partition or drive to an LVM volume group, and then divide that volume group into logical volumes.
We'll use the partition we created in the last video for this. To prepare it for LVM use, we need to make it a physical volume. In the terminal, type in sudo, space, pvcreate, space, /dev/vdb1 and hit enter. Type in your password if prompted, and hit Enter again. We can verify this with PVS, or Physical Volume Summary. Type in sudo, space, pvs, and hit Enter. We see that we have a physical volume of 500 megs. If you want more information about your PV, type in sudo, space, pvdisplay, and hit enter.
Note that we reference physical volumes by their absolute path to the partition, /dev/vdb1. Now that our partition is a PV, let's create a volume group and include it. We'll use VG Create for this. Type in clear, then type in sudo, space, vgcreate, space, RHCSA, that's the name of the volume group we're creating, and then we're going to include the PV. Type in /dev/vdb1, and hit enter.
If you wanted to include more than one PV, you would just SCParate them by spaces. This'll create a volume group called RHCSA and include the /dev/vdb1 physical volume. Verify with VGS. Type in sudo, space, vgs, and hit enter. Now we see that we have a volume group called RHCSA, and it's 496 megs in size. For more information, type in vgdisplay. Type in sudo, space, vgdisplay, and hit enter. Note that when we reference volume groups, we just use the name without a path.
Now that we have a volume group, let's create a logical volume in it. We'll use LV Create for this. Type in clear, and then type in sudo, space, lvcreate, space, --name, space, and the name of our logical volume. Let's call it lvdata, and then space, --size, space, 495, capital M for 495 megabytes, space, and the last item is the name of the volume group you're going to create it in, RHCSA, and hit enter.
We can verify again with LVS. Type in sudo, space, LVS, and hit enter. Now we see in our RHSCA volume group we have a logical volume called lvdata at 496 megs in size. For more information, type in lvdisplay. Type in sudo, lvdisplay, and hit enter. Notice when we reference logical volumes, we use a /dev/ volume group name, slash logical volume name. It's not the only way we reference them, though. We have two different ways.
/dev/VolumeGroupName/LogicalVolumeName, and /dev/mapper/VolumeGroupName-LogicalVolumeName. Both of these paths work fine. So now we'll need to format the logical volume with a file system. We have two commands for this. The very simple mkfs, and the more powerful mke2fs. The latter has more options for choosing journal types and optimizations. The historic Linux file system is ext2, which supports permissions and ownership, but is not journalized.
If the system crashes, the operating system doesn't know what it was doing last, because it wasn't writing in a journal. When the system boots back up, it will have to do a file system check to find corrupt files. Ext3 is ext2 but with a different journal. You should consider the lowest common file system to use. There's no reason going older than ext3. The newest in the series is ext4, which supports much larger drives than 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 3 drives can be migrated to ext4. The new default in Enterprise Linux 7 is XFS, a file system created by Silicon Graphics for its version of Unix. It supports much larger drives than even ext4, and larger maximum file sizes. It supports snapshots as well. Btfrs, or Butter File System is the most capable, but not everyone is convinced it's ready for prime time. It's not as fast as the others, nor is it as mature.
However, it has some amazing features that largely replace the Linux RAID subsystem, LVM, and file systems all in one. It's available as a technology preview. Let's format our logical volume as XFS. Type in clear, and then type in sudo, space, mkfs, space, -t for type, space, xfs, space, /dev/ our volume group name, which is RHCSA, slash, then our logical volume name, which is lvdata, and then hit enter.
Now, verify this with a block ID command. Type in sudo, space, blkid, and hit enter. We can see our logical volume is in the last line, and it's formatted with XFS file system. The last steps are to create a mount point, and mount it. Type in clear again, type in sudo, space, mkdir, space, /media/lvdata. You can really create the mount point anywhere you like. Hit enter, now type in sudo, space, mount, space, the device path, which is /dev/RHCSA/lvdata, space, and then the mount point we just created, /media/lvdata, and hit enter.
We can verify this with a df command. Type in df, space, dash capital T, and hit enter. We can see it's mounted and it's formatted through with XFS. If you want to list the file system options it was mounted with, use the mount command without any arguments. Type in clear, and then type in mount, and hit enter. The very bottom line is the logical volume with the mount options. This mount won't survive a reboot, though, without adding it to the /etc/fstab, or file system table. We need to edit this file, and add a line for our new logical volume.
Type in clear, and then type in sudo, space, vi, space, /etc/fstab, file system table, and hit Enter. We'll go to insert mode and add a line. For the device path, it's going to be /dev/RHCSA/lvdata. For the mount point, we'll put it at /media/lvdata. For the file system, we'll put in xfs, and then for file system options, defaults.
The last two options are for backup and restore, and scanning the file system on boot up, and we'll put zeroes for both of those to turn it off. Now press escape, colon, x, exclamation point to save and exit. The last thing we need to do is test the line in the etc/fstab. We want to unmount /media/lvdata first. Type in sudo, space, umount, space, /media/lvdata and hit enter. And then we'll test the fstab with mount-a. Type in sudo, space, mount, space, -a, and hit enter.
This reads the fstab and attempts to mount anything not mounted. If this works without error, you're free to reboot. Your new LV should mount up automatically when the system comes up. If you have access to the exercise files, browse the cheat sheets and view the cheatsheet-lvm.pdf. This covers about 90% of what you'll ever need with LVM. The cheatsheet-lvm-advanced covers the rest.
Instructor Grant McWilliams covers network and internet services administration, kernel management, and intrusion prevention. He shows how to make your systems more efficient with virtualization, manage users and groups, and lock everything down with SELinux mandatory access control. Plus, get access to 25 PDF "cheat sheets" and 100 practice questions so you can solidify and test your knowledge.
- Installing Linux on a physical machine
- Managing systemd services
- Managing reoccurring jobs with cron
- Limiting system access
- Configuring networking
- Creating, editing, and moving files and directories
- Analyzing text with grep and regular expressions
- Installing software and packages
- Managing the kernel
- Managing users, accounts, and groups
- Setting permissions
- Using access control lists
- Securing Linux with SELinux
- Accessing Linux remotely
- Configuring local storage