Redhat
如何增加 XFS 文件系統的大小?
我剛剛創建了一個執行的 Amazon AWS EC2 實例
RHEL7
:[root@ip-10-184-161-46 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.0 (Maipo) [root@ip-10-184-161-46 ~]#
即使我選擇
10GB
了我的儲存容量,無論出於何種原因,我只看到6GB
它可供我立即使用:[root@ip-10-184-161-46 ~]# mount | grep xfs | grep -v selinux /dev/xvda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota) [root@ip-10-184-161-46 ~]# df -h | grep xvda /dev/xvda1 6.0G 2.2G 3.9G 37% / [root@ip-10-184-161-46 ~]# fdisk -l /dev/xvda Disk /dev/xvda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0000b85c Device Boot Start End Blocks Id System /dev/xvda1 * 2048 12584959 6291456 83 Linux [root@ip-10-184-161-46 ~]#
這就是我所做的:
[root@ip-10-164-175-246 ~]# fdisk -l /dev/xvda Disk /dev/xvda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0000b85c Device Boot Start End Blocks Id System /dev/xvda1 * 2048 12584959 6291456 83 Linux /dev/xvda2 12584960 20971519 4193280 83 Linux [root@ip-10-164-175-246 ~]# xfs_growfs / meta-data=/dev/xvda1 isize=256 agcount=4, agsize=393216 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=1572864, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@ip-10-164-175-246 ~]# df -h | grep xvda /dev/xvda1 6.0G 2.3G 3.8G 38% / [root@ip-10-164-175-246 ~]#
我的另一個
4GB
呢?我認為執行xfs_growfs /
會增加我的xfs
分區的大小。我究竟做錯了什麼?
有趣的是,前幾天我在 EC2 上發現我的 RHEL 實例僅分配了 10GB 空間中的 6GB 左右後,我就這樣做了……
[root@ip-172-31-20-177 ~]# xfs_info / meta-data=/dev/xvda1 isize=256 agcount=4, agsize=393216 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=1572864, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
這裡的問題是您創建了第二個分區。
相反,您應該調整第一個分區的大小。
因此,您將使用刪除第二個分區,然後同時
fdisk
刪除並重新創建第一個分區。預設值將導致它填滿磁碟(並正確對齊)。fdisk
啟動
fdisk
和刪除分區:[root@ip-172-31-20-177 ~]# fdisk /dev/xvda 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/xvda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0000b85c Device Boot Start End Blocks Id System /dev/xvda1 * 2048 12584959 6291456 83 Linux 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): p Partition number (1-4, default 1): First sector (2048-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): Using default value 20971519 Partition 1 of type Linux and of size 10 GiB is set Command (m for help): p Disk /dev/xvda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0000b85c Device Boot Start End Blocks Id System /dev/xvda1 2048 20971519 10484736 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.
重新啟動時,文件系統應自動為您調整大小
cloud-init
。如果沒有,您可以使用xfs_growfs /
手動擴展文件系統。[root@ip-172-31-20-177 ~]# xfs_info / meta-data=/dev/xvda1 isize=256 agcount=7, agsize=393216 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=2621184, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@ip-172-31-20-177 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvda1 10474496 818560 9655936 8% /