目錄
1、通過VirtualBox6.0.4內置命令擴展磁盤的最大空間
一、寫在前面
在實際工作中,我們會經常用到虛擬機去搭建環境。但是也會出現前期資源方面考慮不周的情況,導致後期需要擴展資源。這裏我們講解一下怎麼在VirtualBox6.0.4中擴展磁盤的空間
二、環境介紹
OS:win10
虛擬機:VirtualBox6.0.4
Linux:CentOS7.3
三、操作步驟
1、通過VirtualBox6.0.4內置命令擴展磁盤的最大空間
例如我這裏原來是100GB。如下圖所示:
這裏我們將這個最大可用100GB擴展到120GB。
首先,我們進入到VirtualBox安裝目錄。執行如下命令:
VBoxManage modifyhd “E:\VirtualBox\Linux-init\Linux-init.vdi” –-resize 122880
執行效果如下圖所示:
此時,我們再看VirtualBox的效果,如下圖所示:
2、通過gparted工具將剩餘的20GB空間進行格式化
軟件下載鏈接:
掛載鏡像
開機
這裏直接回車
這裏直接回車
這裏選擇中文,26
這裏選擇 0
等待出現如下圖所示界面:
選擇更改大小,如下圖所示:
鼠標拖拽上圖所示的位置,拖到最右邊。如下圖所示:
確認調整大小。
應用全部操作
確定
quit退出軟件
等待執行關機完畢(過程中需要回車一次)!
再次開啓虛擬機,通過xshell工具連接虛擬機。執行下面的命令:
從上圖我們可以看到分配的20GB並沒有變成可用。因爲還需要掛載!
3、掛載
[root@Linux-init ~]# df -h
文件系統 容量 已用 可用 已用% 掛載點
/dev/mapper/cl-root 97G 1.5G 95G 2% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 1014M 140M 875M 14% /boot
tmpfs 100M 0 100M 0% /run/user/0
[root@Linux-init ~]# vgs
VG #PV #LV #SN Attr VSize VFree
cl 1 2 0 wz--n- 119.00g 22.00g
[root@Linux-init ~]# lvextend -L +20G /dev/cl/
/dev/cl/root /dev/cl/swap
[root@Linux-init ~]# lvextend -L +20G /dev/cl/root
Size of logical volume cl/root changed from 96.20 GiB (24626 extents) to 116.20 GiB (29746 extents).
Logical volume cl/root successfully resized.
[root@Linux-init ~]# resize2fs /dev/
Display all 149 possibilities? (y or n)
[root@Linux-init ~]# resize2fs /dev/mapper/cl-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block 當嘗試打開 /dev/mapper/cl-root 時
找不到有效的文件系統超級塊.
[root@Linux-init ~]# xfs_growfs /dev/mapper/c
cl-root cl-swap control
[root@Linux-init ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root isize=512 agcount=63, agsize=406016 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=25217024, 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 25217024 to 30459904
[root@Linux-init ~]# df -h
文件系統 容量 已用 可用 已用% 掛載點
/dev/mapper/cl-root 117G 1.5G 115G 2% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 1014M 140M 875M 14% /boot
tmpfs 100M 0 100M 0% /run/user/0
上述執行命令的過程有遇到
報錯:resize2fs: Bad magic number in super-block 當嘗試打開 /dev/mapper/cl-root 時
找不到有效的文件系統超級塊.
這裏我們將命令換成:xfs_growfs /dev/mapper/cl-root即可
執行上述命令操作之後,我們可以看到如下圖所示的效果:
此時,根目錄空間已經擴展到115G了!