AWS EC2 Expanding linux root partition
Posted By : Mohd Adnan | 31-Jul-2018
Image Credits: Daniel Lopez
If the partition you want to expand is not root partition, then you can simply unmount the volume and resize it from the instance itself. There is a problem when you want to expand a root partition. You cannot directly expand the root volume from your instance. There are steps involved that you need to follow.
Preparing your instance for root partition expansion
Note: Create a snapshot of your root volume (EBS) before you attempt to expand root volume. The methods are destructive and cannot be reverted back.
1. run
2. You cannot expand your root partition from your running instance. You need to stop your primary instance from AWS EC2 dashboard
3. Detach the root volume of your primary EC2 instance
4. Create a secondary instance - you can use nano instance and start it. You've to start the instance before you can begin the process. Having two root partitions while booting the instance can corrupt the file system.
5. Once your secondary instance is started, attach a root volume of your primary instance to it.
Expanding a Linux Partition using parted
The parted utility is a partition editing tool that is available on most of the Linux distributions. It can create & edit both MBR partition tables,GPT partition table.
Here are the steps to expand your root partition using parted utility.
1. Identify the
[ec2-user ~]$
NAME MAJ:MIN RM SIZE RO MOUNTPOINT
xvdf1 202:81 0 10G 0 /mnt
xvda1 202:1 0 30G 0 /
In the above example,
2. Unmount the
[ec2-user ~]$
3. Run parted command on the device
[ec2-user ~]$
GNU Parted 2.1
Using /dev/
Welcome to GNU Parted! Type 'help' to view a list of commands.
4. Change the parted units of measure to sectors.
(parted) unit s
5. Run the print command to list the partitions on the device.
If you receive messages regarding backup of GPT table and to fix GPT - you should ignore it
6. Examine the output for the total size of the disk, the partition table type, the number of the partition, the start point of the partition, and any flags, such as boot
Model: Xen Virtual Block Device (
Disk /dev/
Sector size (logical/physical): 512B/512B
Partition Table:
Number Start End Size Type File system Flags
1 2048s 35649535s 35647488s primary ext3
7. Delete the partition entry for the partition using the number (1) from the previous step.
(parted) rm 1
8. Create a new partition that extends entire volume.
(parted)
9. Run the print command to verify your partition.
(parted) print
Model: Xen Virtual Block Device (
Disk /dev/
Sector size (logical/physical): 512B/512B
Partition Table:
Number Start End Size Type File system Flags
1 2048s 104857599s 104855552s primary ext3
10. Check to see that any flags that were present earlier are still present for the partition that you expanded
(parted) set 1 boot on
11. Run the quit command to exit parted.
(parted) quit
Returning an Expanded Partition to Its Original Instance
Now that you've expanded the partition.
1. Detach the expanded volume from the secondary instance
2. Re-attach it to the primary instance
3. Start your primary instance and your root partition should be expanded. You can run
4. You can terminate your secondary instance now
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Mohd Adnan
Adnan, an experienced Backend Developer, boasts a robust expertise spanning multiple technologies, prominently Java. He possesses an extensive grasp of cutting-edge technologies and boasts hands-on proficiency in Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as relational databases such as MySQL and PostgreSQL. Adnan consistently delivers invaluable contributions to a variety of client projects, including Vision360 (UK) - Konfer, Bitsclan, Yogamu, Bill Barry DevOps support, enhedu.com, Noorisys, One Infinity- DevOps Setup, and more. He exhibits exceptional analytical skills alongside a creative mindset. Moreover, he possesses a fervent passion for reading books and exploring novel technologies and innovations.