How to Resize an Ext Root Partition at Runtime in Ubuntu?
Tags: ubuntu
Published: 2021-12-14 05:05:56

---
title: How to Resize an Ext Root Partition at Runtime in Ubuntu?
published: true
date: 2021-11-29 06:14:30 UTC
tags: Ubuntu
canonical_url: https://stackallflow.com/ubuntu/how-to-resize-an-ext-root-partition-at-runtime-in-ubuntu/
---

<header>
<p><span style="font-size: 1.2em; color: initial;">ext4</span><span style="font-size: 1.2em; color: initial;">partitioning</span></p>
</header>

How can I increase the size of the root partition of a system at runtime?

I have a partition that is not allocated after the root partition (which is also ext4), how can I add that unallocated space to the space allocated to the root partition without having to shutdown the server?

#### Accepted Answer

**GUI (Ubuntu 14.04 and later)**:  
GParted v0.17 and later provide a nice GUI for this. (Older versions will refuse to resize a mounted partition).

**Command line (any Ubuntu version):** There are three steps to this.

**Step 1.** The partition must first be resized. If you’re using LVM, it’s easy, and you presumably know how to proceed. If you’re using classic partitions, it’s a bit more complicated, and _may_ require a reboot (though you never have to boot another system or live CD).

This is how I do it: Use `fdisk` to first delete the partition (the idea is that the data on disk will be preserved), then carefully recreate it with a larger size at the same position.

Example:

```
$ sudo fdisk /dev/sda

Command (m for help): p

   Device Boot Start End Blocks Id System
/dev/sda1 * 2048 9437183 4717568 83 Linux

Command (m for help): d
Selected partition 1

Command (m for help): p

   Device Boot Start End Blocks Id System

Command (m for help): n
Command action
   e extended
   p primary partition (1-4)
p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759

Command (m for help): p

   Device Boot Start End Blocks Id System
/dev/sda1 2048 10485759 5241856 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

```

Again, it is critical that the new partition starts at the same block as the old. The Id should also match (83 for Linux systems). Be prepared to lose all your data at the slightest typo.

To be on the safe side, you may also restore the boot flag (which [according to Wikipedia](https://en.wikipedia.org/wiki/Boot_flag) is still required on some computers) by pressing `a`.

See the comment section for what to do if your swap partition is in the way.

By now it should be apparent why people recommend using a live CD. ![😉](https://s.w.org/images/core/emoji/13.1.0/72x72/1f609.png)

**Step 2.** As `fdisk` helpfully reminds you, you must reload the partition table before proceeding. The safest way is to simply reboot; but you can also use `partprobe` or `kpartx` [(more information)](https://serverfault.com/questions/36038/reread-partition-table-without-rebooting).

**Step 3.** Once the partition is resized and the partition table reloaded, it’s a simple matter of running `resize2fs` on the file system, and you can do this even when it’s mounted as the root partition.

Example:

```
$ sudo resize2fs /dev/sda1

```

The post [How to Resize an Ext Root Partition at Runtime in Ubuntu?](https://stackallflow.com/ubuntu/how-to-resize-an-ext-root-partition-at-runtime-in-ubuntu/) appeared first on [Stack All Flow](https://stackallflow.com).