Format a MicroSD for Raspberry Pi

  Raspberry Pi

Download the latest version of Raspberry Pi OS from here:

 

Discovering the SD card mountpoint and unmounting it

  • Run lsblk -p to see which devices are currently connected to your machine.
  • If your computer has a slot for SD cards, insert the card. If not, insert the card into an SD card reader, then connect the reader to your computer.
  • Run lsblk -p again. The new device that has appeared is your SD card (you can also usually tell from the listed device size). The naming of the device will follow the format described in the next paragraph.
  • The left column of the results from the lsblk -p command gives the device name of your SD card and the names of any partitions on it (usually only one, but there may be several if the card was previously used). It will be listed as something like /dev/mmcblk0 or /dev/sdX (with partition names /dev/mmcblk0p1 or /dev/sdX1 respectively), where X is a lower-case letter indicating the device (eg. /dev/sdb1). The right column shows where the partitions have been mounted (if they haven’t been, it will be blank).
  • If any partitions on the SD card have been mounted, unmount them all with umount, for example umount /dev/sdX1 (replace sdX1 with your SD card’s device name, and change the number for any other partitions).

 

Copying the image to the SD card

  • In a terminal window, write the image to the card with the command below, making sure you replace the input file if= argument with the path to your .img file, and the /dev/sdX in the output file of= argument with the correct device name. This is very important, as you will lose all the data on the hard drive if you provide the wrong device name. Make sure the device name is the name of the whole SD card as described above, not just a partition. For example: sdd, not sdds1 or sddp1; mmcblk0, not mmcblk0p1.
    # quiet
    dd bs=4M if=2020-02-13-raspios-buster.img of=/dev/sdX conv=fsync
    # With status updates
    dd bs=4M if=2020-02-13-raspios-buster.img of=/dev/sdX status=progress conv=fsync
  • Please note that block size set to 4M will work most of the time. If not, try 1M, although this will take considerably longer.
  • Also note that if you are not logged in as root you will need to prefix this with sudo.

This process took about 4 minutes, although the time stopped after 127 seconds.

Copying a zipped image to the SD card

In Linux it is possible to combine the unzip and SD copying process into one command, which avoids any issues that might occur when the unzipped image is larger than 4GB. This can happen on certain filesystems that do not support files larger than 4GB (e.g. FAT), although it should be noted that most Linux installations do not use FAT and therefore do not have this limitation.

The following command unzips the zip file (replace 2020-02-13-raspios-buster.zip with the appropriate zip filename), and pipes the output directly to the dd command. This in turn copies it to the SD card, as described in the previous section.

unzip -p 2020-02-13-raspios-buster.zip | sudo dd of=/dev/sdX bs=4M conv=fsync

 

LEAVE A COMMENT