# Resizing the Raspberry Pi Boot Partition

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/032/733/medium800/raspberry_pi_banner.jpg?1464295304)

Though&nbsp;the Raspberry Pi computer is eminently networkable, some projects still just work best by physically moving the SD card to a desktop system to exchange data…but normally only a small section of the card is accessible to Windows and Mac computers. This guide explains one way of making more space available&nbsp;to both the Pi and other systems.

Some examples of projects that work this way include cameras, data loggers and handheld game consoles…anywhere a network connection can’t be assumed. This is the decades-old tradition of “Sneakernet” — once done with floppy disks or tape, but still occasionally relevant in our age of flash memory.

Utilities exist&nbsp;to allow Windows and Mac systems to&nbsp;access the main SD partition,&nbsp;but I prefer the following&nbsp;method&nbsp;as it allows a stock PC to read and write the card, vital when working in the field or on a borrowed&nbsp;computer.

# Items Needed

In most cases, **_two_ Raspberry Pi computers** are required…

One is the “ **target** ” system — usually embedded into a project, this is the camera or data logger or game console, whatever you’re building. Sometimes it might be a “headless” system with no display.

The other is the “ **setup** ” system — this runs a full version of the Raspbian desktop operating system, has **networking** capability, with **keyboard** , **mouse** and **monitor** attached. A Raspberry **Pi 3** , **Pi 2** , or **Model B+** are ideal for this, since they have ample USB ports (and built-in WiFi on the Pi 3).

There are some exceptions where this can be done with a single system, or an alternate setup system…more on that in a moment.

**Also required:**

- USB flash card reader.
- **Two** micro SD cards: the **setup** system requires an **8 GB or larger** card, the **target** can be most any size, though **4 to 32 GB** is ideal… **whatever your target operating system requires** , plus space for the data to be moved between systems.
- Depending on your network and setup system features, an Ethernet connection or a USB WiFi adapter may be required (WiFi is built-in on Pi 3).

**Some prior Raspberry Pi experience&nbsp;is assumed; writing an SD card, connecting to networks, etc. If you’re new to Raspberry Pi and any of this is unfamiliar,&nbsp;begin with our starter tutorials in the [Learn Raspberry Pi](../../../../category/learn-raspberry-pi)&nbsp;series.**

# What if I’ve Only Got One Raspberry Pi?

If your target system is a “full featured” Pi — something like a Pi 3, Pi 2 or Model B+, easily networked and with many USB ports — it’s no problem, the target system can also act as the setup system, just switch&nbsp;SD cards when needed.

If your target is a “feature-limited” Pi — like a Model A+ or Pi Zero — you can still do your setup on this system, but unless you already own&nbsp;a collection of the required dongles (powered USB hub, WiFi or Ethernet adapter, mini-to-full-size HDMI adapter for Pi Zero, etc.), it’s easier and often cheaper just to order the latest Pi board to do the setup than to deal with all these parts. And when you’re done, now&nbsp;you have an extra Pi to play around with.

But there’s one more option…if you have a desktop or laptop computer running any of the popular Linux desktop distributions (e.g. Ubuntu, Debian, etc.)…often you can&nbsp;use this as the “setup” system, the necessary software (gparted) is usually already installed. You’ll only need one Raspberry Pi (the target system) and one SD card in this situation.

# Resizing the Raspberry Pi Boot Partition

