背景为Linux虚拟机添加一块150G磁盘并把空间添加到/opt目录。添加磁盘过程略过不讲
1、执行”fdsik -l“来验证是否添加成功。并用fdisk来对新添加的硬盘进行分区。如下图:
2.创建好分区后,执行命令partprone同步一下
[[email protected] ~]# partprobe
3.执行命令pvcreate /dev/sdb1在分区/dev/sdb1 上创建物理卷。
[[email protected] ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
- 执行命令pvs查看当前物理卷,当然也可以用pvdisplay命令来查看。
[[email protected] ~]# pvs
/dev/hdc: open failed: PV VG Fmt Attr PSize PFree
/dev/sda2 vg00 lvm2 a- 99.88G 0 --------------
/dev/sdb1 lvm2 a- 150.00G 150.00G - 执行命令lvs查看/home目录所在逻辑卷所属的卷组名称
[[email protected] ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv01 vg00 -wi-ao 4.00G
lv02 vg00 -wi-ao 7.81G
lv03 vg00 -wi-ao 2.00G
lv04 vg00 -wi-ao 10.00G
lv05 vg00 -wi-ao 4.00G
lv07 vg00 -wi-ao 72.06G ------------可以看到所有的分区都是在vg00的卷组下面 - 执行命令vgextend vg00 /dev/sdb1, 把新创建的物理卷/dev/sdb1添加到该卷组中
[[email protected] ~]# vgextend vg00 /dev/sdb1
Volume group "vg00" successfully extended - 执行命令lvextend将逻辑卷/opt增大100G
[[email protected] ~]# lvextend -L +100G /dev/mapper/vg00-lv07
Extending logical volume lv07 to 172.06 GB
Logical volume lv07 successfully resized
8.执行命令resize2fs 同步一下
[[email protected] ~]# resize2fs /dev/mapper/vg00-lv07
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/vg00-lv07 is mounted on /opt; on-line resizing required
Performing an on-line resize of /dev/mapper/vg00-lv07 to 45105152 (4k) blocks.
The filesystem on /dev/mapper/vg00-lv07 is now 45105152 blocks long.
9.df -h查看/opt目录空间是否增大
[[email protected] ~]# df -h
?? % /dev/mapper/vg00-lv01
3.9G 1.7G 2.1G 44% /
/dev/mapper/vg00-lv03
2.0G 246M 1.6G 14% /home
/dev/mapper/vg00-lv04
9.7G 5.8G 3.5G 63% /usr
/dev/mapper/vg00-lv07
167G 46G 113G 29% /opt
/dev/mapper/vg00-lv05
3.9G 2.9G 872M 77% /var
/dev/sda1 99M 13M 81M 14% /boot
tmpfs 7.9G 0 7.9G 0% /dev/shm
原文地址:http://blog.51cto.com/11381091/2091234
时间: 2024-10-19 11:20:49