home |  electronics |  toolbox |  science club |  tuxtalk |  photos |  e-cards |  online-shop



Using a Linux PC to create Raspberry PI SDcards

I have never found a good and concise instruction on how to create boot-able Raspberry PI SDcards using just normal Linux commands. The below instruction should solve that problem.

There are 2 kinds of images for Raspberry-PIs: NOOBS and actual images. NOOBS allow for more customization at first boot. I think NOOBS are the best way to create Raspberry PI SDcards but those NOOBS are not really images and therefore the procedure is a little different from putting actual images onto the sdcard. You will find both procedures below.

Creating a Raspberry-PI NOOBS SDcard, linux procedure

Overview:
  1. make sure the sdcard is not mounted
  2. use fdisk: prepare the sdcard to have one (primary) partition with a FAT32 filesystem, partition type: "c"
  3. create the filesystem: mkfs.vfat -F 32 /dev/sdX
  4. mount
  5. unzip NOOBS_v*.zip onto the sdcard
  6. this takes a moment: if you are getting impatient then monitor the progress with the command "iostat" from another shell window
  7. umount
Detailed procedure:

Put the sdcard into a USB sdcard reader and plug it in. To figure out which device the sdcard is you can type "dmesg". You will see something like this:
# dmesg | tail -14
[ 1736.400115] usb 2-1.1: new high-speed USB device number 5 using ehci-pci
[ 1736.492440] usb 2-1.1: New USB device found, idVendor=1908, idProduct=0226
[ 1736.492450] usb 2-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 1736.493047] usb-storage 2-1.1:1.0: USB Mass Storage device detected
[ 1736.499301] scsi host5: usb-storage 2-1.1:1.0
[ 1737.496968] scsi 5:0:0:0: Direct-Access     Generic  Mass-Storage     1.11 PQ: 0 ANSI: 2
[ 1737.497845] sd 5:0:0:0: Attached scsi generic sg1 type 0
[ 1738.093058] sd 5:0:0:0: [sdb] 31299584 512-byte logical blocks: (16.0 GB/14.9 GiB)
[ 1738.094061] sd 5:0:0:0: [sdb] Write Protect is off
[ 1738.094067] sd 5:0:0:0: [sdb] Mode Sense: 03 00 00 00
[ 1738.095050] sd 5:0:0:0: [sdb] No Caching mode page found
[ 1738.095055] sd 5:0:0:0: [sdb] Assuming drive cache: write through
[ 1738.101442]  sdb: sdb1
[ 1738.105047] sd 5:0:0:0: [sdb] Attached SCSI removable disk 

The above sdcard has already just one primary partiton (sdb1) however it might not be the right type. Before running fdisk you need to be root (run: sudo bash) and make sure the SDcard is not mounted. Use lsblk to check that. Unmount all mounted partions of the card if they are mounted (command: umount /dev/sdb1, if it has more partitions then unmount them as well e.g: umount /dev/sdb2)
# fdisk /dev/sdb

use command p to print the partion table
use command d to delete partions if needed
use command t to change the type to "c W95 FAT32 (LBA)", select type c
use command p to print the partion table
use command w to write the partion table

Note: replace /dev/sdb with the right device (from dmesg output).
Note: You write partiion to the whole disk, therefore no number in the device name (sdb).

Create a FAT32 filesystem on the card:
# mkfs.vfat -F 32 /dev/sdb1
mkfs.fat 3.0.28 (2015-05-16)

Note: replace /dev/sdb1 with the right device (from dmesg output).

Create a mount point, mounte the sdcard and then unzip the NOOP-zip file onto it:
mkdir /tmp/sdcard
mount /dev/sdb1 /tmp/sdcard
cd /tmp/sdcard
unzip /home/guido/NOOBS_v3_0_1.zip
cd /tmp
umount /tmp/sdcard

Note: replace /dev/sdb1 with the right device (from dmesg output).

The writing of the data could take a while. If you want to monitor the progress then run the command iostat from a second shell window.

That's it. The sdcard is ready for booting in your RaspberryPI

At the first boot there will be a simple menu were you can install and customize the actual image installation. The NOOBS is an installer that will re-partition the sdcard and do the actual installation. Be sure to have a monitor and keyboard when you power-on your PI. Don't forget to change the keyboard layout. Raspbien uses unfortunately by default a British keyboard layout instead of the US English layout.

change keyboard layout during noobs boot

Creating a Raspberry-PI SDcard from an image file, linux procedure

Overview:
  1. Do not mount the sdcard
  2. dd bs=1M if=raspbian-stretch.img of=/dev/sdX conv=fsync
  3. if you are getting impatient then monitor the progress with the command "iostat" from another shell window


Detailed procedure:

Put the sdcard into a USB sdcard reader and plug it in. To figure out which device the sdcard is you can type "dmesg". You will see something like this:
# dmesg | tail -14
[ 1736.400115] usb 2-1.1: new high-speed USB device number 5 using ehci-pci
[ 1736.492440] usb 2-1.1: New USB device found, idVendor=1908, idProduct=0226
[ 1736.492450] usb 2-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 1736.493047] usb-storage 2-1.1:1.0: USB Mass Storage device detected
[ 1736.499301] scsi host5: usb-storage 2-1.1:1.0
[ 1737.496968] scsi 5:0:0:0: Direct-Access     Generic  Mass-Storage     1.11 PQ: 0 ANSI: 2
[ 1737.497845] sd 5:0:0:0: Attached scsi generic sg1 type 0
[ 1738.093058] sd 5:0:0:0: [sdb] 31299584 512-byte logical blocks: (16.0 GB/14.9 GiB)
[ 1738.094061] sd 5:0:0:0: [sdb] Write Protect is off
[ 1738.094067] sd 5:0:0:0: [sdb] Mode Sense: 03 00 00 00
[ 1738.095050] sd 5:0:0:0: [sdb] No Caching mode page found
[ 1738.095055] sd 5:0:0:0: [sdb] Assuming drive cache: write through
[ 1738.101442]  sdb: sdb1
[ 1738.105047] sd 5:0:0:0: [sdb] Attached SCSI removable disk 

Before running dd you need to be root (run: sudo bash) and make sure the SDcard is not mounted. Use lsblk to check that. Unmount all mounted partitions of the card if they are mounted (command: umount /dev/sdb1, if it has more partitions then unmount them as well e.g: umount /dev/sdb2)

Now just use the command dd to write the image (not the zip file) to the sdcard:
dd bs=1M if=raspbian-stretch.img of=/dev/sdb conv=fsync

Note: replace /dev/sdb with the right device (from dmesg output).
Note: You write to the whole disk, not a partition, therefore no number in the device name (sdb).
If your have a zip-ed image then first check what is inside the zip file with the command "unzip -l thefile.zip" and then unpack it with "unzip thefile.zip". You need to put the plain image file onto the sdcard not the zip file.

The writing of the data could take a while. If you want to monitor the progress then run the command iostat from a second shell window.

That's it. The sdcard is ready for booting in your RaspberryPI

References


Back to: "No preservatives added"



© 2004-2024 Guido Socher