## Setup

 **Download** an&nbsp; **operating system SD card image** for each system ( **setup** and **target** ). For the “setup” system, this will be **[Raspbian Jessie](https://www.raspberrypi.org/downloads/raspbian/)**&nbsp;(the full version, not “Lite”)…2016-05-10 or later, whatever the current release is. For the “target” system…this depends on the project…sometimes it’ll use the same Raspbian Jessie image, others will use Raspbian Jessie Lite (which lacks the GUI desktop and other features), or an entirely different SD card image from another project.

“ **Burn** ” each OS to an SD card using a tool such as [Etcher](http://www.etcher.io)&nbsp;or your utility of choice. For the “setup” system running full Raspbian, this requires an **8 GB or larger** card. For the “target” system, this depends…whatever the operating system requires, plus some extra working space for exchanging data…this could be as small as **2 GB** for something like Raspbian Jessie Lite, or up to **32 GB** maximum.

Keep track of which card is which…setup or target.

# Boot and Configure Target System

Let’s set up the **target** system first, though I realize this is a bit counter-intuitive.

If your target system OS is based on a recent version of **Raspbian Jessie** (or Lite), one nice feature is that it will boot on **_any_ Raspberry Pi&nbsp;board**. So if your target hardware is a feature-limited&nbsp;Model A+ or a Pi Zero, you can boot on a more capable system (Pi 3, etc.) which is faster and more easily networked, then move the card later.

Go through the usual **first-boot configuration** process. For Raspbian,&nbsp;that means logging&nbsp;in with the default “ **pi** ” / “ **raspberry** ” username and password and running the **raspi-config** utility…

```auto
sudo raspi-config
```

![](https://cdn-learn.adafruit.com/assets/assets/000/032/674/medium800/raspberry_pi_Screen_Shot_2016-05-23_at_5.14.58_PM.png?1464112396)

At the very least, you should expand the filesystem and set up the _Internationalisation Options_ (especially the keyboard…if you’re getting unexpected characters when typing, this is why). Depending on the project this is going into, you may want to enable the camera, disable overscan (under _Advanced Options_), etc. Totally depends on the project…choose your own adventure.

With the basic setup done (it may prompt you&nbsp;to reboot…this is fine), you may want to get the Pi connected to your network to download additional software, apply updates, etc. That’s beyond the scope of this guide, but&nbsp;you’ll find pointers in the [Learn Raspberry Pi](../../../../series/learn-raspberry-pi)&nbsp;series.

Basically…your goal is to get the target system card **as close to finished as possible** , all software installed and configured.

Once that’s ready, shut the system down gracefully…if working from the Raspbian command line, that’s…

```auto
sudo shutdown -h now
```

After the system has halted (it takes about 20 seconds or so), disconnect power, remove the SD card and **put it into the USB card reader**.

# Boot and Configure the Setup System

Now we’ll repeat that process for the **setup** system…except this one will definitely be running the **_full_ Raspbian Jessie** OS, so you’ll have a mouse and GUI desktop for all of this.

The system configuration utility can be accessed&nbsp;at&nbsp; **Pi Menu→Preferences→Raspberry Pi Configuration**.

![raspberry_pi_config-gui.png](https://cdn-learn.adafruit.com/assets/assets/000/032/736/medium640/raspberry_pi_config-gui.png?1464301253)

Once the basic system is configured to your liking, set up networking. Sometimes this is as easy as plugging in an Ethernet cable or using the WiFi icon near&nbsp;the top-right of the screen.

This Pi system&nbsp;_must_&nbsp;have a&nbsp; **working internet connection** &nbsp;to complete this guide.

# Back Up Target SD Card

Put the target system’s SD card in a USB reader and plug it into your normal desktop computer, or wherever you originally “burned” the SD card images.

Most utilities for burning SD cards also have a feature for working the other direction…they can back up an SD card to a file. (Etcher doesn’t have this feature yet, but other utilities do.)

Make a backup image of your target SD card before proceeding. We’ll be doing some serious shenanigans on the next page. There’s the possibility of messing things up, so this “save point” is insurance against having to start completely from scratch.

Once you have a backup, eject the USB reader and plug it into the setup system.

# Resizing the Raspberry Pi Boot Partition

## Edit Partitions

At this point, your “setup” system should be up and running the Raspbian graphical desktop, with networking, keyboard and mouse connected, with&nbsp;the “target” system's SD card in a USB reader connected to one of the setup system’s USB ports.

We’ll use the **_gparted_** utility to edit the partition table. This is not installed with Raspbian by default, hence the need for a network connection.

It’s usually fastest and easiest to open a Terminal window and type:

```auto
sudo apt-get install -y gparted
sudo gparted
```

If you _insist_ on using a GUI to install the software, click&nbsp; **Pi Menu→Preferences→Add / Remove Software**. You’ll find gparted in the “Gnome Desktop” section, or use the search field to locate it. Tick the check&nbsp;box and click “Apply” to install.

You can then run&nbsp;gparted via&nbsp; **Pi Menu→Preferences→GParted**. You’ll be asked for the root password, since this is a system-level operation.

But really, the Terminal way is _much_ quicker.

![raspberry_pi_add-remove-1.png](https://cdn-learn.adafruit.com/assets/assets/000/032/675/medium640/raspberry_pi_add-remove-1.png?1464117680)

![raspberry_pi_add-remove-2.png](https://cdn-learn.adafruit.com/assets/assets/000/032/676/medium640/raspberry_pi_add-remove-2.png?1464117691)

![raspberry_pi_gparted.png](https://cdn-learn.adafruit.com/assets/assets/000/032/677/medium640/raspberry_pi_gparted.png?1464117716)

# Select Device
When you first run gparted, it will select the **internal** SD card by default.

We want to edit the card in the **USB reader**. To do this, use the pop-up menu near the top-right of the window, or the **GParted→Devices** menu.

It should appear as **/dev/sda** &nbsp;or similar…the name’s not important, just make sure you’re **not** selecting /dev/mmcblk0, which is the internal card.

![raspberry_pi_device-menu-1.png](https://cdn-learn.adafruit.com/assets/assets/000/032/660/medium640/raspberry_pi_device-menu-1.png?1464112069)

![raspberry_pi_device-menu-2.png](https://cdn-learn.adafruit.com/assets/assets/000/032/661/medium640/raspberry_pi_device-menu-2.png?1464112076)

# Save /boot Partition Contents

You’ll see&nbsp;a graph and list of at least two partions on the card — the tiny _boot_&nbsp;partition, and a much larger partition taking up the bulk of the card — and perhaps one or more small “unallocated” spaces.

_The unallocated spaces are used to align partitions to specific&nbsp;start and end points on the card. You can ignore these._

The first “real”&nbsp;partition is a FAT16 filesystem…that’s the boot partition on the target system SD card. Note the _mount point_ of this partition…it’s probably **/media/pi/boot** or similar. We’ll need this exact path in a moment.

![](https://cdn-learn.adafruit.com/assets/assets/000/032/714/medium800/raspberry_pi_partitions-before-meddling.png?1464238910)

Open a Terminal window if you don’t already have one running, and type the following commands…

```auto
cd
sudo cp -r /media/pi/boot .
```

You may need to change “/media/pi/boot” if a different mount point was shown in gparted. Also, there should be a space between “boot” and the final period.

This copies the full contents of the /boot partition (from the&nbsp;card in the USB reader, not the setup system’s card) to a directory called “boot” in your home folder. This is a temporary measure…we’ll move these files back later.

# Unmount Partitions Before Editing

**You can not&nbsp;edit partitions while mounted** (e.g. accessing&nbsp;files). If there’s a **key&nbsp;icon** next to one or both partitions, it’s necessary to unmount these filesystems first…

![](https://cdn-learn.adafruit.com/assets/assets/000/032/664/medium800/raspberry_pi_partitions-locked.png?1464112176)

Highlight&nbsp;the /boot partition, then select **Partition→Unmount**.

_As a shortcut, you can also right-click on a partition in the graph or list and select Unmount there._

**Repeat** for the second (root) partition. There should be **no key icons** in the list…everything’s editable now.

![raspberry_pi_unmount-1.png](https://cdn-learn.adafruit.com/assets/assets/000/032/670/medium640/raspberry_pi_unmount-1.png?1464112292)

![raspberry_pi_unmount-2.png](https://cdn-learn.adafruit.com/assets/assets/000/032/671/medium640/raspberry_pi_unmount-2.png?1464112300)

When everything’s&nbsp;ready, it should look something like this…

![](https://cdn-learn.adafruit.com/assets/assets/000/032/672/medium800/raspberry_pi_unmounted.png?1464112315)

# Resize the Root Partition

To increase the /boot partition, we first need to _shrink_ the root partition to make space.

Highlight&nbsp;the **root** partition ( **/dev/sda2** ) and&nbsp;select&nbsp; **Partition→Resize/Move** _(or use the right-click shortcut)._

![](https://cdn-learn.adafruit.com/assets/assets/000/032/665/medium800/raspberry_pi_root-resize.png?1464112213)

The Resize/Move dialog visually shows the full partition size (white) and the amount of data actually present within (yellow).

Because this is a Linux system, there needs to be _some_ space left for caches and log files…or for future updates and additions…we can’t shrink it down to an _exact_ fit.

There’s no hard-and-fast rule for exactly _how much_ should be kept free. One third to one half felt “safe”…with Raspbian Jessie Lite, I rounded to an even 2000 MB.

**Any surplus should go to the _Free space preceding_&nbsp;field…_Free space following_ should be 0.**

You can do this either with the numeric fields or by dragging and moving the partition graph&nbsp;with the mouse. When it’s adjusted to your liking, click the “Resize/Move” button.

A&nbsp;pop-up dialog will warn about moving partitions. It’s all good, just click “OK.”

![raspberry_pi_root-resize-1.png](https://cdn-learn.adafruit.com/assets/assets/000/032/716/medium640/raspberry_pi_root-resize-1.png?1464288961)

![raspberry_pi_root-resize-2.png](https://cdn-learn.adafruit.com/assets/assets/000/032/717/medium640/raspberry_pi_root-resize-2.png?1464288970)

![raspberry_pi_root-resize-3.png](https://cdn-learn.adafruit.com/assets/assets/000/032/718/medium640/raspberry_pi_root-resize-3.png?1464288980)

Afterward, it should look something like this (though your partition sizes may vary with card capacity and installed operating system version):

![](https://cdn-learn.adafruit.com/assets/assets/000/032/719/medium800/raspberry_pi_root-resized.png?1464289577)

_The partition map isn’t actually changed on the card yet._ Several operations can be queued up and applied all at once…

# Create a Larger&nbsp;Boot Partition

This next sequence is the _secret sauce_ that makes this guide work…

**Using gparted’s Resize/Move feature on the boot partition renders the card unreadable** on Windows and Mac systems (though it still works with Linux). So the trick here is to **delete the existing&nbsp;boot partition** , **create a new one** with the desired size, then **restore the files** there that we backed up earlier.

Highlight&nbsp;the&nbsp; **boot** &nbsp;partition ( **/dev/sda1** ) and&nbsp;select&nbsp; **Partition→Delete** &nbsp;_(or use the right-click shortcut)._

You’ll then have the root partition on the right, and a lot of unallocated space on the left.

Then select&nbsp; **Partition→New** to begin creating a replacement…

![raspberry_pi_boot-delete.png](https://cdn-learn.adafruit.com/assets/assets/000/032/721/medium640/raspberry_pi_boot-delete.png?1464290610)

![raspberry_pi_boot-deleted.png](https://cdn-learn.adafruit.com/assets/assets/000/032/722/medium640/raspberry_pi_boot-deleted.png?1464290645)

![raspberry_pi_boot-new.png](https://cdn-learn.adafruit.com/assets/assets/000/032/723/medium640/raspberry_pi_boot-new.png?1464290661)

The _Create new Partition_ dialog is similar to the Resize/Move dialog, but with some additional options…

![](https://cdn-learn.adafruit.com/assets/assets/000/032/724/medium800/raspberry_pi_boot-new-dialog.png?1464290835)

Adjust the size (using the mouse or text fields) to fill the available space, but note that there is an&nbsp; **upper limit** &nbsp;to the /boot partition size…it&nbsp; **cannot exceed 32GB** , even on a very large SD card. If there’s room&nbsp;left over, you can edit the root partition again, enlarging it to claim this space, or create extra partition(s) there (these will appear as separate drives, not a contiguous space).

For the other options, select/enter the following _exactly:_

- Create as: **Primary Partition**
- File system: **fat32**
- Label: **boot**

Then click the “Add” button.

When you’re done, the partition map should look something like the following. It _may or may not_ include small “unallocated” blocks — either way is completely&nbsp;normal, it varies with partition sizes and SD card capacity.

![](https://cdn-learn.adafruit.com/assets/assets/000/032/725/medium800/raspberry_pi_new-partition-map.png?1464291204)

# Apply Changes

Nothing has actually changed yet; all operations are queued up. Clicking the “ **Apply** ” button (the green check mark) will commence reorganizing&nbsp;the data and partitions on&nbsp;the card…

![](https://cdn-learn.adafruit.com/assets/assets/000/032/726/medium800/raspberry_pi_apply.png?1464291336)

…but not without warning you first. Take heed, if something goes amiss you might end up with a scrambled card and have to start over from scratch. This is why it’s a good idea to make a backup before any serious disk editing.

![](https://cdn-learn.adafruit.com/assets/assets/000/032/659/medium800/raspberry_pi_confirm.png?1464112039)

Once you click “Apply,” the system will be&nbsp;moving around a lot of data…these operations can take a long time, so this is a good opportunity to take a break or tidy up your desk or something.

![raspberry_pi_applying-1.png](https://cdn-learn.adafruit.com/assets/assets/000/032/734/medium640/raspberry_pi_applying-1.png?1464295800)

![raspberry_pi_applying-2.png](https://cdn-learn.adafruit.com/assets/assets/000/032/735/medium640/raspberry_pi_applying-2.png?1464295808)

Once those operations are complete, you’ll see the same partition map again, but without the “pending” messages at the bottom…everything is now “real” on the card.

To mount the new partitions, it’s easiest just to **unplug and re-plug the USB card adapter**. You’ll get a “Removable medium” dialog box when you do this (two, actually…one for the boot partition, one for root). Just click “ **Cancel** ” for each. We want the partitions mounted but don’t need to browse the files.

![raspberry_pi_insert.png](https://cdn-learn.adafruit.com/assets/assets/000/032/730/medium640/raspberry_pi_insert.png?1464291964)

Back in gparted now, select **GParted→Refresh Devices** and then select **/dev/sda** from the device list.

It should resemble&nbsp;the following, with a key next to each partition (indicating that it’s mounted). This is with an 8 GB card, with Raspbian Jessie Lite in the root partition, the rest allocated to the /boot partition. There might be one or more small unallocated spaces depending on your card.

![](https://cdn-learn.adafruit.com/assets/assets/000/032/731/medium800/raspberry_pi_final-partitions.png?1464292256)

# Restore /boot Data

Last step now is to restore the data we saved from the original /boot partition. In a Terminal window, type the following commands.

(If you encounter an error, **do not** continue with the next command, since the last step&nbsp; **deletes** all the saved data! Check your typing and that the named directories exist, etc.)

```auto
cd
sudo cp -r boot /media/pi
sudo umount /media/pi/*
sudo rm -r boot
```

# Done!

You can quit from gparted now and unplug the SD card reader.

Perform an orderly shutdown of your setup system ( **Pi Menu→Shutdown…** ), then swap the SD cards and confirm the system can still boot from the&nbsp;newly-reconfigured&nbsp;card.

Since mine was a Jessie Lite system, this boots to a command line. I can log in and type “ **df -k** ” to see the partition sizes and free space, in kilobytes (the mount points “/” and “/boot” are of interest — the root and boot partitions, respectively).

![](https://cdn-learn.adafruit.com/assets/assets/000/032/732/medium800/raspberry_pi_Screen_Shot_2016-05-25_at_10.35.46_PM.png?1464292658)

# Resizing the Raspberry Pi Boot Partition

## Bonus! Shrinking Images

Once you create an image from an SD card, the resulting file is always the _full capacity_ of the card, which may be _way_ more than the actual data storage size. Copy the script below and paste it in a new file…suppose it’s called **script.sh** …which can then be executed as follows to shrink the image file to a more manageable size:

```terminal
sudo bash ./script.sh pi.img
```

The script:

```auto
#!/bin/env bash

IMG="$1"

if [[ -e $IMG ]]; then
  P_START=$( fdisk -lu $IMG | grep Linux | awk '{print $2}' ) # Start of 2nd partition in 512 byte sectors
  P_SIZE=$(( $( fdisk -lu $IMG | grep Linux | awk '{print $4}' ) * 512 )) # Partition size in bytes
  losetup /dev/loop2 $IMG -o $(($P_START * 512)) --sizelimit $P_SIZE
  fsck -f /dev/loop2
  resize2fs -M /dev/loop2 # Make the filesystem as small as possible
  fsck -f /dev/loop2
  P_NEWSIZE=$( dumpe2fs /dev/loop2 2>/dev/null | grep '^Block count:' | awk '{print $3}' ) # In 4k blocks
  P_NEWEND=$(( $P_START + ($P_NEWSIZE * 8) - 1 )) # in 512 byte sectors
  losetup -d /dev/loop2
  echo -e "p\nd\n2\nn\np\n2\n$P_START\n$P_NEWEND\np\nw\n" | fdisk $IMG
  I_SIZE=$((($P_NEWEND + 1) * 512)) # New image size in bytes
  truncate -s $I_SIZE $IMG
else
  echo "Usage: $0 filename"
fi
```

After writing this image to a card and booting from it, the filesystem can be re-expanded to the full card using:

```terminal
sudo raspi-config --expand-rootfs
```


## Related Guides

- [NeoTrellis M4 MIDI File Synthesizer](https://learn.adafruit.com/neotrellism4-midi-file-player-synthesizer.md)
- [Matrix Portal M4 Boxing Interval Timer](https://learn.adafruit.com/matrix-portal-m4-boxing-interval-timer.md)
- [Portable Qi Charger](https://learn.adafruit.com/portable-qi-charger.md)
- [Feather + Raspberry Pi Weather Monitoring Network with LoRa or LoRaWAN](https://learn.adafruit.com/multi-device-lora-temperature-network.md)
- [File Glider](https://learn.adafruit.com/file-glider.md)
- [LED Matrix Display for Bitmap Pixel Art and Animation](https://learn.adafruit.com/pixel-art-matrix-display.md)
- [Adafruit IO Basics: Schedule Actions](https://learn.adafruit.com/adafruit-io-basics-scheduled-triggers.md)
- [MakeCode Arcade with Raspberry Pi Zero](https://learn.adafruit.com/makecode-arcade-with-raspberry-pi-zero.md)
- [Matrix Portal New Guide Scroller](https://learn.adafruit.com/matrix-portal-new-guide-scroller.md)
- [MUNNY Glowing Friend with Bluetooth Control!](https://learn.adafruit.com/munny-lamp.md)
- [IoT Temperature Logger with Analog Devices ADT7410, Raspberry Pi, and Adafruit IO](https://learn.adafruit.com/iot-temperature-logger-with-python-and-adafruit-io.md)
- [Light Up Paper Dragon Wall Sconce](https://learn.adafruit.com/light-up-paper-dragon-wall-sconce.md)
- [ABC Soundboards with NeoTrellis](https://learn.adafruit.com/abc-soundboards-with-neotrellis.md)
- [Using a Raspberry Pi as a Router](https://learn.adafruit.com/using-a-raspberry-pi-as-a-router.md)
- [Purple Air AQI Display](https://learn.adafruit.com/purple-air-aqi-display.md)
