LoginSignup
3
2

More than 3 years have passed since last update.

Raspberry Pi のイメージファイルのダウンロード、SDカードへの書き込み

Last updated at Posted at 2020-03-15

Raspberry PiのイメージファイルをmacOSで書き込みするまでのメモです。
以下を参考にしました。

Copying an operating system image to an SD card using Mac OS
https://www.raspberrypi.org/documentation/installation/installing-images/mac.md

MacでSDカードにRaspberryPiイメージを書き込む
https://pocketlog.net/20180906/raspberrypi_image_dd_for_mac/

MAC OS上でのオペレーティングシステムイメージのインストール
http://igarashi-systems.com/sample/translation/raspberry-pi/installation/install-mac.html

環境

macOS High Sierra 10.13.6
Raspberry Pi Zero WH

イメージファイルのダウンロード

公式サイトはダウンロードスピードが遅いので、日本国内のミラーサイトからダウンロードします。
今回はLite版をダウンロードしました。
例:http://ftp.jaist.ac.jp/pub/raspberrypi/raspbian_lite/images/

イメージファイルは以下に格納しておきます。

$ ls -lh /Users/user/Downloads/2020-02-13-raspbian-buster-lite.img 
-rw-r--r--@ 1 nikofu501  staff   1.7G  2 13 16:10 /Users/nikofu501/Downloads/2020-02-13-raspbian-buster-lite.img

イメージファイルのインストール

SDカードにイメージを書き込みます。ここから、rootでの作業になります。

SDカードのディスクのフォーマット

まず、以下のコマンドを実行し、SDカードのディスクを確認します。今回は/dev/disk2がSDカードのディスクです。

# diskutil list

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *8.0 GB     disk2
   1:             Windows_FAT_32 NO NAME                 8.0 GB     disk2s1

パーティションを削除します。

# diskutil partitionDisk /dev/disk2 1 MBR "Free Space" "%noformat%" 100%

Started partitioning on disk2
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Finished partitioning on disk2
/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                                                   *7.9 GB     disk2

ディスクをアンマウントします。

# diskutil unmountDisk /dev/disk2*

Unmount of all volumes on disk2 was successful

ディスクをフォーマッットします。アンマウントした状態で以下のコマンドを実行します。

# diskutil eraseVolume FAT32 BLANK /dev/disk2

フォーマットコマンドを実行時に、以下のようなエラーが出た場合、パーティションを削除できていません。
パーティションを削除してください。
Started erase on disk2
Unmounting disk
Error: -69888: Couldn't unmount disk

フォーマットが終わると以下のように出力されます。
Started erase on disk2
Unmounting disk
Erasing
512 bytes per physical sector
/dev/rdisk2: 15436312 sectors in 1929539 FAT32 clusters (4096 bytes/cluster)
bps=512 spc=8 res=32 nft=2 mid=0xf0 spt=32 hds=255 hid=0 drv=0x00 bsec=15466496 bspf=15075 rdcl=2 infs=1 bkbs=6
Mounting disk
Finished erase on disk2 BLANK

以下のコマンドでフォーマットできていることを確認します。(NAMEにBRANKが表示されていること)

# diskutil list

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            BLANK                  *7.9 GB     disk2

イメージファイルの書き込み

イメージファイルをSDカードに書き込みます。
書き込み前にアンマウントします。

# diskutil unmountDisk /dev/disk2*
# cd /Users/user/Downloads
# dd bs=1m if=2020-02-13-raspbian-buster-lite.img of=/dev/rdisk2

書き込み中は「controlキー+T」で状況を確認できます。
出力例:
load: 2.49 cmd: dd 4337 uninterruptible 0.00u 0.13s
6+0 records in
5+0 records out
5242880 bytes transferred in 4.021259 secs (1303791 bytes/sec)

書き込みが終わるとコマンドラインが表示されます。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2