centos7虛擬機擴容

 

將虛擬機設置爲更大硬盤空間以後,內部還須要再設置一下

一、首先確認當前各文件系統大小,能夠看到根目錄對應文件系統大小是10GB,/boot對應文件系統大小是0.4GB。

df -h
vgdisplay
vgdisplay -v centos

二、確認當前磁盤容量信息,/dev/sda大小爲53.7GB,劃分了2個分區,已劃分的總容量不到20GB。還有將近30GB可用空間

fdisk -l

 

三、在未用空間建立新的分區sda3。(很重要)

主要輸入:n   p   w,其餘的就默認就好centos

[root@backup03 ~]# fdisk /dev/sdaCommand (m for help): n
​
Select (default p): p
​
Partition number (3,4, default 3): 
​
First sector (25593856-104857599, default 25593856): 
​
Using default value 25593856
​
Last sector, +sectors or +size{K,M,G} (25593856-104857599, default 104857599): 
​
Using default value 104857599
​
Partition 3 of type Linux and of size 37.8 GiB is set
​
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.

 

四、根據上面步驟的提示,須要重啓或者運行命令partprobe從新同步磁盤分區信息,分區從新識別後能夠看到新分區sda3。

[root@backup03 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

 

五、使用lvm命令pvcreate格式化sda3分區。

[root@backup03 ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
[root@backup03 ~]# pvdisplay

 


六、將分區sda3加入root所在的vg(centos)裏 。

[root@backup03 ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended
[root@backup03 ~]# vgdisplay -v centos

 

七、擴展root根分區所在的邏輯卷大小,vgdisplay能夠看到root所在lv大小已經發生變化。

這裏37G要按照實際狀況來。固然也能夠不掛在/dev/centos/root,有些是掛在/dev/centos/home裏面的。ide

lvextend -L +37G /dev/centos/root
vgdisplay -v

 

八、根目錄大小依然沒變化

df -h 

 

9,確認root文件系統的類型是xfs後,使用xfs_growfs命令擴展根目錄大小。

mount

 

10,使用xfs_growfs命令擴展根目錄大小

xfs_growfs /dev/centos/root

 

11,最後使用df命令,確認根目錄大小已經從原來的10GB擴展爲40GB。

df -h
相關文章
相關標籤/搜索