https://www.cnblogs.com/emanlee/p/13927972.html
1. 关闭虚拟机
2. 编辑虚拟机设置:增加硬盘的置备大小,或者添加新的硬盘
3. 启动虚拟机,查看可用磁盘大小,root用户登录 然后init 1,进入单用户模式。
# df -Th
此时为未扩容前:20G,目标扩容挂载在根目录的/dev/mapper/VolGroup-lv_root 逻辑卷。
4. 查看分区信息:
# fdisk -l
磁盘/dev/sda已有两个分区sda1、sda2, sda3。
5. 接下来要新建分区sda3:
# fdisk /dev/sda
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 4 (根据前面已经有的来设置;有三个设置为4,有两个设置为3)
First cylinder (2611-5221, default 2611): 回车默认
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-5221, default 5221): 回车默认
Using default value 5221
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
6. 尝试 partprobe 命令更新分区,若失败,则 reboot。
[root@localhost ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
reboot,重新启动系统,然后init 1,同样进入单用户模式。
执行“fdisk -l /dev/sda”
7. 创建pv(物理卷):
# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created
8. 查看vg(卷组),确认需要扩展的vg:
# vgdisplay
No volume groups found
查看物理卷:
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda4 lvm2 a-- 5.00g 5.00g
查看逻辑卷:
# lvdisplay
No volume groups found
查看卷组:
# vgs
No volume groups found
创建卷组、逻辑卷
创建卷组:
# vgcreate vgdata /dev/sda4 ##vgdata为卷组名
Volume group "vgdata" successfully created
查看创建结果
# vgs
VG #PV #LV #SN Attr VSize VFree
vgdata 1 0 0 wz--n- 4.99g 4.99g
# vgdisplay
No volume groups found
创建逻辑卷:
# lvcreate -L19.9G vgdata -n lvolhome /dev/sda4
查看结果:
# lvdisplay
No volume groups found
格式化磁盘:
# mkfs.ext4 /dev/sda4
mke2fs 1.41.12 (17-May-2010)
/dev/sda4 is apparently in use by the system; will not make a filesystem here!
解决方法如下:
------------
# cat /proc/partitions
major minor #blocks name
253 0 5253223 dm-0
253 1 2104515 dm-1
从上面可以看到dm工具确实在用。
# dmsetup status
sdb3: 0 6313545 linear
sdb2: 0 4209030 linear
# dmsetup remove_all
# dmsetup status
No devices found
------------
再次执行 mkfs.ext4 /dev/sda4
mkdir /home/soft_sda4
mount /dev/sda4 /home/soft_sda4
12. df -Th 确认扩容成功
# df -Th
参考:
https://www.jianshu.com/p/94ab4588d77c
https://blog.csdn.net/ddshang/article/details/53436757
标签:CentOS,虚拟机,dev,volume,sda4,根目录,found,table From: https://www.cnblogs.com/wcxia1985/p/17201472.html