Online Capacity Expansion online
Data migration online
====================================================================================
Creating LVM LVM called the Logical Volume Manager
VG expand / shrink
LV dilatation
Online file system expansion and the expansion of 300G + 900G hard disk to do a single disk RAID0 in production
Primary partition (MBR | GPT) ----> Filesystem ----> mount
Logical LVM ----> Filesystem ----> mount
VG is called volume group
extents is called extended block
PE: Physical extent physical expansion 4M 8M 16M 32M 64M -s 8M specified when creating VG
LE: Logical extent logical extension
Sina practical work
Start the Linux operating system in VMware environments, adding a new partition, you need the root account status.
[3.1] The maximum partition fdisk -l / dev / sda3, explained the newly created partition will be sda4
3.2 input [fdisk / dev / sda]
[M] input command line prompt 3.2.1
3.2.2 Enter the command [n] to add a new partition.
3.2.3 Enter the command [p] create a primary partition.
3.2.4 Input [Enter], select the default size, so do not waste space
3.2.5 Input [Enter], select the default start cylinder.
W [3.2.6] input, holding modifications
3.3 Input [reboot] to restart linux, you must reboot, or / dev / sda4 can not be formatted.
3.4 At this point in the / dev / directory to see the new partition such as / dev / sda4
3.5 [mkfs.ext2 / dev / sda4] formatted
3.6 disk4 create a directory in the root directory
3.7 [mount / dev / sda4 / disk4 /] to mount the partition / disk4 /
3.8 modify the vim / etc / fstab file, add [/ dev / sda4 / disk4 ext2 defaults 0 0] line, and save, and boot automatically mount.
Note that with a snapshot of a virtual machine after adding a hard disk to install software
First, create LVM
- Prepare physical disk
It can be: / dev / sdb / dev / sdc1
[root@server0 ~]# ll /dev/vd{c,d,e}
brw-rw----. 1 root disk 253, 32 Jun 6 17:38 /dev/vdc
brw-rw----. 1 root disk 253, 48 Jun 6 17:38 /dev/vdd
brw-rw----. 1 root disk 253, 64 Jun 6 17:38 /dev/vde
- pv
[root@server0 ~]# pvcreate /dev/vdd
Physical volume "/dev/vdd" successfully created
[root@server0 ~]# pvscan
PV /dev/vdd lvm2 [2.00 GiB]
Total: 1 [2.00 GiB] / in use: 0 [0 ] / in no VG: 1 [2.00 GiB]
[root@server0 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdd lvm2 a-- 2.00g 2.00g
- vg
[root@server0 ~]# vgcreate vg1 /dev/vdd
Volume group "vg1" successfully created
[root@server0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 0 0 wz--n- 2.00g 2.00g
[root@server0 ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg1" using metadata type lvm2
[root@server0 ~]# vgdisplay vgdisplay datevg
--- Volume group ---
VG Name vg1
System ID
format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 2.00 GiB
PE Size 4.00 MiB
Total PE 511
Alloc PE / Size 0 / 0
Free PE / Size 511 / 2.00 GiB
VG UUID 7E4tlj-l0a2-ph52-OytH-eaq7-58K6-2S4n8V
- lv
[root@server0 ~]# lvcreate -l 10 -n lv1 vg1
[root@server0 ~]# lvcreate -L 200M -n lv2 vg1
[root@server0 ~]# lvscan
ACTIVE '/dev/vg1/lv1' [640.00 MiB] inherit
ACTIVE '/dev/vg1/lv2' [256.00 MiB] inherit
- Create a file system and mount
[root@server0 ~]# mkfs.xfs /dev/vg1/lv1
[root@server0 ~]# mkfs.ext4 /dev/vg1/lv2
[Root @ server0 ~] # mkdir / mnt / LV1 / mnt / LV2
[root@server0 ~]# vim /etc/fstab
/dev/vg1/lv1 /mnt/lv1 xfs defaults 0 0
/dev/vg1/lv2 /mnt/lv2 ext4 defaults 0 0
[root@server0 ~]# mount -a
[root@server0 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/ Dev / folders / vg1-lv1 651,948 32,928 619,020 6% / mnt / lv1
/dev/mapper/vg1-lv2 245671 2062 226406 1% /mnt/lv2
Two, VG management
VG vgextend == == expand
- pv
[root@server0 ~]# pvcreate /dev/vde
- vgextend
[root@server0 ~]# vgextend vg1 /dev/vde
Volume group "vg1" successfully extended
[root@server0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 2 0 wz--n- 3.99g 3.76g
VG vgreduce == == reduced
Usually do first migrating data
1. Review the current usage of PV in the VG
[root@server0 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdd vg1 lvm2 a-- 2.00g 1.76g
/dev/vde vg1 lvm2 a-- 2.00g 2.00g
- pvmove data to other PV
[root@server0 ~]# pvmove /dev/vdd
/dev/vdd: Moved: 16.7%
/dev/vdd: Moved: 100.0%
[root@server0 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdd vg1 lvm2 a-- 2.00g 2.00g
/dev/vde vg1 lvm2 a-- 2.00g 1.76g
3.vgreduce VG
[root@server0 ~]# vgreduce vg1 /dev/vdd
Removed "/dev/vdd" from volume group "vg1"
[root@server0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 2 0 wz--n- 2.00g 1.76g
Three, LV dilatation
- lv expansion
[root@server0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 2 0 wz--n- 1.88g 1.00g
[root@server0 ~]# lvextend -L 800M /dev/vg1/lv1
[root@server0 ~]# lvextend -L +800M /dev/vg1/lv1
[root@server0 ~]# lvextend -l 15 /dev/vg1/lv1
[root@server0 ~]# lvextend -l +15 /dev/vg1/lv1
=======================================
+50%FREE
=======================================
[root@server0 ~]# lvscan
ACTIVE '/dev/vg1/lv1' [768.00 MiB] inherit
ACTIVE '/dev/vg1/lv2' [512.00 MiB] inherit
- FS expansion
[root@server0 ~]# df -Th
/dev/mapper/vg1-lv1 xfs 637M 67M 570M 11% /mnt/lv1
/dev/mapper/vg1-lv2 ext4 240M 32M 192M 15% /mnt/lv2
a. xfs
[root@server0 ~]# xfs_growfs /dev/vg1/lv1
b. ext2/3/4
[root@server0 ~]# resize2fs /dev/vg1/lv2
[root@server0 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg1-lv1 xfs 765M 67M 698M 9% /mnt/lv1
/dev/mapper/vg1-lv2 ext4 488M 32M 429M 7% /mnt/lv2
1.创建pv
[root@localhost ~]# pvcreate /dev/sda5 /dev/sda6
[root@localhost ~]# pvdisplay
[root@localhost ~]# pvs
2.创建vg
[root@localhost ~]# vgcreate vg0 /dev/sda5 /dev/sda6
[root@localhost ~]# vgdisplay
[root@localhost ~]# vgs
3.创建lv
[root@localhost ~]# lvcreate -L 250M -n /dev/vg0/lv0 vg0
[root@localhost ~]# lvdisplay
[root@localhost ~]# lvs
注意:
pv不能跨越vg
lv不能跨越vg
系统中可以创建多个vg
vg中可以创建多个lv
删除lvm
1.umount /dev/vg0/lv0
2.[root@localhost ~]# lvremove /dev/vg0/lv0
3.[root@localhost ~]# vgremove vg0
4.[root@localhost ~]# pvremove /dev/sda{5,6,8}
企业中的应用 如果根分区满了 怎么做??
df -h 查看
pvcreate /dev/sdb
vgs
vgextend centos /dev/sdb
lvscan
lvextend -L +5G /dev/centos/root
df -T
xfs_growfs /dev/centos/root
df -Th
lvextend -L +5G /dev/centos/root
xfs_growfs /dev/centos/root
df -h
准备3块硬盘 可不分区 思路---PV----VG---LV
lsblk
##创建PV
pvcreate /dev/sdb
##查看当前PV
pvscan
pvs
vgcreate datavg /dev/sdb (datavg是起的名字)
vgscan
pvscan ##得到回显 pv/dev/sdb 加入到了VG datevg 容量XXfree
#创建LV
lvcreate -L 200M -n lv1 datavg -L(指定lv的大小) 指定为200m lv1为起的名字 从datevg里创建
lvcreate -L 300M -n lv2 datavg
lvscan ## 得到回显 /dev/datevg/lv1 200m
/dev/datevg/lv2 300m
这时候看lsblk 去看看/dev/sdb????
##格式化,创建文件系统挂载
mkfs.xfs /dev/datevg/lv1
mkfs.ext4 /dev/datevg/lv2
mkdir /mnt/lv1 /mnt/lv2
挂载
mount /dev/datevg/lv1 /mnt/lv1
mount /dev/datevg/lv2 /mnt/lv2
mount -a
df -h (df-Th) 加上TYPE 类型
LVM完成
#########################################################
扩大VG
vgs
pvcreate /dev/sdc 先变成PV
vgextend datevg /dev/sdc 查看pvscan
vgs free变大 实验成功
继续扩容
pvcreate /dev/sdd
vgextend datevg /dev/sdd
继续查看 VFree 继续变大
###############################################################
减小VG 数据迁移 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
pvs 查看
pvmove /dev/sdb /dev/sdc 将sdb数据仍到sdc
vgreduce datevg /dev/sdb
pvscan
查看变化。数据迁移完成
注意:
pv不能跨越vg
lv不能跨越vg
系统中可以创建多个vg
vg中可以创建多个lv