CentOS7.3 ARM虛擬機擴容系統磁盤

 

因爲擴容磁盤的操做非同小可,一旦哪一步出現問題,就會致使分區損壞,數據丟失等一系列嚴重的問題,所以建議:在進行虛擬機分區擴容以前,必定要備份重要數據文件,而且先在測試機上驗證如下步驟,再應用於您的生產機器。若是虛擬機的磁盤不夠用了,建議附加新磁盤進行使用,不到萬不得已通常不要擴容磁盤分區。linux

 

操做系統環境:ide

[root@hlmc73t ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)測試

 

1.關閉虛擬機spa

備註:擴容磁盤須要關閉虛擬機,不然沒法調整磁盤的大小操作系統

 

2.調整磁盤的大小(示例中將原來的30GB調整爲了150GB)code

 

 

3.等待跟新完成,啓動虛擬機,查看到整塊磁盤已經變爲150G,但/dev/sda2分區仍是30Gblog

 

 

4.使用命令:fdisk /dev/sda,從新劃分分區/dev/sda2ci

[root@hlmc73t ~]# fdisk -l /dev/sda Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c1fec Device Boot Start End Blocks Id System /dev/sda1   *        2048     1026047      512000   83 Linux /dev/sda2         1026048    62914559    30944256   83 Linux [root@hlmc73t ~]# clear [root@hlmc73t ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p ##查看目前的分區信息 Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c1fec Device Boot Start End Blocks Id System /dev/sda1   *        2048     1026047      512000   83 Linux /dev/sda2         1026048    62914559    30944256   83 Linux Command (m for help): d ##將原來的/dev/sda2分區刪除 Partition number (1,2, default 2): 2 Partition 2 is deleted Command (m for help): p Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c1fec Device Boot Start End Blocks Id System /dev/sda1   *        2048     1026047      512000   83 Linux Command (m for help): n ##從新建立分區 Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): 2 First sector (1026048-314572799, default 1026048): ##該值須要與上述標黃的start值相同 Using default value 1026048 Last sector, +sectors or +size{K,M,G} (1026048-314572799, default 314572799): Using default value 314572799 Partition 2 of type Linux and of size 149.5 GiB is set Command (m for help): p Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c1fec Device Boot Start End Blocks Id System /dev/sda1   *        2048     1026047      512000   83 Linux /dev/sda2         1026048   314572799   156773376   83 Linux 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.

 

5.使用fdisk –l查看/dev/sda2已經變爲了150G,但使用df –h查看/dev/sda2仍是30Grem

 

6.此時拉伸文件系統的話,輸出信息相似以下,拉伸沒有生效。須要重啓電腦以便重讀分區表後,才能成功拉伸文件系統。備註:可使用「blkid」命令查看分區的文件系統虛擬機

 

7.重啓電腦後,從新使用命令:xfs_growfs,拉伸文件系統,能夠看到成功拉伸文件系統

 

 

8.從新查看,發現/dev/sda2成功拉伸爲了150G,而且以前的數據文件仍然存在並可正常使用。

 

相關文章
相關標籤/搜索