Reflash using SD card

You’ve posted something similar before, and then, as now, I am not clear on just what you did. If you are dd’ing the image from the SD card aren’t you using a file that is in use as the input to dd?

If anywhere in either very long post you had posted the exact dd command then everything would be clear. Usually detailing a general dd operation there can be a problem giving device names in linux because hardware configuarations can vary, but in the case of dd from SD card to eMMC under PureOS on a librem 5, all the device names should be fixed.

One thing I wondered about when you first posted about this is whether you epanded the image on the SD card to fill it, then mounted the card on a computer and copied the image as a file onto the mounted card and then put the card in the L5, booted from the card and dd’d the image file to the eMMC. That seems more complicated than you implied.

So I ask, aren’t you using an active partition as an input to dd?

1 Like

In my most recent case using this, I downloaded the .img, then according to bash_history did this:

sudo dd if=./librem5r4.img of=/dev/sda bs=10M status=progress

This overwrote the SD card with a bootable partition. Upon booting, it automatically expanded to fill the card. It’s a terrabyte card, so it is infinitely big relative to everything else.

Once booted from the SD card, my bash history shows the following:

sudo dd if=/dev/mmcblk0 of=./my-liberty.img bs=10M status=progress

At this point, I removed the SD card from the device, and put it into a different new device I wanted to replace my daily driver with.

Then, I booted the SD card – same partition, new hardware – and ran the opposite of the prior command:

sudo dd of=/dev/mmcblk0 if=./my-liberty.img bs=10M status=progress

(note that if and of are reversed.)

The result of the operation is that the eMMC on the new device matches the eMMC on the old device, having flashed to be its direct replica. And this was accomplished from L5 without using the laptop, from what I recall. (I don’t have timestamps and the first command actually is in my bash history a whole bunch of times, flashing multiple SD cards from the handset. But I probably did it all without PC, because why not.)

Sorry that I omitted the commands in my other post. The point of what I was saying was moreso that learning to use dd in general is advantageous, so it’s possible that posting explicit commands is contrary to that and encourages users to think of dd as a line to copy rather than an idea for something useful to use in any direction.

Edit: Although my above .bash_history is specific to doing a transfer from an old device to a new device, a user could apply the same principle to flash their Librem 5 with no additional hardware beyond the SD card. The difference would be to omit the middle command – don’t clone eMMC. And instead, redownload librem5r4.img from Purism on the SD card storage that we’re booted from, then write it onto the (not currently in use) eMMC while the SD card’s OS is running.

5 Likes

As a general comment about any such instructions, it is important to be clear about which device is executing the shell command - since we are “all” using Linux “everywhere” :wink:. So, let’s say that we are talking about a single phone scenario (what most customers would face), and let’s say two different situations:

a) the phone is still perfectly bootable but needs reflashing for whatever reason

b) the phone is borked and won’t boot any more (e.g. bad LUKS passphrase set, but could be many other different scenarios) and hence needs reflashing. (I guess in this situation, and assuming no other computer is available, you would have had to prepare the µSD card in advance, which wouldn’t be a bad idea to have available.)

4 Likes

