|« PreviousNext »|
|Did this page help you? Yes | No | Tell us about it...|
Sometimes, it is necessary for you to increase the storage space of an existing volume without losing the data that is on the volume. This topic explains how to expand the storage space of an Amazon EBS volume by migrating your data to a larger volume, and then extending the file system on the volume to recognize the newly-available space. After you verify that your new volume is working properly, you may delete the old volume.
To migrate your data to a larger Amazon EBS volume
Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
Ensure that the instance's Shutdown Behavior value is set to Stop and not Terminate. If it is already set to Stop, go on to step 3.
In the navigation pane, click Instances, right-click on the instance to check, and select Change Shutdown Behavior.
If the Shutdown behavior is set to Terminate, select Stop from the list and click Apply.
If the Shutdown behavior is set to Stop, click Cancel.
Stop the instance. For more information about how to stop an instance, see Stopping and Starting Your Instances.
Create a snapshot of the volume to expand.
In the navigation pane, click Volumes, right-click on the volume to be expanded, and select Create Snapshot.
Enter a Name and Description for the snapshot, and click Yes, Create.
Create a new volume from the snapshot.
In the navigation pane, click Snapshots.
When the status of the snapshot that you just created is set to completed, select the snapshot and click Create Volume.
It can take several minutes for the snapshot to complete.
In the Create Volume dialog box, select the desired volume type, enter the new size for the volume, set the Availability Zone to the same Availability Zone as the instance, and click Yes, Create.
Detach the old volume.
In the navigation pane, click Volumes, select the old volume
from the list of volumes, and make note of the value of
name in Attachment information.
The attachment information value takes the following form:
Right-click the old volume and select Detach Volume.
In the Detach Volume dialog box, click Yes, Detach. It may take several minutes for the volume to be detached.
Attach the newly expanded volume
In the navigation pane, click Volumes, select the new volume from the list of volumes, right-click the new volume, and select Attach Volume.
Start typing the name or ID of the instance in the Instance field, select the instance, enter the same device name retrieved in Step 6.a, and click Yes, Attach.
Restart the instance.
In the navigation pane, click Instances, right-click the instance, and select Start.
In the Start Instances dialog box, select Yes,
Start. If the instance fails to start, and the volume being expanded is a
root volume, verify that you attached the expanded volume using the same device name
as the original volume (root volumes must be attached as
Only EC2-VPC instances with Elastic IP addresses retain their public IP address when they are stopped. If your instance is running in EC2-Classic, the EIP address is disassociated when the instance is stopped, and you must re-associate the EIP after restarting the instance. For more information, see Elastic IP Addresses (EIP). If your instance is not using an EIP, then you need to retrieve your new public DNS name for your instance from the Instances page of the Amazon EC2 console to connect to it.
After the instance has started, you can check the file system size to see if your instance recognizes the larger volume space. On Linux, use the df -h command to check the file system size.
df -hFilesystem Size Used Avail Use% Mounted on /dev/xvda1 7.9G 943M 6.9G 12% / tmpfs 1.9G 0 1.9G 0% /dev/shm
the value in the
Size column does not indicate your newly-expanded volume
size, you need to extend the file system on your device so that your instance can use the new
space. This procedure varies depending on the operating system running on the instance. For
information about how to do this on different operating systems, see the following
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
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
-s command to list the file system data for a device. The following example shows
ext4 file system and an SGI XFS file
sudo file -s /dev/xvd*/dev/xvda1: Linux rev 1.0 ext4 filesystem data ... /dev/xvdf: SGI XFS filesystem data ...
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. For more information, see Expanding a Linux Partition.
To check if your volume partition needs resizing
Use the lsblk command to list the block devices attached to your
instance. The example below shows three volumes:
lsblkNAME 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
/dev/xvda1, is a partition on
/dev/xvda. Notice that they are both 30 GiB in size. In this case,
the partition occupies all of the room on the device, so it does not need resizing.
/dev/xvdb is not partitioned at all, so it does not
/dev/xvdf1 is an 8 GiB partition on a 35 GiB device and
there are no other partitions on the volume. In this case, the partition must be resized
in order to use the remaining space on the volume. For more information, see Expanding a Linux Partition. After you
resize the partition, you can follow the next procedure to extend the file system to
occupy all of the space on the partition.
To extend a Linux file system
Log in to your Linux instance using an SSH client. For more information about connecting to a Linux instance, see Connecting to Your Linux/Unix Instances Using SSH.
Use the df -h command to report the existing file system disk space
usage. In this example, the
/dev/xvda1 device has already been expanded to 70
GiB, but the
ext4 file system only sees the original 8 GiB size, and
/dev/xvdf device has been expanded to 100 GiB, but the XFS file
system only sees the original 1 GiB size.
df -hFilesystem Size Used Avail Use% Mounted on /dev/xvda1 7.9G 943M 6.9G 12% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/xvdf 1014M 33M 982M 4% /mnt
Use the file system-specific command to resize the file system to the new size of the
volume. For a Linux
ext4 file system, use the following command, substituting the device
name that you want to extend.
sudo resize2fsresize2fs 1.42.3 (14-May-2012) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 5 Performing an on-line resize of /dev/xvda1 to 18350080 (4k) blocks. The filesystem on /dev/xvda1 is now 18350080 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).
sudo xfs_growfs -dmeta-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
If you receive an
xfsctl failed: Cannot allocate memory error,
you may need to update the Linux kernel on your instance. For more information, refer
to your specific operating system documentation.
Use the df -h command to report the existing file system disk space
usage, which should now show the full 70 GiB on the
ext4 file system
and 100 GiB on the XFS file system.
df -hFilesystem Size Used Avail Use% Mounted on /dev/xvda1 69G 951M 68G 2% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/xvdf 100G 45M 100G 1% /mnt
In Windows, you use the Disk Management utility to extend the disk size to the new size of the volume.
To extend a Windows file system
Log in to your Windows instance using Remote Desktop.
Windows Server 2012: Go to the Start screen.
Windows Server 2008: On the taskbar, click Start, and then click Run.
Type diskmgmt.msc and press Enter. The Disk Management utility opens.
Right-click the expanded drive and select Extend Volume.
In the Extend Volume Wizard, click Next, then set the Select the amount of space in MB field to the number of megabytes by which to extend the volume. Normally, you set this to the maximum available space. Complete the wizard.
After the new volume has been attached and extended in the instance, you can delete the old volume if it is no longer needed.