8

How to format an SD card or USB flash drive

 3 years ago
source link: https://www.devdungeon.com/content/how-format-sd-card-or-usb-flash-drive
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introduction

If you want to create a bootable SD card or USB flash drive using a disk image like a .iso or .img you have a few options.

  • Use the dd command-line tool
  • Use a GUI tool like BalenaEtcher

This is a common task when setting up an SD card for a Raspberry Pi or creating a USB flash drive with a Linux LiveCD distro. In this example we will review both the Etcher option and dd option.

Format with Balena Etcher

Balena Etcher which has an simple GUI. Etcher is available on on Windows, Mac, and Linux. This is your best option if you have a desktop available.

Simply download and run Etcher. It will ask you to pick the .iso or .img, and the SD card or USB device you want to flash. Click "Flash" and just wait until it is coplete. It's that simple.

If you want to automate Etcher in a script, you can use the Balena CLI, but the dd option in the next section may be a better option if you are using a terminal.

Format with dd

If the GUI option is not available, Another option is to use a command-line tool dd. This option is good in Linux and Mac but not for Windows. The format for usage is like this:

# if = in file
# of = out file
# bs = block size (1 megabyte)
sudo dd if=/path/to/iso of=/path/to/device bs=1m

The in file is the disk image like an .iso or .img. The outfile is the disk, SD card, or USB drive.

For example:

sudo dd if=/Users/nanodano/raspbian.img of=/dev/disk2 bs=1m

Note it may take several minutes for the operation to complete. Be patient.

If you need to find the path to your disk, you can use one of the following commands:

# Mac
diskutil list
# Linux
sudo fdisk -l

If you get an error about the disk being used or resource busy, you need to eject/unmount the disk with diskutil unmountDisk in Mac or umount in Linux. For example:

#Mac
disktutil unmountDisk /dev/disk2

# Linux
sudo umount /dev/sdc

Conclusion

After reading this guide, you should understand how to flash an SD card or USB drive (or any other kind of disk) using a GUI tool named BalenaEtcher and a command-line tool named dd. This knowledge will let you create SD cards for devices like Raspberry Pi or flash a USB drive with a Live Linux distribution.

References


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK