Linux 虚拟机/根目录空间满解决办法

一、背景

很多时候虚拟机安装的时候会分配的磁盘空间比较小,当根目录空间满就很头疼,下面这个办法。

二、解决办法

在虚拟机控制端先给虚拟机扩容,就是给原来的盘符扩容,然后执行以下步骤。

1、当/目录空间可用空间为0时,不能通过apt install 安装gparted

解决步骤:
a.除/目录下一些没有用的文件.
b.重新挂载/目录
#mount -o remount,rw /
c.df -h查看挂载分区磁盘使用情况,/目录有一定余量。
d.安装gparted
#sudo apt-get install gparted
e.重新分区
#gparted /dev/vda

2、当/目录空间可用空间不为0,可以通过apt install 安装gparted
a.安装gparted
#sudo apt-get install gparted
b.重新分区
#gparted /dev/vda

server版需要重启下才能正常使用gpartedgparted其实就是将pvvg扩容,gparted是如何实现的呢?。

# 配置对应盘符大小为240G,lsblk可以看到vda的容量
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0              11:0    1  1024M  0 rom
vda             252:0    0   240G  0 disk
├─vda2          252:2    0     1G  0 part /boot
├─vda3          252:3    0 118.8G  0 part
│ ├─centos-swap 253:1    0     8G  0 lvm  [SWAP]
│ ├─centos-home 253:2    0  60.8G  0 lvm  /home
│ └─centos-root 253:0    0    50G  0 lvm  /
└─vda1          252:1    0   200M  0 part /boot/efi
[root@localhost ~]# gpated /dev/vda
[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda3
  VG Name               centos
  PV Size               118.80 GiB / not usable 0
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              30413
  Free PE               0
  Allocated PE          30413
  PV UUID               xdHgua-1rqG-07Ey-S3OT-FS6b-zhoS-xvCBzx
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  10
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               238.80 GiB
  PE Size               4.00 MiB
  Total PE              61133
  Alloc PE / Size       30413 / 118.80 GiB
  Free  PE / Size       30720 / 120.00 GiB
  VG UUID               NPjeQK-R3Z3-kx3K-AgPD-UWSE-ind4-v4551N

gpated提示信息The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)?,直接点击fix就行了,做GPT表的移动备份。

pvvg扩容之后,只需要将对应的逻辑卷扩容就行了,查看所有逻辑卷信息lvdisplay,我这里根分区对应的LV paht/dev/centos/root

[root@localhost ~]# lvextend -r -l +100%FREE /dev/centos/root
  Size of logical volume centos/root changed from 50.00 GiB (12801 extents) to 170.00 GiB (43521 extents).
  Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=512    agcount=5, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13108224, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13108224 to 44565504
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0              11:0    1  1024M  0 rom
vda             252:0    0   240G  0 disk
├─vda2          252:2    0     1G  0 part /boot
├─vda3          252:3    0 238.8G  0 part
│ ├─centos-swap 253:1    0     8G  0 lvm  [SWAP]
│ ├─centos-home 253:2    0  60.8G  0 lvm  /home
│ └─centos-root 253:0    0   170G  0 lvm  /
└─vda1          252:1    0   200M  0 part /boot/efi
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