Red Hat RHCE Examination Morning-RHCSA (RH134)
serverb.example.com task
5.Create Logical Volume
- Create a new logical volume as follows:
Task Requirements
- Logical volume name database, volume group is datastorage, size is 60 PE size s
- The PESIZE of datastore is 16MiB
- Format into an ext4 file system. Automatically mount to/mnt/data at system startup
Complete steps
- Create a partition on an empty disk first
- If one PE is 16M, 60 PE is 960M and the smallest partition size is greater than 950M
- If one extension is fast 20M, 45 extensions require a partition size greater than 900M
- Use -s to specify the size of PE 16M when creating volume group vg. Note that the name of the volume group is datastorage
- When creating the logical volume lv, specify 60 PE s with a small l, note that the name of the logical volume is database
lsblk parted /dev/vdb (parted) print (parted) mkpart primary 1305M 3000M (parted) quit #Pared can also be replaced with the fdisk command to create partitions
fdisk /dev/vdb # Find which empty disk to partition first pvcreate /dev/vdb2 # Create a PV for the specified partition first vgcreate -s 16M datastorage /dev/vdb2 # Creating a vg of a specified size lvcreate -l 60 -n database datastorage # Creates a logical volume that is injured and sized in a specified volume group mkfs.ext4 /dev/datastorage/database # Create a file system and format it mkdir /mnt/data #Create mount directory vim /etc/fstab # Configure boot-up automount /dev/datastorage/database /mnt/data ext4 defaults 0 0 mount -a # View hangings df -h # View partitions
pvdisplay vgdisplay lvdisplay
- That's it, restart it now to see if all of the things ahead are finished, and if it's a good name, do it again.
Inspection Points of Knowledge
Logical Volume Manager (LVM)
- LVM: Logical Volume Manager allows easy-to-operate abstraction layers for volumes.
- Includes resizing the file system, allowing the reorganization of the file system among multiple physical devices, and the LVM can resiliently change the capacity of the LVM
The Principle and Process of LVM Logical Volume Implementation
- Specify a storage block device as a physical volume, and organize one or more underlying block devices into a logical device PV physical volume
- Create a volume group VG from one or more physical volumes defined by a fixed size physical area (PE)
- Logical Volume LVS created on a physical volume is composed of a physical area (PE)
- Create a file system on a logical volume and mount it
Logical Volume Management Tool
- Related tools come from the lvm2 package
[root@centos8 ~]#yum -y install lvm2
- Show Create Delete pv Physical Volume
pvs #Brief pv information display pvdisplay #Real-world pv details pvcreate /dev/DEVICE pvremove /dev/DEVICE
- Show Create Management vg Volume Group
vgs vgdisplay vgcreate -s 16M vg0 /dev/sdb /dev/sdc #Specify PE size, default 4M vgextend <Existing Volume Group Name> <Physical Volume> [There can be multiple]# Dynamically expands an LVM volume group by adding physical volumes to the volume group to increase its capacity. vgreduce <Existing Volume Group Name> <Physical Volume> [There can be multiple]# Reduce volume group capacity by deleting physical volumes in the LVM volume group. You cannot delete the last remaining physical volume in the LVM volume group.
- Show Create Managed lv Logical Volume
- Large L specifies the specific value, and small l specifies the proportion
lvs Lvdisplay lvcreate -L #[mMgGtT] -n NAME VolumeGroup lvcreate -L 200m -n rhel rhcsa lvcreate -l 60 -n yourHermes testvg lvcreate -l 60%VG -n mylv testvg lvcreate -l 100%FREE -n yourlv testvg lvremove /dev/VG_NAME/LV_NAME
Create LVM Example
#Create physical volume pvcreate /dev/sda3 pvcreate /dev/sdac6 #Assign physical volumes to volume groups vgcreate vg0 /dev/sda3 /dev/sdac6 #Creating logical volumes from volume groups lvcreate -L 256M -n data vg0 #mkfs.xfs /dev/vg0/data #mount mount /dev/vg0/data /mnt/data
Online Extended Logical Volume
-
Expanding logical volumes in one step with the -r parameter does not require a two-step expansion
-
One-step expansion of cubicles and file systems
lvresize -r -l +100%FREE /dev/VG_NAME/LV_NAME -
Two-step implementation
#The first step is to achieve spatial expansion of the logical volume lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME #Step 2 Extension of File System #For ext resize2fs /dev/VG_NAME/LV_NAME #For xfs xfs_growfs MOUNTPOINT
Reduce Logical Volume
- Note: Reduction is at risk of data corruption. It is recommended that you back up and then reduce. Reduction is not supported by the xfs file system
umount /dev/VG_NAME/LV_NAME e2fsck -f /dev/VG_NAME/LV_NAME resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT] lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME mount /dev/VG_NAME/LV_NAME mountpoint