close-circle
Close
0%
0%

Raspbian Squeezed

How I automate the slaughter of the Official Raspberry Pi's Debian-based OS to create reliable headless, embedded systems

Similar projects worth following
close
(obsolete project)

Please join this project and let's see how much room and reliability we can squeeze out of the stock Raspbian. I use it since 2013 and I have always had to hack it and tweak it for my embedded, headless applications! However everytime a new board or a new Raspbian version appears, I have to restart from scratch all over again... It's becoming tiring ! What can be scripted ?

You can see this project as a "reverse Linux From Scratch" where instead of following instructions to build an OS ad nihilo, you deconstruct an existing system :-) Seriously, who needs all those bells and whistles : Wolfram Alpha, Minecraft, Oracle's Java or even X11 for a single-purpose, headless embedded nanoPC ?

I have gathered notes over time, I'm turning them into scripts and I now share them, hoping that contributors will tell me how to save some more megabytes, seconds during boot or simply hassles.

I have hacked my own Rasbpbian images since february 2013. It is embedded in #Rosace, #SPI Flasher, #Mons2015 LED Screen ElectroSuper and several other projects!

Now it's time to make my methods public, yet without my personal, custom and project-specific files. You can save precious hours when you start your next project by following my logs, executing my scripts or even by downloading the resulting image. It provides some interesting benefits such as

  • Booting in read-only mode to avoid Flash wear or filesystem corruption (log in to switch to read-write mode)
  • Increasing room on the memory card (only 520MB occupied instead of ... OMG). A smaller footprint means you can use a smaller (cheaper!) memory card, or you can store more useful data.
  • Better real-time behaviour (less deamons started)

You should be able to modify the parameters: aptitude is still installed and networking is operational so you can (re)download the packages you need.


Logs:
1. First revision... or so
2. Gotta script'em all!
3. SD card size question
4. Bloatwar(e)
5. Partial release
6. Other configuration tips from ALSA
7. And...
8. Raspbian in 2017

plain - 20.89 kB - 02/25/2017 at 21:37

download-circle
Download

  • 1 × Raspberry Pi B or B+
  • 1 × microSD Flash card (8GB or more) (Raspbian Jessie needs more than 4G at first but this is reduced by the scripts so the resulting image fits in 4GB)
  • 1 × USB Keyboard
  • 1 × HDMI screen
  • 1 × microUSB power supply, at least 1A

