Though 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 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 to allow Windows and Mac systems to access the main SD partition, but I prefer the following method as it allows a stock PC to read and write the card, vital when working in the field or on a borrowed computer.
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.
- 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 is assumed; writing an SD card, connecting to networks, etc. If you’re new to Raspberry Pi and any of this is unfamiliar, begin with our starter tutorials in the Learn Raspberry Pi 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 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 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 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 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.
Download an operating system SD card image for each system (setup and target). For the “setup” system, this will be Raspbian Jessie (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 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 board. So if your target hardware is a feature-limited 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, that means logging in with the default “pi” / “raspberry” username and password and running the raspi-config utility…
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 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 you’ll find pointers in the Learn Raspberry Pi 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…
sudo shutdown -h now
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 at Pi Menu→Preferences→Raspberry Pi Configuration.
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 the top-right of the screen.
This Pi system must have a working internet connection 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.
At this point, your “setup” system should be up and running the Raspbian graphical desktop, with networking, keyboard and mouse connected, with 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:
sudo apt-get install -y gparted
sudo apt-get install -y gparted
If you insist on using a GUI to install the software, click 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 box and click “Apply” to install.
You can then run gparted via 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.
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 or similar…the name’s not important, just make sure you’re not selecting /dev/mmcblk0, which is the internal card.
Save /boot Partition Contents
You’ll see a graph and list of at least two partions on the card — the tiny boot 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 start and end points on the card. You can ignore these.
The first “real” 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.
Open a Terminal window if you don’t already have one running, and type the following commands…
sudo cp -r /media/pi/boot .
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 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 edit partitions while mounted (e.g. accessing files). If there’s a key icon next to one or both partitions, it’s necessary to unmount these filesystems first…
Highlight 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.
When everything’s ready, it should look something like this…
Resize the Root Partition
To increase the /boot partition, we first need to shrink the root partition to make space.
Highlight the root partition (/dev/sda2) and select Partition→Resize/Move (or use the right-click shortcut).
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 field…Free space following should be 0.
You can do this either with the numeric fields or by dragging and moving the partition graph with the mouse. When it’s adjusted to your liking, click the “Resize/Move” button.
A pop-up dialog will warn about moving partitions. It’s all good, just click “OK.”
Afterward, it should look something like this (though your partition sizes may vary with card capacity and installed operating system version):
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 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 boot partition, create a new one with the desired size, then restore the files there that we backed up earlier.
Highlight the boot partition (/dev/sda1) and select Partition→Delete (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 Partition→New to begin creating a replacement…
The Create new Partition dialog is similar to the Resize/Move dialog, but with some additional options…
Adjust the size (using the mouse or text fields) to fill the available space, but note that there is an upper limit to the /boot partition size…it cannot exceed 32GB, even on a very large SD card. If there’s room 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 normal, it varies with partition sizes and SD card capacity.
Nothing has actually changed yet; all operations are queued up. Clicking the “Apply” button (the green check mark) will commence reorganizing the data and partitions on the card…
…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.
Once you click “Apply,” the system will be 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.
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.
Back in gparted now, select GParted→Refresh Devices and then select /dev/sda from the device list.
It should resemble 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.
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 deletes all the saved data! Check your typing and that the named directories exist, etc.)
sudo cp -r boot /media/pi
sudo umount /media/pi/*
sudo rm -r boot
sudo cp -r boot /media/pi
sudo umount /media/pi/*
sudo rm -r boot
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 newly-reconfigured 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).
Once you read an image from as SD card, it'll be the full 4 or 8 G, which may be way more than the actual data storage size. This script, which you can download run as "script.sh pi.img" on the image will resize the binary file