非LVM意思是底層分區是物理分區不是通過lvm管理的邏輯卷。
問題是這樣的:
使用中突然發現根分區空間不足,結果發現分區配成下面這樣:
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 1024M 0 rom
vda 253:0 0 100G 0 disk
├─vda1 253:1 0 200M 0 part [SWAP]
└─vda2 253:2 0 1.8G 0 part /
vdb 253:16 0 300G 0 disk
└─vdb1 253:17 0 300G 0 part /data1
根分區是/dev/vda2,雖然/dev/vda共有100G,但是不知怎么滴給vda2只分配了1.8G(我估計最初是要把vda除了vda1之余的所有空間都給vda2的)。
如何處理?經過查找資料發現parted有個resizepart命令可以使用,而文件系統好像也有resize之類的命令(沒有細看)。因為錯誤的認知,以為resize之類的操作需要在文件系統unmounted的狀態才能進行,所以考慮重啟系統進入一種不使用根文件系統的模式,然后再進行處理(當然后面明白,這種做法是完全多余的,因為文件系統的擴大操作可以在文件系統處於掛載狀態的時候進行——注意只是擴大)。雖然走了彎路,但是也記錄下。
根分區是xfs文件系統,而且需要顯示終端連接了機器。
步驟:
1. 重啟系統進入啟動菜單界面,然后編輯默認的啟動菜單項。
2. 進入編輯界面后,找到linux啟動參數那一行。64-Bit IBM Power Series是linux那一行,x86-64 BIOS-based systems是linux16那一行,UEFI systems是linuxefi那一行。然后先從這一行參數中刪除rhgb 和quiet ,再添加 rd.break enforcing=0 到參數行中。(這些操作是參考的RHEL7的system_administrators_guide中關於"Resetting the Root Password Using rd.break"的做法)
3. 按Ctrl-x,以修改后的參數啟動系統。
4. 啟動后,根文件系統是個臨時的文件系統,不包含parted命令。原有根分區以只讀的方式掛載在/sysroot下面,所以使用parted之前(實際上可以執行使用/sysroot下面的命令,然后當時以為需要卸載/dev/vda2上的文件系統才能操作對/dev/vda進行操作,所以采取的方法是將parted拷貝出來運行),需要執行:
cp /sysroot/sbin/parted /sbin/
cp /sysroot/lib64/libparted.so.2 /lib64/
cp /sysroot/lib64/libdevmapper.so.1.02 /lib64/
cp /sysroot/lib64/libsepol.so.1 /lib64/
可能實際中因為版本不同導致這些需要拷貝的文件不同。可以先拷貝parted可執行程序本身,然后運行/sbin/parted /dev/vda,如果缺某個庫文件,會報錯提示,根據提示再拷貝即可。
5. 運行/sbin/parted /dev/vda,進入parted界面。先查看下分區狀態,確認根分區正好是最后一個分區,然后執行 resizepart 2 100%,其中2是/dev/vda2的分區號(之前可用p命令查看獲知),100%表示擴展到最尾部。
6. 然后以rw方式重新掛載原來的根分區:mount -o remount,rw /sysroot
7. 執行文件系統擴展: /sysroot/sbin/xfs_growfs /sysroot 。注意xfs_growfs命令也不在那個臨時根文件系統下。執行成功后,顯示信息的最后一行會提示 "data blocks changed from xxxx to yyyyyy" 只在的信息。
8. 重啟系統,根分區應該就擴展成功了。
========================================================================
實際上對於文件系統增大(擴展)是可以在線(即文件系統本身處於掛載狀態)進行的:
resize2fs的man page說明:
The resize2fs program will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located on device. If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.).
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/storage_administration_guide/xfsgrow
xfs_growfs
command:
# xfs_growfs /mount/point -D size
-D size
option grows the file system to the specified
size
(expressed in file system blocks). Without the
-D size
option,
xfs_growfs
will grow the file system to the maximum size supported by the device.
Note