Linux-標準分區_數據盤擴容

【以下操作僅適用於雲服務器且未做磁盤陣列】

操作系統爲CentOS 7.3 64位,未擴容前的數據盤僅有一個主分區(/dev/vdb1,ext4文件系統),文件系統的掛載點爲 /data,文件系統擴容完成後,數據盤仍然只有一個主分區。
1.遠程連接實例。
2.運行 umount 命令卸載主分區。
umount /dev/vdb1
#說明 使用 df -h 查看是否卸載成功,如果看不到 /dev/vdb1 的信息表示卸載成功

df -h

使用 fdisk 命令刪除原來的分區並創建新分區:
fdisk -l 羅列分區信息並記錄擴容前數據盤的最終容量、起始扇區(First sector)位置。
運行命令 fdisk [數據盤設備名] 進入 fdisk 界面。本示例中,命令爲 fdisk /dev/vdb。
輸入 d 並按回車鍵,刪除原來的分區。
###說明 刪除分區不會造成數據盤內數據的丟失。
輸入 n 並按回車鍵,開始創建新的分區。
輸入 p 並按回車鍵,選擇創建主分區。因爲創建的是一個單分區數據盤,所以只需要創建主分區。
輸入第一個可用的扇區編號:爲了保證數據的一致性,按回車鍵採用默認值。
注:如果發現First sector顯示的位置和之前記錄的不一致,說明之前可能使用 parted 來分區,那麼就停止當前的 fdisk 操作,使用 parted 重新操作。
輸入最後一個扇區編號:因爲這裏僅創建一個分區,所以按回車鍵採用默認值。
輸入 wq 並按回車鍵,開始分區。
[root@VM_0_3_centos ~]# fdisk /dev/vdb
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): d
Selected partition 1
Partition 1 is deleted
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-62914559, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
Using default value 62914559
Partition 1 of type Linux and of size 30 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
注:部分操作系統裏,修改分區後可能會重新自動掛載文件系統。建議先執行 df -h 重新查看文件系統空間和使用情況。如果文件系統重新被掛載,執行 umount [文件系統名稱] 再次卸載文件系統。
檢查文件系統,並變更文件系統大小。
[root@VM_0_3_centos ~]##e2fsck -f /dev/vdb1 # 檢查文件系統
[root@VM_0_3_centos ~]##resize2fs /dev/vdb1 # 變更文件系統大小
說明
使用 e2fsck 時,由於系統需要檢查並訂正文件系統元數據,所以速度較慢、耗時較長,請耐心等待。
正確使用 e2fsck 和 resize2fs 指令,不會造成原有數據丟失。
以下爲示例輸出結果。
[root@VM_0_3_centos ~]## e2fsck -f /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 11/1835008 files (0.0% non-contiguous), 159218/7339776 blocks
[root@VM_0_3_centos ~]## resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 7864064 (4k) blocks.
The filesystem on /dev/vdb1 is now 7864064 blocks long.
將擴容完成的文件系統掛載到原來的掛載點

#mount /dev/vdb1 /data
查看文件系統空間和使用情況:運行命令 df -h。如果出現擴容後的文件系統信息,說明掛載成功,可以使用擴容後的文件系統了。

注:掛載操作完成後,不需要在控制檯上重啓實例即可開始使用擴容後的文件系統。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章