今天正在做一个实验,突然发现根目录满了,把这个过程记录下来(当初创建的时候给根目录分配的磁盘太小了.ahhhhh)
先关闭虚拟机电源,做如下设置:“ 虚拟机”–“虚拟机设置”–“磁盘”–“扩展
- 这是目前的磁盘情况
- 我查看了一下磁盘/dev/sda还有空余的空间
- 这种情况下,我只需要扩展vg的容量,然后给lv扩容即可,首先进行/dev/sda的磁盘分区,记得把新分的区改成8e
[root@centos7 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1306-1958, default 1306): +1306
Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): +1958
Value out of range.
Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958):
Using default value 1958
Command (m for help): p
Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
/dev/sda3 1306 1958 5245222+ 83 Linux
Command (m for help): t
Partition number (1,2, default 2): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
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: Device or resource busy.
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.
[root@centos7 ~]# partprobe /dev/sda #使kernel重新读取分区 信息,从而避免重启系统。
- 再次查看,发现已经分区了一块5G大小的空间
- 创建pv
[root@centos7 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
- 扩展vg,首先先查看一下vg的信息,以免出错
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- 12.00g 4.00m
[root@centos7 ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 3 0 wz--n- 17.00g 5.00g
- 扩展lv,让lv的大小增加5G
[root@centos7 ~]# lvextend -L +5G /dev/mapper/centos-root
Size of logical volume centos/root changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents).
Logical volume centos/root successfully resized.
[root@centos7 ~]# xfs_growfs /dev/mapper/centos-root # 命令使系统重新读取大小
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1310720 to 2621440
- 查看效果,根目录已经扩容
[root@centos7 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
app centos -wi-ao---- 5.00g
root centos -wi-ao---- 10.00g
swap centos -wi-ao---- 2.00g
[root@centos7 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 10G 4.6G 5.4G 46% /
devtmpfs 471M 0 471M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 21M 467M 5% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/mapper/centos-app 5.0G 33M 5.0G 1% /app
/dev/sda1 97M 60M 38M 62% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
版权声明:本文为JAVA_LuZiMaKei原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。