LVM
Logical Volume Manager(逻辑卷管理)
[root@node69 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xb9800444 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xb9800444
设备 Boot Start End Blocks Id System
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-20971519,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519):+1G
分区 1 已设置为 Linux 类型,大小设为 1 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xb9800444
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xb9800444
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
命令(输入 m 获取帮助):
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xb9800444
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
/dev/sdb2 2099200 4196351 1048576 8e Linux LVM
/dev/sdb3 4196352 6293503 1048576 8e Linux LVM
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
pvcreate /dev/sdb1
pvcreate /dev/sdb2
pvcreate /dev/sdb3
pvdisplay 列出当前的物理卷
pvremove /dev/sdb3 删除物理卷
[root@node69 ~]# yum install -y lvm2
[root@node69 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@node69 ~]# partprobe
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
[root@node69 ~]# ls /dev/sdb1
/dev/sdb1
[root@node69 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@node69 ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[root@node69 ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created.
[root@node69 ~]# pvdisplay
[root@node69 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 1.00g 1.00g
/dev/sdb2 lvm2 --- 1.00g 1.00g
/dev/sdb3 lvm2 --- 1.00g 1.00g
[root@node69 ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2
Volume group "vg1" successfully created
[root@node69 ~]# vgdisplay
--- Volume group ---
VG Name vg1
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 1.99 GiB
PE Size 4.00 MiB
Total PE 510
Alloc PE / Size 0 / 0
Free PE / Size 510 / 1.99 GiB
VG UUID IPWEHB-aUw1-qtZt-6Yeq-JynK-AaG6-DrM2wR
[root@node69 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 0 0 wz--n- 1.99g 1.99g
vgremove 删除卷组
创建逻辑卷
[root@node69 ~]# lvcreate -L 100M -n lv1 vg1
Logical volume "lv1" created.
[root@node69 ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
[root@node69 ~]# ls -l /dev/vg1/lv1
lrwxrwxrwx 1 root root 7 11月 6 22:08 /dev/vg1/lv1 -> ../dm-0
[root@node69 ~]# ls -l /dev/mapper/vg1-lv1
lrwxrwxrwx 1 root root 7 11月 6 22:08 /dev/mapper/vg1-lv1 -> ../dm-0
[root@node69 ~]# mkdir /mnt/1212
[root@node69 ~]# touch /mnt/23.txt
[root@node69 ~]# echo "11111111" > /mnt/23.txt
[root@node69 ~]# umount /mnt/
[root@node69 ~]# lvresize -L 200M /dev/vg1/lv1
New size (50 extents) matches existing size (50 extents).
[root@node69 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/25688 files (7.7% non-contiguous), 8898/102400 blocks
[root@node69 ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
[root@node69 ~]# umount /mnt/
umount: /mnt/:未挂载
[root@node69 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/49400 files (7.7% non-contiguous), 11886/204800 blocks
[root@node69 ~]# resize2fs /dev/vg1/lv1 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 102400 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 102400 blocks long.
[root@node69 ~]# lvresize -L 100M /dev/vg1/lv1
WARNING: Reducing active logical volume to 100.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: y
Size of logical volume vg1/lv1 changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).
Logical volume vg1/lv1 successfully resized.
[root@node69 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg1/lv1
LV Name lv1
VG Name vg1
LV UUID 2S1lhk-pqM6-Gjb5-WYW2-8jye-MhG2-Klkqnj
LV Write Access read/write
LV Creation host, time node69, 2017-11-06 22:07:21 +0800
LV Status available
# open 0
LV Size 100.00 MiB
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@node69 ~]# vgextend vg1 /dev/sdb3
Volume group "vg1" successfully extended
[root@node69 ~]# vgdisplay
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size <2.99 GiB
PE Size 4.00 MiB
Total PE 765
Alloc PE / Size 25 / 100.00 MiB
Free PE / Size 740 / 2.89 GiB
VG UUID IPWEHB-aUw1-qtZt-6Yeq-JynK-AaG6-DrM2wR