标签:png rip The nal aos system 其他 系统 改变
内核模块dm可以实现以下功能
快照:保留数据当时状态,提供数据另外访问路径。如果访问快照里面的数据没改变,那么会使用原来路径,如果发生改变则访问快照数据。可以用来进行备份。
多路径:每条路径,操作系统会认为是一个实际存在的物理盘,但实际上只是通向同一个物理盘的不同路径而已
LVM2:
物理卷(PV):
物理盘区(PE):逻辑存储单位
逻辑卷组(VG):为LV提供统一接口容器。镜像功能:在不同物理卷中都存放一份相同数据
逻辑卷(LV):动态扩展缩减的文件系统
逻辑分区(LE):指定多个PE为一个LE
快照卷:为逻辑卷预留空间创建快照
LVM操作:
pv:pvcreate,pvremove,pvscan,pvdisplay,pvmove
vg:vgcreate,vgremove,vgextend,vgreduce,vgs,vgscan
lv:lvcreate,lvremove,lvextend,lvreduce,lvresize,lvs,lvdisplay
[root@localhost ~]# pvcreate /dev/sdd{1,2} Physical volume "/dev/sdd1" successfully created. Physical volume "/dev/sdd2" successfully created. [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- <93.82g 4.00m /dev/sdd1 lvm2 --- 1.41g 1.41g /dev/sdd2 lvm2 --- 599.00m 599.00m
详细信息查看pvdisplay
[root@localhost ~]# pvscan PV /dev/sda2 VG rhel lvm2 [<93.82 GiB / 4.00 MiB free] PV /dev/sde2 lvm2 [699.00 MiB] PV /dev/sdf1 lvm2 [600.00 MiB] PV /dev/sdd2 lvm2 [599.00 MiB] PV /dev/sdf2 lvm2 [1.41 GiB] PV /dev/sde1 lvm2 [<1.32 GiB] PV /dev/sdd1 lvm2 [1.41 GiB] Total: 7 [99.81 GiB] / in use: 1 [<93.82 GiB] / in no VG: 6 [<6.00 GiB]
|
vg操作:
vgcreate vgname path_to_pv -s指定pe大小默认4M
[root@localhost ~]# vgs -------------------查看vg VG #PV #LV #SN Attr VSize VFree rhel 1 2 0 wz--n- <93.82g 4.00m [root@localhost ~]# vgcreate yellow /dev/sd{d,e,f}{1,2} -------------------创建vg Volume group "yellow" successfully created [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree rhel 1 2 0 wz--n- <93.82g 4.00m yellow 6 0 0 wz--n- <5.98g <5.98g [root@localhost ~]# vgdisplay yellow --- Volume group --- VG Name yellow System ID Format lvm2 Metadata Areas 6 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 6 Act PV 6 VG Size <5.98 GiB PE Size 4.00 MiB Total PE 1530 Alloc PE / Size 0 / 0 Free PE / Size 1530 / <5.98 GiB VG UUID u5fZZK-BWLN-RtSt-kvL9-cyfr-oJUW-F0e52L
[root@localhost ~]# vgremove yellow --------------删除vg Volume group "yellow" successfully removed
从vg中删除pv:
[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- <93.82g 4.00m /dev/sdd1 yellow lvm2 a-- 1.41g 1.41g /dev/sdd2 yellow lvm2 a-- 596.00m 596.00m /dev/sde1 yellow lvm2 a-- 1.31g 1.31g /dev/sde2 yellow lvm2 a-- 696.00m 696.00m /dev/sdf1 yellow lvm2 a-- 596.00m 596.00m /dev/sdf2 yellow lvm2 a-- 1.41g 1.41g [root@localhost ~]# pvmove /dev/sdf2 -----------------先把pv数据移动到其他vg No data to move for yellow. [root@localhost ~]# vgreduce yellow /dev/sdf2 -----------------从vg中删除vg Removed "/dev/sdf2" from volume group "yellow" [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree rhel 1 2 0 wz--n- <93.82g 4.00m yellow 5 0 0 wz--n- <4.57g <4.57g [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- <93.82g 4.00m /dev/sdd1 yellow lvm2 a-- 1.41g 1.41g /dev/sdd2 yellow lvm2 a-- 596.00m 596.00m /dev/sde1 yellow lvm2 a-- 1.31g 1.31g /dev/sde2 yellow lvm2 a-- 696.00m 696.00m /dev/sdf1 yellow lvm2 a-- 596.00m 596.00m /dev/sdf2 lvm2 --- 1.41g 1.41g [root@localhost ~]# pvremove /dev/sdf2 --------------------删除pv Labels on physical volume "/dev/sdf2" successfully wiped. [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- <93.82g 4.00m /dev/sdd1 yellow lvm2 a-- 1.41g 1.41g /dev/sdd2 yellow lvm2 a-- 596.00m 596.00m /dev/sde1 yellow lvm2 a-- 1.31g 1.31g /dev/sde2 yellow lvm2 a-- 696.00m 696.00m /dev/sdf1 yellow lvm2 a-- 596.00m 596.00m
加入一个vg
[root@localhost ~]# pvcreate /dev/sdf2 Physical volume "/dev/sdf2" successfully created. [root@localhost ~]# vgextend yellow /dev/sdf2 Volume group "yellow" successfully extended [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree rhel 1 2 0 wz--n- <93.82g 4.00m yellow 6 0 0 wz--n- <5.98g <5.98g
|
lv操作:
创建lv:
lvcreate -n lv_name -L (大小KMG)[-l 多少个盘区] vg_name
[root@localhost ~]# lvcreate -L 80M -n testlv yellow Logical volume "testlv" created.
[root@localhost ~]# lvdisplay /dev/yellow/testlv --- Logical volume --- LV Path /dev/yellow/testlv LV Name testlv VG Name yellow LV UUID 1zCsL4-YEZt-Nh1P-RTAw-dH7R-LG7B-1cVx5D LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-05-30 23:47:15 +0800 LV Status available # open 0 LV Size 80.00 MiB Current LE 20 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2
[root@localhost ~]# mkfs.ext4 -j /dev/yellow/testlv -------------创建文件系统 mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=1024 (log=0) 分块大小=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 20480 inodes, 81920 blocks 4096 blocks (5.00%) reserved for the super user 第一个数据块=1 Maximum filesystem blocks=33685504 10 block groups 8192 blocks per group, 8192 fragments per group 2048 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729
Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (4096 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
[root@localhost ~]# mount /dev/yellow/testlv /mnt/ --------挂在到相关目录
逻辑卷移除:
移除前确认挂载点已经umount
[root@localhost ~]# lvremove /dev/mapper/yellow-testlv Logical volume yellow/testlv contains a filesystem in use. [root@localhost ~]# umount /mnt/ [root@localhost ~]# lvremove /dev/mapper/yellow-testlv Do you really want to remove active logical volume yellow/testlv? [y/n]: y Logical volume "testlv" successfully removed
|
扩展逻辑卷:
lvextend -L [+]#(加号表示扩展多少,#表示扩展到多少)
[root@localhost mapper]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/rhel-root 90G 33G 58G 37% / devtmpfs 1.4G 0 1.4G 0% /dev tmpfs 1.5G 0 1.5G 0% /dev/shm tmpfs 1.5G 9.4M 1.4G 1% /run tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup /dev/sda1 1014M 170M 845M 17% /boot tmpfs 287M 28K 287M 1% /run/user/0 /dev/mapper/yellow-qq 477M 2.3M 445M 1% /uuu [root@localhost mapper]# vgs ---------------------扩展前查看vg free有足够大小 VG #PV #LV #SN Attr VSize VFree rhel 1 2 0 wz--n- <93.82g 4.00m yellow 6 1 0 wz--n- <5.98g <5.49g [root@localhost mapper]# lvextend -L 2G /dev/yellow/qq Size of logical volume yellow/qq changed from 500.00 MiB (125 extents) to 2.00 GiB (512 extents). Logical volume yellow/qq successfully resized. [root@localhost mapper]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/rhel-root 90G 33G 58G 37% / devtmpfs 1.4G 0 1.4G 0% /dev tmpfs 1.5G 0 1.5G 0% /dev/shm tmpfs 1.5G 9.4M 1.4G 1% /run tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup /dev/sda1 1014M 170M 845M 17% /boot tmpfs 287M 28K 287M 1% /run/user/0 /dev/mapper/yellow-qq 477M 2.3M 445M 1% /uuu
|
缩减逻辑卷:
1、不能在线缩减,得先卸载。
2、确保缩减后大小能承载原有数据
3、缩减之前强行检查文件,确保文件系统处于一致性检查
[root@localhost mapper]# umount /uuu
[root@localhost mapper]# e2fsck -f /dev/mapper/yellow-qq e2fsck 1.42.9 (28-Dec-2013) 第一步: 检查inode,块,和大小 第二步: 检查目录结构 第3步: 检查目录连接性 Pass 4: Checking reference counts 第5步: 检查簇概要信息 /dev/mapper/yellow-qq: 11/128016 files (0.0% non-contiguous), 26684/512000 blocks
[root@localhost mapper]# lvreduce -L 1G /dev/yellow/qq WARNING: Reducing active logical volume to 1.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce yellow/qq? [y/n]: y Size of logical volume yellow/qq changed from 2.00 GiB (512 extents) to 1.00 GiB (256 extents). Logical volume yellow/qq successfully resized.
[root@localhost mapper]# mount /dev/yellow/qq /uuu [root@localhost mapper]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/rhel-root 90G 33G 58G 37% / devtmpfs 1.4G 0 1.4G 0% /dev tmpfs 1.5G 0 1.5G 0% /dev/shm tmpfs 1.5G 9.4M 1.4G 1% /run tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup /dev/sda1 1014M 170M 845M 17% /boot tmpfs 287M 28K 287M 1% /run/user/0 /dev/mapper/yellow-qq 477M 2.3M 445M 1% /uuu
|
快照卷:
1、生命周期内数据增长量不能超过快照卷大小(可以指定lv中数据量大小)
2、快照卷是只读的
3、跟原卷在同一个卷组
lvcreate -L(大小) -s(快照卷) -p r|w lv_name
[root@localhost mapper]# lvcreate -L 10M -n testlv_snap -s /dev/yellow/qq -p r Rounding up size to full physical extent 12.00 MiB Logical volume "testlv_snap" created.
|
镜像卷:
[root@localhost mapper]# lvcreate -L 1G -m1 -n bbq yellow /dev/sdf1 /dev/sdf2 /dev/sde1 Logical volume "bbq" created. [root@localhost mapper]# lvs -a -o +devices LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices root rhel -wi-ao---- 90.00g /dev/sda2(976) swap rhel -wi-ao---- 3.81g /dev/sda2(0) bbq yellow rwi-a-r--- 1.00g 100.00 bbq_rimage_0(0),bbq_rimage_1(0) [bbq_rimage_0] yellow iwi-aor--- 1.00g /dev/sdf2(1) [bbq_rimage_1] yellow iwi-aor--- 1.00g /dev/sde1(1) [bbq_rmeta_0] yellow ewi-aor--- 4.00m /dev/sdf2(0) [bbq_rmeta_1] yellow ewi-aor--- 4.00m /dev/sde1(0) qq yellow owi-aos--- 1.00g /dev/sdd1(0) testlv_snap yellow sri-aos--- 12.00m qq 0.10 /dev/sdd1(256)
[root@localhost mapper]# lvdisplay /dev/yellow/bbq --- Logical volume --- LV Path /dev/yellow/bbq LV Name bbq VG Name yellow LV UUID mVwhvG-djHj-0jdM-6MlR-T4iG-0vNx-PHz8s4 LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-05-31 01:25:13 +0800 LV Status available # open 0 LV Size 1.00 GiB Current LE 256 Mirrored volumes 2 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:10
[root@localhost ~]# lvextend bbq /dev/sde1
[root@localhost ~]# lvconvert -m1 /dev/yellow/bbq /dev/sde1 /dev/sdf1 /dev/sdf2
|
参考:
https://blog.csdn.net/cybertan/article/details/7623356
https://blog.csdn.net/yanggd1987/article/details/48676347
linux--lvm2学习
标签:png rip The nal aos system 其他 系统 改变
原文地址:https://www.cnblogs.com/huayng/p/9114175.html