Resizing volumes
At times you may need to resize a volume. If you are using LVM, see the EBS LVM discussion. LVM is great for large storage partitions, but if you just need to enlarge a regular EBS volume, this procedure should work. A common example is to expand the size of a root volume to increase storage for applications.
In the example below, we will assume we are working with an instance's root (OS) volume; if this is not the case, you may skip all steps after resizing the volume (i.e. those steps pertaining to making an image).
The succinct summary of what we will do is: snapshot, save as X GB volume, mount volume and resize partition, created snapshot from X GB volume, registered snapshot as image, boot a new instance of the new image.
BEFORE TAKING SNAPSHOT one must delete the cached MAC address - otherwise one can't ssh to a new VM booted from the snapshot:
rm /etc/udev/rules.d/70-persistent-net.rules
To expand the root partition (assuming the volume is attached to /dev/vdc):
sudo fdisk /dev/vdc # [interactive commands to delete root partition (!) and re-create it larger: # p, d, p, n, p, 1, defaults... p, w] sudo sudo e2fsck -f /dev/vdc1 sudo resize2fs /dev/vdc1
Here is a transcript of output from an example procedure:
brandon@euca-128-84-11-149:~$ sudo fdisk /dev/vdc Welcome to fdisk (util-linux 2.25.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/vdc: 30 GiB, 32212254720 bytes, 62914560 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 Disklabel type: dos Disk identifier: 0x61e75f2d Device Boot Start End Sectors Size Id Type /dev/vdc1 * 2048 20971519 20969472 10G 83 Linux Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): p Disk /dev/vdc: 30 GiB, 32212254720 bytes, 62914560 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 Disklabel type: dos Disk identifier: 0x61e75f2d Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 11 Value out of range. Partition number (1-4, default 1): 1 First sector (2048-62914559, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-62914559, default 62914559): Created a new partition 1 of type 'Linux' and of size 30 GiB. Command (m for help): p Disk /dev/vdc: 30 GiB, 32212254720 bytes, 62914560 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 Disklabel type: dos Disk identifier: 0x61e75f2d Device Boot Start End Sectors Size Id Type /dev/vdc1 2048 62914559 62912512 30G 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. brandon@euca-128-84-11-149:~$ sudo resize2fs /dev/vdc1 resize2fs 1.42.12 (29-Aug-2014) Please run 'e2fsck -f /dev/vdc1' first. brandon@euca-128-84-11-149:~$ sudo e2fsck -f /dev/vdc1 e2fsck 1.42.12 (29-Aug-2014) /dev/vdc1: recovering journal Clearing orphaned inode 475259 (uid=108, gid=116, mode=0100664, size=2379) Clearing orphaned inode 475232 (uid=108, gid=116, mode=0100664, size=2379) Clearing orphaned inode 475249 (uid=108, gid=116, mode=0100664, size=2379) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Free blocks count wrong (578868, counted=578802). Fix<y>? yes Free inodes count wrong (344343, counted=344342). Fix<y>? yes /dev/vdc1: ***** FILE SYSTEM WAS MODIFIED ***** /dev/vdc1: 311018/655360 files (6.2% non-contiguous), 2042382/2621184 blocks
Similarly, you can create a larger scratch disk in the 200 GB of ephemeral space (usually attached to /dev/vdb):
fdisk /dev/vdb [interactive commands: n, p, 1, defaults... p, w] mke2fs -j /dev/vdb1 e2fsck -f /dev/vdb1 mkdir /scratch mount -t ext3 /dev/vdb1 /scratch