一、硬盤分區擴容
1、查看擴容之前分區(硬盤)大小
可以看到掛載點 “/” 的利用率達到100%,空間不夠,所以要對其進行擴容分區。
2、對虛擬機配置進行增大磁盤空間
3、登錄虛擬機,再次查看虛擬機硬盤大小
4、硬盤分區
[root@localhost ~]# fdisk /dev/sda ///新增分區
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。
命令(輸入 m 獲取幫助):n ///添加一個分區
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p ///新建主分區
分區號 (3,4,默認 3):
起始 扇區 (41943040-104857599,默認爲 41943040):
將使用默認值 41943040
Last 扇區, +扇區 or +size{K,M,G} (41943040-104857599,默認爲 104857599):
將使用默認值 104857599
分區 3 已設置爲 Linux 類型,大小設爲 30 GiB
命令(輸入 m 獲取幫助):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)
正在同步磁盤。
5、 創建物理卷
[root@localhost ~]# pvcreate /dev/sda3 ///如果提示sda3找不到,輸入:partprobe或者重啓虛擬機
Device /dev/sda3 not found.
[root@localhost ~]# partprobe
Warning: 無法以讀寫方式打開 /dev/sr0 (只讀文件系統)。/dev/sr0 已按照只讀方式打開。
[root@localhost ~]# pvcreate /dev/sda3 ///再次創建成功
Physical volume "/dev/sda3" successfully created.
6、 查詢物理卷
可以查到本機物理卷名稱爲"centos"
[root@localhost ~]# vgscan
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2
7、使用新增物理卷擴展"centos"
[root@localhost ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
8、擴展lv
命令:lvextend -L +29G
(硬盤擴容30G,這裏-1G) 加上要擴展的分區名
[root@localhost ~]# lvextend -L +29G /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <46.00 GiB (11775 extents).
Logical volume centos/root successfully resized.
接着用 dh –f
,發現實際容量並沒有變化,因爲我們的系統還不認識剛剛添加進來的磁盤的文件系統,所以還需要對文件系統進行擴容
9、對文件系統進行擴容
xfs_growfs
:加上要擴展的分區名
或者resize2fs – f
:加上要擴展的分區名
[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, 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 4455424 to 12057600
10、再次查看分區大小
[root@localhost ~]# df -h
文件系統 容量 已用 可用 已用% 掛載點
/dev/mapper/centos-root 46G 4.4G 42G 10% /
devtmpfs 894M 0 894M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 11M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 182M 12K 182M 1% /run/user/42
tmpfs 182M 0 182M 0% /run/user/0
二、解決 VMware 虛擬機環境佔用宿主機磁盤空間越來越大的問題
三、虛擬機硬盤與宿主機磁盤的關係
查看VM ware 虛擬機硬盤大小
切換到windows中,可以看到 Centos7-3
文件夾(也就是192.168.182.13
虛擬機的虛擬硬盤)的大小爲4.57G
而Centos7-3
所處的文件夾即G盤根目錄的大小爲59G,可以看到G盤已經接近飽和了,此時運行虛擬機再安裝軟件的時候,就會報錯
這正是因爲虛擬機所在的宿主機盤符已滿導致的
這時就可以看到,虛擬機的硬盤大小設置爲了50G,實際只用了4.57G,爲什麼就不能運行了呢?
原因就是虛擬機硬盤與宿主機磁盤的關係是下面這樣的:
-
虛擬機設置的硬盤大小(如50G)指的是虛擬機最大佔用內存爲50G;
-
虛擬機實際佔用內存爲多大也就是相應的文件夾有多大(4.57G);
-
如果虛擬機所在的宿主機盤符只有50G,那麼虛擬機最多能佔用50G的內存;