Saturday, July 4, 2015

EBS expand file system to recognize volume size in Ubuntu

A common scenario when dealing using EC2 is expanding EBS/volume sizes. You may be doing a new AMI or just expanding an existing volume. This article is about how to make your file system (ex. xfs, ext) to recognize the size of your new volumes.

After you expand your volume, ssh into the instance.

Show the instance's volumes and their sizes.

> sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

NAME    FSTYPE              SIZE MOUNTPOINT        LABEL
xvda1   ext4                128G /                 /
xvdb    ext3                840G /media/ephemeral0
xvdm    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdn    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdo    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdl    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdj    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdk    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdf    ext4                 30G /mnt/shared

In the example above, we see /dev/xvda1 has 128G and is using file system ext4.

If you want more details on the file system types of each volume, you can use the file command:

> sudo file -s /dev/xvd*

/dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=ebbf1b1c-fb71-40aa-93a3-056b455e5127 (needs journal recovery) (extents) (large files) (huge files)
/dev/xvdb:  Linux rev 1.0 ext3 filesystem data, UUID=07b9bb55-97cc-47e8-b968-6f158e66ff60 (needs journal recovery) (large files)
/dev/xvdf:  Linux rev 1.0 ext4 filesystem data, UUID=bff77q92-806c-44a5-a260-5a50025283ba (needs journal recovery) (extents) (large files) (huge files)
/dev/xvdj:  data
/dev/xvdk:  data
/dev/xvdl:  data
/dev/xvdm:  data
/dev/xvdn:  data
/dev/xvdo:  data

> lsblk

NAME    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
xvda1   202:1    0   128G  0 disk  /
xvdb    202:16   0   840G  0 disk  /media/ephemeral0
xvdm    202:192  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdn    202:208  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdo    202:224  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdl    202:176  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdj    202:144  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdk    202:160  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdf    202:80   0    30G  0 disk  /mnt/shared

> df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  4.0G  3.9G  52% /
tmpfs                  17G     0   17G   0% /dev/shm
/dev/xvdb             827G  201M  785G   1% /media/ephemeral0
/dev/xvdf              30G  8.0G   21G  29% /mnt/shared
/dev/md127             60G   15G   46G  25% /mnt/data

For ext2, ext3, ext4, you can use the resize2fs command.

Resize /dev/xvda1

> sudo resize2fs /dev/xvda1

For xfs, you can do

> sudo xfs_growfs -d /mnt

No comments:

Post a Comment