View all 8 components

  • Raspbian in 2017

    Yann Guidon / YGDES03/23/2017 at 16:01 0 comments

    The new images fit in less than 2GB so no more stupidly buying 8GB cards ! I'm glad I kept my stock of 2GB and 4GB cards !

    However, there is a BIG problem when you want to "cook" your own images : the stock image automatically resizes/expands the main partition ON FIRST BOOT !

    How braindead is that ? I can see some justification but there is no obvious way to turn this off...


    Edit : Google is your friend, remember...

  • And...

    Yann Guidon / YGDES12/22/2015 at 22:36 0 comments

    https://ubuntu-pi-flavour-maker.org/

    Why bother anymore ?

    (ah yes, the "read only" technique is still relevant)

  • Other configuration tips from ALSA

    Yann Guidon / YGDES12/22/2015 at 20:42 0 comments

    http://wiki.linuxaudio.org/wiki/raspberrypi

    The configuration of the Pi is not automated but the little script to configure JACK is similar to what I already do:

    #!/bin/bash
    
    ## Stop the ntp service
    sudo service ntp stop
    
    ## Stop the triggerhappy service
    sudo service triggerhappy stop
    
    ## Stop the dbus service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
    sudo service dbus stop
    
    ## Stop the console-kit-daemon service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
    sudo killall console-kit-daemon
    
    ## Stop the polkitd service. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
    sudo killall polkitd
    
    ## Only needed when Jack2 is compiled with D-Bus support (Jack2 in the AutoStatic RPi audio repo is compiled without D-Bus support)
    #export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/dbus/system_bus_socket
    
    ## Remount /dev/shm to prevent memory allocation errors
    sudo mount -o remount,size=128M /dev/shm
    
    ## Kill the usespace gnome virtual filesystem daemon. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
    killall gvfsd
    
    ## Kill the userspace D-Bus daemon. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
    killall dbus-daemon
    
    ## Kill the userspace dbus-launch daemon. Warning: this can cause unpredictable behaviour when running a desktop environment on the RPi
    killall dbus-launch
    
    ## Uncomment if you'd like to disable the network adapter completely
    #echo -n “1-1.1:1.0” | sudo tee /sys/bus/usb/drivers/smsc95xx/unbind
    ## In case the above line doesn't work try the following
    #echo -n “1-1.1” | sudo tee /sys/bus/usb/drivers/usb/unbind
    
    ## Set the CPU scaling governor to performance
    echo -n performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    Except that I don't stop the services, I remove the corresponding packages...

  • Partial release

    Yann Guidon / YGDES10/03/2015 at 09:36 0 comments

    "Release early, release often" they say, but at least release something that somehow works ;-)

    When I started this, I had just squeezed raspbian down to 520MB (a 200MB .gz can be found there http://ygdes.com/Squeezed/ please be nice with my bandwidth and quota) but it was not automated and I had broken a few things. It's still usable over ssh or if you have a QWERTY keyboard but I'm not totally happy with it.

    Now Jessie is out (of proportions) and I'm fighting with the dead weight. I learn to use resize2fs but the official image won't resize when the image in loop-mounted, for reasons that still escape me. I have conceded that a 8GB card is necessary during the image configuration, then resize2fs can be run on the skimmed card. So yes it can fit in 4GB.

    This is not finished however but the beginning works so I put the scripts there http://ygdes.com/Squeezed/Squeezed.20151003.tgz
    I know I have a weird coding style with bash and I hope you don't mind. It's just memories from an old Linux From Scratch-based project ;-)

    The "hardening part" is not yet provided but it's a little procedure that is described in the previous log at the end of http://ygdes.com/Squeezed/install_20150926.txt

  • Bloatwar(e)

    Yann Guidon / YGDES09/30/2015 at 07:43 2 comments

    I am doing a routine test of the scripts before I release an early version and I discover that a new archive version is available:

    2015-09-24-raspbian-jessie.zip : 1332985725 bytes

    25% larger than the previous version ! That's insane ! But not as much as the image's size itself:

    2015-09-24-raspbian-jessie.img : 4325376000 bytes

    SDcards, and storage devices in general, don't have all the same exact size so with some bad luck, it is easy to get a 4GB flash card that is not suitable for this image... So I insert my work card in my computer to check :

    fdisk -l

    Disk /dev/mmcblk0: 3,7 GiB, 3980394496 bytes, 7774208 sectors

    What the f*** Raspberry Pi Foundation, what the holly f*** ?

    The filesystem has 715MB free, before the 100MB swap file is created. The filesystem should be 350MB smaller to fit in a 4BG card, and it's not hard to achieve. Just stop bundling junk with your images.

    Correction :

    # dd if=/dev/zero of=ZERO bs=4K

    946167808 octets (946 MB) copiés

    So why expand beyond the 4GB limit ?

  • SD card size question

    Yann Guidon / YGDES09/28/2015 at 23:50 1 comment

    The current Raspbian image takes 3GB and contains about 2GB of data (compressed down to 1GB of archive). This means that a 4GB card is necessary. It's today's standard size but can it be cheaper with a smaller image ?

    I managed to squeeze Raspbian down to about 520MB so a 2GB SD card is possible. But I will have to shrink the ext4 fs instead of expanding it. Who needs to fit in 2GB? Does it make sense economically? What about older systems?


    OK, I have one argument for the reduction : it saves time when writing the image to the flash card so I'll see how to reduce the partition's size to about 1GB...

  • Gotta script'em all!

    Yann Guidon / YGDES09/27/2015 at 23:28 6 comments

    The last version was quick and dirty and as it could be expected, it has a few shortcomings. So much in fact that it's better to do it all over, it's faster than trying to fix it.

    The second time I do something, I don't want to have to do it by hand a 3rd time, which is ... likely. So I make more efforts and instead of just writing things down, I simply write a set of scripts. Like in the old times of LFS :-D

    The problem is that there are now 2 platforms to run (host and Pi), so 2 sets of scripts. A new challenge for me, I'll see how I'll handle that gracefully :-D

    Hopefully the 2nd version will be better, faster, maybe even smaller...


    Update:

    I have now a set of bash scripts to safely automate the first parts, the easy ones. It runs on Linux and now uses a new trick to reduce the number of manipulations : simple data are changed or uploaded from the host computer by loop-mounting the image before it is written to Flash and booted.
    The big issue is still the management of the debian/apt packages and so far this can only be done from the booted system. Similarly, the raspi-config part can't be automated yet, so more manual operations...

    At least the set of scripts is modular and new steps can be added to provide more functionalities, on demand, for each project. Just "su" and run each script in order :-)

  • First revision... or so

    Yann Guidon / YGDES09/26/2015 at 06:02 0 comments

    Today (saturday sept. 26th) I started with the original, official image

    [yg@localhost RPi]$ wget 'https://downloads.raspberrypi.org/raspbian_latest'
    [yg@localhost RPi]$ mv raspbian_latest 2015-05-05-raspbian-wheezy.img.zip
    [yg@localhost RPi]$ shasum 2015-05-05-raspbian-wheezy.img.zip
    cb799af077930ff7cbcfaa251b4c6e25b11483de  2015-05-05-raspbian-wheezy.img.zip
    [yg@localhost RPi]$ /usr/bin/time unzip 2015-05-05-raspbian-wheezy.img.zip
    [yg@localhost RPi]$ ls -al
    -rw-r--r--.  1 yg   yg   3276800000  7 mai   01:00 2015-05-05-raspbian-wheezy.img
    -rw-rw-r--.  1 yg   yg   1038523231  7 mai   17:55 2015-05-05-raspbian-wheezy.img.zip
    [yg@localhost RPi]$ shasum 2015-05-05-raspbian-wheezy.img
    fd11a319a8e93fc5f93902c67d337ad419706e5e  2015-05-05-raspbian-wheezy.img
    and ended up with an image that weights 1/5th of the original archive :
    [root@localhost RPi]# sha1sum 2015-09-26_Raspbian_Hardened.3276800000.img
    694fc3dca01f8393675d5e7dbc705ec371af7554  2015-09-26_Raspbian_Hardened.3276800000.img
    [root@localhost RPi]# gzip -k 2015-09-26_Raspbian_Hardened.3276800000.img
    [root@localhost RPi]# sha1sum 2015-09-26_Raspbian_Hardened.3276800000.img.gz
    4cec82c359ab7e8d0b74976309f9243f091b819b  2015-09-26_Raspbian_Hardened.3276800000.img.gz
    [root@localhost RPi]# l 2015-09-26_Raspbian_Hardened.3276800000.img*
    -rw-r--r--.  1 yg   yg   3276800000 26 sept. 06:27 2015-09-26_Raspbian_Hardened.3276800000.img
    -rw-r--r--.  1 yg   yg    200269221 26 sept. 06:27 2015-09-26_Raspbian_Hardened.3276800000.img.gz
    All the steps are explained there : http://ygdes.com/squeezed/install_20150926.txt

    BEWARE ! IT'S CRUDE !

    but I'm in a sort of rush because I want to have a complete public and working #SPI Flasher as soon as possible. Since you have all the instructions, you can spot errors, make your own version and send me patches.

