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.


  • 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 1: 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. Replace ‘update_config=1’ with ‘update_config=0’.
    • Possible change 2: Enable SSH-server

      As of the November 2016 release, Raspbian has the SSH server disabled by default. It can be enabled by placing a file named ‘ssh’, without any extension, onto the boot partition of the SD card. When the Pi boots, it looks for the ssh file. If it is found, SSH is enabled, and the file is deleted. For this change you have to mount the boot partition instead of the second partition. In this example the boot partition starts at: 8192. Use this value in step 3 (Mount the partition).

  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
  5. Flush the write cache

    Before removing the SD card, issue the command:

    and wait for the prompt. Maybe your computer detected the new partitions at the SD card and mounted them automatically, please unmount them again. Now it’s safe to remove the SD card from the computer.