Seems like the tutorial above is not fully describing the simple answer to the question: “How do I reflash a Librem 5 without a PC?” Here’s a tutorial specific to that:

  1. Buy a micro SD card.

  2. Turn off your Librem 5.

  3. Remove the battery from your Librem 5. If you do not, your SIM card and micro SD card might be destroyed due to a known issue with Librem 5 shorting.

  4. Using the little metal poker stick that comes with the Librem 5, or a sufficiently long and thin paperclip, pop out your SIM card and micro SD card tray from the side of your device. [If you do this step prior to Step 3, your SIM card and/or micro SD card may be destroyed.]

  5. Now that you have your card tray removed, place the new and empty micro SD card onto the tray.

  6. Insert the tray back into your Librem 5.

  7. Insert the battery back into your Librem 5

  8. When the battery contacts the Librem 5, it immediately turns on the moment it sees the battery. Go ahead and finish booting (enter your LUKS encryption pass phrase if needed)

  9. Inside the Librem 5, using your favorite web browser, go to the following URL: Index of /librem5/images/

  10. Navigate the url until you find the version right for you. Crimson is the newer version, and Byzantium is the older stable version (more info on that is all over these forums if you search)

  11. Based on your Librem 5 version, pick the folder for you. Mine is the newer Evergreen style of Librem 5, so I always use the librem5r4 images (“revision 4”). Most people probably have that version of Librem 5. If your Librem 5 is older than spring 2023 when I got mine, perhaps you have an older revision. It will be in your email from Purism when the device was shipped to you.

  12. Pick the luks folder if you want the encrypted version of PureOS, or the plain version if you do not want your hard drive encrypted.

  13. Click the artifact/ folder.

  14. Now in that folder, click on librem5r4.img.xz or the similarly named .img.xz file so that it will download to your device. For example, you might download from https://storage.puri.sm/librem5/images/byzantium/2025.04/librem5r4/luks/artifact/librem5r4.img.xz if you are using Byzantium stable version, reading this in 2025, using an Evergreen version of the Librem 5, and you want a LUKS encrypted hard drive.

  15. Now that you have librem5r4.img.xz in your downloads folder, open Terminal app

  16. In the terminal, type cd Downloads or to whatever folder you saved the .img.xz file into using your web browser of choice

  17. Now in the terminal, if you type ls it should show a list of files. One of the files should be librem5r4.img.xz or whatever name your downloaded image has.

  18. Use unxz librem5r4.img.xz and wait for it to finish. When the command has finished, it will have uncompressed the Librem 5 image. This may use a substantial amount of storage space, possibly up to 6 GB. (I did this on a Librem 5 Liberty device that has 128 GB of main storage instead of 32 GB, so the 6 GB wasted on this download was not so painful. If you’re struggling with disk space on a 32 GB storage device, consider removing your stuff. You should already have your own backups, and at the end of the tutorial we will erase the device storage and reflash it anyway)

  19. Use ls -htlr librem5r4.img to see that the .img file was automatically created without .xz on the end of the name. It will say something such as 5.6 GB for the size if all is well.

  20. Use lsblk and/or df commands if you would like to inspect your system to review the device name of your SD card. In all likelihood, your SD card will show up as sda in these

  21. Now that you are confident that /dev/sda describes your SD card, issue the following command to erase all data on the SD card and replace it with the bootable Librem 5 PureOS image:

    sudo dd bs=10M status=progress if=./librem5r4.img of=/dev/sda
    
  22. This command will take some time to finish, since it is erasing all data on your SD card and replacing it with the 5.6 GB of the clean PureOS installation

  23. Once the command has finished, power off your Librem 5 normally.

  24. Hold the power button to boot the Librem 5 back on. As soon as the light flashes green, move your finger to the Volume Down key and hold it.

  25. After some delay, the phone should boot into a clean installation of PureOS. NOTE: Your phone is not flashed yet – we are booting from the SD card

  26. After entering the 123456 password - or no password if you did not choose LUKS – you should be welcomed to a totally clean PureOS Phosh home screen of a new install.

  27. If your SD card is a big one, and you plan to keep it the same for a long time, see Appendix: Creating an Extra Backup for notes on how you can backup your current OS install on your phone, creating an exact image of it that you could put back later if you don’t like how flashing goes. [You would have to do that now before flashing.]

  28. Repeat steps 9 to 19 of this tutorial while keeping the device powered ON in this “boot from SD card” state.

  29. Now your Librem 5 is running from the SD card and not the hard drive, but you have a file in the current directory called librem5r4.img. It’s time to flash the device itself with this file, which we do with the following command (Note that we are writing to mmcblk0, the eMMC internal storage this time, and not “sda” the SD card):

    sudo dd bs=10M status=progress if=./librem5r4.img of=/dev/mmcblk0
    
  30. When this command has completed, it should be safe to power off your device, then start it back up. This time do not touch the Volume Down button, and allow it to boot normally.

  31. After logging in through the default 123456 encryption key and pin number, you should be looking at the totally reset flashed PureOS Phosh homescreen – all without using a PC, just by flashing the Librem 5 to itself with itself!