View all 8 project logs

Enjoy this project?

Share

Discussions

Adam Vadala-Roth wrote 10/31/2016 at 17:51 point

my friend just installs Jessie ARM build straight to his pi via net install, but this was on RPi2

  Are you sure? yes | no

Arsenijs wrote 04/25/2016 at 18:02 point

Why not use raspbian-ua-netinst? It comes to be freaking small, used it a lot.

Edit: just noticed this is quite old. Regardless, it was around in the start of 2015.

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/25/2016 at 18:10 point

Yeah, I started "cooking" Raspbian in 2013...

  Are you sure? yes | no

Jarrett wrote 09/30/2015 at 23:25 point

Check out DietPi for a custom image that comfortably fits on a 1 gig card. It has some good scripting ability, too, with files that are accessible when reading the card on Windows

  Are you sure? yes | no

Yann Guidon / YGDES wrote 09/30/2015 at 23:34 point

Thank you ! The weird size of the new file image is driving me crazy.

  Are you sure? yes | no

Yann Guidon / YGDES wrote 10/06/2015 at 03:35 point

I looked a little at DietPi and this is close to what I try to achieve. It is missing the "hardening" part (read-only system) and Jessie is not yet done. The latter is going to be done soon so I'd rather wait a bit than duplicate efforts and waste my own time.
Then I'll adjust my scripts and add some features, which I hope to submit back to Fourdee. This will save me/us even more time !

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates