系統(tǒng)盤擴容 擴展分區(qū)與文件系統(tǒng)_Linux系統(tǒng)盤
創(chuàng)建時間:2019年6月3日(星期一) 下午5:16|?分類:未分類
?| 字數(shù):4341??|?另存為...?|?打印?|?添加到日歷

擴展分區(qū)與文件系統(tǒng)_Linux系統(tǒng)盤??https://help.aliyun.com/document_detail/111738.html?spm=a2c4g.11186623.6.771.356d77eeyzuN5K#h2-url-2
本文提供了如何使用growpart和resize2fs工具完成Linux系統(tǒng)盤分區(qū)擴容及文件系統(tǒng)擴展的操作指導(dǎo)。
適用范圍
本文的操作步驟適用于以下分區(qū)和文件系統(tǒng)格式的云盤:
分區(qū)格式支持:mbr、gpt
文件系統(tǒng)支持:ext、xfs、btrfs、ufs
準備工作
通過ECS控制臺或者API擴容云盤。
創(chuàng)建快照以備份數(shù)據(jù)。
實例已處于運行中狀態(tài)。連接方式請參見連接方式導(dǎo)航。
根據(jù)操作系統(tǒng)安裝growpart擴容格式化工具。
CentOS 7、Aliyun Linux:
yuminstallcloud-utils-growpart
Ubuntu 14、Ubuntu 16、Ubuntu 18、Debian 9:
aptinstallcloud-guest-utils
Debian 8、OpenSUSE 42.3、OpenSUSE 13.1、SUSE Linux Enterprise Server 12 SP2:請使用上游版本(upstream)的growpart工具
檢查實例的內(nèi)核版本,如通過uname -a查看內(nèi)核版本。
內(nèi)核版本大于3.6.0,則無需重啟reboot便能完成擴容分區(qū)和文件系統(tǒng)。該情況請參見高內(nèi)核版本的操作步驟。
內(nèi)核版本小于3.6.0,如CentOS 6、Debian 7和SUSE Linux Enterprise Server 11 SP4等發(fā)行版,需要經(jīng)過一次重啟reboot才能完成分區(qū)擴容。該情況請參見低內(nèi)核版本的操作步驟。
高內(nèi)核版本的操作步驟
此處以CentOS 7操作系統(tǒng)為例演示分區(qū)擴展的步驟。
運行fdisk -l查看現(xiàn)有磁盤大小。示例返回磁盤(/dev/vda)容量是100 GiB。
[root@localhost ~]# fdisk -lDisk /dev/vda:107.4GB,107374182400bytes,209715200sectorsUnits = sectors of1*512=512bytesSector size (logical/physical):512bytes /512bytesI/O size (minimum/optimal):512bytes /512bytesDisk label type: dosDisk identifier:0x0008d73aDevice Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System/dev/vda1? *2048419430392097049683Linux
運行df -h查看磁盤分區(qū)大小。示例返回分區(qū)容量(/dev/vda1)是20 GiB。
[root@localhost ~]# df -hFilesystem? ? ? Size? Used Avail Use% Mounted on/dev/vda120G1.5G18G8% /devtmpfs7.8G07.8G0% /devtmpfs7.8G07.8G0% /dev/shmtmpfs7.8G344K7.8G1% /runtmpfs7.8G07.8G0% /sys/fs/cgrouptmpfs1.6G01.6G0% /run/user/0
運行g(shù)rowpart<DeviceName>?<PartionNumber>調(diào)用growpart為需要擴容的磁盤和對應(yīng)的第幾個分區(qū)擴容。示例命令表示為系統(tǒng)盤的第一個分區(qū)擴容。
[root@localhost ~]# growpart /dev/vda 1CHANGED:partition=1start=2048 old:size=41940992end=41943040 new:size=209710462,end=209712510
運行resize2fs<PartitionName>調(diào)用resize2fs擴容文件系統(tǒng)。示例命令表示為系統(tǒng)盤的/dev/vda1分區(qū)擴容文件系統(tǒng)。
[root@localhost ~]# resize2fs /dev/vda1resize2fs1.42.9(28-Dec-2013)Filesystem at /dev/vda1ismounted on /; on-line resizing requiredold_desc_blocks =2, new_desc_blocks =7The filesystem on /dev/vda1isnow26213807blocks long.
運行df -h查看磁盤分區(qū)大小。返回分區(qū)(/dev/vda1)是100 GiB,表示已經(jīng)成功擴容。
[root@localhost ~]# df -hFilesystem? ? ? Size? Used Avail Use% Mounted on/dev/vda199G1.6G93G2% /devtmpfs7.8G07.8G0% /devtmpfs7.8G07.8G0% /dev/shmtmpfs7.8G500K7.8G1% /runtmpfs7.8G07.8G0% /sys/fs/cgrouptmpfs1.6G01.6G0% /run/user/0
低內(nèi)核版本的操作步驟
此處以CentOS 6操作系統(tǒng)為例演示分區(qū)擴展的步驟。
安裝dracut-modules-growroot工具。
[root@AliYunOS~]# yum install -y dracut-modules-growroot
如果您使用的是其他軟件包管理器,請將yum修改為對應(yīng)的命令。
覆蓋已有的initramfs文件。
[root@AliYunOS~]# dracut -f
運行fdisk -l查看現(xiàn)有磁盤大小。示例返回磁盤(/dev/vda)容量是100 GiB。
[root@AliYunOS ~]# fdisk -lDisk /dev/vda:107.4GB,107374182400bytes255heads,63sectors/track,13054cylindersUnits = cylinders of16065*512=8225280bytesSector size (logical/physical):512bytes /512bytesI/O size (minimum/optimal):512bytes /512bytesDisk identifier:0x0003a7b4Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System/dev/vda1? *126112097049683Linux
運行df -h查看磁盤分區(qū)大小。示例返回分區(qū)容量(/dev/vda1)是20 GiB。
[root@AliYunOS ~]# df -hFilesystem? ? ? Size? Used Avail Use% Mounted on/dev/vda120G1.1G18G6% /tmpfs7.8G07.8G0% /dev/shm
運行g(shù)rowpart<DeviceName><PartionNumber>調(diào)用growpart為需要擴容的磁盤和對應(yīng)的第幾個分區(qū)擴容。示例命令表示為系統(tǒng)盤的第一個分區(qū)擴容。
[root@AliYunOS ~]# growpart /dev/vda 1CHANGED:partition=1start=2048 old:size=41940992end=41943040 new:size=209710462,end=209712510
重啟實例。
[root@AliYunOS~]# reboot
再次遠程連接實例。
運行resize2fs<PartitionName>調(diào)用resize2fs擴容文件系統(tǒng)。示例命令表示為系統(tǒng)盤的/dev/vda1分區(qū)擴容文件系統(tǒng)。
[root@AliYunOS ~]# resize2fs /dev/vda1resize2fs1.41.12(17-May-2010)Filesystemat/dev/vda1ismountedon/;on-line resizing requiredold desc_blocks =2, new_desc_blocks =7Performing anon-line resizeof/dev/vda1to26213807(4k) blocks.The filesystemon/dev/vda1isnow26213807blocks long.
運行df -h查看磁盤分區(qū)大小。返回分區(qū)(/dev/vda1)是100 GiB,表示已經(jīng)成功擴容。
[root@AliYunOS ~]# df -hFilesystem? ? ? Size? Used Avail Use% Mounted on/dev/vda199G1.1G93G2% /tmpfs7.8G07.8G0% /dev/shm
need-to-insert-img