Creating a Raspberry Pi Image

Nicole Murillo
Code|Beta Blog
Published in
4 min readMay 2, 2016

As with a lot of things, there are a million ways to do something and it all depends on who you ask. So knowing that flash memory has a certain amount of read and write cycles, I wondered what would be a good file system to use on a thumb drive and eventually on a Micro SD card and that lead to me creating a custom image for my Raspberry Pi.

There are some images that are somewhat complex to make as this isn’t always straightforward unless you’ve done it before or depending what the image is being built for.

As to why I’m building a custom one, well it goes back to the file system. To reduce the amount of read and writes to the flash media some people I consulted with suggested going with ext4 but not using the journaling feature, so the thumb drives that I’m using specifically with the Raspberry Pi were formatted using the command

# mkfs.ext4 -O ^has_journal /dev/sdxn

This formats the partition n in the device sdx with ext4 file system and disables the journaling. The caret (^) character tells the mkfs command to disable the feature that follows it.

After I ran into a weird issue earlier this week with the Raspberry Pi acting up, it wouldn’t allow remote access and the web server was responding but only throwing 404 errors, I looked into it briefly and the file system being used is ext4 with journaling enabled. That might not be what caused the issue but certainly want to expand the life of the card, so I ended up looking into either disabling journaling or recreating the whole thing with journaling disabled.

Creating the Image

There are several ways you can go about creating a custom image, in my case I decided to go with a script and found a couple but sadly they aren’t simple to implement.

I don’t really have a machine running Linux all the time so I have a virtual machine in VMWare running Debian and tried to create an image using this script but the script is straightforward into making the image and any errors it’s up to the user to resolve.

Creating the image on a faster machine than the Raspberry Pi is ideal because it will do it in a short amount of time, but if time is no issue then you can create it on the Raspberry Pi itself with the use of this really nice script. This script not only has the option to write the image directly to the SD card once it’s done but it’s easy to configure and customize, plus also creates the EXT4 file system with the journaling disabled.

The script defaults to a basic image though it creates a 1.3GB file to store the image on. Even if you set it to write to the SD card it still has a failover to a file so that you don’t run the script and install everything to find out that you’ve wasted all that time and resources when it fails to write to the SD card, plus you will be left with a nice image file that you can write to other SD cards.

Configuring the script isn’t that difficult, just download the script and edit it on your favorite text editor, on your personal machine or on the Raspberry Pi itself.

What you’ll want to look at are the first 79 lines of the file which contains the configuration section where you can tell it to write to the SD card once it’s finished creating the image or to just create the image. As well as which repository to use and what packages to install. The script by default installs the very minimal amount of packages but if you’re working on a project that requires certain packages then you’ll want to add them to the list.

There is also a section to give the root user a password and later on the script there is a section which configures the SSH to allow root login with that password. This script doesn’t create the pi user, so you’ll want to have a good root password and then create a regular user once the image is installed and running.

Several hours later, if you’re running this on the Model 3, you’ll have a working system with minimal packages or with the software you need.

--

--

Nicole Murillo
Code|Beta Blog

[ Feminist | Queer Trans Woman | Technical Consultant | Infosec | Fan of Vinyl Records and Film Photography ]