PINE64
Command line flashing script with media verification, xz image support - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: Pinebook Pro (https://forum.pine64.org/forumdisplay.php?fid=111)
+--- Forum: General Discussion on Pinebook Pro (https://forum.pine64.org/forumdisplay.php?fid=112)
+--- Thread: Command line flashing script with media verification, xz image support (/showthread.php?tid=8583)



Command line flashing script with media verification, xz image support - Arglebargle - 12-17-2019

Hi all,

I've seen a lot of people struggling flashing images to sd cards/emmc from the command line and even more people asking for support after flashing images improperly or without media verification. I wrote a script to make this process easier, hopefully it will reduce the number of problems people are experiencing.

The script handles both raw images (.img files) and xz compressed images and will write and then verify, or with the --verify-only flag simply verify, that your media has been written correctly.

The script is located here: https://github.com/foundObjects/sbc-flasher

Installation is simple, either download the script and optionally make it executable and place it somewhere in your path or just run the installer code below. If pv isn't installed in your distribution by default you'll need to install it if you want pretty progress meters. The installer will ask for sudo permission to install the script in /usr/local/sbin as needed, so there's no need to run it with sudo or as root.

Code:
bash <(wget -o /dev/null -qO- https://raw.githubusercontent.com/foundObjects/sbc-flasher/master/install.sh)
sudo apt install -y pv

Use:

Code:
# sudo flasher.sh
Usage: /usr/local/sbin/flasher.sh (--flags) image(.img|.xz) /dev/target_block_device

Flags:
  -W | --write-only  | --write    Write pass only, no verification
  -V | --verify-only | --verify   Verify only
  -x | --debug                    Extremely verbose output (like bash -x ...)
       --no-pv                    Don't use pipeviewer

Flashing an image:

Code:
root@pinebookpro:/data/images# flasher.sh pinebookpro-debian-mrfixit-191127.img.xz /dev/mmcblk0
writing xz compressed image to /dev/mmcblk0
5.01GiB 0:02:46 [30.8MiB/s] [==================================================================>] 100%
0+574861 records in
0+574861 records out
5377097728 bytes (5.4 GB, 5.0 GiB) copied, 181.469 s, 29.6 MB/s
Write successful
Verifying xz image
5.01GiB 0:03:37 [23.6MiB/s] [==================================================================>] 100%
Image verified successfully

Flash verification is simple as well:

Code:
root@pinebookpro:/data/images# flasher.sh --verify-only pinebookpro-debian-mrfixit-191127.img /dev/mmcblk0
Verifying raw image
335MiB 0:00:11 [26.6MiB/s] [===>                                                                               ]  6% ETA 0:02:37

Debugging:

Run the script with -x: `sudo flasher.sh -x yourimage /dev/flash_target |& tee flashlog` to see what's going wrong and dump execution flow to a file. Please use pastebin.com (or hastebin.com, everyone should use hastebin because hastebin is awesome) instead of pasting debug output here if you need help.

You're welcome to do whatever you want with this script, hopefully it saves everyone some time.


RE: Command line flashing script with media verification, xz image support - Luke - 12-18-2019

Well done!


RE: Command line flashing script with media verification, xz image support - Arglebargle - 12-19-2019

Hey all,

It looks like 'pv' isn't installed by default on Debian so you'll need to "sudo apt install pv" before using the script if you want pretty progress bars. I'll push an update that checks for pv and works without it soon™.

Edit: And done. Script now supports running without pv (use --no-pv), lives in a proper git repo and has a one-line installer from the shell. Have fun!