Raspberry Pi: Raspbian – Modify image

Raspbian logoIn this post you will learn how to make some (tiny) changes in the Raspbian SD card image before writing it on the micro SD card.

Assumptions

  • You downloaded a Raspbian image (i.e. 2015-11-21-raspbian-jessie.img)
  • You are using a computer running Ubuntu (or other linux distribution)
  1. Mount Raspbian partition

    You need to mount the Raspbian partition of the image.

    1. Create a new mountpoint

      Creating a mountpoint is as easy as creating a new directory

    2. 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:

      …in the output there is a line like this:

      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.

    3. Mount the partition

      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?

  2. 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!


      Add these lines:

      Of course replace the ‘the_ssid_of_your_network‘ and ‘the_psk_of_your_network‘-values with those of your network.
  3. Unmount the disk image

    When you are ready making your modifications, you can unmount the image again.

  4. Ready to write image

    Now you are ready to write the image in the usual way to the SD card.
    Use for example:


    …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