NAME

piflash - Raspberry Pi SD-flashing script with safety checks to avoid erasing the wrong device

SYNOPSIS

piflash [--verbose] [--resize] input-file output-device

piflash [--verbose] --sdsearch

piflash --version

DESCRIPTION

This script writes (or "flashes") an SD card for a Raspberry Pi. It includes safety checks so that it can only erase and write to an SD card, not another device on the system. The safety checks are probably of most use to beginners. For more advanced users (like the author) it also has the convenience of flashing directly from the file formats downloadable from raspberrypi.org without extracting a .img file from a zip/gz/xz file.

Safety Checks

The program makes a number of safety checks for you. Since the SD card flashing process may need root permissions, these are considered prudent precautions.

Automated Flashing Procedure

Piflash automates the process of flashing an SD card from various Raspberry Pi OS images.

INSTALLATION

The piflash script only works on Linux systems. It depends on features of the Linux kernel to look up whether the output device is an SD card and other information about it. It has been tested so far on Fedora and Ubuntu to get the kernel parameters right for various USB SD card adapters.

System Dependencies

Some programs and libraries must be installed on the system for piflash to work - most packages have such dependencies.

On RPM-based Linux systems (Red Hat, Fedora, CentOS) the following command, run as root, will install the dependencies.

    dnf install coreutils util-linux sudo perl file-libs perl-File-LibMagic perl-IO perl-Exception-Class perl-Try-Tiny perl-Module-Pluggable perl-File-Path perl-YAML-LibYAML gzip unzip xz e2fsprogs dosfstools

On Deb-based Linux systems (Debian, Ubuntu, Raspbian) the following command, run as root, will install the dependencies.

    apt-get install coreutils util-linux klibc-utils sudo perl-base libmagic1 libfile-libmagic-perl libio-all-perl libexception-class-perl libtry-tiny-perl libmodule-pluggable-perl  libyaml-libyaml-perl gzip xz-utils e2fsprogs dosfstools

On source-based or other Linux distributions, make sure the following are installed:

Piflash script

This is the Perl distribution PiFlash.

Installing PiFlash is straightforward.

Installation with cpanm

If you have cpanm, you only need one line:

% cpanm PiFlash

If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment.

Installing with the CPAN shell

Alternatively, if your CPAN shell is set up, you should just be able to do:

% cpan PiFlash

Manual installation

As a last resort, you can manually install it. Download the tarball, untar it, install configure prerequisites (see below), then build it:

% perl Makefile.PL
% make && make test

Then install it:

% make install

If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib

The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: MYMETA.yml or MYMETA.json generated by running the manual build process described above.

Configure Prerequisites

This distribution requires other modules to be installed before this distribution's installer can be run. They can be found under the "configure_requires" key of META.yml or the "{prereqs}{configure}{requires}" key of META.json.

Documentation

PiFlash documentation is available as POD. You can run perldoc from a shell to read the documentation:

% perldoc piflash

For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html

Bug reporting

Report bugs via GitHub at https://github.com/ikluft/piflash/issues - this location may eventually change if piflash becomes popular enough to warrant having its own source code repository.

When reporting a bug, please include the full output using the --verbose option. That will include all of the program's state information, which will help understand the bigger picture what was happening on your system. Feel free to remove information you don't want to post in a publicly-visible bug report - though it's helpful to add "[redacted]" where you removed something so it's clear what happened.

For any SD card reader hardware which piflash fails to recognize (and therefore refuses to write to), please describe the hardware as best you can including name, product number, bus (USB, PCI, etc), any known controller chips.