Linux下擴展根分區-非LVM
在將workstation虛擬機導入至vsphere esxi 6.7 過程中因**/**根分區只有幾百兆了,因此需要對根分區進行擴容,本文是在參考如下博文https://www.cnblogs.com/youngchaolin/p/11478740.html
另外虛擬機爲workstation版本,在導入Vsphere Esxi過程中存在以下問題:
1.原虛擬機vmx文件版本不兼容,需查看現有Vsphere環境虛擬機vmx文件版本,並將原VM的vmx文件修改後上傳
2.原虛擬機vmdk磁盤文件在上傳至Vsphere Esxi後需使用vmfstools工具轉換後方可使用(參考文章:https://blog.csdn.net/weixin_34185364/article/details/92690553)
- 成功測試系統爲:
- Centos7.6,根分區文件類型爲xfs
- Ubuntu18.04,根分區文件類型爲ext4(Vsphere Esxi6.7虛擬機環境)
(1) 可以看出sda3是根分區,下面按照博客提示,先刪除sda3根分區,然後重新創建sda3根分區,具體參考註釋。
複製代碼
1 [root@node03 ~]# fdisk /dev/sda
2 Welcome to fdisk (util-linux 2.23.2).
3
4 Changes will remain in memory only, until you decide to write them.
5 Be careful before using the write command.
6
7
8 Command (m for help): m
9 Command action
10 a toggle a bootable flag
11 b edit bsd disklabel
12 c toggle the dos compatibility flag
13 d delete a partition
14 g create a new empty GPT partition table
15 G create an IRIX (SGI) partition table
16 l list known partition types
17 m print this menu
18 n add a new partition
19 o create a new empty DOS partition table
20 p print the partition table
21 q quit without saving changes
22 s create a new empty Sun disklabel
23 t change a partition's system id
24 u change display/entry units
25 v verify the partition table
26 w write table to disk and exit
27 x extra functionality (experts only)
28
29 Command (m for help): d ##刪除分區
30 Partition number (1-3, default 3): 3 ##臨時先刪除sda3分區
31 Partition 3 is deleted
32
33 Command (m for help): n #添加一個新的分區
34 Partition type:
35 p primary (2 primary, 0 extended, 2 free)
36 e extended
37 Select (default p): p #添加主分區
38 Partition number (3,4, default 3): 3 #指定分區號3,重新創建sda3分區
39 First sector (17303552-104857599, default 17303552): #回車
40 Using default value 17303552
41 Last sector, +sectors or +size{K,M,G} (17303552-104857599, default 104857599): #回車
42 Using default value 104857599
43 Partition 3 of type Linux and of size 41.8 GiB is set #提示OK
44
45 Command (m for help): w #按w保存退出
46 The partition table has been altered! #提示OK
複製代碼
(2)重啓系統
重啓當前系統,可以選擇systemctl reboot或者init 6來執行。
(3)擴容文件系統,使用命令 xfs_growfs /dev/sda3,可以看到成功擴展分區,根分區已擴容20G。
複製代碼
1 [root@node03 ~]# xfs_growfs /dev/sda3
2 meta-data=/dev/sda3 isize=512 agcount=8, agsize=769984 blks
3 = sectsz=512 attr=2, projid32bit=1
4 = crc=1 finobt=0 spinodes=0
5 data = bsize=4096 blocks=5701376, imaxpct=25
6 = sunit=0 swidth=0 blks
7 naming =version 2 bsize=4096 ascii-ci=0 ftype=1
8 log =internal bsize=4096 blocks=2560, version=2
9 = sectsz=512 sunit=0 blks, lazy-count=1
10 realtime =none extsz=4096 blocks=0, rtextents=0
11 data blocks changed from 5701376 to 10944256
12 [root@node03 ~]# df -h
13 Filesystem Size Used Avail Use% Mounted on
14 /dev/sda3 42G 11G 32G 25% /
15 devtmpfs 2.9G 0 2.9G 0% /dev
16 tmpfs 3.0G 0 3.0G 0% /dev/shm
17 tmpfs 3.0G 13M 2.9G 1% /run
18 tmpfs 3.0G 0 3.0G 0% /sys/fs/cgroup
19 /dev/sda1 253M 153M 101M 61% /boot
20 tmpfs 595M 8.0K 595M 1% /run/user/990
21 tmpfs 595M 0 595M 0% /run/user/0
22 You have new mail in /var/spool/mail/root