标签:manager structure 环境 map wrap XML tab 而在 rgb
lvm 虽然不常用,但是在小型应用上偶尔还是需要扩容之类的操作。当我们使用的一个分区所剩空间大小已经不够使用了,这个时候我们没法对分区进行扩充,因为受到传统磁盘管理的限制,其不能够进行动态的磁盘管理。因此,为了解决这个问题,LVM技术就诞生了。
LVM的全称是Logical Volumn Manager,是在Linux2.4内核以上实现的磁盘管理技术。它是Linux环境下对磁盘分区进行管理的一种机制。现在不仅仅是Linux系统上可以使用LVM这种磁盘管理机制,对于其它的类UNIX操作系统,以及windows操作系统都有类似与LVM这种磁盘管理软件。LVM的工作原理其实很简单,它就是通过将底层的物理硬盘抽象的封装起来,然后以逻辑卷的方式呈现给上层应用。在传统的磁盘管理机制中,我们的上层应用是直接访问文件系统,从而对底层的物理硬盘进行读取,而在LVM中,其通过对底层的硬盘进行封装,当我们对底层的物理硬盘进行操作时,其不再是针对于分区进行操作,而是通过一个叫做逻辑卷的东西来对其进行底层的磁盘管理操作。比如说我增加一个物理硬盘,这个时候上层的服务是感觉不到的,因为呈现给上次服务的是以逻辑卷的方式。
pvcreate, pvs, pvdisplay, pvremove, pvmove, pvscan
vgcreate, vgs, vgdisplay, vgremove, vgextend, vgreduce, vgscan
lvcreate, lvs, lvdisplay, lvremove, lvextend, lvreduce, lvscan
lvcreate
-n lv_name
-L #UNIT {mMgGtT}
VG_NAME
lv的访问路径:
1、/dev/VG_NAME/LV_NAME
/dev/myvg/mylv
2、/dev/mapper/VG_NAME-LV_NAME
/dev/mapper/myvg-mylv
此两者均为符号链接,指向的文件为/dev/dm-#
lvcreate
-L
-n
-s
-p r
注意:快照卷是对某逻辑卷进行的,因此必须跟目标逻辑卷在同一个卷组中;无须指明卷组;
创建一个由至少两个物理卷组成的大小为10G的卷组;要求,PE大小8M;而后在卷组中创建大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录;
[root@backup ~]# pvcreate /dev/sdb5 /dev/sdb10
Physical volume "/dev/sdb5" successfully created.
Physical volume "/dev/sdb10" successfully created.
[root@backup ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb10 lvm2 --- 5.00g 5.00g
/dev/sdb5 lvm2 --- 5.00g 5.00g
[root@backup ~]# pvdisplay (查看详细信息)
"/dev/sdb5" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb5
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Ta4n50-e2vo-PyE2-w7hZ-Ikbp-wP6w-gncbuk
"/dev/sdb10" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb10
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 167d2z-y5Hy-rQc3-fdyy-UZmn-0ara-9uNgiF
[root@backup ~]# vgcreate myvg -s 8m /dev/sdb5 /dev/sdb10
Volume group "myvg" successfully created
[root@backup ~]#
[root@backup ~]#
[root@backup ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 2 0 0 wz--n- 9.98g 9.98g
[root@backup ~]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 9.98 GiB
PE Size 8.00 MiB
Total PE 1278
Alloc PE / Size 0 / 0
Free PE / Size 1278 / 9.98 GiB
VG UUID GioUVV-eno8-vipm-7sdu-TsiP-BOUF-HGhwit
[root@backup ~]# lvcreate -n mylv1 -L 5G myvg
WARNING: ext4 signature detected on /dev/myvg/mylv1 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/myvg/mylv1.
Logical volume "mylv1" created.
[root@backup ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 2 1 0 wz--n- 9.98g 4.98g
[root@backup ~]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 9.98 GiB
PE Size 8.00 MiB
Total PE 1278
Alloc PE / Size 640 / 5.00 GiB
Free PE / Size 638 / 4.98 GiB
VG UUID GioUVV-eno8-vipm-7sdu-TsiP-BOUF-HGhwit
[root@backup ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv1 myvg -wi-a----- 5.00g
[root@backup ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv1
LV Name mylv1
VG Name myvg
LV UUID gBbQGU-2deH-1lSY-7a4i-G3Ev-mFmB-SQQXyt
LV Write Access read/write
LV Creation host, time backup, 2019-07-18 09:14:51 +0800
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 640
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@backup ~]# mke2fs -t ext4 -L ‘mylv1‘ /dev/myvg/mylv1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=mylv1
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
[root@backup ~]# echo "LABEL="mylv1" /users ext4 defaults 0 0 " >>/etc/fstab
[root@backup ~]# mount -a
[root@backup ~]# df -h |grep /users
/dev/mapper/myvg-mylv1 4.8G 20M 4.6G 1% /users
新建用lvm1,其家目录为/users/lvm1,而后su至lvm1用户,复制/etc/fstab文件至自己的家目录;扩展mylv1至7G,确保/users/lvvm1的数据不受影响;而后su至mageedu用户,验正数据可正常访问;
lvextend -L 4G /dev/myvg/mylv
resize2fs /dev/myvg/mylv
[root@backup ~]# useradd -m -d /users/lvm1 lvm1
[root@backup ~]# cp /etc/fstab /users/lvm1/
[root@backup lvm1]# lvextend -L 7G /dev/myvg/mylv1
Size of logical volume myvg/mylv1 changed from 5.00 GiB (640 extents) to 7.00 GiB (896 extents).
Logical volume myvg/mylv1 successfully resized.
[root@backup lvm1]# resize2fs /dev/myvg/mylv1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv1 is mounted on /users; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long.
[root@backup lvm1]# df -h |grep users
/dev/mapper/myvg-mylv1 6.8G 23M 6.4G 1% /users
[root@backup lvm1]# ls -l /users/lvm1/
total 4
-rw-r--r--. 1 root root 605 Jul 18 10:04 fstab
缩减mylv1至4G,确保/users/mageedu的数据不受影响;而后su至mageedu用户,验正数据可正常访问;
注意缩减lv卷风险很高,谨慎使用。
e2fsck -f
resize2fs DEVICE
lvreduce
[root@backup /]# umount /users/
[root@backup /]# e2fsck -f /dev/mapper/myvg-mylv1
e2fsck 1.42.9 (28-Dec-2013)
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
mylv1: 16/458752 files (0.0% non-contiguous), 67332/1835008 blocks
[root@backup ~]# resize2fs /dev/mapper/myvg-mylv1 4g
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/myvg-mylv1 to 1048576 (4k) blocks.
The filesystem on /dev/mapper/myvg-mylv1 is now 1048576 blocks long.
[root@backup ~]# lvreduce -L 4G /dev/mapper/myvg-mylv1
WARNING: Reducing active logical volume to 4.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce myvg/mylv1? [y/n]: y
Size of logical volume myvg/mylv1 changed from 7.00 GiB (896 extents) to 4.00 GiB (512 extents).
Logical volume myvg/mylv1 successfully resized.
[root@backup /]# mount /dev/mapper/myvg-mylv1 /users
[root@backup /]# cd /users && ls -l
total 20
drwx------. 2 root root 16384 Jul 18 09:17 lost+found
drwx------. 2 lvm1 lvm1 4096 Jul 18 10:04 lvm1
对mylv1创建快照卷snap-mylv1,并通过其cp内部的数据至/backups/目录中,要求保留原有属主属组等信息;
[root@backup mapper]# lvcreate -s -n myvg-snap -p r -L 30m /dev/mapper/myvg-mylv1
Rounding up size to full physical extent 32.00 MiB
Logical volume "myvg-snap" created.
[root@backup mapper]# mount /dev/mapper/myvg-myvg--snap /mnt
mount: /dev/mapper/myvg-myvg--snap is write-protected, mounting read-only
[root@backup mnt]# echo "aaaaaa=bbbbb" >/users/aaa
[root@backup mnt]# cat /users/aaa
aaaaaa=bbbbb
[root@backup mnt]#
[root@backup mnt]# cat /mnt/aaa
aaa
标签:manager structure 环境 map wrap XML tab 而在 rgb
原文地址:https://www.cnblogs.com/chacha51/p/11380206.html