RHCSA Rapid Track
In this lab, you will add a physical volume, volume group, logical volume, and an XFS file system. You will persistently mount the logical volume file system.
| Resources: | |
|---|---|
| Machines: | serverX |
Outcomes
A 400MiB logical volume called storage in the volume group
shazam, mounted at /storage. The volume group consists
of two physical volumes, each 256MiB in size.
Reset your serverX system.
Log into serverX.
Open a terminal.
Switch to root (sudo -i).
Create the Physical Resources
Use fdisk to create two partitions of 256MiB apiece and set them to type Linux LVM.
[root@serverX ~]#fdisk /dev/vdbNote: The following steps omit some output.
Add a new primary partition of 256MiB.
Command (m for help):
nPartition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p):EnterUsing default response p Partition number (1-4, default 1):EnterFirst sector (2048-20971519, default 2048):EnterUsing default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):+256MChange the partition type to Linux LVM - 0x8e.
Command (m for help):
tSelected partition 1 Hex code (type L to list all codes):8eChanged type of partition 'Linux' to 'Linux LVM'Repeat the previous two steps to add a second primary partition of the same size in the next available partition space.
Write the changes to the partition table and quit.
Command (m for help):
wThe partition table has been altered!Use partprobe to register the new partitions with the kernel.
[root@serverX ~]#partprobe
Create the Physical Volumes
Use pvcreate to add the two new partitions as PVs.
[root@serverX ~]#pvcreate /dev/vdb1 /dev/vdb2Physical volume "/dev/vdb1" successfully created Physical volume "/dev/vdb2" successfully createdCreate the Volume Group
Use vgcreate to create a new VG named
shazambuilt from the two PVs.[root@serverX ~]#vgcreate shazam /dev/vdb1 /dev/vdb2Volume group "shazam" successfully createdCreate the Logical Volume
Use lvcreate to create a 400MiB LV named
storagefrom theshazamVG.[root@serverX ~]#lvcreate -n storage -L 400M shazamLogical volume "storage" createdThis will create a device called
/dev/shazam/storage, currently without a file system on it.Add a Persistent File System
Use mkfs to place an
xfsfile system on thestorageLV; use the LV device name.[root@serverX ~]#mkfs -t xfs /dev/shazam/storagemeta-data=/dev/shazam/storage isize=256 agcount=4, agsize=25600 blks ...Use mkdir to create a mount point at
/storage.[root@serverX ~]#mkdir /storageUse vim to add the following line to the bottom of
/etc/fstabon serverX:/dev/shazam/storage /storage xfs defaults 1 2
Use mount to verify the
/etc/fstabentry and mount the newstorageLV device.[root@serverX ~]#mount -a
Test and Review Your Work
As a final test, copy some files onto
/storageand verify how many were copied.[root@serverX ~]#cp -a /etc/*.conf /storage[root@serverX ~]#ls /storage | wc -l47We will check that we still have the same number of files in the next practice exercise.
fdisk -l /dev/
vdbwill show you the partitions that exist on/dev/vdb.[root@serverX ~]#fdisk -l /dev/vdbCheck the
/dev/vdb1and/dev/vdb2entries, and notice theIdandSystemcolumns showing8eandLinux LVM, respectively.pvdisplay will show you information about each of the physical volumes. Optionally, include the device name to limit details to a specific PV.
[root@serverX ~]#pvdisplay /dev/vdb2--- Physical volume --- PV Name /dev/vdb2 VG Name shazam PV Size 256.00 MiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 63 Free PE 26 Allocated PE 37 PV UUID N64t6x-URdJ-fVU3-FQ67-zU6g-So7w-hvXMcMThis shows that our PV is allocated to VG shazam, is 256MiB in size (although 4MiB is not usable), and our physical extent size (
PE Size) is 4MiB (the smallest allocatable LV size).There are 63 PEs, of which 26 PEs are free for allocation to LVs in the future and 37 PEs are currently allocated to LVs. These translate to MiB values as follows:
Total 252MiB (63 PEs x 4MiB); remember, 4MiB are unusable.
Free 104MiB (26 PEs x 4MiB)
Allocated 148MiB (37 PEs x 4MiB)
vgdisplay
vgnamewill show you information about the volume group namedvgname.[root@serverX ~]#vgdisplay shazamCheck the following values:
VG Sizeis504.00MiB.Total PEis126.Alloc PE / Sizeis100 / 400.00MiB.Free PE / Sizeis26 / 104.00MiB.
lvdisplay /dev/
vgname/lvnamewill show you information about the logical volume namedlvname.[root@serverX ~]#lvdisplay /dev/shazam/storageNotice the
LV Path,LV Name,VG Name,LV Status,LV Size, andCurrent LE(logical extents, which map to physical extents).mount will show all the devices that are mounted and any mount options. It should include
/dev/shazam/storage.Note
Reminder: Many tools will report the device mapper name instead,
/dev/mapper/shazam-storage; it is the same logical volume.[root@serverX ~]#mountYou should see (probably on the last line)
/dev/mapper/shazam-storagemounted on/storageand the associated mount information.df -h will show human-readable disk free space. Optionally, include the mount point to limit details to that file system.
[root@serverX ~]#df -h /storageFilesystem Size Used Avail Use% Mounted on /dev/mapper/shazam-storage 397M 21M 377M 6% /storageAllowing for file system metadata, these values are what we would expect.