Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
create a new sd card image for a raspberry pi using a raspberry pi

Create Raspberry Pi Image using a Raspberry Pi

My 2019 Macbook Pro w/Catalina 10.15.6 will not write to micro sd cards with any of the adapters I have available. They appear as "read only". OSX Disk Utility app will not format the SD cards. Error is Couldn't modify partition map. : (-69874)

To get around this, I used a Raspberry Pi to download the image and write it to the micro SD card.

I used a usb micro SD card reader from Canakit https://www.canakit.com/mini-micro-sd-usb-reader.html. I inserted the USB/SD reader after the Pi booted.

For this example, I'm using an Ubuntu image. This will likely work for other Raspberry Pi images.

Steps are:

  1. curl download image
  2. xz uncompress image if necessary
  3. fdisk -l find where the USB drive is located in /dev (it shouldn't be mounted)
  4. if the drive is mounted, umount /dev/sda
  5. dd write image to the SD card

Done!

$ curl https://cdimage.ubuntu.com/releases/20.04.1/release/ubuntu-20.04.1-preinstalled-server-arm64+raspi.img.xz -o ubuntu-20.04.1-preinstalled-server-arm64+raspi.img.xz
$ xz -dv ubuntu-20.04.1-preinstalled-server-arm64+raspi.img.xz
$ sudo su
$ fdisk -l
...trucated...

Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6c586e13

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      532480 62333951 61801472 29.5G 83 Linux


Disk /dev/sda: 119.1 GiB, 127865454592 bytes, 249737216 sectors
Disk model: Storage Device
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1       32768 249737215 249704448 119.1G  7 HPFS/NTFS/exFAT

$ dd if=ubuntu-20.04.1-preinstalled-server-arm64+raspi.img of=/dev/sda bs=32
101588256+0 records in
101588256+0 records out
3250824192 bytes (3.3 GB, 3.0 GiB) copied, 1017.56 s, 3.2 MB/s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.