Appendix: Creating an Extra Backup

While you are inside of the SD card boot, but before you flash your phone, if you want to create a backup of your phone that you could restore later, and if your SD card is much bigger than your phone, then you can use the following command (the name my-backup.img is replaceable – choose whatever name for the file you prefer):

sudo dd bs=10M status=progress if=/dev/mmcblk0 of=./my-backup.img

This will take some time, possibly multiple hours if you are on a 128 GB Liberty phone, because it will create a file containing the exact storage of the device even if the device is empty. As such, the newly created file will be 32 GB for a Librem 5, or will be 128 GB for a Librem 5 Liberty. [So your SD card must be bigger than that!]

The key intuition here is that when you flash your phone in the future, you can use this my-backup.img file as the input to flash from instead of librem5r4.img when flashing your phone again in this way in the future.

Given the time these backups take to create and to flash, I often like to do this step with the battery removed from the Librem 5 while it is connected to power. This may reduce heating on the device, offering it a pocket of air to dissipate heat into on the back instead of a battery that might be discharging and then charging back up periodically, or however that works.

3 Likes

Two minor additional comments:

  • If you are currently using the uSD card before you start this procedure and it is listed in
    /etc/fstab then it might be as well to comment that line out before shutting down to install the new, empty uSD card.
  • Regardless of the previous step, before using dd to operate on a disk device, either as input or output, you must ensure that it is not mounted. So I usually do
    mount -l | grep something-suitable to check and then
    sudo umount /dev/whatever-partition if it is listed as mounted.
    This applies at multiple points in the procedure.
1 Like

Note, however, that Purism started shipping Evergreens in the autumn of 2020.

3 Likes

Thanks Dlonk. I’ll try this.

Is it possible to install images of Mobian and of PostmarketOS, the same way you download, save, and install PureOS? Is it possible to store multiple different operating systems on the SD card and then select the one you want to boot in to, from Grub or something similar.

It seems like it should be possible to load up several bootable mobile operating systems from a PC on to an SD Card. Then insert that card in to your Librem 5 to select which OS you want to boot in to.

1 Like

Yes, that would be a nice-to-have. I don’t think anyone has done the work for that though e.g. to use GRUB or whatever it is that the Raspberry Pi uses (at least as supplied by some vendors). There probably isn’t a lot of incentive for Purism to do that work (would just increase support cost) so it may have to come from the community. (The good news is that no matter how badly you break the contents of the uSD card, you can always just boot from the main eMMC drive.)

So probably right now your only option is to have one card per operating system and swap cards when you want to swap operating systems.

1 Like

If Grub doesn’t come installed already on the Librem 5, it seems like it should be possible to install it from sources. That would be quick to do for someone who knows how to do it. Once Grub is installed, then using it to boot in to various different operating systems located on different drives is what Grub is made to do. But if the volume key at boot time allows the selection of different OS’s as Dlonk suggests, then maybe Grub isn’t even needed. I guess it would depend on exactly what the volume key tool is capable of doing.

1 Like

It doesn’t. The Volume Down key chooses the boot device i.e. eMMC (not pressed) v. uSD (pressed). (Yes, it is possible that that functionality might be extended in the future.) So today you would be looking at something like GRUB - and there’s nothing inherently bad about the idea.

PS The Raspberry Pi implementation of this that I was thinking of is NOOBS.

1 Like

This is where I deviate from your guide.

When I get to this point, I just click on the file in my Downloads folder and when gnome-disks opens, I choose the disk to write to and wait for it to finish.

2 Likes