Linux 基础入门 08
视频讲解在微信公众号
问渠清源
回复关键词视频
即可观看
一、LVM(逻辑卷管理器)
逻辑卷管理器是Linux系统用于对硬盘分区进行管理的一种机制,理论性较强,其创建初衷是为了解决硬盘设备在创建分区后不易修改分区大小的缺陷。尽管对传统的硬盘分区进行强制扩容或缩容从理论上来讲是可行的,但是却可能造成数据的丢失。而LVM技术是在硬盘分区和文件系统之间添加了一个逻辑层,它提供了一个抽象的卷组,可以把多块硬盘进行卷组合并。这样一来,用户不必关心物理硬盘设备的底层架构和布局,就可以实现对硬盘分区的动态调整。
物理卷处于LVM中的最底层,可以将其理解为物理硬盘、硬盘分区或者RAID磁盘阵列,这都可以。卷组建立在物理卷之上,一个卷组可以包含多个物理卷,而且在卷组创建之后也可以继续向其中添加新的物理卷。逻辑卷是用卷组中空闲的资源建立的,并且逻辑卷在建立后可以动态地扩展或缩小空间。这就是LVM的核心理念。
二、部署逻辑卷
常用的LVM部署命令
功能/命令 | 物理卷管理 | 卷组管理 | 逻辑卷管理 |
---|---|---|---|
扫描 | pvscan | vgscan | lvscan |
建立 | pvcreate | vgcreate | lvcreate |
显示 | pvdisplay | vgdisplay | lvdisplay |
删除 | pvremove | vgremove | lvremove |
扩展 | vgextend | lvextend | |
缩小 | vgreduce | lvreduce |
我们在日常工作中,对卷组的管理是必须要掌握的
LVM( logical volume manager
)是Linux环境下,对磁盘分区进行管理的一个机制,保证零停机前提下,对文件系统的大小进行调整,实现文件跨越不同的磁盘和分区,LVM提供了一个完美的解决方案
PP:物理分区 用来存储数据的块设备,可以是分区,可以是磁盘,RAID,SAN
PV:物理卷 LVM
的基础逻辑块,但是和基本的物理介质(磁盘,分区)不同,包含了LVM
的管理参数
VG:卷组:由一个或多个物理卷组成
LV:逻辑卷,LVM
的逻辑卷类似于非LVM
中的硬盘分区,LV
就可以建立文件系统了,基于LV
来建立文件系统文件系统,mkfs
来格式化这个/dev/sda
最后变成一个个不同的文件系统
PE:每一个物理卷被划分为PE基本单元,是LVM
最小的存储单元,具有唯一编号,PE
大小可以手动制动,默认4MB
LE:逻辑卷也被划分成LE
,可被寻址的基本单元,在同一个卷组中,PE
和LE
大小一定是相同的,而且要一一对应。 说白了就是把PE
一个一个映射成LE
三、逻辑卷管理实验
3.1 普通逻辑卷创建
首先在服务器上添加一块硬盘
#查看磁盘信息[root@wentan ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 6.6G 0 rom nvme0n1259:0 0 25G 0 disk ├─nvme0n1p1 259:1 0 1G 0 part /boot└─nvme0n1p2 259:2 0 24G 0 part ├─rhel-root 253:0 0 22G 0 lvm / └─rhel-swap 253:1 0 2G 0 lvm [SWAP]nvme0n2259:3 0 20G 0 disk nvme0n3259:4 0 20G 0 disk #接下来把硬盘分区 分成一个5G大小的物理分区[root@wentan ~]# fdisk /dev/nvme0n2Welcome to fdisk (util-linux 2.32.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition table.Created a new DOS disklabel with disk identifier 0x0230473b.Command (m for help): nPartition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)Select (default p): pPartition number (1-4, default 1): 1First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +5GCreated a new partition 1 of type 'Linux' and of size 5 GiB.Command (m for help): pDisk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0230473bDevice Boot Start End Sectors Size Id Type/dev/nvme0n2p12048 10487807 10485760 5G 83 LinuxCommand (m for help): wThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.#接下来查看分区结构[root@wentan ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 6.6G 0 rom nvme0n1259:0 0 25G 0 disk ├─nvme0n1p1 259:1 0 1G 0 part /boot└─nvme0n1p2 259:2 0 24G 0 part ├─rhel-root 253:0 0 22G 0 lvm / └─rhel-swap 253:1 0 2G 0 lvm [SWAP]nvme0n2259:3 0 20G 0 disk └─nvme0n2p1 259:6 0 5G 0 part nvme0n3259:4 0 20G 0 disk#创建pv[root@wentan ~]# pvcreate /dev/nvme0n2p1 Physical volume "/dev/nvme0n2p1" successfully created.#查看详细信息[root@wentan ~]# pvdisplay /dev/nvme0n2p1 "/dev/nvme0n2p1" is a new physical volume of "5.00 GiB" --- NEW Physical volume --- PV Name /dev/nvme0n2p1 VG Name PV Size 5.00 GiB Allocatable NO PE Size 0 Total PE0 Free PE 0 Allocated PE 0 PV UUID 9lWVmv-IwRw-OgXz-2Jed-je5e-nKiA-fRS0C3#创建一个VG[root@wentan ~]# vgcreate -s 4M testvg /dev/nvme0n2p1 Volume group "testvg" successfully created[root@wentan ~]# vgdisplay testvg --- Volume group --- VG Name testvg 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 <5.00 GiB PE Size 4.00 MiB Total PE1279 Alloc PE / Size0 / 0 Free PE / Size1279 / <5.00 GiB VG UUID Ryu6s1-AglO-x4gY-UZL3-swFD-H07i-1Zw5Pb #创建lv[root@wentan ~]# lvcreate -l 1024 -n testlv testvg Logical volume "testlv" created.[root@wentan ~]# lvdisplay /dev/testvg/testlv --- Logical volume --- LV Path /dev/testvg/testlv LV Name testlv VG Name testvg LV UUID dH7xlu-9cJa-eQ4P-Dui1-0RoL-02gY-lxeH1v LV Write Access read/write LV Creation host, time wentan, 2022-01-18 13:59:30 +0800 LV Statusavailable # open 0 LV Size 4.00 GiB Current LE 1024 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 # 创建文件系统[root@wentan ~]# mkfs.ext4 /dev/mapper/testvg-testlv mke2fs 1.44.3 (10-July-2018)Creating filesystem with 1048576 4k blocks and 262144 inodesFilesystem UUID: b8fe5156-37d8-4f31-9363-659d76ddd4daSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: doneWriting inode tables: doneCreating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done #挂载[root@wentan ~]# mkdir /volume1[root@wentan ~]# vim /etc/fstab #外加一行/dev/mapper/testvg-testlv /volume1 ext4 defaults 0 0[root@wentan ~]# mount -a[root@wentan ~]# df -hTFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 1.9G 0 1.9G 0% /devtmpfstmpfs 1.9G 0 1.9G 0% /dev/shmtmpfstmpfs 1.9G 9.7M 1.9G 1% /runtmpfstmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/rhel-root xfs 22G 4.2G 18G 19% //dev/nvme0n1p1 xfs 1014M 169M 846M 17% /boottmpfstmpfs 376M 16K 376M 1% /run/user/42tmpfstmpfs 376M 4.0K 376M 1% /run/user/0/dev/mapper/testvg-testlv ext4 3.9G 16M 3.7G 1% /volume1#看到最后这个逻辑卷挂载成功即实验完成
3.2 逻辑卷扩容
注意点 扩容大小限制是VG的大小限制,最多扩容不能超过VG的总大小
#扩容4.8G[root@wentan ~]# lvextend -L 4.8G /dev/testvg/testlv Rounding size to boundary between physical extents: 4.80 GiB. Size of logical volume testvg/testlv changed from 4.00 GiB (1024 extents) to 4.80 GiB (1229 extents). Logical volume testvg/testlv successfully resized. #刷新挂载点[root@wentan ~]# resize2fs /dev/testvg/testlv resize2fs 1.44.3 (10-July-2018)Filesystem at /dev/testvg/testlv is mounted on /volume1; on-line resizing requiredold_desc_blocks = 1, new_desc_blocks = 1The filesystem on /dev/testvg/testlv is now 1258496 (4k) blocks long.[root@wentan ~]# df -hTFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 1.9G 0 1.9G 0% /devtmpfstmpfs 1.9G 0 1.9G 0% /dev/shmtmpfstmpfs 1.9G 9.7M 1.9G 1% /runtmpfstmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/rhel-root xfs 22G 4.2G 18G 19% //dev/nvme0n1p1 xfs 1014M 169M 846M 17% /boottmpfstmpfs 376M 16K 376M 1% /run/user/42tmpfstmpfs 376M 4.0K 376M 1% /run/user/0/dev/mapper/testvg-testlv ext4 4.7G 16M 4.4G 1% /volume1
注意
- 扩展文件系统
xfs
类型的文件系统用xfs_growfs /volume1
,后面接的是挂载点的位置 - 如果是
ext
文件系统刷新要用resize2fs /dev/testvg/testlv
后面接的是逻辑卷的位置
3.3 swap分区的创建
注意: swap分区不需要通过LVM来管理,物理分区完成后,可以直接做成swap类型
[root@wentan /]# fdisk /dev/nvme0n2Welcome to fdisk (util-linux 2.32.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): nPartition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions)Select (default p): pPartition number (3,4, default 3): 3First sector (20973568-41943039, default 20973568): Last sector, +sectors or +size{K,M,G,T,P} (20973568-41943039, default 41943039): +2GCreated a new partition 3 of type 'Linux' and of size 2 GiB.Command (m for help): pDisk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0230473bDevice Boot Start End Sectors Size Id Type/dev/nvme0n2p1 2048 10487807 10485760 5G 83 Linux/dev/nvme0n2p2 10487808 20973567 10485760 5G 83 Linux/dev/nvme0n2p3 20973568 25167871 4194304 2G 83 LinuxCommand (m for help): wThe partition table has been altered.Syncing disks.#直接做成swap[root@wentan ~]# mkswap /dev/nvme0n2p3 Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)no label, UUID=47a1f300-73b6-464c-9d62-4f8527ff108e#查看UUID[root@wentan ~]# blkid /dev/nvme0n2p3/dev/nvme0n2p3: UUID="47a1f300-73b6-464c-9d62-4f8527ff108e" TYPE="swap" PARTUUID="0230473b-03"[root@wentan ~]# vim /etc/fstab/dev/nvme0n2p3 swap swap defaults 0 0#挂载所有swap[root@wentan ~]# swapon -a#查看所有swap[root@wentan ~]# swapon -sFilenameTypeSizeUsedPriority/dev/dm-1 partition21463000-2/dev/nvme0n2p3 partition20971480-3#查看系统所有swap总大小[root@wentan ~]# freetotal used free shared buff/cache availableMem: 3848776 726408 257468010096 547688 2859772Swap:4243448 0 4243448
3.4 VDO卷的创建
什么是VDO
技术,这是RHEL8
中特有的技术
红帽公司收购了一个公司 叫 permabit
,VDO
就是 permabit
这个公司的技术
VDO
也不是使用LVM
来管理,是一个单独的技术。
VDO
最大的作用就是节省硬盘空间,可以做到一个1TB
的硬盘,直接存放3TB
的数据甚至更多
VDO 是怎么实现这个功能的?
靠的就是删除和压缩解压缩技术 重删就是把硬盘里相同的数据以前要存多份,现在会把多余的删掉,只留一份。,压缩算法来节省空间。
我们要使用VDO技术 将一块20 GD的硬盘,直接做成60G,并且挂载到系统上直接使用
#安装两个软件#安装时间较长,大约需要几分钟,安装完成以后需要重启设备 [root@wentan ~]# yum install -y vdo kmod-kvdo[root@wentan ~]# reboot[root@wentan ~]# vdo create --name=testvdo --device=/dev/nvme0n3 --vdoLogicalSize=60GCreating VDO testvdo The VDO volume can address 16 GB in 8 data slabs, each 2 GB. It can grow to address at most 16 TB of physical storage in 8192 slabs. If a larger maximum size might be needed, use bigger slabs.Starting VDO testvdoStarting compression on VDO testvdoVDO instance 0 volume is ready at /dev/mapper/testvdo[root@wentan ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 6.6G 0 rom nvme0n1259:0 0 25G 0 disk ├─nvme0n1p1 259:1 0 1G 0 part /boot└─nvme0n1p2 259:2 0 24G 0 part ├─rhel-root 253:0 0 22G 0 lvm / └─rhel-swap 253:1 0 2G 0 lvm [SWAP]nvme0n2259:3 0 20G 0 disk └─testvdo 253:2 0 60G 0 vdo [root@wentan ~]# mkfs.xfs /dev/mapper/testvdo meta-data=/dev/mapper/testvdo isize=512 agcount=4, agsize=3932160 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1data = bsize=4096 blocks=15728640, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2bsize=4096 ascii-ci=0, ftype=1log =internal log bsize=4096 blocks=7680, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0[root@wentan ~]# mkdir /vdoblock[root@wentan ~]# vim /etc/fstab/dev/mapper/testvdo /vdoblock xfs defaults,x-systemd.requires=vdo.service 0 0[root@wentan ~]# mount -a[root@wentan ~]# df -hTFilesystem Type Size Used Avail Use% Mounted ondevtmpfsdevtmpfs 1.8G 0 1.8G 0% /devtmpfs tmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs tmpfs 1.9G 9.6M 1.9G 1% /runtmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/rhel-root xfs 22G 4.5G 18G 21% //dev/nvme0n1p1 xfs 1014M 269M 746M 27% /boottmpfs tmpfs 371M 16K 371M 1% /run/user/42tmpfs tmpfs 371M 4.0K 371M 1% /run/user/0/dev/mapper/testvdo xfs 60G 461M 60G 1% /vdoblock
3.5 逻辑卷的缩小
#查看一下目前的大小[root@wentan ~]# df -hTFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 1.9G 0 1.9G 0% /devtmpfstmpfs 1.9G 0 1.9G 0% /dev/shmtmpfstmpfs 1.9G 9.7M 1.9G 1% /runtmpfstmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/rhel-root xfs 22G 4.2G 18G 19% //dev/nvme0n1p1 xfs 1014M 169M 846M 17% /boottmpfstmpfs 376M 16K 376M 1% /run/user/42/dev/mapper/testvg-testlv ext4 4.7G 16M 4.4G 1% /volume1tmpfstmpfs 376M 4.0K 376M 1% /run/user/0/dev/mapper/mvvg-mylv xfs4.0G 61M 4.0G 2% /new-volume#在做磁盘裁剪的时候,首先必须要把文件系统给取消挂载[root@wentan ~]# umount /dev/mapper/testvg-testlv [root@wentan ~]# df -hTFilesystem Type Size Used Avail Use% Mounted ondevtmpfsdevtmpfs 1.9G 0 1.9G 0% /devtmpfs tmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs tmpfs 1.9G 9.7M 1.9G 1% /runtmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/rhel-root xfs 22G 4.2G 18G 19% //dev/nvme0n1p1 xfs 1014M 169M 846M 17% /boottmpfs tmpfs 376M 16K 376M 1% /run/user/42tmpfs tmpfs 376M 4.0K 376M 1% /run/user/0/dev/mapper/mvvg-mylv xfs4.0G 61M 4.0G 2% /new-volume#裁剪前必须要检测文件系统,避免把文件系统的错误扩大化导致文件系统奔溃[root@wentan ~]# e2fsck -f /dev/testvg/testlv e2fsck 1.44.3 (10-July-2018)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/testvg/testlv: 11/319488 files (0.0% non-contiguous), 40540/1258496 blocks[root@wentan ~]# resize2fs /dev/testvg/testlv 2Gresize2fs 1.44.3 (10-July-2018)Resizing the filesystem on /dev/testvg/testlv to 524288 (4k) blocks.The filesystem on /dev/testvg/testlv is now 524288 (4k) blocks long.[root@wentan ~]# lvreduce -L 2G /dev/testvg/testlv WARNING: Reducing active logical volume to 2.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce testvg/testlv? [y/n]: y Size of logical volume testvg/testlv changed from 4.80 GiB (1229 extents) to 2.00 GiB (512 extents). Logical volume testvg/testlv successfully resized.[root@wentan ~]# mount -a[root@wentan ~]# df -hTFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 1.9G 0 1.9G 0% /devtmpfstmpfs 1.9G 0 1.9G 0% /dev/shmtmpfstmpfs 1.9G 9.7M 1.9G 1% /runtmpfstmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/rhel-root xfs 22G 4.2G 18G 19% //dev/nvme0n1p1 xfs 1014M 169M 846M 17% /boottmpfstmpfs 376M 16K 376M 1% /run/user/42tmpfstmpfs 376M 4.0K 376M 1% /run/user/0/dev/mapper/mvvg-mylv xfs4.0G 61M 4.0G 2% /new-volume/dev/mapper/testvg-testlv ext4 2.0G 12M 1.8G 1% /volume1
3.6 逻辑卷的删除
[root@wentan ~]# umount /dev/mapper/testvg-testlv [root@wentan ~]# vim /etc/fstab #删除含有/dev/mapper/testvg-testlv的一行[root@wentan ~]# lvremove /dev/testvg/testlv Do you really want to remove active logical volume testvg/testlv? [y/n]: y Logical volume "testlv" successfully removed[root@wentan ~]# vgremove testvg Volume group "testvg" successfully removed[root@wentan ~]# pvremove /dev/nvme0n2p1 Labels on physical volume "/dev/nvme0n2p1" successfully wiped.[root@wentan ~]# df -hTFilesystem Type Size Used Avail Use% Mounted ondevtmpfsdevtmpfs 1.9G 0 1.9G 0% /devtmpfs tmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs tmpfs 1.9G 9.7M 1.9G 1% /runtmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/rhel-root xfs 22G 4.2G 18G 19% //dev/nvme0n1p1 xfs 1014M 169M 846M 17% /boottmpfs tmpfs 376M 16K 376M 1% /run/user/42tmpfs tmpfs 376M 4.0K 376M 1% /run/user/0/dev/mapper/mvvg-mylv xfs4.0G 61M 4.0G 2% /new-volume
3.7 逻辑卷快照技术
LVM还具备有“快照卷”功能,该功能类似于虚拟机软件的还原时间点功能。例如,可以对某一个逻辑卷设备做一次快照,如果日后发现数据被改错了,就可以利用之前做好的快照卷进行覆盖还原。LVM的快照卷功能有两个特点:
-
快照卷的容量必须等同于逻辑卷的容量;
-
快照卷仅一次有效,一旦执行还原操作后则会被立即自动删除。
[root@wentan ~]# vgdisplay --- Volume group --- VG Name mvvg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size <5.00 GiB PE Size 4.00 MiB Total PE1279 Alloc PE / Size1024 / 4.00 GiB Free PE / Size255 / 1020.00 MiB VG UUID peXZzy-ldiM-hwer-d9Ih-Yfu4-F7dT-hWP1FB --- Volume group --- VG Name rhel System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <24.00 GiB PE Size 4.00 MiB Total PE6143 Alloc PE / Size6143 / <24.00 GiB Free PE / Size0 / 0 VG UUID tLKo9C-urRn-PQ4C-lFCK-NnxX-5uSF-g7oknF#在还原时间点快照前写入一个文件,验证恢复快照不会丢失之前的文件 [root@wentan ~]# echo "hello,world" > /new-volume/readme.txt#检查刚刚写入的文件是否存在[root@wentan ~]# ls -l /new-volume/total 4-rw-r--r--. 1 root root 12 Jan 18 19:37 readme.txt#给这个lv卷打一个快照[root@wentan ~]# lvcreate -L 120M -s -n SNAP /dev/mvvg/mylv Logical volume "SNAP" created.#查看lv所有卷组,会发现快照卷已经存在了[root@wentan ~]# lvdisplay --- Logical volume --- LV Path /dev/mvvg/mylv LV Name mylv VG Name mvvg LV UUID mJoWZN-8lfH-lWTd-KEHZ-6eBs-bzl8-BAT8iw LV Write Access read/write LV Creation host, time wentan, 2022-01-18 19:23:25 +0800 LV snapshot status source of SNAP [active] LV Statusavailable # open 1 LV Size 4.00 GiB Current LE 1024 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 --- Logical volume --- LV Path /dev/mvvg/SNAP LV Name SNAP VG Name mvvg LV UUID ZuO0eN-rEkX-9iYR-iDUu-Jrt2-w2wV-dE74rV LV Write Access read/write LV Creation host, time wentan, 2022-01-18 19:38:00 +0800 LV snapshot status active destination for mylv LV Statusavailable # open 0 LV Size 4.00 GiB Current LE 1024 COW-table size 120.00 MiB COW-table LE 30 Allocated to snapshot 0.02% Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:5 --- Logical volume --- LV Path /dev/rhel/swap LV Name swap VG Name rhel LV UUID 88Em5N-b1ye-gxHz-cPZN-eY0O-1RR7-2ZI1A2 LV Write Access read/write LV Creation host, time localhost, 2022-01-05 04:16:15 +0800 LV Statusavailable # open 2 LV Size <2.05 GiB Current LE 524 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/rhel/root LV Name root VG Name rhel LV UUID wGxFLg-lFhu-cNG4-4TeI-DRxn-AnLu-HhfBQf LV Write Access read/write LV Creation host, time localhost, 2022-01-05 04:16:15 +0800 LV Statusavailable # open 1 LV Size <21.95 GiB Current LE 5619 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 #在逻辑卷所挂载的目录中创建一个100MB的垃圾文件,然后再查看快照卷的状态。可以发现存储空间占的用量上升了[root@wentan ~]# dd if=/dev/zero of=/new-volume/files count=1 bs=100M1+0 records in1+0 records out104857600 bytes (105 MB, 100 MiB) copied, 0.751014 s, 140 MB/s[root@wentan ~]# lvdisplay --- Logical volume --- LV Path /dev/mvvg/mylv LV Name mylv VG Name mvvg LV UUID mJoWZN-8lfH-lWTd-KEHZ-6eBs-bzl8-BAT8iw LV Write Access read/write LV Creation host, time wentan, 2022-01-18 19:23:25 +0800 LV snapshot status source of SNAP [active] LV Statusavailable # open 1 LV Size 4.00 GiB Current LE 1024 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 --- Logical volume --- LV Path /dev/mvvg/SNAP LV Name SNAP VG Name mvvg LV UUID ZuO0eN-rEkX-9iYR-iDUu-Jrt2-w2wV-dE74rV LV Write Access read/write LV Creation host, time wentan, 2022-01-18 19:38:00 +0800 LV snapshot status active destination for mylv LV Statusavailable # open 0 LV Size 4.00 GiB Current LE 1024 COW-table size 120.00 MiB COW-table LE 30 Allocated to snapshot 83.68% Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:5 --- Logical volume --- LV Path /dev/rhel/swap LV Name swap VG Name rhel LV UUID 88Em5N-b1ye-gxHz-cPZN-eY0O-1RR7-2ZI1A2 LV Write Access read/write LV Creation host, time localhost, 2022-01-05 04:16:15 +0800 LV Statusavailable # open 2 LV Size <2.05 GiB Current LE 524 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/rhel/root LV Name root VG Name rhel LV UUID wGxFLg-lFhu-cNG4-4TeI-DRxn-AnLu-HhfBQf LV Write Access read/write LV Creation host, time localhost, 2022-01-05 04:16:15 +0800 LV Statusavailable # open 1 LV Size <21.95 GiB Current LE 5619 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 #恢复快照之前必须要取消挂载[root@rhel8-server /]# umount /new-volume#通过lvconvert --merge 来指定快照SNAP恢复[root@wentan ~]# lvconvert --merge /dev/mvvg/SNAP Merging of volume mvvg/SNAP started. mvvg/mylv: Merged: 28.05% mvvg/mylv: Merged: 100.00% #挂载所有卷组[root@wentan ~]# mount -a[root@wentan ~]# cd /new-volume/#此时刚刚的100M垃圾随着快照技术已经删除了[root@wentan new-volume]# lltotal 4-rw-r--r--. 1 root root 12 Jan 18 19:37 readme.txt
视频讲解在微信公众号
问渠清源
回复关键词视频
即可观看