In the previous article, we had an introduction to LVM. We have gone through the procedure to create a large file system from two smaller disks using LVM. We have stopped after creating and verifying a volume group that contains two disks of sizes 4 GB and 6 GB. So, let’s complete what we have started.
Creating Logical Volume
5. Create an 8 GB logical volume using the lvcreate command.
lvcreate –n LVNAME –l NUMBER_of_LOGICAL_EXTENTS VGNAME
lvcreate –n LVNAME –L LVSIZE [bBsSkKmMgGtTpPeE] VGNAME
The following command will create a logical volume with 8 GB size in the vgdata volume group.
lvcreate -n lv_sales_data -L 8G vgdata
To review and verify the result of the previous command, we can use either lvs or lvdisplay.
6. On top of the lv_sales_data logical volume, the required file system is built. The same commands we used with basic partitions also apply here: the mkfs command, and its derivatives.
7. Create the directory that will be used as mount point.
8. Edit the /etc/fstab file, and add a line for /sales_data. This is to ensure that the file system will be mounted automatically after reboots.
/dev/vgdata/lv_sales_data /sales_data ext4 defaults 0 0
Or using the UUID:
UUID=66902b61-d4c1-4b85-b626-49eeac4a15d3 /sales_data ext4 defaults 0 0
Where the UUID is the universally unique identifier. To obtain the UUID for a block device (like a hard disk, or logical volume), use the blkid command:
Copy the UUID part of the output into your /etc/fstab file as above.
In either cases, save and exit the file.
9. To mount /sales_data, use one of the following commands:
10. Now, check the mounted file systems using either the mount command or df command:
That was the full procedure, starting from physical disks, until building and mounting the file system using the LVM, using the CLI commands. Now, we are going to investigate the other method: the GUI tool.
Implementing LVM using GUI Method
If the GUI tool wasn’t installed on your Linux box, you can easily install it using the command:
yum install -y system-config-lvm
Now, start the GUI tool using the command system-config-lvm from your terminal:
The application window is divided into three panes:
The left pane: displays the existing volume groups, and any disk devices not yet initialized as physical volume.
The middle pane: displays graphical views for the physical and logical structures of volume groups.
The right pane: displays detailed info on the object/part selected on the left or middle panes.
You can easily notice the existence of three un-initialized disks:
- /dev/sda: this is the first SCSI, SATA disk in the system. In our case, it contains two partitions: /dev/sda1 that is used for /boot, and /dev/sda2 that is used as physical volume for the volume group vg_rhel67srv created by the Red Hat installation wizard.
If you select this disk from the left pane, you will get its graphical view on the middle, and some info including the size on the right.
Select it to see it is the 6 GB size disk we used in our previous procedure.
/boot is always mounted on /dev/sda1 which is created as a basic partition.
As we did with CLI commands, we are going to implement the same previous requirements using the GUI tool this time. Here is the procedure:
- Select /dev/sdb from the left pane, and click Initialize Entity button in the bottom of the middle pane.
- You get a confirmation message box that tells you that everything on this disk will be lost, and whether you are sure you want to continue. Click Yes.
- Now, the view looks like the following:
We have the option to create a new volume group using this new physical volume, add it to an existing volume group, or un-initialize it.
- Click Create new Volume Group.
- Type the volume group name, and click OK.
The new volume group appears on the left pane, and its physical and logical views appear on the middle pane.
- repeat the procedure for /dev/sdc
- Click Add to existing Volume Group.
- Select the vgdata volume group and click Add.
Now, vgdata contains two physical volumes /dev/sdb and /dev/sdc with total space of ten gigabytes.
- Click Logical View
- From the middle pane, click Create New Logical Volume.
- Fill in the “Create New Logical Volume” dialog.
- In the LV name, type: lv_sales_data.
- In the LV size, type: 8 Gigabytes
- Under the Filesystem section, select Ext4 from the dropdown list.
- Select the Mount checkbox.
- Select the Mount when rebooted checkbox.
- In the Mount point textbox, type /sales_data.
When finished, click OK.
- The tool creates the file system, creates /sales_data directory, mounts the file system, and creates the /etc/fstab entry for you.
That was the procedure, simply.
- The lvcreate command creates a logical volume in a volume group.
- The commands lvs and lvdisplay display information about existing logical volumes.
- The system-config-lvm command starts the GUI tool that manages LVM tasks.
In the next article, we are going to continue our journey with LVM. See you there.