Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an EC2 instance which I created a 500GB EBS volume for. Unfortunately, the EC2 instance shows only 8GB available.

I have only one drive, which is right.

[root@ip-10-244-134-250 ~]# ls -la /dev/x*
brw-rw---- 1 root disk 202, 1 Aug  7 08:54 /dev/xvda1

But, that drive is only 8GB

[root@ip-10-244-134-250 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            8.0G  1.3G  6.7G  16% /
tmpfs                 3.7G     0  3.7G   0% /dev/shm

But, fdisk and /proc/partitions both show correct size

[root@ip-10-244-134-250 ~]# fdisk -l

Disk /dev/xvda1: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/xvda1 doesn't contain a valid partition table

[root@ip-10-244-134-250 ~]# cat /proc/partitions 
major minor  #blocks  name

 202        1  524288000 xvda1

Any help would be greatly appreciated, thanks.

share|improve this question

3 Answers 3

up vote 19 down vote accepted

If the root file system is ext3 or ext4, then run:

sudo resize2fs /dev/xvda1

If the root file system is xfs (less common), then run:

sudo xfs_growfs /

You can omit "sudo" if you are logged in as root.

These commands should be run while the system is running and the file system is mounted.

It's standard for EBS volumes to not contain a partition table. The EBS volume is generally formatted as a file system in its entirety without partitions.

share|improve this answer
1  
Irritates me when people vote you down with no explanation. Anyway, this worked beautifully. Thanks very much! –  Christian Aug 7 '12 at 11:32
1  
/me shrugs and moves on with life :-) Glad to help. Here are a couple related articles I've written: alestic.com/2009/12/ec2-ebs-boot-resize alestic.com/2010/02/ec2-resize-running-ebs-root –  Eric Hammond Aug 7 '12 at 22:21
1  
Note that the cloud-init package included in Ubuntu AMIs automatically runs resize2fs on boot. I'm surprised this isn't in Amazon Linux since they are also using cloud-init. –  Eric Hammond Aug 7 '12 at 22:24
    
I have the same problem and when I run the command it says: The filesystem is already 2096896 blocks long. Nothing to do! It is still 8GB! –  Neo Oct 28 at 21:05

Resize the filesystem on the EBS volume. If you're running ext3 (which is usually the default), you can just run e2resize /dev/xvda1.

share|improve this answer
    
The volume first needs to be offline and dis-mounted. –  Farhan Aug 7 '12 at 9:12
1  
Not with any even vaguely modern Linux distribution. Online expansion of ext3 filesystems has been supported for years. –  womble Aug 7 '12 at 9:15
    
Thanks womble, I am using the aws distro and e2resize is not on there. Its not in any yum repo's either. Should I just get the source and build it myself? –  Christian Aug 7 '12 at 11:16

The answers here seem to be missing a few steps prior to re-sizing specially for people who are changing their EBS volume size. If you have used a snapshot to create the EBS or with certain AMIs you will need to extend the disk (xvda), extend the partition (xvda1), then extend the filesystem (/).

If I'm reading this correctly, your disk looks like this:

/dev/xvda
|__/dev/xvda1__|______________ Free space______________|

It needs to look like this:

/dev/xvda
|______________________/dev/xvda1______________________|

After that, running resize2fs will grow into that new space within xvda1, using fdisk we can increase the block size by deleting and creating it again and making the partition bootable. all it requires is a reboot. In most cases it shouldn't effect your data if you use same start cylinder but Note that any mistake in recreating the partion will result in losing all data and/or the server will not reboot. I would recommend doing this as the first step on a newly created instance. Otherwise take a snapshot of your EC2 EBS Storage/etc.

I have marked the steps with <<#>> in the block below, so the are not a part of the command. You need root permissions, so do a "sudo sh" if you are not root.

<<1>> Look at the filesystem, it is 6G
<<2>> Look at the disk and the partition, the disk is 21.5 GB but the partition is 6 GB (6291456 blocks)
<<3>> Start fdisk for that disk (xvda, so not the partition xvda1)
<<4>> Switch to sector display.
<<5>> Print the partition(s), and remember the start sector (2048 in the example).
<<6>> Delete the partition.
<<7>> Create a new partition.
<<8>> Make it primary.
<<9>> First partition.
<<10>> Enter the old start sector, do NOT make any typo here!!! (2048 in the example) 
<<11>> Hit enter to accept the default (this is the remainder of the disk)
<<12>> Print the changes and make sure the start sector is ok, if not restart at <<6>>
<<13>> Make the partition bootable. do NOT forget this!!!
<<14>> Enter your partition number (1 in the example)
<<15>> Write the partition info back, this will end the fdisk session.
<<16>> Reboot the server, and wait for it to come up (this may take longer than usual).
<<17>> Verify the filesystem size.
<<18>> If the filesystem is not around 20Gb as expected, you can use this command.


# df -h  <<1>>

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      6.0G  2.0G  3.7G  35% / 
tmpfs            15G     0   15G   0% /dev/shm

# fdisk -l  <<2>>

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
97 heads, 17 sectors/track, 25435 cylinders
Units = cylinders of 1649 * 512 = 844288 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003b587

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           2        7632     6291456   83  Linux

# fdisk /dev/xvda  <<3>>

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): u  <<4>>
Changing display/entry units to sectors

Command (m for help): p  <<5>>

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
97 heads, 17 sectors/track, 25435 cylinders, total 41943040 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 identifier: 0x0003b587

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    12584959     6291456   83  Linux

Command (m for help): d  <<6>>
Selected partition 1

Command (m for help): n  <<7>>
Command action
   e   extended
   p   primary partition (1-4)
p  <<8>>
Partition number (1-4): 1  <<9>>
First sector (17-41943039, default 17): 2048  <<10>>
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): <<11>>
Using default value 41943039

Command (m for help): p <<12>>

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
97 heads, 17 sectors/track, 25435 cylinders, total 41943040 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 identifier: 0x0003b587

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048    41943039    20970496   83  Linux

Command (m for help): a  <<13>>
Partition number (1-4): 1  <<14>>


Command (m for help): w  <<15>>
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: ...
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.

# reboot  <<16>>

<wait>

# df -h  <<17>>
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       20G  2.0G   17G  11% / 
tmpfs            15G     0   15G   0% /dev/shm

# resize2fs /dev/xvda1  <<18>>
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/xvda1 to 5242624 (4k) blocks.
The filesystem on /dev/xvda1 is now 5242624 blocks long.

root@vs120 [~]#  df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       20G  7.8G   11G  42% /
tmpfs           498M     0  498M   0% /dev/shm
/usr/tmpDSK     399M   11M  368M   3% /tmp
root@vs120 [~]#
share|improve this answer
    
Extending the partition is only necessary if the volume is partitioned. That is pretty rare on EC2. The common best practice with EBS is to format the entire raw volume with the file system without positioning it first. This is especially true for boot volumes. Positioning is an artifact of physical disks, where they aren't quite the size you want for your file systems. On EC2, you simply create EBS volume(s) of the right size and drop the file system on the raw volume without partitions. –  Eric Hammond Oct 29 at 16:15
    
I don't know about rare, it happened to me on both CentOS EC2 instances I launched with Generic SSD EBS Storage. –  Neo Oct 30 at 2:22
    
Who published the CentOS AMIs you used? –  Eric Hammond Nov 2 at 9:02
    
@EricHammond centos.org –  Neo Nov 2 at 19:52
    
@EricHammond Most people encounter this problem because they create a new EBS from a snapshot that was a different size. –  Neo Dec 6 at 23:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.