Viewing Disk Information
fdisk -l
Copy the code
Formatting disk Partitions
mkfs.ext4 /dev/sdxxx
Copy the code
Creating a Disk Partition
fdisk /dev/sdxxx
Copy the code
step1
Command (m for help): n Type n to add a new partition
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p Select p to create a primary partition
Copy the code
step2
Partition number (2-4, default 2): # press Enter
Copy the code
step3
First sector (14682112-15109515, default 14682112): # press Enter
Using default value 14682112
Copy the code
step4
Last sector, +sectors or +size{K,M,G} (14682112-15109515, default 15109515): +1G Enter the size of the partition to create
Partition 2 of type Linux and of size 1G is set
Copy the code
step5
Command (m for help): t Enter t to change the system ID of the partition
Partition number (1,2, default 2): # enter
Hex code (type L to list all codes): 8e Enter 8e to change the partition type to Linux LVM
Changed type of partition 'Linux' to 'Linux LVM'
Copy the code
step6
Command (m for help): w Type w to write the table to disk and exit
The partition table has been altered!
Copy the code
Create LVM
1. Initialize the physical disk as a physical volume
pvcreate /dev/sdxxx /dev/sdxxx2 # you can specify more than one
Copy the code
2. Create a volume group and add the PV to the volume group
vgcreate mygroup /dev/sdxxx dev/sdxx2 You can specify more than one at a time
Copy the code
3. Create a logical volume based on the volume group
lvcreate -n mylv -L 8G mygroup
Copy the code
4. Create a file system for the logical volume
mkfs.ext4 /dev/mygroup/mylv
Copy the code
5. Mount the formatted logical volume
mount /dev/mygroup/mylv /disk1
Copy the code
Look at the LVM
View physical volume information
pvdisplay
pvs
Copy the code
View information about volume groups
vgdisplay
vgs
Copy the code
Viewing logical Volumes
lvdisplay
lvs
Copy the code
Logical Volume Expansion
lvextend -L +20G /dev/mygroup/mylv
Copy the code
lvscan
Copy the code
At this time, df -h finds that the disk size does not change and needs to use resize2fs to manually synchronize the file system
resize2fs /dev/mygroup/mylv
Copy the code
Delete the LVM
1. Remove the LVM
lvremove /dev/mygroup/mylv
Copy the code
2. Delete the vg
vgremove mygroup
Copy the code
3. Delete the physical volume
pvremove /dev/sdxxx
Copy the code