Skip to main content

how I set up my Raspberry Pi to boot from an external USB drive

I have a raspberry pi that serves a Nextcloud instance and some other personal sites. Rather than storing data in the cloud, we say we store ours in the cupboard.

Until this week, it was a Raspberry Pi 3. Working on it was a bit of a pain because it didn't have much memory, so I've finally cracked and bought an 8GB Raspberry Pi 5.

The old machine had been booting from an SD card, but with big things like databases, server files and the nextcloud data on an external USB hard disk.

I'd already lost some data and had to remake it once due to a corrupted SD card, so I wanted to take the opportunity to switch to booting from the hard disk.

All the guides I found online on booting from USB assume you're happy to wipe the USB disk. I didn't want to do that because it had all my data on it. I've worked out how to do it, so I thought I'd write this down in case it helps anyone else.

The old Pi had a 32GB SD card in it, with a FAT boot partition and an ext4 partition called rootfs which had the real filesystem. The USB disk is a 1TB drive, with a single ext4 partition. My first question was whether it was safe to make the partition smaller, without losing any data. The answer is yes: I took the easy route and plugged the drive into my laptop, then used Ubuntu's Disks app to resize it so there's 32GB free at the end.

I then added a FAT partition the same size as the one on the SD card, and another ext4 partition to use up the rest of the space. I used dd to copy the data from the SD card into those partitions. I also edited the FAT partition to say it's bootable, but I don't know if that was necessary.

On a separate SD card, I used the Raspberry Pi Imager to wipe it and set up Raspbian for the Raspberry Pi 5. I did that twice, because the first time round I didn't notice the other tabs where you set up wifi details and ssh access. I put that in the Pi 5 and turned it on, then connected through ssh. I ran raspi-config and in the Advanced settings menu changed the boot order to try USB first.

But it turns out that isn't enough: you also have to edit /boot/firmware/cmdline.txt and change the root option to the UUID of the partition on the USB disk. I got that by running lsblk -o name,partuuid on the machine with the USB drive plugged in.

Once I'd done that, the Pi 5 booted up well enough: it's using the boot partition on the SD card, but the filesystem root is mounted from the USB drive.

I don't know why it's not using the boot partition on the USB disk. I'm not too bothered about that, though.

Help me work out what's wrong with this LaTeX (now solved!)

One of my jobs at work is to help lecturers to get their LaTeX documents working with Chirun.

Doing this, I've learnt a lot more about LaTeX than I ever wanted to. I've spent hours debugging errors.

Usually, I delete sections of the code until I get to the smallest document that has the error, then I spend a while working out what's wrong and how to resolve it.

Well, today I've spent hours doing that, and I've got to a point where I'm completely stuck.

Read more…

Thinkserver: my web-based coding environment

I've made my own web-based coding environment for working on little projects.

A few years ago I found Glitch.

It's great: a web-based coding environment that makes it really easy to quickly start editing a web page. It has a live preview that helps to quickly see changes take effect.

But over time, as more and more of my stuff ended up living on Glitch, I was a bit uneasy about relying on someone else's service, and I also wanted to make some changes that would be idiosyncratic. In particular, I make a lot of things with Elm and while Glitch has some mechanisms for changing how a project is built, it's not documented well and my solution kept breaking. I also keep having trouble logging into Glitch, and the editor doesn't work particularly well on my phone.

So I decided to try making my own knock-off.

Read more…

How I worked out what character set web Excel uses for its CSV export

I'm collecting registrations for a work conference through Microsoft Forms, because that's the tool my employer gives me.

I want to get the data out of Excel as soon as possible, so I clicked the button to export it as a .CSV file.

I loaded that in Python, and got an error message:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position 4071: invalid continuation byte

Read more…

A script to convert a WCAG-EM report from JSON to reStructuredText for a VPAT

At work, I've had to produce VPAT documents for the software I'm responsible for.

The VPAT template asks you to list, for each of the WCAG criteria, whether you support it or not, or if it doesn't apply.

The W3C have made a WCAG-EM Report Tool which helps you to work through the WCAG criteria and make notes about whether they're satisfied.

At the end, you can download a copy of the report in either summarised HTML format, or a JSON file with all the data you entered.

The first time I did a VPAT, I mostly manually converted the information from the WCAG-EM report to a reStructuredText table, to go in our Sphinx documentation.

Now I'm doing it a second time, I know I don't want to waste my time doing that!

So I've written a Python script which takes in the JSON file from the report tool and prints out the tables for the VPAT template, in reStructuredText format.

Read more…

My development PC's homepage lists all the servers I'm running

A lot of what I do on a computer involves web development. For work, I develop several projects which involve running a Django server, which I have to run locally while I'm working on them. And for client-side stuff, I always run a simple HTTP server to serve static files, because browsers apply a lot of security restrictions to pages loaded through file://.

For years, I would type in things like http://localhost:8000 into my browser's address bar, like a chump. Then one day, a lightbulb turned on and I realised that since I already have an HTTP server running on port 80, I could make its homepage be a list of links to the ports I usually run servers on.

A little while later, another, brighter lightbulb turned on and I realised that the homepage could be a script which scans every port to automatically find every server I'm running.

A webpage with two columns. The first lists "moodle" and "wordpress" under the heading "On port 80". The other has the header "Other open ports" and there are two list items. The first reads, "Directory listing for /", with port: 1535, cwd: ~/websites/checkmyworking.com, pid: 63072. The second reads, "Numbas development server", port: 8000, cwd: ~/numbas/editor, pid: 45650.

Read more…

Finding all my recent git commits

At the moment I'm writing up one of my regular development update posts on the Numbas blog. I try to write one every couple of months. The posts act as a changelog for the various projects related to Numbas.

It's been just over seven months since the last one, because of everything, so this time there's a lot to talk about.

Read more…