Guangning Yu's Blog
Home
Code
Data
Setup
Industry
MachineLearning
Archive
Expand the EBS root volume of EC2 Linux instance
2019-02-24 15:10:42
|
AWS
1. Modify the EBS Volume from the console https://console.aws.amazon.com/ec2/ 2. Use the `lsblk` command to list the block devices attached to the instance ``` $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 30G 0 disk `-xvda1 202:1 0 8G 0 part / loop0 7:0 0 91M 1 loop /snap/core/6405 loop1 7:1 0 87.9M 1 loop /snap/core/5742 loop2 7:2 0 17.9M 1 loop /snap/amazon-ssm-agent/1068 loop3 7:3 0 16.5M 1 loop /snap/amazon-ssm-agent/784 loop4 7:4 0 18M 1 loop /snap/amazon-ssm-agent/930 ``` 3. Use the `df -h` command to report the existing disk space usage on the file system ``` $ sudo df -h /dev/xvd* Filesystem Size Used Avail Use% Mounted on udev 488M 0 488M 0% /dev /dev/xvda1 7.7G 7.4G 370M 96% / ``` 4. Expand the modified partition using `growpart` ``` $ sudo growpart /dev/xvda 1 CHANGED: partition=1 start=2048 old: size=16775135 end=16777183 new: size=62912479,end=62914527 ``` ``` $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 30G 0 disk `-xvda1 202:1 0 30G 0 part / loop0 7:0 0 91M 1 loop /snap/core/6405 loop1 7:1 0 87.9M 1 loop /snap/core/5742 loop2 7:2 0 17.9M 1 loop /snap/amazon-ssm-agent/1068 loop3 7:3 0 16.5M 1 loop /snap/amazon-ssm-agent/784 loop4 7:4 0 18M 1 loop /snap/amazon-ssm-agent/930 ``` 5. Use the `file -s` command to list the file system data for the device ``` $ sudo file -s /dev/xvd* /dev/xvda: DOS/MBR boot sector /dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=96950bba-70e8-4a4b-9d78-d2bc1c767e04, volume name "cloudimg-rootfs" (needs journal recovery) (extents) (large files) (huge files) ``` 6. For a Linux ext2, ext3, or ext4 file system, use the following command to resize each file system to the new volume capacity ``` $ sudo resize2fs /dev/xvda1 resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/xvda1 is now 7864059 (4k) blocks long. ``` ``` $ df -h Filesystem Size Used Avail Use% Mounted on udev 488M 0 488M 0% /dev tmpfs 100M 3.3M 96M 4% /run /dev/xvda1 30G 7.4G 22G 26% / tmpfs 496M 0 496M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/loop0 91M 91M 0 100% /snap/core/6405 /dev/loop1 88M 88M 0 100% /snap/core/5742 /dev/loop2 18M 18M 0 100% /snap/amazon-ssm-agent/1068 /dev/loop3 17M 17M 0 100% /snap/amazon-ssm-agent/784 /dev/loop4 18M 18M 0 100% /snap/amazon-ssm-agent/930 tmpfs 100M 0 100M 0% /run/user/1001 ```
Previous:
Fix Chinese characters won't display in SSH
Next:
Create Free SSL/TLS Certificates using Certbot