‘gparted’ is the graphical version of ‘parted’ and is the tool to use to resize the main partition used for raspbian (or you could use use parted if you prefer the command line of course!).  It can also be used to check and repair a SD card disk.

To do this you’ll need to put the SD card you want to work on in a USB to SD card adaptor and boot your RPi from a separate SD card.  If you’d rather use a windows tool we’ve found that gparted just works whereas all of the windows based partition managers we tried don’t, so better to just get over the hassle factor and use the RPi to do this if you don’t have a separate Linux system.

Installing gparted on the separate Raspbian SD card that will perform the change

From the command line use:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install gparted

Running gparted

To run it use ‘sudo startx’ to load the GUI as gparted needs root user privileges

Then from the start menu select run and enter ‘gparted’

Resizing Your Main Partition

From the top bar devices drop down select “dev/sda” (or whatever your external USB adaptor has been called).

Right click somewhere on the graphic and select ‘unmount’ first as operations can’t be carried out on a mounted partition.

Right click the main ‘ext4’ partition and select ‘check’, then click the green tick and let it check the partition for you (this isn’t essential but its a good idea as if there are issues it will likely cause the resize to fail).

Right click the main ‘ext4’ partition and select ‘resize’ then enter the new size you want it to be.

Right click the main ‘ext4’ partition and select ‘check’ (we’ve found this to be necessary to ensure the new partition size is correctly updated in the file system even though it should be done as part of the resize – kept us chasing constantly failed resizes for hours before we discovered this).

Finally click the green arrow button to carry out the changes.

Reboot the RPi (yep its stupid but we’ve found a reboot to be needed even after removing and re-inserting the SD card), sudo startx, run gparted, select the USB drive and check the ext4 partition is locked again (mounted) and has its boot string back.

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

  1. Xanatos

    5 years ago

    I performed the above steps and all went normally until:

    sudo startx

    Immediately after this it flashed an error for about 1/2 second (something about “agent already started”?), then the terminal window and browser I had open both closed, and I could not reopen.

    I rebooted, now I am getting a login screen. It gives me the option of Pi or Other. I have read that the default password for Pi is raspberry, and when I try that, it seems to accept it, but the screen goes black, then returns to the normal desktop background screen, and again presents me with the login box. Any other password, including not entering anything, says “Incorrect password, please try again”. I seem to be thoroughly locked out of my Pi now.

    Any suggestions?

    Thanks,

    Dave

    1. PAULO RAPHAEL MENEZES CORREA

      4 years ago

      CTRL+ALT+F6 login and…

      reset permissions on your home folder: sudo chown -R pi /home/pi

      After that reset. Works for me.

    2. Ricky Tsc

      4 years ago

      Thanks, i wonder if that will ever get fixed, seems really odd to me that you would have to do this just to use your pi after using gparted

    3. anand doshi

      9 months ago

      CTRL+ALT+F1
      $>sudo mv /home/pi/.Xauthority /home/pi/.Xauthority.bk
      $>reboot

      This will fix the problem. Because you ran startx, the .Xauthority file is not owned by root, instead of the pi user. so when you log in as pi, the log in process cannot overwrite that file.

    4. Cuvtixo

      8 months ago

      This is old, I know, but “sudo startx” is no longer needed, if it ever was, and the information here was probably outdated when you tried four years ago. Gparted will now ask for authentication when started, and gives options to authenticate as users (pi) or root. AFAIK this has not been needed in any flavor of x86 linux, at least not for quite some time. I’ve been using linux since ’99 and gparted is one of my favorite programs as I’ve been distro-hopping and using multiboot configurations all that time, I much prefer this to running virtual machines. I don’t really see the logic of it anyways. “Gparted” needs permissions, the gui doesn’t.

  2. anand doshi

    9 months ago

    i wanted to create a partition on the main file system (/dev/mmcblk0p7 mounted on / in my case which is currently 28.26gb), so i can bring it down to 20gb and create a new partition for the 8gb. But, even though i am running gparted as root (after running startx), i can not unmount that and so cannot resize it.
    any advice?
    TIA.

    1. Cuvtixo

      8 months ago

      You cannot resize the partition while simultaneously using it. In x86 linux, the usual procedure is to run gparted from a bootable USB or optical disk. https://gparted.org/livecd.php the “LiveCD: is an entire linux distro specifically made for manipulating disk partitions. I prefer other utility distros because Gparted Live hasn’t had wifi utilities by default, although apparently there’s resources for one to build Gparted Live from scratch. So you will need a bootable USB for the Pi that already has Gparted on it. AFAIK Gparted Live doesn’t have a Raspberry Pi version, perhaps not even an ARM version. With a little thought, you’ll see why it’s unsafe to manipulate the partition you booted into; you could theoretically accidentally erase the disk (including gparted) while using it, which would immediately crash it (unless it’s running in RAM). It’s fundamentally unsafe, which is part of the reason root permission is always necessary to run Gparted.

    2. Cuvtixo

      8 months ago

      I’m not sure my previous answer was published. Anyways you can never use Gparted on the partition it’s on. You need a second disk to boot into.

  3. Anonymous

    8 months ago

    Hi I used this:

    CTRL+ALT+F1
    $>sudo mv /home/pi/.Xauthority /home/pi/.Xauthority.bk
    $>reboot

    This will fix the problem. Because you ran startx, the .Xauthority file is not owned by root, instead of the pi user. so when you log in as pi, the log in process cannot overwrite that file.

    How do I return it to its original state?

Comments

Your email address will not be published.