Resizing disc on Raspberry Pi

I want to resize the storage on the sd card I am using for Raspberry Pi. Being a newbie the instructions go beyond my limited knowledge. Can some one please spell out hoe to do the following from the frontpage:-
Re-size file system
https://ubuntu-mate.community/top
There are no utilities included for automatic file system re-sizing. However, it’s not hard to do manually. Once booted:

sudo fdisk /dev/mmcblk0 :- this gives me a welcome to fdisk and Command (m for help) : :-what next before I can do :_

Delete the second partition (d, 2), (How?) then re-create it using the defaults (n, p, 2, enter, enter), then write and exit (w). Reboot the system, then:

sudo resize2fs /dev/mmcblk0p2
Apart form all that - this entry system is weird!
Cheers
John

These commands are to be entered into a terminal, which is like a command line interface, but it’s very powerful. :smile: To open a terminal, press CTRL+ALT+T on your keyboard or start it from Applications → System Tools → Terminal.

Now to explain what’s happening:

There are no utilities included for automatic file system re-sizing. However, it’s not hard to do manually. Once booted:

sudo fdisk /dev/mmcblk0

This is the command that will enter an “interactive mode” to manipulate this partition containing Ubuntu MATE, which is identified as “mmcblk0”.

Delete the second partition (d, 2), then re-create it using the defaults (n, p, 2, enter, enter), then write and exit (w).

Press the keys in that order:

  1. d → 2 to delete the existing structure.
  2. n → p → 2 → Enter ⏎ → Enter ⏎ to re-create to use all remaining space.

You should just check that each operation is successful before proceeding to the next key. If you’re curious, press h to display command help.

Reboot the system, then:

sudo resize2fs /dev/mmcblk0p2

Now that the partition boundaries have been resized, the actual filesystem needs to be resized to use the new space. Once this command is complete, your Raspberry Pi is now using all of the available SD card space. :thumbsup:

1 Like

Thank you- I was wary of doing such potentially drastic actions - it now works a treat - it is a good backup for my laptop -I DO like Ubuntu (I dislike and distrust Windows (as for Windows 10 - I wont be touching it with a bargepole)) thanks again
John

1 Like

Yep, these are the commands to type in a terminal window. The steps described are very easy to follow.

why not just do sudo apt-get install raspi-config and use resize (and some other options while you’re at it)?

Just an update to this thread, the option to resize SD card partitions is avaliable as a one-click operation in Welcome’s Raspberry Pi page.

Resizing from the welcome screen was the first thing I did upon installing to my first 16Gb card. However after using it for a few days and realizing a 32Gb card was only 8 bucks I decided to upgrade. I used dd to move my install over to the new card but then when I went to welcome it said my card had already been resized. The original instructions worked like a charm, but I wonder if I had done something different would that have been the case.

On another topic I threw a standard apt based Ubuntu server on the original 16Gb card and the manual instructions worked to resize that partition as well. No real surprise but wanted to mention the results.

Welcome isn’t smart enough to detect this. It’s mostly there for convenience. There’s a hidden file that tracks whether it was resized or not, deleting it would show the option again:

sudo rm /.resized

Glad to hear the original instructions are still handy. :thumbsup:

Oh man, that is great info. I’ll keep it in mind for next time I bump up to the next card size.

That has me curious though, what little experience I have seems to show this as seamless, painless, and safe. Especially given how easy it is to do a full backup. Isn’t there some way to look at the partition and drive and just offer the option any time there is space not being utilized?

Technically possible, but gets more complicated when you consider other partitions and custom setups. Welcome is intended to be a easy for newcomers who mostly want to plug in and go. :wink:


Protip – you don’t need Welcome – After you have dd'd the image to a new card, use GParted on the same system to resize and grow that card’s partition. Kill two birds with one stone, as they say. :slight_smile:

Another way of imaging cards is using Disks. :slight_smile:

I now use a Python script that can do the job in the background as described with “rootfs-resize” and I got it running manually on Ubuntu MATE using the “systemd” services setup.

Might be worth to consider whether this described mechanism can be included in the next image release to be fired automatically during 1st OS setup :wink: