32

I have upgraded an EC2 instance from m4 to m5, and now want to increase the size of the attached EBS storage volume. I am using an solid-state (SSD) EBS volume mounted as an NVMe drive.

After some research, I performed this command:

growpart /dev/nvme0n1 p1

After doing so, I received this error message in response:

FAILED: partition-number must be a number

I have tried to find instructions in the AWS docs and forums, but have not found a solution to this error message.

How can I increase the size of the EBS volume?

bwright
  • 347
  • 1
  • 15

5 Answers5

102

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html

growpart [OPTIONS] DISK PARTITION-NUMBER

$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1       259:0    0  16G  0 disk 
├─nvme0n1p1   259:1    0   8G  0 part /
└─nvme0n1p128 259:2    0   1M  0 part 

So to grow the partition, we use the diskname nvme0n1 (see disk under TYPE) and desired partition is 1

sudo growpart /dev/nvme0n1 1

And then to extend the fs - resize2fs device [ size ]

(device refers to the location of the target filesystem)

$ df -h
Filesystem                                 Size  Used Avail Use% Mounted on
devtmpfs                                   470M   52K  470M   1% /dev
tmpfs                                      480M     0  480M   0% /dev/shm
/dev/nvme0n1p1                             7.8G  7.7G  3.1M 100% /

So to extend the fs, we use the device name /dev/nvme01np1:

sudo resize2fs /dev/nvme0n1p1

Voila!

$ df -h
Filesystem                                 Size  Used Avail Use% Mounted on
devtmpfs                                   470M   52K  470M   1% /dev
tmpfs                                      480M     0  480M   0% /dev/shm
/dev/nvme0n1p1                              16G  7.7G  7.9G  50% /
MetricMike
  • 1,203
  • 1
  • 10
  • 9
  • 1
    If I had to increase /dev/nvme0n1p128, then do I have to use "sudo growpart /dev/nvme0n1 2" ? – kevin peter Jun 05 '19 at 11:17
  • Thanks! Worked for me on Ubuntu server 18.04!! – Chau Giang Oct 13 '20 at 01:46
  • If you are on FCOS and you can't use any of the native tools than mount the partition as rw then reboot sudo mount -o remount,rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,prjquota /dev/nvme0n1p4 /sysroot – eramm Jan 26 '21 at 12:01
  • Interesting. I followed all of the above (as well as referenced the AWS article you provided). When I issued the "sudo growpart /dev/nvme0n1 1" command I got: NOCHANGE: partition 1 is size 25161695. it cannot be grown So then I issued the "sudo xfs_growfs -d /" command and got: data size unchanged, skipping -- I read somewhere that after you reboot (after modifying the volume) that AWS expands it for you but I couldn't find that article, so I went through all these steps. Looks like it does do it for you. – 00fruX Mar 02 '21 at 20:53
22

resize2fs didn't work for me, so I used this instead:

xfs_growfs /dev/nvme0n1p1

resize2fs gave me this error when I used it:

[root@ip-1-2-3-4 ~]# resize2fs /dev/nvme0n1p1
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/nvme0n1p1
Couldn't find valid filesystem superblock.

I noticed the disk was using xfs under /etc/fstab:

UUID=4cbf4a19-1fba-4027-bf92-xxxxxxxxxxxx     /           xfs    defaults,noatime  1   1
hobbes3
  • 28,078
  • 24
  • 87
  • 116
  • The latest amazon-linux-2 ami on Ec2 uses XFS as the root partition. Which is why it worked for me, after the regular resize2fs failed me with bad blocksize magic type. – bailey.cosier Jan 07 '20 at 13:51
  • @Thanks, for the help.. I was facing the exact same issue.. all hail to stackoverflow – danD Nov 17 '20 at 21:28
2

Prerequesities:

  1. You found the partition you want to extend and there is just one partition on this particular NVME: /dev/nvme0n1p1 but not /dev/nvme0n1p2. Note the mount location: /
df
Filesystem     1K-blocks     Used Available Use% Mounted on
...
/dev/nvme0n1p1 _________ ________  ________  99% /
  1. You run lsblk and it confirms a single partition under the volume nvme0n1
lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
nvme0n1     259:2    0   400G  0 disk
└─nvme0n1p1 259:3    0   400G  0 part /

Than you first extend your volume through AWS console and then run next code block.

Single place script:

# /dev/nvme0n1 - volume name, 1 - partition index
sudo growpart /dev/nvme0n1 1 
# block for xfs
# / - mount from above. Command will safely fail for non xfs
sudo xfs_growfs -d / 
# block for ext4
# /dev/nvme0n1p1 - partition you would like to extend
sudo resize2fs /dev/nvme0n1p1

Assembled from this resource: Extend a Linux file system after resizing a volume

y.selivonchyk
  • 8,987
  • 8
  • 54
  • 77
1

Below worked for me in AWS CENTOS - Amazon Linux 2 AMIS( Karoo)

Step 1 : Update the EBS volume from AWS console of attached EC2

Step 2 : Login( SSH ) to EC2 instance in which the volume is attached

Step 3 : Follow the below commands and just replace the disk name. i.e xda or nvme0n1

Commands :

lsblk

sudo growpart /dev/nvme0n1 1

df -h

sudo xfs_growfs /dev/nvme0n1p1

Note : You have to use xfs_growfs instead of resize2fs

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Mayur Chavan
  • 833
  • 8
  • 14
0

To extend the XFS filesystem, instead of xfs_growfs after the growpart command I ran:

sudo pvresize /dev/nvme0n1p2
sudo lvextend -L +40G -r /dev/mapper/centos_sstemplate-root

and it worked.