I just noticed that the Raspberry Pi OS page now has links that dynamically redirect to the latest available images, letting us do these cool shell one-liners to download and install it automatically. Scroll down for instructions and breakdown.
Commands for the different editions of the latest version:
- full version (desktop + additional software)
curl -L 'https://downloads.raspberrypi.org/raspios_full_armhf_latest' | bsdtar -xOvf- | sudo dd bs=4M of=/dev/sdX; sync
- desktop version
curl -L 'https://downloads.raspberrypi.org/raspios_armhf_latest' | bsdtar -xOvf- | sudo dd bs=4M of=/dev/sdX; sync
- lite version
curl -L 'https://downloads.raspberrypi.org/raspios_lite_armhf_latest' | bsdtar -xOvf- | sudo dd bs=4M of=/dev/sdX; sync
Please read the instructions below carefully, as /dev/sdX
needs to be replaced with the correct identifier of your device.
Usage
- If you are on Windows, you’re out of luck.
- Before plugging in the SD card, take a note of the devices already plugged into the computer. Open a terminal; on Linux, type in
lsblk -f
; on macOS, type indiskutil list
; then press Enter/Return. - Plug in the SD card.
- Run the previous command again, and take a look at the new entries. You will probably see more than one line added, because partitions are displayed alongside drives. The name of the drive will usually be something like
/dev/sdb
,/dev/mmcblk0
or/dev/disk2
(with partition names/dev/sdb1
,/dev/mmcblk0p1
or/dev/disk2s1
respectively, if the SD card was already used for something). Check if its size is what you expect. - Look again. Warning: any data already on the drive will be overwritten in the next step.
- Paste one of the commands from above, and replace
/dev/sdX
with the drive name you just looked up. Press Enter/Return to run the command. Even though the prompt is obstructed by the download progress bar, you need to type in your user password and press Enter/Return. - Keep an eye out for error messages. If the download fails, or the drive runs out of space or disconnects, you will be left with a damaged installation. If there is a message about partitions being mounted/busy, unmount them with
sudo umount /dev/sdX1
on Linux ordiskutil unmountDisk /dev/disk2s1
on macOS. You may also need to installcurl
andbsdtar
(package might be namedlibarchive
) with your distro’s package manager. Don’t forget to run it for each partition if there are multiple on the card. Then try again. If it were to fail for another reason, install Raspberry Pi OS with a method you already know. - When the command is finished, you will get a helpful message about how much data was written out. Because of the extraction, it is significantly more than what was downloaded.
Command breakdown
curl
: a command-line tool for downloading files from the internet. AFAIK, it comes standard with macOS, and most Linux distros, with Ubuntu and Debian being the notable exceptions.-L
: makes curl follow redirects.'url'
: download the file from this URL. Quoted so that the shell doesn’t get confused by special chatacters
|
: pipe character. It feeds the output of the previous command into the next as input.bsdtar
: a tool for working with many kinds of compressed files. I am going to explain each flag separately, but these one-character options can be written at once. This should also come standard with macOS, and may need to be installed on some distros.-x
: eXtract the file-O
and-f-
: output the extracted file not to a folder, but to the terminal or next command.-v
: print out what’s happening
|
: pipe character. It feeds the output of the previous command into the next as input.sudo dd
: command for writing raw data to disks as an administrator.Ifif=/path/to/image.file
is not specified, it takes input from the pipe.bs=4M
: write in 4 MiB blocks at a time, the usual increment of SD cards. This actually makes the process of flashing faster.of=/dev/sdX
: output file. In this case, it is a device, but it’s the same for the operating system.
;
: wait for the previous command to finish, then execute the nextsync
: write all cached/pending data to disk immediately
Why?
short version: because we can.
Most manual methods and and programs do the three phases of this command in discrete, synchronous steps. You download the image onto the disk, you extract that file, and finally, write the extracted file to the SD card. By chaining the 3 commands together (called piping in technical terms), the RAM will act as a buffer instead of the temporary files. Both downloading and extracting a file works on streams, meaning that they process and output data in small chunks. This way, the next command can work on a part of a file and does not need the previous one to finish, to start working.
Unix, and its clones like Linux and macOS have the philosophy that programs should do one thing, but do it well and efficiently. Shells, like bash and zsh allows these commands to be chained together to produce more complex commands and shell scripts. In my opinion, downloading and writing a disk image does not reach the threshold for requiring a pretty GUI, not to mention one using clunky web technologies (cough Etcher cough).
It’s also a cool way to learn about how the the operating system works, and with a Pi, you are eventually going to find a task that is way easier to do in the terminal. And do not forget, think before you type!
submitted by /u/BertalanD
[link] [comments]
Read the Full Article here: >Raspberry Pi – More than just magic mirrors and kodi!