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/vdb
Note: 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):+256M
Change 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): w
The 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 created
Create the Volume Group
Use vgcreate to create a new VG named shazam built
from the two PVs.
[root@serverX ~]#vgcreate shazam /dev/vdb1 /dev/vdb2Volume group "shazam" successfully created
Create the Logical Volume
Use lvcreate to create a 400MiB LV named storage from
the shazam VG.
[root@serverX ~]#lvcreate -n storage -L 400M shazamLogical volume "storage" created
This 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 xfs file system on the
storage LV; 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 /storage
Use vim to add the following line to the bottom of
/etc/fstab on serverX:
/dev/shazam/storage /storage xfs defaults 1 2
Use mount to verify the /etc/fstab entry
and mount the new storage LV device.
[root@serverX ~]#mount -a
Test and Review Your Work
As a final test, copy some files onto /storage and verify
how many were copied.
[root@serverX ~]#cp -a /etc/*.conf /storage[root@serverX ~]#ls /storage | wc -l47
We will check that we still have the same number of files in the next practice exercise.
fdisk -l /dev/vdb will show you the
partitions that exist on /dev/vdb.
[root@serverX ~]#fdisk -l /dev/vdb
Check the /dev/vdb1 and
/dev/vdb2 entries, and notice the
Id and System
columns showing 8e and Linux
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-hvXMcM
This 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 vgname will show you
information about the volume group named vgname.
[root@serverX ~]#vgdisplay shazam
Check the following values:
VG Size is 504.00MiB.
Total PE is
126.
Alloc PE / Size is 100 /
400.00MiB.
Free PE / Size is 26 / 104.00MiB.
lvdisplay /dev/vgname/lvname will
show you information about the logical volume named lvname.
[root@serverX ~]#lvdisplay /dev/shazam/storage
Notice the LV Path, LV
Name, VG Name, LV
Status, LV Size, and
Current 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.
Reminder: Many tools will report the device
mapper name instead, /dev/mapper/shazam-storage; it is the same
logical volume.
[root@serverX ~]#mount
You should see (probably on the last line)
/dev/mapper/shazam-storage mounted on
/storage and 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% /storage
Allowing for file system metadata, these values are what we would expect.