- Snapshot the root volume (this step is done as a backup)
1. Create a new ebs volume (smaller than current one)
2. Stop the instance and detach the current root volume
3. Attach both volumes to another running instance
- new /dev/sdf - /dev/xvdf on the instance
- old /dev/sdg - /dev/xvdg on the instance
4. Run the following commands
[cc lang='bash']
# needed by resize2fs
\$ e2fsck -f /dev/xvdg
e2fsck 1.42 (29-Nov-2011)
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
cloudimg-rootfs: 123578/33292288 files (0.1% non-contiguous),
2845320/133169152 blocks
\$ resize2fs -M -p /dev/xvdg
resize2fs 1.42 (29-Nov-2011)
Resizing the filesystem on /dev/xvdg to 1035624 (4k) blocks.
Begin pass 2 (max = 540150)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 4064)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 18619)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/xvdg is now 1035624 blocks long.
\$ echo "1035624*4/(16*1024)" | bc
252
\$ dd bs=16M if=/dev/xvdg of=/dev/xvdf count=300
300+0 records in
300+0 records out
5033164800 bytes (5.0 GB) copied, 202.99 s, 24.8 MB/s
\$ resize2fs -p /dev/xvdf
resize2fs 1.42 (29-Nov-2011)
Resizing the filesystem on /dev/xvdf to 2097152 (4k) blocks.
Begin pass 1 (max = 32)
Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/xvdf is now 2097152 blocks long.
\$ e2fsck -f /dev/xvdf
e2fsck 1.42 (29-Nov-2011)
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
cloudimg-rootfs: 123578/524288 files (0.3% non-contiguous),
784755/2097152 blocks
[/cc]
5. Detach both volumes from the instance
6. Attach new volume to original instance as /dev/sda1 and start it