udev automount shell script (no daemon)

/etc/udev/rules.d/85-storage-automount.rules :

ENV{DEVTYPE}=="partition", RUN+="/etc/automount/automount.sh", ENV{REMOVE_CMD}="/etc/automount/autoumount.sh"

/etc/automount/automount.sh :

#!/bin/sh

# set the mountpoint name according to partition or uuid
mount_point=$ID_FS_LABEL
if [ -z $mount_point ]; then
    mount_point=${ID_FS_UUID##*/}
fi

# if a plugdev group exist, retrieve it's gid set & it as owner of mountpoint
plugdev_gid="$(grep plugdev /etc/group|cut -f3 -d:)"
if [ -z $plugdev_gid ]; then
    gid=''
else
    chown root:plugdev $mount_point
    gid=",gid=$plugdev_gid"
fi

# create the mountpoint directory in /media/ (if not empty)
if [ -n $mount_point ]; then
    mkdir -p /media/$mount_point
    # other options (breaks POSIX): noatime,nodiratime,nosuid,nodev
    mount -t $ID_FS_TYPE \
      -o rw,user,uid=0$gid,umask=002,dmask=002,fmask=002 \
      $DEVNAME /media/$mount_point
    /etc/automount/autorun.sh mount $ID_FS_UUID
fi

/etc/automount/autoumount.sh :

#!/bin/sh

# set the mountpoint name according to partition or device name
mount_point=$ID_FS_LABEL
if [ -z $mount_point ]; then
    mount_point=${DEVNAME##*/}
fi

# remove the mountpoint directory from /media/ (if not empty)
if [ -n $mount_point ]; then
    umount -l /media/$mount_point || \
    umount -f /media/$mount_point
    rm -R /media/$mount_point
    /etc/automount/autorun.sh umount $ID_FS_UUID
fi

example /etc/automount/autorun.sh :

#!/bin/sh

#[ "$1" = "mount" ] && [ "$2" = "ABCDEF0123456789" ] && service transmission-daemon restart
#[ "$1" = "umount" ] && [ "$2" = "ABCDEF0123456789" ] && service transmission-daemon stop

return 0

The rpi-live init script

# RPI specific live script			-*- shell-script -*-

if [ -e /scripts/functions ]
then
	. /scripts/functions
fi

mountroot()
{
	modprobe loop
	modprobe aufs
	wait_for_udev 10
	mntpts=""
	aufs=""
	i=0
	mkdir -p /live-media
	mkdir -p /live-loop
	mount -t vfat /dev/mmcblk0p1 /live-media

	for f in /live-media/live/*.squashfs; do
		losetup /dev/loop${i} ${f}
		mkdir /live-loop/ro${i}
		mount -t squashfs -o loop,ro /dev/loop${i} /live-loop/ro${i}
		aufs="/live-loop/ro${i}=ro:${aufs}"
		mntpts="${mntpts} /live-loop/ro${i}"
		i=$(( ${i} + 1 ))
	done

	mkdir /live-loop/cow
	mntpts="${mntpts} /live-loop/cow"
	if [ -e /live-media/live/rpi-live ]; then
		losetup /dev/loop${i} /live-media/live/rpi-live
		mount -t ext4 /dev/loop${i} /live-loop/cow
	else
		mount -t tmpfs tmpfs /live-loop/cow
	fi
	aufs="noatime,noxino,dirs=/live-loop/cow=rw:${aufs}"
	mount -t aufs -o ${aufs} aufs ${rootmnt}
	#sleep 1

	[ -d ${rootmnt}/boot ] || mkdir ${rootmnt}/boot
	mount -o move /live-media ${rootmnt}/boot
	for mntpt in ${mntpts}
	do
		local newmount
		newmount="${rootmnt}/lib/live/mount/${mntpt#/live/}"
		mkdir -p "${newmount}"
		mount -o move "${mntpt}" "${newmount}" > /dev/null 2>&1 || \
		mount -o bind "${mntpt}" "${newmount}" > /dev/null
	done
}

How i do that : Quick & dirty howto

###########
## Bootstrap part
#####################

# install the required packages
apt-get install qemu qemu-user qemu-user-static binfmt-support debootstrap git squashfs-tools

# debootstrap the raspbian
mkdir chroot
qemu-debootstrap --no-check-gpg --arch armhf wheezy chroot http://archive.raspbian.org/raspbian

# Get the Adafruit files & cp the broadcom libs
git clone https://github.com/raspberrypi/firmware.git
cp -r firmware/hardfp/opt/vc/ chroot/opt/
rm -r chroot/opt/vc/src/

# get the initscript
wget http://l33thium.free.fr/content/rpi-live
cp rpi-live chroot/etc/initramfs-tools/scripts/

# chroot
mount -t proc proc chroot/proc
mount -t sysfs sysfs chroot/sys
mount -o bind /dev chroot/dev
LC_ALL=C chroot chroot

############
## chroot part
#################

# link the Broadcom libs
echo "/opt/vc/lib/" >> /etc/ld.so.conf
ldconfig

# configure network
echo "allow-hotplug eth0" >> /etc/network/interfaces
echo "iface eth0 inet dhcp" >> /etc/network/interfaces

# Get the minimum required packages
echo "deb http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi" > /etc/apt/sources.list

apt-get update
apt-get install linux-image-rpi-rpfv openssh-server ntp fake-hwclock locales tzdata console-setup squashfs-tools

# make the initramfs
echo "aufs" >> /etc/initramfs-tools/modules
echo "squashfs" >> /etc/initramfs-tools/modules
update-initramfs -u

# set hostname & password
echo "Pi" > /etc/hostname
passwd

# cleaning & exit
apt-get clean
exit

###########
## Final part
###################

# cleaning the chroot
umount chroot/{proc,sys,dev}
rm -r chroot/root/.* chroot/var/log/* chroot/var/cache/debconf/* chroot/var/lib/apt/lists/*
mkdir chroot/var/log/fsck

# squashing the root
mkdir -p sd/live
mksquashfs chroot sd/live/00-base.squashfs -comp xz -e boot

# prepare the scdcard content
cp firmware/boot/* sd/
rm sd/{kernel.img,kernel_emergency.img} # (On a pas besoin du noyau Adafruit)
cp chroot/boot/vmlinuz-3.10-3-rpi sd/
cp chroot/boot/initrd.img-3.10-3-rpi sd/

echo "kernel vmlinuz-3.10-3-rpi" > sd/config.txt
echo "initramfs initrd.img-3.10-3-rpi" >> sd/config.txt

echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 boot=rpi-live elevator=deadline rootwait quiet" > sd/cmdline.txt

#################
## XBMC part on the PI
#########################

# make the persistence file
cd /boot/live/
dd if=/dev/zero of=rpi-live bs=1M count=1024
mkfs.ext4 rpi-live
reboot

# install required packages
echo "deb http://archive.mene.za.net/raspbian wheezy contrib" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-key 5243CDED

apt-get update
apt-get install xbmc udisks-glue
apt-get clean

# Configure auto-mount :
# add "fmask=0,dmask=0" to /etc/udisks-glue.conf
# like that : "...--mount-options sync,fmask=0,dmask=0"
# and add "udisks-glue" to /etc/rc.local, before "exot 0"

# create é configure the xbmc user
addgroup --system input
adduser xbmc
usermod -a -G audio,video,input,dialout,plugdev,tty xbmc

# udev rules for xbmc
nano -w /etc/udev/rules.d/99-input.rules
# add
# SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"
# SUBSYSTEM=="input", GROUP="input", MODE="0660"
# KERNEL=="tty[0-9]*", GROUP="tty", MODE="0660"

# To allow xbmc to shutdown the system
nano -w /var/lib/polkit-1/localauthority/50-local.d/xbmc.pkla
add :
# [Actions for xbmc user]
# Identity=unix-user:xbmc
# Action=org.freedesktop.upower.*;org.freedesktop.consolekit.system.*
# ResultAny=yes
# ResultInactive=yes
# ResultActive=yes

# turn "ENABLED=0" to 1 in /etc/default/xbmc

# move the persistence file for the last part
cd /boot/live/
mv rpi-live xbmc.img
reboot

##################
## Squasing xbmc
######################

# mount the old persistence file
cd /boot/live/
mkdir loop
mount -o loop xbmc.img loop/

# Some cleanings and squashing
rm -r loop/root/.* loop/var/log/* loop/var/cache/debconf/* loop/var/lib/apt/lists/* loop/home/xbmc/.*
mksquashfs loop 01-xbmc.squashfs -comp xz -e boot

# remove the now useless image file
umount loop
rm -r loop/ xbmc.img

# make another persistence file
dd if=/dev/zero of=rpi-live bs=1M count=256
mkfs.ext4 rpi-live

# config gpu_mem to allow xbmc to play HD videos
# add  gpu_mem=128 to /boot/config.txt
reboot

First Release: Raspbian+XBMC.

Instructions:

  • Get the archive
  • Uncompress it onto a fresh fat32 formated SDcard
  • Boot your Pi

First run :

  • Configure your xbmc as you like in the standard way

First shell login :

  • The passord for root is « root » and for the user xbmc… « xbmc »
  • Log you as root, configure your language, region, … and change these passwords :
  • dpkg-reconfigure locales tzdata keyboard-configuration
    passwd
    passwd xbmc
    

Tips for xbmc :

  • Force Always activated v-sync
  • Deactivate gl-spectrum

General tips :

  • for reset your raspbian live, just delete or format in ext4 the file /boot/live/rpi-live.
  • Without this file your raspbian live runs in ram.

  • For remove xbmc and get the minimal raspbian, delete or move /boot/live/01-xbmc.squashfs

En français :

Instructions:

  • Téléchargez l’archive
  • Décompressez la sur une carte SD formatée en FAT32
  • Bootez le Pi

Premier démarrage :

  • Configurez xbmc à votre gout.

Premier login shell :

  • Le mot de passe root est « root » et pour xbmc… « xbmc »
  • connectez vous en tant que root, configurez langue, région, … et changez ces mots de passe :
  • dpkg-reconfigure locales tzdata keyboard-configuration
    passwd
    passwd xbmc
    

Astuces pour xbmc :

  • Reglez le v-sync à « toujours activé »
  • Deactivez gl-spectrum

General tips :

  • pour reset votre raspbian live, supprimez ou formatez en ext4 le fichier /boot/live/rpi-live.
  • Sans ce fichier, votre raspbian live fonctionnera en ram.

  • Pour supprimer xbmc et obtenir une raspbian minimale, supprimez ou déplacez le fichier /boot/live/01-xbmc.squashfs