Resizing AWS Linux image volume

Modify volume size inside AWS console first.

Image for post
Image for post

then log into your command line environment of your virtual machine.

  1. If you are unsure of which file system you are using, you can use the file -s 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 ~]$ sudo file -s /dev/xvd*
/dev/xvda1: Linux rev 1.0 ext4 filesystem data ...
/dev/xvdf: SGI XFS filesystem data ...

2. Use the lsblk command to list the block devices attached to your instance. The example below shows three volumes: , , and .

[ec2-user ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 30G 0 disk
└─xvda1 202:1 0 30G 0 part /
xvdb 202:16 0 30G 0 disk /mnt
xvdf 202:80 0 35G 0 disk
└─xvdf1 202:81 0 8G 0 part

3. Use the df -h command to report the existing disk space usage on the file system. In this new example, device has already been expanded to 35 GiB, but the operating system still sees only an original 8 GiB ext4 file system. Similarly, the device has been expanded to 35 GiB, but the operating system still only sees an original 1 GiB XFS file system.

[ec2-user ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 8.0G 943M 6.9G 12% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/xvdf 1014M 33M 982M 4% /mnt

4. Expand the modified partition using growpart (and note the unusual syntax of separating the device name from the partition number):

$sudo growpart /dev/xvdf 1
CHANGED: disk=/dev/xvdf partition=1: start=4096 old: size=16773086,end=16777182 new: size=73396190,end=73400286

A look at the lsblk output confirms that the partition now fills the available space on the volume:

[ec2-user ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
...
xvdf 202:80 0 35G 0 disk
└─xvdf1 202:81 0 35G 0 part

5. Use a file system-specific command to resize each file system to the new volume capacity.

For a Linux ext2, ext3, or ext4 file system, use the following command, substituting the device name to extend:

[ec2-user ~]$ sudo resize2fs /dev/xvdf1
resize2fs 1.42.3 (14-May-2012)
old_desc_blocks = 1, new_desc_blocks = 3
The filesystem on /dev/xvdf1 is now 9174523 blocks long.

6. Use the df -h command to report the existing file system disk space usage, in this example showing 70 GiB on the ext4 file system and 100 GiB on the XFS file system:

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 70G 951M 69G 2% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/xvdf 100G 45M 100G 1% /mnt

Tip

If the increased available space on your volume remains invisible to the system, try re-initializing the volume as described in Initializing Amazon EBS Volumes.

Written by

自由撰稿人,时评人,平等公义追求者

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store