# Expand root partition after the installation

**URL:** https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249
**Category:** Requests
**Created:** [23 January 2016 10:08 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249 "2016-01-23T10:08:14Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![nemeth9](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/n/919ad9/32.png) [@nemeth9](https://dietpi.com/forum/u/nemeth9)
#### Post date: [23 January 2016 10:08 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/1 "2016-01-23T10:08:14Z")

</div>

Hi,

I installed DietPi on a 4GB SD card, set up everything, working fine. I made an image from the installed system than copied to a 16GB SD card.  
I know that the first step of the installation is that the installer expand the root file system to the maximum size of SD card but how can I do this after the migration? In raspbian config there is a setup of this but in dietpi config I haven’t seen.  
Is there any method to do this after the installation?

Thanks!

Regards,  
nemeth9

---

<div class="post-metadata">

### Author: ![Fourdee](https://dietpi.com/forum/user_avatar/dietpi.com/fourdee/32/11_2.png) [@Fourdee](https://dietpi.com/forum/u/Fourdee)
#### Post date: [23 January 2016 12:48 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/2 "2016-01-23T12:48:56Z")

</div>

> [@nemeth9](#):
>
> Hi,
> 
> I installed DietPi on a 4GB SD card, set up everything, working fine. I made an image from the installed system than copied to a 16GB SD card.  
> I know that the first step of the installation is that the installer expand the root file system to the maximum size of SD card but how can I do this after the migration? In raspbian config there is a setup of this but in dietpi config I haven’t seen.  
> Is there any method to do this after the installation?
> 
> Thanks!
> 
> Regards,  
> nemeth9

Hi Nemeth9,

As per the re-partition and resize ext4 code in DietPi: [https://github.com/Fourdee/DietPi/blob/master/dietpi/boot#L44-L72](https://github.com/Fourdee/DietPi/blob/master/dietpi/boot#L44-L72).

**You could essentially make the following scripts to complete the above:**  
_Remember to chmod +x before executing them._

Resize Partition (run 1st):

```plaintext
#!/bin/bash
#Stop Services
/DietPi/dietpi/dietpi-services stop

#Resize partition
cat << _EOF_ | fdisk /dev/mmcblk0
p
d
2
n
p
2
$(parted /dev/mmcblk0 -ms unit s p | grep ':ext4::;' | sed 's/:/ /g' | sed 's/s//g' | awk '{ print $2 }')

p
w

_EOF_

```

Reboot System (run 2nd):

```plaintext
reboot

```

Resize ext4 filesystem (run 3rd):

```plaintext
#!/bin/bash
# Stop Services
/DietPi/dietpi/dietpi-services stop

# Resize Filesystem to new partition size
resize2fs /dev/mmcblk0p2

# Start services
/DietPi/dietpi/dietpi-services start

```

---

<div class="post-metadata">

### Author: ![nemeth9](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/n/919ad9/32.png) [@nemeth9](https://dietpi.com/forum/u/nemeth9)
#### Post date: [23 January 2016 12:58 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/3 "2016-01-23T12:58:47Z")

</div>

> [@Fourdee](#):
>
> > [@nemeth9](#):
> >
> > Hi,
> > 
> > I installed DietPi on a 4GB SD card, set up everything, working fine. I made an image from the installed system than copied to a 16GB SD card.  
> > I know that the first step of the installation is that the installer expand the root file system to the maximum size of SD card but how can I do this after the migration? In raspbian config there is a setup of this but in dietpi config I haven’t seen.  
> > Is there any method to do this after the installation?
> > 
> > Thanks!
> > 
> > Regards,  
> > nemeth9
> 
> Hi Nemeth9,
> 
> As per the re-partition and resize ext4 code in DietPi: [https://github.com/Fourdee/DietPi/blob/master/dietpi/boot#L44-L72](https://github.com/Fourdee/DietPi/blob/master/dietpi/boot#L44-L72).
> 
> **You could essentially make the following scripts to complete the above:**  
> _Remember to chmod +x before executing them._
> 
> Resize Partition (run 1st):
> 
> ```plaintext
> #!/bin/bash
> #Stop Services
> /DietPi/dietpi/dietpi-services stop
> 
> #Resize partition
> cat << _EOF_ | fdisk /dev/mmcblk0
> p
> d
> 2
> n
> p
> 2
> $(parted /dev/mmcblk0 -ms unit s p | grep ':ext4::;' | sed 's/:/ /g' | sed 's/s//g' | awk '{ print $2 }')
> 
> p
> w
> 
> _EOF_
> 
> ```
> 
> Reboot System (run 2nd):
> 
> ```plaintext
> reboot
> 
> ```
> 
> Resize ext4 filesystem (run 3rd):
> 
> ```plaintext
> #!/bin/bash
> # Stop Services
> /DietPi/dietpi/dietpi-services stop
> 
> # Resize Filesystem to new partition size
> resize2fs /dev/mmcblk0p2
> 
> # Start services
> /DietPi/dietpi/dietpi-services start
> 
> ```

Thanks for your fast reply!  
It’s working!

Regards,  
nemeth9

---

<div class="post-metadata">

### Author: ![rhkean1](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/r/bb73d2/32.png) [@rhkean1](https://dietpi.com/forum/u/rhkean1)
#### Post date: [2 February 2016 20:07 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/4 "2016-02-02T20:07:02Z")

</div>

I would like to see an option for MAX\_ROOT\_PARTITION in dietpi.txt that would allow for partition expansion… but not to the maximum size of the uSD card.

```nohighlight
#Resize partition
cat << _EOF_ | fdisk /dev/mmcblk0
p
d
2
n
p
2
$(parted /dev/mmcblk0 -ms unit s p | grep ':ext4::;' | sed 's/:/ /g' | sed 's/s//g' | awk '{ print $2 }')
                          <<<<-------------HERE
p
w

_EOF_

```

the blank line in the script (that I marked as “HERE”) is essentially taking fdisk’s default value for the ending sector (which is the last sector of the uSD). However, if you change that line to “+2048M” , then you get a 2GB partition… even on a 4-64GB card. By adding a setting in the dietpi.txt file, it can be caught during that initial boot where the resizing occurs.

This would allow the admin to come back in and add additional partitions if desired.

or, just resize to 2GB during initial boot and allow for resize in the dietpi-config script to any arbitrary larger size.

---

<div class="post-metadata">

### Author: ![rhkean1](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/r/bb73d2/32.png) [@rhkean1](https://dietpi.com/forum/u/rhkean1)
#### Post date: [4 April 2016 15:01 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/5 "2016-04-04T15:01:06Z")

</div>

Much simpler, with no I/O redirect or sub-shells…

parted /dev/mmcblk0 -s resizepart 2 100%  
  
  
(I haven’t tested this yet with a “+500M” type of parameter)

---

<div class="post-metadata">

### Author: ![perlian](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/p/9de053/32.png) [@perlian](https://dietpi.com/forum/u/perlian)
#### Post date: [7 June 2016 07:13 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/6 "2016-06-07T07:13:06Z")

</div>

i do that kind of things with gparted on another linux PC

works perfectly

---

<div class="post-metadata">

### Author: ![markfree](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/m/dfb087/32.png) [@markfree](https://dietpi.com/forum/u/markfree)
#### Post date: [6 May 2020 00:02 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/7 "2020-05-06T00:02:14Z")

</div>

After first boot my partition was expanded, but I didn’t want that.  
I wanted to shrink my partion again.  
Is there an option to do so at DietPi?  
Thanks

---

<div class="post-metadata">

### Author: ![Joulinar](https://dietpi.com/forum/user_avatar/dietpi.com/joulinar/32/57_2.png) [@Joulinar](https://dietpi.com/forum/u/Joulinar)
#### Post date: [25 May 2020 13:05 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/8 "2020-05-25T13:05:50Z")

</div>

There is no build in option to do that. Using gparted on another PC (booting from Live USB Stick) would be best option

---

<div class="post-metadata">

### Author: ![MDAR](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@MDAR](https://dietpi.com/forum/u/MDAR)
#### Post date: [28 May 2022 11:15 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/9 "2022-05-28T11:15:49Z")

</div>

For some strange reason a system didn’t expand when it was installed, so I had to find a manual way of doing it

These are the steps I followed

```auto
fdisk -l /dev/mmcblk1

```

Which showed me

```auto
Disk /dev/mmcblk1: 14.56 GiB, 15634268160 bytes, 30535680 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
Disklabel type: dos
Disk identifier: 0x2c2a3e4f

Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 8192 8268096 8259904 3.6G 83 Linux

```

```auto
df -h

```

Which showed me

```auto
Filesystem Size Used Avail Use% Mounted on
udev 1.5G 0 1.5G 0% /dev
tmpfs 379M 5.7M 373M 2% /run
/dev/mmcblk1p1 3.9G 3.9G 0 100% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/loop0 2.2M 2.2M 0 100% /snap/avahi/277
tmpfs 1.9G 0 1.9G 0% /tmp
tmpfs 50M 8.0K 50M 1% /var/log
/dev/loop2 49M 49M 0 100% /snap/core18/2289
/dev/loop1 99M 99M 0 100% /snap/core/13253
/dev/loop3 58M 58M 0 100% /snap/core20/1380
/dev/loop4 58M 58M 0 100% /snap/core20/1437
/dev/loop6 49M 49M 0 100% /snap/core18/2406
/dev/loop5 98M 98M 0 100% /snap/core/12837
/dev/loop7 39M 39M 0 100% /snap/snapd/15541
/dev/loop8 39M 39M 0 100% /snap/snapd/15909
/dev/loop9 10M 10M 0 100% /snap/velbus-tcp/140

```

Enlarge the partition: `fdisk -u /dev/mmcblk1`.

`p` to print the partition table, take note of the number, start, end, type of sda1.

Delete it: `d`:

Recreate it using command `n` with same number (1), start and type but with a bigger _end_ (taking care not to overlap with other partitions).

- However, fdisk suggested the maximum value as Default, so I didn’t type any value in and just pressed Enter

if choosing a different end point try to align things on a megabyte boundary that is for _end_, make it a multiple of 2048 minus 1. Change the type if needed with `t` (for partitions holding an `extX` or `btrfs` filesystem, the default of `83` is fine).

Then `w` to write and `q` to quit.

I ran `partprobe` but nothing seems to change, `df -h` still showed as only using 3.6GB.

I rebooted, but nothing changed.

this last step did the trick.

(run each command on it’s own)

```auto
/boot/dietpi/dietpi-services stop
resize2fs /dev/mmcblk1p1
df -h
/boot/dietpi/dietpi-services start`

```

I now have the full 14GB available to me

```auto
Disk /dev/mmcblk1: 14.56 GiB, 15634268160 bytes, 30535680 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
Disklabel type: dos
Disk identifier: 0x2c2a3e4f

Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 8192 30535679 30527488 14.6G 83 Linux

```

---

<div class="post-metadata">

### Author: ![MichaIng](https://dietpi.com/forum/user_avatar/dietpi.com/michaing/32/7_2.png) [@MichaIng](https://dietpi.com/forum/u/MichaIng)
#### Post date: [28 May 2022 14:05 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/10 "2022-05-28T14:05:03Z")

</div>

You can also do it via `dietpi-drive_manager` or:

```bash
systemctl enable dietpi-fs_partition_resize
reboot

```

Doing this on reboot is a bit safer, and that service/script assures that the kernel is informed about the partition table change before expanding the filesystem 🙂.

---

<div class="post-metadata">

### Author: ![master\_lam](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@master\_lam](https://dietpi.com/forum/u/master_lam)
#### Post date: [6 April 2023 03:45 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/11 "2023-04-06T03:45:30Z")

</div>

thank you so much, it’s more easier and safer.  
[https://dietpi.com/docs/dietpi\_tools/system\_configuration/#dietpi-drive-manager](https://dietpi.com/docs/dietpi_tools/system_configuration/#dietpi-drive-manager)

---

<div class="post-metadata">

### Author: ![Jappe](https://dietpi.com/forum/user_avatar/dietpi.com/jappe/32/1788_2.png) [@Jappe](https://dietpi.com/forum/u/Jappe)
#### Post date: [5 December 2023 08:04 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/12 "2023-12-05T08:04:39Z")

</div>

3 posts were split to a new topic: [Expanding partition does not work](https://dietpi.com/forum/t/expanding-partition-does-not-work/18589)

---

<div class="post-metadata">

### Author: ![Joulinar](https://dietpi.com/forum/user_avatar/dietpi.com/joulinar/32/57_2.png) [@Joulinar](https://dietpi.com/forum/u/Joulinar)
#### Post date: [5 December 2023 08:09 UTC](https://dietpi.com/forum/t/expand-root-partition-after-the-installation/249/13 "2023-12-05T08:09:49Z")

</div>

A post was merged into an existing topic: [Expanding partition does not work](https://dietpi.com/t/expanding-partition-does-not-work/18589/5)
