Tuesday, 8 July 2014

Creating a Raspberry Pi SD card Image

The default Raspbian image from the Raspberry Pi website is set up for a UK keyboard, and is missing some software I want to use in school. So what I have been doing is installing Raspbian on one SD card, tweaking it to my liking, and then making an image from that card, which I can write to SD cards for students. Since our cards are 8GB, this technique saves a lot of time when you have many cards to write, since it only copies occupied sectors to the image, and not the whole card.



Procedure

1. Write Rasbian onto an SD card and boot the Raspberry Pi. Set up the keyboard layout to jp, boot to desktop, overclock to "High", but DO NOT expand the filesystem.

2. Remove wolfram-engine. This also removes Mathematica. The wolfram language has been pushed as a selling point for the Raspberry Pi, because this expensive software is made available for free on the Pi. However, I'm not a big fan of proprietary software, and I'm suspicious that this is just an attempt to hook people who otherwise wouldn't come across Mathematica. So after a 500MB update to wolfram-engine brought my whole class to a standstill when I was teaching them "aptitude upgrade" (which I expected to take a couple of minutes, with our fairly up-to-date system, but which took more than a 45 minute lesson. Actually I went round ctrl-c ing many of them after the lesson, as it was trickling in byte-by-byte from the underpowered wolfram repo. But I digress). I now joyfully aptitude remove wolfram-engine and good-riddance to it.

3. Clean the desktop. It doesn't need those random icons. I just leave the "shutdown" button, because it gives a faster route to shutting down than the one in the system tray. While I'm here, I also move the panel to the top (imposing my preference on the kids I suppose), and switch it to "system theme" instead of that ugly black. I add a CPU temperature monitor into the system tray (interesting to see how hot the Pi gets; sometimes worth taking the lid off), and also a memory monitor so that kids can see when they need to close some programs. I also switch file opening to single-click, because double-click is a pointless legacy of Windows.

4. Install the following, some for programming, but others so that the Pi can be used as a normal computer at home, if necessary
via aptitude:

  • geany, bluefish, chromium, iceweasel, inkscape, gimp, libreoffice, vlc, ...(from memory, will update later)
separately:

  • minecraft-pi and its textbook and cheat-sheet (download from websites) 
https://s3.amazonaws.com/assets.minecraft.net/pi/minecraft-pi-0.1.1.tar.gz
http://arghbox.wordpress.com/2013/06/13/programming-minecraft-pi-with-python-early-draft/
  • scratchtomcpi (from its git repo)
https://github.com/scratch2mcpi/scratch2mcpi
  • my own sample Scratch and Python programs.

5. Shutdown the Pi and transfer the SD card to the computer (running Debian).
Dmesg to find the card device ID

Then follow this, which I am pasting from Stack Overflow


» fdisk /dev/mmcblk0

Command (m for help): p
Disk /dev/mmcblk0: 16.1 GB, 16138633216 bytes
4 heads, 16 sectors/track, 492512 cylinders, total 31520768 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
Disk identifier: 0x00017b69

Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1    8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2  122880    26746879    13312000   83  Linux
Hopefully that's clear (I typed fdisk /dev/mmcblk0 then entered p as the command). The "Start" and "End" units are sectors, and notice the sector size is given, 512 bytes. For /dev/mmcblk0p2, 26746879 (the last sector) - 122880 (the first sector) = 26623999 / 2 (for 2 sectors per kB) / 1024 (kB per MB) / 1024 (MB per GB) = 12.69, which I grew the partition using gparted to 12 GB, so this looks correct (really I should be using 1000 and not 1024 as the divisor with storage, which works out to 13.31 GB, but I suspect gparted and some other tools also use 1024).
So the first thing you want to check is that your second partition is really the smaller size that you set it to. Next, just use those numbers with dd; for me it would be:
dd if=/dev/mmcblk0 of=rpi.img bs=512 count=26746880
I've got an extra sector there to avoid any kind of off by one misunderstanding of how dd works.  

6. Write the image to the SD cards. I write 4 simultaneously, using card readers from the 100 yen shop (it seems like only a couple of years since you couldn't get a card reader for much under 2000 yen!). It takes about 10 minutes for a 2.7GB image.

update: This link is handy for re-sizing an existing image: https://softwarebakery.com//shrinking-images-on-linux

No comments:

Post a Comment