brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: rpi-imager --cli --sha256 checks the image hash before it writes the card

CLI
~/tips/tip-rpi-imager-cli-sha256

sudo rpi-imager --cli --sha256 <hash> raspios.img.xz /dev/sdb

Writes a Raspberry Pi image from the terminal, and refuses it if the SHA-256 hash does not match.

Raspberry Pi Imager is not only a window with buttons. It also has a command-line mode, which fits scripts and a stack of cards that all need the same image.

sudo rpi-imager --cli --sha256 <hash> raspios.img.xz /dev/sdb

The first argument after the options is the image, as a path or a URL. The second is the storage device to write to, for example /dev/mmcblk0 or /dev/sdb. With --sha256, Imager checks that the image matches the hash you give before it writes anything.

A few more documented options for the same mode:

  • --disable-verify skips the verification after writing.
  • --disable-eject does not eject the device after verification.
  • --first-run-script <file> adds a firstrun.sh to the image, for a setup that needs no screen at first boot.
  • --cloudinit-userdata and --cloudinit-networkconfig add cloud-init files.

The caveats matter here. Command-line mode needs root on Linux and macOS and does not ask for confirmation before it erases the device, so check the device name twice. By default it refuses to write to system drives, and --enable-writing-system-drives overrides that, which I would leave alone. On Raspberry Pi OS the command is rpi-imager, with the rpi-imager-cli package providing a version that is always in command-line mode. Run rpi-imager --help to see the options your version has.

Further reading: Imager command-line options

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link