If your root file system has got full or you want to add extra space to it for installing any package in Linux machine on AWS cloud and you are not sure what to do, then this article will definitely help you. In this AWS cloud tutorial, we will tell you how to increase the root filesystem size of AWS Linux instance.
This is a very simple article and we assume your AWS Linux machine is already running. In this Virtual instance, we are using “Amazon Linux 2 AMI” with 8 GB EBS.
Steps to Increase the Size of Root File System in AWS Linux Instance without Reboot
1. First of all, we will have to increase the size of root volume from the AWS management console. For that go to the EC2 dashboard in the AWS management console and then go to the Elastic Block Store as shown below and increase the size of EBS volume to the desired size. For this example, we are increasing it to 10G from 8G.
2. Now, once the size of the EBS volume has been increased, just very it using the ‘dmesg‘ logs and using ‘fdisk‘ command as shown below.
[root@ip-172-31-18-148 ]# dmesg | tail -10 [ 3.754254] EXT4-fs (xvda1): re-mounted. Opts: (null) [ 3.789274] random: dd: uninitialized urandom read (4096 bytes read) [ 3.909201] random: vgs: uninitialized urandom read (4 bytes read) [ 4.000939] NET: Registered protocol family 10 [ 4.009619] Segment Routing with IPv6 [ 6.279139] urandom_read: 1 callbacks suppressed [ 6.279140] random: rngd: uninitialized urandom read (16 bytes read) [ 6.317849] random: crng init done [ 3806.626451] Setting capacity to 20971520 [ 3806.630899] xvda: detected capacity change from 8589934592 to 10737418240 [root@ip-172-31-18-148 ]# fdisk -l /dev/xvda Disk /dev/xvda: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/xvda1 1 16777215 8388607+ ee GPT [root@ip-172-31-18-148 ]#
3. Now with the help of “lsblk” command check the partition size and then with the “growpart” command increase the size of the partition.
[root@ip-172-31-18-148 ]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 10G 0 disk └─xvda1 202:1 0 8G 0 part / [root@ip-172-31-18-148 ]# [root@ip-172-31-18-148 ]# growpart /dev/xvda 1 CHANGED: disk=/dev/xvda partition=1: start=4096 old: size=16773086,end=16777182 new: size=20967390,end=20971486 [root@ip-172-31-18-148 ]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 10G 0 disk └─xvda1 202:1 0 10G 0 part / [root@ip-172-31-18-148 html]#
In the above terminal output, you will see that before the size of the partition xvda1 was 8G, but after increasing it with growpart command with was increased automatically to 10G. So you don’t have to specify any size while increasing it.
4. Once the partition is increased, it’s time to increase the size of the root file system. Here we will use “resize2fs” command to resize the filesystem and df command to verify.
[root@ip-172-31-18-148 ]# resize2fs /dev/xvda1 resize2fs 1.43.5 (04-Aug-2017) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/xvda1 is now 2620923 (4k) blocks long. [root@ip-172-31-18-148 ]# df -hP Filesystem Size Used Avail Use% Mounted on devtmpfs 483M 60K 483M 1% /dev tmpfs 493M 4.0K 493M 1% /dev/shm /dev/xvda1 9.8G 1.7G 8.0G 18% / [root@ip-172-31-18-148 ]#
This is it!
This was a very simple Amazon Web Services (AWS) cloud tutorial which teaches us how to increase the size of the root file system.
We will be creating more AWS tutorials, so please subcribe to our FREE newsletter, so that you get the email notification and also follow us on all the social media channels.