- You downloaded a Raspbian image (i.e. 2015-11-21-raspbian-jessie.img)
- You are using a computer running Ubuntu (or other linux distribution)
Mount Raspbian partition
You need to mount the Raspbian partition of the image.
Create a new mountpoint
Creating a mountpoint is as easy as creating a new directory1mkdir mountpoint
Find the Raspbian partition in the disk image
Raspbian is at the second partition in the disk image. So you need to find the offset of this partition to be able to mount it.
Execute the command:1file 2015-11-21-raspbian-jessie.img
…in the output there is a line like this:12015-11-21-raspbian-jessie.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x0,130,3), end-CHS (0x8,40,32), startsector 8192, 122880 sectors; partition 2 : ID=0x83, start-CHS (0x8,40,33), end-CHS (0x1de,79,49), startsector 131072, 7553024 sectors
Find here the start sector of the second partition (131072). To calculate the offset of this partition you have to multiply this by 512 bytes.
Mount the partition1sudo mount 2015-11-21-raspbian-jessie.img -o offset=$[512*131072] mountpoint
Remark 1: Calculation of the offset is done inline.
Remark 2: When you see this error: “mount: wrong fs type, bad option, bad superblock on /dev/loop0” probably you specified the wrong offset, did you multiply the start sector with 512 bytes?
Make changes in the Raspbian image
Now that you mounted the Raspbian partition at ‘mountpoint’, you can make changes.
Possible change: Configure WLAN-settings
Pre configure for example the WiFi/WLAN-settings. For this you need to have the service set identifier (SSID) of your wireless network and the pre-shared key (PSK). Remember also to grant new WiFi-devices at your wireless router when booting up the Raspberry Pi!
1sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
Add these lines:
Of course replace the ‘the_ssid_of_your_network‘ and ‘the_psk_of_your_network‘-values with those of your network.
Unmount the disk image
When you are ready making your modifications, you can unmount the image again.
1sudo umount mountpoint
Ready to write image
Now you are ready to write the image in the usual way to the SD card.
Use for example:
1sudo dd bs=4M if=2015-11-21-raspbian-jessie.img of=/dev/sdb
…when you like to write disk image 2015-11-21-raspbian-jessie.img to the SD card which is known by: /dev/sdb
Caution: All data will be lost at device: /dev/sdb