查看磁盘信息. 如下图所示, 我们添加了两块新的物理磁盘sdb(8G)和sdc(7G).
[root@localhost ~]# pvcreate /dev/sdb /dev/sdc
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
[root@localhost ~]# vgcreate vgtest /dev/sdb /dev/sdc
Volume group "vgtest" successfully created
后续也可以继续向这个卷组中加入新的PV.
[root@localhost ~]# lvcreate -n lvtest -L 2G vgtest
Logical volume "lvtest" created.
[root@localhost ~]# mkfs.ext4 /dev/vgtest/lvtest
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost mnt]# ls /dev/vgtest/lvtest -l
lrwxrwxrwx. 1 root root 7 Sep 5 11:56 /dev/vgtest/lvtest -> ../dm-3
[root@localhost ~]# mount /dev/vgtest/lvtest /mnt
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
lost+found
[root@localhost mnt]# mount
......
/dev/mapper/vgtest-lvtest on /mnt type ext4 (rw,relatime,seclabel,data=ordered)
可以看到, /dev/vgtest/lvtest
其实是一个链接, 其实际位置是在/dev/mapper/vgtest-lvtest
.
(1) 取消挂载
umount /mnt/
(2) 删除LV
lvremove /dev/vgtest/lvtest
(3) 删除VG (必须先删除该VG的所有LV)
vgremove vgtest
(4) 删除物理卷 (必须先删除该物理卷相关的所有VG)
pvremove /dev/sdb
逻辑卷的伸缩可以在线执行, 不需要卸载(unmount)逻辑卷
(1) 保证该LV (lvtest) 所在的VG (vgtest) 中有足够的空闲空间
[root@localhost mnt]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- 47.45g
root centos -wi-ao---- 50.00g
swap centos -wi-ao---- 2.00g
lvtest vgtest -wi-ao---- 2.00g
[root@localhost mnt]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- 99.51g 64.00m
vgtest 2 1 0 wz--n- 14.99g 12.99g
(2) 扩充逻辑卷
[root@localhost mnt]# lvextend -L +1G /dev/vgtest/lvtest
Size of logical volume vgtest/lvtest changed from 2.00 GiB (512 extents) to 3.00 GiB (768 extents).
Logical volume lvtest successfully resized.
(3) 查看扩充后的LV大小
[root@localhost mnt]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- 47.45g
root centos -wi-ao---- 50.00g
swap centos -wi-ao---- 2.00g
lvtest vgtest -wi-ao---- 3.00g
(4) 更新文件系统
[root@localhost mnt]# resize2fs /dev/vgtest/lvtest
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vgtest/lvtest is mounted on /mnt; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vgtest/lvtest is now 786432 blocks long.
(5) 查看更新后的文件系统
[root@localhost mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
......
/dev/mapper/vgtest-lvtest 2.9G 6.0M 2.8G 1% /mnt
可以看到, 文件系统的大小已经被更新 (resize2fs
之前这里还是2G).
(1) 将要添加到VG的硬盘格式化为PV
pvcreate /dev/sdd
(2) 将新的PV添加到指定的卷组中
vgextend vgtest /dev/sdd
场景: 拿走一块硬盘. (linuxcast在这里是卷组名)
pvremove