build your own basic Raspberry Pi Debian image

Debian / Raspberry Pi


Outdated! May I point you to Raspbian Lite Image by the Raspberry Pi Foundation.
Outdated! May I point you to raspbian-ua-netinst.

Seems that I’m one of these lucky guys already received their Raspberry Pi. I ordered it from RS on the 5th and got it on the 10th of May. Posted my unboxing on Google+.

But which distribution should I install? There are many on the downloads page. First choice was the Debian image, because I’m a Debian fanboy! Impressive, but its not Wheezy.

There is already a Debian Wheezy distribution available: Raspbian. But not all packages are ported yet. Let’s come back later.

Another choice is Chris Boot’s Debian Wheezy image with a Linux 3.2 kernel. He has also already prepared a pre-compiled binary for Debian. One great improovement of Chris‘ kernel is that IPv6 is enabled and its based on Linux 3.2! In the meantime, also the stock Raspberry Pi kernel got IPv6 enabled.

By the way, if your Raspberry Pi always hangs during boot at:

Waiting for root device /dev/mmcblk0p2
mmc0: problem reading SD Status register.
mmc0: error -110 whilst initialising SD card

Then just take an other SD card and it would boot like a charm. Hopefully. 🙂

Ok, I also could have upgraded Debian Squeeze to Wheezy, but I’d like to have a basic system without anything, so I decided to debootstrap my own image.

Based on

I’ve developed a script which generates the SD card for your Raspberry Pi on your Desktop PC. You can download it from kmp.or.at/~klaus/raspberry. There you can also download a recently generated image.

Before you start, you should have installed some packages:

# apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools

As only parameter give the blockdevice of your SD card (like /dev/sdc) and run it as root.

# sudo build_rpi_sd_card.sh /dev/sdc

Or just leave the parameters and the script will produce an image file.

The shell script will perform following steps:

  • check for root and blockdevice or create empty file for looping
  • remove MBR on SD card
  • setup new partitions and generate filesystems
  • debootstrap first stage
  • chroot into new system
  • debootstrap second stage
  • create config files
  • install kernel, modules and firmware with Hexxeh’s rpi-update
  • install ntp, openssh-server and some other usefull stuff
  • set root password to raspberry
  • cleanup

If you have created an image, just put it with the following command onto your SD card.

# sudo dd if=<image file> of=<blockdevice of your SD card> bs=1M

Plug the SD card into your Raspberry Pi and power it up. It should boot up with DHCP and the root password is raspberry (what else? 🙂 ).

Enjoy your basic, virgin Debian Wheezy on your Raspberry Pi. Any comments are welcome.

History of build_rpi_sd_card.sh
# 2012-06-24
#    just checking for how partitions are called on the system (thanks to Ricky Birtles and Luke Wilkinson)
#    using http.debian.net as debian mirror, see http://rgeissert.blogspot.co.at/2012/06/introducing-httpdebiannet-debians.html
#    tested successfully in debian squeeze and wheezy VirtualBox
#    added hint for lvm2
#    added debconf-set-selections for kezboard
#    corrected bug in writing to etc/modules
# 2012-06-16
#    improoved handling of local debian mirror
#    added hint for dosfstools (thanks to Mike)
#    added vchiq & snd_bcm2835 to /etc/modules (thanks to Tony Jones)
#    take the value fdisk suggests for the boot partition to start (thanks to Mike)
# 2012-06-02
#    improoved to directly generate an image file with the help of kpartx
#    added deb_local_mirror for generating images with correct sources.list
# 2012-05-27
#    workaround for https://github.com/Hexxeh/rpi-update/issues/4 just touching /boot/start.elf before running rpi-update
# 2012-05-20
#    back to wheezy, http://bugs.debian.org/672851 solved, http://packages.qa.debian.org/i/ifupdown/news/20120519T163909Z.html
# 2012-05-19
#    stage3: remove eth* from /lib/udev/rules.d/75-persistent-net-generator.rules
#    initial

