LVM build case

It should be noted that the /boot partition cannot be created based on LVM and must be independent.

Create an lvm case:
1. View the system type:
uname -r:
Insert picture description here
cat /etc/centos-release
Insert picture description here

2. View the partition capacity
df -Th
Insert picture description here

3. Use fdisk to partition and convert the partition type to 8e lvm type
fdisk /dev/sdb
pnp 1 2048 +1G p
pnp 2 4096 +2G p
w

4. Create pv

[root@test-2 ~]# pvcreate /dev/sdb1
Physical volume “/dev/sdb1” successfully created.
[root@test-2 ~]# pvcreate /dev/sdb2
Physical volume “/dev/sdb2” successfully created.
[root@test-2 ~]#
Insert picture description here

5.创建vg
[root@test-2 ~]# vgcreate database /dev/sdb1 /dev/sdb2
Volume group “database” successfully created
[root@test-2 ~]#
[root@test-2 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
cl 1 2 0 wz–n- 49.00g 4.00m
database 2 0 0 wz–n- 2.99g 2.99g
[root@test-2 ~]#
[root@test-2 ~]# pvdisplay
— Physical volume —
PV Name /dev/sdb1
VG Name database
PV Size 1.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 255
Free PE 255
Allocated PE 0
PV UUID uxRYlC-MbvM-sRKJ-3Urx-Jrey-3opk-UofDdV

— Physical volume —
PV Name /dev/sdb2
VG Name database
PV Size 2.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 511
Free PE 511
Allocated PE 0
PV UUID nYzjRo-Wbjp-3eQo-iLRV-HgZU-9LAE-2wAt7y

— Physical volume —
PV Name /dev/sda2
VG Name cl
PV Size 49.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12543
Free PE 1
Allocated PE 12542
PV UUID aakJHq-OHN0-Fnnk-kNhd-UG82-qD8W-7drZmq

[root@test-2 ~]#

6.创建lv
[root@test-2 ~]# lvcreate -L 500M -n lvdata1 database
Logical volume “lvdata1” created.
[root@test-2 ~]#

7. Format the partition:
[root@test-2 ~]# mkfs.ext4 /dev/database/lvdata1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: Complete
File system label =
OS type: Linux
block size =1024 (log=0)
Block size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: completed
Writing to inode table: completed
Creating journal (8192 blocks): completed
Writing superblocks and filesystem accounting information: completed

[root@test-2 ~]#

8. Mount the mirror:
mkdir /data
mount //dev/database/lvdata1 /data
compile /etc/fatab

mount -a

The logical volume lvdata1 is not enough, how to expand.
[root@test-2 ~]# lvcreate -L +500M /dev/database
Logical volume “lvol0” created.
[root@test-2 ~]#
[root@test-2 ~]#
[root@test-2 ~ ]# resize2fs /dev/database/lvdata1 //Synchronize file system

扩大卷组:
[root@test-2 ~]# vgextend database /dev/sdb5
Physical volume “/dev/sdb5” successfully created.
Volume group “database” successfully extended

When the hard disk space is not enough, if the space of the logical volume is reduced, it is released to other logical volumes.
To reduce the space of the logical volume, the steps are as follows:
1. Unmount the logical volume data1
2. Then use the e2fsck command to check the free space on the logical volume.
3. Use resize2fs to reduce the file system to 700M.
4. Use the lvreduce command to reduce the logical volume to 700M.
Note: The size of the file system and the logical volume must be the same. If the logical volume is larger than the file system, the space will be wasted because some areas are not formatted into the file system. If the logical volume is smaller than the file system, there is a problem with the data.

[root@test-2 ~]# umount /data
[root@test-2 ~]# e2fsck -f /dev/database/lv
lvdata1 lvol0
[root@test-2 ~]# e2fsck -f /dev/database/lv
lvol0 lvdata1
[the root @ ~ Test-2] # the e2fsck -f / dev / Database / lvdata1
the e2fsck 1.42.9 (-on Dec-28, 2013)
Step 1: Make the inode, block size and
the second step: check the directory structure
of Step 3: Check directory connectivity
Pass 4: Checking reference counts
Step 5: Check cluster summary information
/dev/database/lvdata1: 11/128016 files (0.0% non-contiguous), 26684/512000 blocks
[root@test-2 ~]# resize2fs /dev/database/lvdata1 700M
resize2fs 1.42.9 (28-Dec-2013)
The containing partition (or device) is only 512000 (1k) blocks.
You requested a new size of 716800 blocks.

[root@test-2 ~]# lvreduce -L 700M /dev/database/lvdata1
New size given (175 extents) not less than existing size (125 extents)
[root@test-2 ~]# mount /dev/database/lvdata1 /data
[root@test-2 ~]# ls /data
lost+found
[root@test-2 ~]#

If a disk or partition fails, how to quickly transfer data to other spaces in the same volume group.
1. Use the pvmove command to transfer space data.
2. Use the vgreduce command to remove the disk or partition that is about to fail from the volume group vgdata.
3. Use the pvremove command to delete the disk or partition that is about to be broken from the system.
4. Manually remove the hard disk or repair the partition with some tools.

6. Delete the entire logical volume
1. Unmount the logical volume lvdata1 through the umount command first.
2. Modify the mount information of the logical volume in /etc/fstab, otherwise the system may not start.
3. Use lvremove to delete the logical volume lvdata1.
4. Use vgremove to delete the volume group vgdata.
5. Use pvremove to convert the physical volume into a normal partition.

LVM logical volume is a great space usage mechanism in Linux, because there is no way to increase or decrease the size of the partition without formatting. Through LVM you can make your disk space flexible.

Guess you like

Origin blog.csdn.net/smileui/article/details/96860539
LVM