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 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 6.6G 0 rom
nvme0n1 259: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]
nvme0n2 259:3 0 20G 0 disk
nvme0n3 259: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): n
Partition typep primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First 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): p
Disk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0230473bDevice Boot Start End Sectors Size Id Type
/dev/nvme0n2p1 2048 10487807 10485760 5G 83 LinuxCommand (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.#接下来查看分区结构
[root@wentan ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 6.6G 0 rom
nvme0n1 259: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]
nvme0n2 259:3 0 20G 0 disk
└─nvme0n2p1 259:6 0 5G 0 part
nvme0n3 259: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/nvme0n2p1VG Name PV Size 5.00 GiBAllocatable NOPE Size 0 Total PE 0Free PE 0Allocated PE 0PV 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 testvgSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 1VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 1Act PV 1VG Size <5.00 GiBPE Size 4.00 MiBTotal PE 1279Alloc PE / Size 0 / 0 Free PE / Size 1279 / <5.00 GiBVG UUID Ryu6s1-AglO-x4gY-UZL3-swFD-H07i-1Zw5Pb#创建lv
[root@wentan ~]# lvcreate -l 1024 -n testlv testvgLogical volume "testlv" created.
[root@wentan ~]# lvdisplay /dev/testvg/testlv --- Logical volume ---LV Path /dev/testvg/testlvLV Name testlvVG Name testvgLV UUID dH7xlu-9cJa-eQ4P-Dui1-0RoL-02gY-lxeH1vLV Write Access read/writeLV Creation host, time wentan, 2022-01-18 13:59:30 +0800LV Status available# open 0LV Size 4.00 GiBCurrent LE 1024Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block 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 inodes
Filesystem UUID: b8fe5156-37d8-4f31-9363-659d76ddd4da
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing 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 -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 9.7M 1.9G 1% /run
tmpfs 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% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 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 required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/testvg/testlv is now 1258496 (4k) blocks long.[root@wentan ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 9.7M 1.9G 1% /run
tmpfs 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% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 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/nvme0n2
Welcome 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): n
Partition typep primary (2 primary, 0 extended, 2 free)e extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
First 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): p
Disk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk 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): w
The 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 -s
Filename Type Size Used Priority
/dev/dm-1 partition 2146300 0 -2
/dev/nvme0n2p3 partition 2097148 0 -3
#查看系统所有swap总大小
[root@wentan ~]# freetotal used free shared buff/cache available
Mem: 3848776 726408 2574680 10096 547688 2859772
Swap: 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 testvdoThe 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 testvdo
Starting compression on VDO testvdo
VDO instance 0 volume is ready at /dev/mapper/testvdo
[root@wentan ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 6.6G 0 rom
nvme0n1 259: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]
nvme0n2 259: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=1
data = bsize=4096 blocks=15728640, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=7680, version=2= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =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 -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 9.6M 1.9G 1% /run
tmpfs 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% /boot
tmpfs tmpfs 371M 16K 371M 1% /run/user/42
tmpfs tmpfs 371M 4.0K 371M 1% /run/user/0
/dev/mapper/testvdo xfs 60G 461M 60G 1% /vdoblock
3.5 逻辑卷的缩小
#查看一下目前的大小
[root@wentan ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 9.7M 1.9G 1% /run
tmpfs 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% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
/dev/mapper/testvg-testlv ext4 4.7G 16M 4.4G 1% /volume1
tmpfs tmpfs 376M 4.0K 376M 1% /run/user/0
/dev/mapper/mvvg-mylv xfs 4.0G 61M 4.0G 2% /new-volume#在做磁盘裁剪的时候,首先必须要把文件系统给取消挂载
[root@wentan ~]# umount /dev/mapper/testvg-testlv
[root@wentan ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 9.7M 1.9G 1% /run
tmpfs 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% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.0K 376M 1% /run/user/0
/dev/mapper/mvvg-mylv xfs 4.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 sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/319488 files (0.0% non-contiguous), 40540/1258496 blocks
[root@wentan ~]# resize2fs /dev/testvg/testlv 2G
resize2fs 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]: ySize 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 -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 9.7M 1.9G 1% /run
tmpfs 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% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.0K 376M 1% /run/user/0
/dev/mapper/mvvg-mylv xfs 4.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]: yLogical volume "testlv" successfully removed
[root@wentan ~]# vgremove testvg Volume group "testvg" successfully removed
[root@wentan ~]# pvremove /dev/nvme0n2p1Labels on physical volume "/dev/nvme0n2p1" successfully wiped.
[root@wentan ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 9.7M 1.9G 1% /run
tmpfs 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% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.0K 376M 1% /run/user/0
/dev/mapper/mvvg-mylv xfs 4.0G 61M 4.0G 2% /new-volume
3.7 逻辑卷快照技术
LVM还具备有“快照卷”功能,该功能类似于虚拟机软件的还原时间点功能。例如,可以对某一个逻辑卷设备做一次快照,如果日后发现数据被改错了,就可以利用之前做好的快照卷进行覆盖还原。LVM的快照卷功能有两个特点:
-
快照卷的容量必须等同于逻辑卷的容量;
-
快照卷仅一次有效,一旦执行还原操作后则会被立即自动删除。
[root@wentan ~]# vgdisplay --- Volume group ---VG Name mvvgSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 3VG Access read/writeVG Status resizableMAX LV 0Cur LV 1Open LV 1Max PV 0Cur PV 1Act PV 1VG Size <5.00 GiBPE Size 4.00 MiBTotal PE 1279Alloc PE / Size 1024 / 4.00 GiBFree PE / Size 255 / 1020.00 MiBVG UUID peXZzy-ldiM-hwer-d9Ih-Yfu4-F7dT-hWP1FB--- Volume group ---VG Name rhelSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 3VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 1Act PV 1VG Size <24.00 GiBPE Size 4.00 MiBTotal PE 6143Alloc PE / Size 6143 / <24.00 GiBFree PE / Size 0 / 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/mylvLogical volume "SNAP" created.#查看lv所有卷组,会发现快照卷已经存在了
[root@wentan ~]# lvdisplay --- Logical volume ---LV Path /dev/mvvg/mylvLV Name mylvVG Name mvvgLV UUID mJoWZN-8lfH-lWTd-KEHZ-6eBs-bzl8-BAT8iwLV Write Access read/writeLV Creation host, time wentan, 2022-01-18 19:23:25 +0800LV snapshot status source ofSNAP [active]LV Status available# open 1LV Size 4.00 GiBCurrent LE 1024Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:3--- Logical volume ---LV Path /dev/mvvg/SNAPLV Name SNAPVG Name mvvgLV UUID ZuO0eN-rEkX-9iYR-iDUu-Jrt2-w2wV-dE74rVLV Write Access read/writeLV Creation host, time wentan, 2022-01-18 19:38:00 +0800LV snapshot status active destination for mylvLV Status available# open 0LV Size 4.00 GiBCurrent LE 1024COW-table size 120.00 MiBCOW-table LE 30Allocated to snapshot 0.02%Snapshot chunk size 4.00 KiBSegments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:5--- Logical volume ---LV Path /dev/rhel/swapLV Name swapVG Name rhelLV UUID 88Em5N-b1ye-gxHz-cPZN-eY0O-1RR7-2ZI1A2LV Write Access read/writeLV Creation host, time localhost, 2022-01-05 04:16:15 +0800LV Status available# open 2LV Size <2.05 GiBCurrent LE 524Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:1--- Logical volume ---LV Path /dev/rhel/rootLV Name rootVG Name rhelLV UUID wGxFLg-lFhu-cNG4-4TeI-DRxn-AnLu-HhfBQfLV Write Access read/writeLV Creation host, time localhost, 2022-01-05 04:16:15 +0800LV Status available# open 1LV Size <21.95 GiBCurrent LE 5619Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:0#在逻辑卷所挂载的目录中创建一个100MB的垃圾文件,然后再查看快照卷的状态。可以发现存储空间占的用量上升了
[root@wentan ~]# dd if=/dev/zero of=/new-volume/files count=1 bs=100M
1+0 records in
1+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.751014 s, 140 MB/s
[root@wentan ~]# lvdisplay --- Logical volume ---LV Path /dev/mvvg/mylvLV Name mylvVG Name mvvgLV UUID mJoWZN-8lfH-lWTd-KEHZ-6eBs-bzl8-BAT8iwLV Write Access read/writeLV Creation host, time wentan, 2022-01-18 19:23:25 +0800LV snapshot status source ofSNAP [active]LV Status available# open 1LV Size 4.00 GiBCurrent LE 1024Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:3--- Logical volume ---LV Path /dev/mvvg/SNAPLV Name SNAPVG Name mvvgLV UUID ZuO0eN-rEkX-9iYR-iDUu-Jrt2-w2wV-dE74rVLV Write Access read/writeLV Creation host, time wentan, 2022-01-18 19:38:00 +0800LV snapshot status active destination for mylvLV Status available# open 0LV Size 4.00 GiBCurrent LE 1024COW-table size 120.00 MiBCOW-table LE 30Allocated to snapshot 83.68%Snapshot chunk size 4.00 KiBSegments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:5--- Logical volume ---LV Path /dev/rhel/swapLV Name swapVG Name rhelLV UUID 88Em5N-b1ye-gxHz-cPZN-eY0O-1RR7-2ZI1A2LV Write Access read/writeLV Creation host, time localhost, 2022-01-05 04:16:15 +0800LV Status available# open 2LV Size <2.05 GiBCurrent LE 524Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:1--- Logical volume ---LV Path /dev/rhel/rootLV Name rootVG Name rhelLV UUID wGxFLg-lFhu-cNG4-4TeI-DRxn-AnLu-HhfBQfLV Write Access read/writeLV Creation host, time localhost, 2022-01-05 04:16:15 +0800LV Status available# open 1LV Size <21.95 GiBCurrent LE 5619Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block 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]# ll
total 4
-rw-r--r--. 1 root root 12 Jan 18 19:37 readme.txt
视频讲解在微信公众号
问渠清源
回复关键词视频
即可观看
发布评论