Running Raspberry Pi OS on a RPI Zero without SD card

{}
January 2nd, 2021

I’ve blogged before about how to boot a Raspberry Pi Zero over USB without an SD card, just powering it with an USB cable in the middle USB connector, and connecting at the same time.

This Christmas I tried it with a new Buster version and a trusty old Raspberry Pi Zero and following the tutorial it’s still running fine with the latest Raspberry Pi OS 2020-12-02-raspios-buster-armhf-lite.img.

Time for some improvements. Updating and upgrading was always possible, but not always successful: you could easily run into disk-space problems.

Default images are shipped/downloaded as small as possible and the default action of booting a Pi with a new image is resizing the root partition to claim all available space on the SD card.

We’re mounting over NFS and of course the resizing did not happen in our case. Luckily, otherwise your guest OS would end up with no space and the Pi would have a partition size of 1GB (or so).

But for upgrades we need more space than the default.

How to increase the image size of an mounted image over NFS?

The image I have downloaded is `2020-12-02-raspios-buster-armhf-lite.zip`, and we have to follow 4 simple steps.

Step 1: unpack it:

unzip 2020-12-02-raspios-buster-armhf-lite.zip 2020-12-02-raspios-buster-armhf-lite.img

Step 2: resize raw image:

Then use qemu-img (QEMU disk image utility) to resize the raw image.

sudo qemu-img resize 2020-12-02-raspios-buster-armhf-lite.img 3G

Here we resize it to 3G, that must be enough to install some extra programs, and download and install updates.

Step 3: set it up as loop device:

sudo losetup -P /dev/loop101 2020-12-02-raspios-buster-armhf-lite.img

These day I set it up as loop101 instead of loop0 as I did in the blogpost of 2018 to avoid conflicting loop devices. Snaps are also installed as loop devices.

Step 4: resize root partition

start gparted with the loop device to resize the root partition.

sudo gparted /dev/loop101

Normally gparted never shows loop devices, but it does when you explicitly start with a loop device.

Then simply push the slider to resize the image, and apply the changes and you’ve gained 900MB of disk-space.

More than enough to do updates and upgrades for years to come.

Tags:

Leave a Reply