How to extend a Linux file system

In Linux, you use a file system-specific command to resize the file system to the larger size of the new volume. This command works even if the volume you wish to extend is the root volume. For ext2, ext3, and ext4 file systems, this command is resize2fs. For XFS file systems, this command is xfs_growfs. For other file systems, refer to the specific documentation for those file systems for instructions on extending them.
If you are unsure of which file system you are using, you can use the file -sL command to list the file system data for a device. The following example shows a Linux ext4 file system and an SGI XFS file system.
[ec2-user@ip-10-11-136-5 ~]$ sudo file -sL /dev/xvd*
/dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=1701d228-e1bd-4094-a14c-8c64d6819362 (needs journal recovery) (extents) (large files) (huge files)
/dev/xvda3: Linux/i386 swap file (new style), version 1 (4K pages), size 229375 pages, no label, UUID=1899c6a5-3be9-480d-9bca-6319771e703b
Note
If the volume you are extending has been partitioned, you need to increase the size of the partition before you can resize the file system. This can be accomplished with the fdisk or parted commands. Because repartitioning can inadvertently result in data loss on a volume, we highly recommend that you create a snapshot of the volume being repartitioned as a backup in case of any data loss.
Use the df -h command to report the existing file system disk space usage.
[ec2-user@ip-10-11-136-5 ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  7.8G   23M 100% /
tmpfs                 829M     0  829M   0% /dev/shm
Use the file system-specific command to resize the file system to the new size of the volume. For a Linux ext2, ext3, or ext4 file system, use the following command, substituting the device name that you want to extend.
[ec2-user@ip-10-11-136-5 ~]$ sudo resize2fs /dev/xvda1
resize2fs 1.42.3 (14-May-2012)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/xvda1 is now 7340032 blocks long.


For an XFS file system, use the following command, substituting the mount point of the file system (XFS file systems must be mounted to resize them).
[ec2-user ~]$ sudo xfs_growfs -d /mnt
meta-data=/dev/xvdf              isize=256    agcount=4, agsize=65536 blks
        =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=262144, imaxpct=25
        =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=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
data blocks changed from 262144 to 26214400
Use the df -h command to report the existing file system disk space usage, which should now show the full 70 GB on the ext4 file system and 100 GB on the XFS file system.
[ec2-user@ip-10-11-136-5 ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1             28G  7.8G   20G  29% /
tmpfs                 829M     0  829M   0% /dev/shm

Comments

Popular posts from this blog

Check MySQL query history from command line