66 Kommentare

  1. Very nice, but I’m wondering where exactly to start. Can I run the script from a running RPi ? I have a USB Card-Reader in place where I can plug in the sd-card???

    • Hödlmoser sagt

      hi Thomas!

      you need at least following software packages: binfmt-support qemu qemu-user-static debootstrap. on a debian system you can install it with aptitude install, as described in the articel.

      I have tested it only on my x86 desktop pc with debian wheezy. if you’d like to run it on the Raspberry itself, you should get rid of all this qemu stuff, because the target system has the same architecture.

      To find the block device of your SD card just plug it into your SD card reader and have a look on the kernel message w/ dmesg.

      hth, but anyway, thanks for the idea, so if time is left I’ll try it on my own and will update the script.

      greetings, Klaus

  2. Hi Klaus,
    thx for Your quick answer. I tried with my Ubuntu system but still no success. Is it possible to provide an image of a working sd-card ?

    • Hödlmoser sagt

      can u just post the errormessages of the script? I can provide a fresh image earliest tomorrow lunch.

      • Hi Klaus,
        it seems that the /boot partition is not fully filled with the files needed:
        root@ubuntu:~/rpi/rootfs# rpi-update
        Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS
        Performing self-update
        /boot/start.elf doesn’t exist.
        Can you check this ?

        Thank’s a lot,
        Greetings,
        Thomas

        • Thasan sagt

          I had same problem and that problem is on rpi-update.
          I „fixed“ it with disabling start.elf check (comment lines 179-182), autoupdate (comment line 63) and added RAM value to installer script (192 to end of line 94)

        • Hödlmoser sagt

          Thasan, you are right, but I’m sure that its easier to just touch start.elf (already tested):

          mount /dev/sdc2 /root/rpi/rootfs
          mount /dev/sdc1 /root/rpi/rootfs/boot
          chroot /root/rpi/rootfs /bin/bash
          touch /boot/start.elf
          /usr/bin/rpi-update
          exit
          umount /root/rpi/rootfs/boot
          umount /root/rpi/rootfs

          means, mount the filesystems, chroot in it, touch start.elf (the missing file), run rpi-update, unmount.

          someone with the same avatar as you has opened an issue for rpi-update already.

  3. Felix sagt

    Thanks for the image. I can’t get apt-get to work, I had to change the server in sources.list manually.

    • Hödlmoser sagt

      thanks Felix! its my private debian mirror, forgot to change it on the image. but you’ve already fixed it, great.
      I will provide an updated image asap.

      • isama sagt

        I’m sorry for asking an unrelated question, but how did you set up your internal mirror? I’ve never got one to work.

        • Hödlmoser sagt

          I’m just using apt-cacher-ng.
          and in /etc/apt/apt.conf.d/02proxy I just give Acquire::http { Proxy "http://:3142"; };

  4. Mike sagt

    Thanks for the instructions. I had to end up just following along in the script and running the commands manually as the script didn’t seem to work running from a Squeeze server. The fdisk command was incorrect for my 4GB SD card (I started the dos partition at block 1 and still made it 64MB) and I also had to ‚apt-get install dosfstools‘ for the mkfs.vfat command. Other than those small issues, it was a great starting point that got me up and running very quickly.

    • Hödlmoser sagt

      hi Mike!
      thanks for your feedback. I’ve added the hint for the dependency of dosfstools. till now I haven’t tested my script running on squeezy, but it seems its worth to setup a vm for testing.
      gre3tings, Klaus

    • Hödlmoser sagt

      hi Mike!
      in squeeze fdisk is using cylinders afaik. in the script I just put 2048 as sectors (!). in the updated script I will use the value fdisk suggests, so it should be save for squeeze and als wheezy.
      gre3tings, Klaus

  5. Hey, great work on this ! I was looking at the different ways of doing this and your script is just what I was after. Anyway thought I would just add that it might be worth adding a line to add vchiq & snd_bcm2835 to /etc/modules . vchiq is for the GPU and snd_bcm2835 will load the sound drive so you no longer need the hdmi_drive=2 in config.txt.

    • Hödlmoser sagt

      hi Tony!
      thats a great idea, thanks. I’ve added it to the script, will be released soon.
      gre3tingsm, Klaus

  6. Hi!

    Due to module incompatibility, I am trying to get the armel version with the older kernel 2.6.3x running on my rpi, but with mo luck. Did you try your script with squeeze too?
    Thank you

    Florian

    • Hödlmoser sagt

      hi Florian!
      my script is not tested on squeeze, but I will go for a vm w/ squeeze to be able to test.
      what’s the error message you get?
      gre3tings, Klaus

    • Hödlmoser sagt

      hi!
      script is now tested also in squeeze as in wheezy. enjoy.
      greetings, Klaus

  7. Ricky Birtles sagt

    Hey dude, think this section of the script needs updating:

    bootp=${device}1
    rootp=${device}2

    to

    bootp=${device}p1
    rootp=${device}p2

    • Hödlmoser sagt

      hi Ricky!
      why do you think so? which linux distribution you’ve in use? which kernel?
      all my devices look like /dev/sd[a-z][0-9] no p for the partition, except I mount an image file with kpartx.
      gre3tings, Klaus

      • Ricky Birtles sagt

        I am using Ubuntu 12.* which mounts the device in the following way:

        brw-rw—- 1 root disk 179, 0 2012-06-22 19:21 /dev/mmcblk0
        brw-rw—- 1 root disk 179, 1 2012-06-22 19:21 /dev/mmcblk0p1
        brw-rw—- 1 root disk 179, 2 2012-06-22 19:22 /dev/mmcblk0p2

        • Hödlmoser sagt

          hi!
          I c. just testing if ${device}1 is a blockdevice, if not, I’ll use ${device}p1. not tested yet, but it should work. see latest script. 🙂
          hth, Klaus

  8. Hello its just i am looking all days about this topic thankyou 🙂

    İ have download your sh script and run without device but i cannot find image file. can you help me?

    Thx.

    • Hödlmoser sagt

      hi!
      image file could be found as /root/rpi/rpi_basic_<release>_<date>.img.
      hth & u r welcome

  9. Looks like a great script and exactly what I’m looking for. Unfortunately I could not get it to work on Squeeze but reading the comments I understand that the issue is known and looking forward to a updated script (or info on what to change to get it to work on Squeeze).

    Thanks for sharing!

    • Hödlmoser sagt

      hi!
      nothing has to be changed, just download the latest script and hopefully it will also work on your squeeze.
      just follow the instructions concerning the packages you need to install.
      hth & u r welcome, Klaus

  10. After getting Wheezy up running in a VM I managed to use your script to generate a minimal Debian Squeeze image. Only issue I experienced was that the script was unable to unmount the image when finished but a simple restart solved that until I have some more time to figure it out.

    Thanks again for making and sharing this script!

  11. Luke Wilkinson sagt

    First, THANKYOU SO MUCH FOR THIS SCRIPT THIS HAS SAVED ME SO MUCH TIME!

    Second, I think ricky is correct for some people/systems.

    I am using ubuntu lucid and for me the sdcard appears under /dev/ like so:

    # ll /dev/mmcblk0*
    brw-rw—- 1 root disk 179, 0 2012-06-22 19:21 /dev/mmcblk0
    brw-rw—- 1 root disk 179, 1 2012-06-22 19:21 /dev/mmcblk0p1
    brw-rw—- 1 root disk 179, 2 2012-06-22 19:22 /dev/mmcblk0p2

    unusual. I had to make the change ricky suggests in order to make this script work.

    this is on a hp dv6000 laptop.

    „lspci -nn“ gives the following information on my multi card reader:

    09:09.1 SD Host controller [0805]: Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter [1180:0822] (rev 22)
    09:09.2 System peripheral [0880]: Ricoh Co Ltd R5C843 MMC Host Controller [1180:0843] (rev 12)
    09:09.3 System peripheral [0880]: Ricoh Co Ltd R5C592 Memory Stick Bus Host Adapter [1180:0592] (rev 12)
    09:09.4 System peripheral [0880]: Ricoh Co Ltd xD-Picture Card Controller [1180:0852] (rev ff)

    probalby this difference is a result of having an unusual card reader.

    kind regards

    Luke

    • Ricky Birtles sagt

      This is due to the SD/MicroSD card being picked up as just that. In cases where the device is mounted as /dev/sda bla bla is due to the device being seen as a hard drive (portable or fixed).

      So guess in some cases it just depends on the system. Not a hard fix to change the script anyway. Glad it helped you.

      • Ricky Birtles sagt

        Hey, I have noticed now and then the sd card does not unmounted correctly which creates a error message.

        I have opted to use umount -l which fixes this random issue.

  12. Luke Wilkinson sagt

    also I changed „wheezy“ to „sid“ but that’s a side matter.

  13. Nathan sagt

    Is there a way to stop it looking for a DHCP and to continue with the boot?

    thanks

  14. Nathan sagt

    Also has the root password changed?

    I’m using raspberry but it’s not working.

    thanks

  15. Thanks a lot. The image you provided saved me a lot of time. Next I’ll try to create my own Debian image with a few more programs integrated.

    I mentioned (and linked) this article in my blog. Hope you don’t mind.

  16. Ricky Birtles sagt

    Hey, is there any way to tweak this script to install armhf that uses floating points to run faster,

  17. Vincent Lemoine sagt

    Questions:
    1. Can I download the DEBIAN ISO for x386 and install it under Virutalbox
    3. and then follow your step above to create a raspberry sd-card?

    Thx, Vincent

  18. Bhuvan sagt

    I am using open SUSE for executing this script and I have installed required packages but whenever the following command execute which involve chroot , there is an error..

    Line number 122
    LANG=C chroot $rootfs /debootstrap/debootstrap –second-stage

    ERROR is:
    chroot: cannot run command `/bin/bash‘: Exec format error

    Anybody please provide some solution.

  19. feuerrot sagt

    Ohai,

    danke für das Script! Das manuell machen zu müssen ist immerwieder fummelig…
    Da ich aber gerne defaultmäßig Neo2 nutzen würde: Wie muss ich die Zeile mit dem debconf-set-selections anpassen, damit ich direkt das neo-layout habe? Reicht da ein „console-common console-data/keymap/full select de-neo“?

    Gruß feuerrot

  20. funnyfrish sagt

    Where can i find the kernel SRC files of „rpi_basic_wheezy_20130126.img“ ?

    thanks for this great work.

    • Hödlmoser sagt

      my script is using Hexxehs rpi-update script which gets the „firmware“ from rpi-firmware. please have a lok there for further informations on the source code used to compile kernel and modules.

  21. ufas sagt

    Thanks for the script, it works and I see the device on the network.
    Unfortunately, I can not ssh- or telnet it. Is this deactivated? Any hints what I have to change to enable it?

    Thanks!

    • Hödlmoser sagt

      openssh-server is installed in third-stage, nothing needed on your side to enable ssh, it should just start. telnet is not installed.

  22. mezo sagt

    hey,
    i cant get this script working only my debian. i get always trust errors from guthub. i rly installed every needed packages and stillt this errors.

    • mezo sagt

      This is the error i always get:
      –2013-03-22 22:01:46– http://goo.gl/1BOfJ
      Resolving goo.gl (goo.gl)… 173.194.69.113, 173.194.69.138, 173.194.69.139, …
      Connecting to goo.gl (goo.gl)|173.194.69.113|:80… connected.
      HTTP request sent, awaiting response… 301 Moved Permanently
      Location: https://raw.github.com/Hexxeh/rpi-update/master/rpi-update [following]
      –2013-03-22 22:01:46– https://raw.github.com/Hexxeh/rpi-update/master/rpi-update
      Resolving raw.github.com (raw.github.com)… 199.27.76.133
      Connecting to raw.github.com (raw.github.com)|199.27.76.133|:443… connected.
      ERROR: The certificate of `raw.github.com‘ is not trusted.
      ERROR: The certificate of `raw.github.com‘ hasn’t got a known issuer.
      Reading package lists… Done
      Building dependency tree… Done
      Package less is not available, but is referred to by another package.
      This may mean that the package is missing, has been obsoleted, or
      is only available from another source

      i tried ur script on ubuntu and debian, but i get always this error. wget without this script works flawless

  23. Nice script, i have modified it to use Raspbian instead of Debian and made a few other changes to hopefully make it more complete and user friendly, Feel free to take a look at it and i hope it can be as usefull as yours.

  24. Heinz sagt

    Hello,
    is it possible to run the image on a cubieboard too ?
    Best regarts Heinz

  25. Jim sagt

    Any reason why I get the following message when the script is run?
    I: Retrieving InRelease
    I: Failed to retrieve InRelease

  26. Walt sagt

    Run the script several times and it seems to just install the Debian installer, i.e. on first boot of the RPi I am presented with the Debian installer, asking for language, keyboard, mirror, etc.
    What am I doing wrong?

    • Walt sagt

      Worked this time. I wonder if something was failing to download? Anyway, working now :-).

  27. Liam Reford sagt

    I’ve got the Debian 7.2 source code as a dual layer blu-ray disc and I’m curious about something – is it possible to use that to create an image for various purposes, like building a web server image, or a mail server image or a mix of what you’d like to do with the Raspberry Pi?

  28. kiko Unfla sagt

    Thanks for this great job!

    I’ve just created an image put it on a SD card, powered de rpi and … 😉

    Fantastic it boots and runs as espected.

    regards

Kommentare sind geschlossen.