Peter Fichtner's Blog

Archive for the ‘MPD’ Category

Read-only Slitaz using aufs

with 3 comments

As SliTaz provides a perfect base for embeded-like systems I used it for another MPD Client. The computer resists behind my stereo and gets its power from it. So when switching off the stereo the computer loses power too which causes a not unmounted filesystem. I didn’t like that and thought of live CDs where the real filesystem (the iso) is mounted on top (overlay) of a ram-filesystem.

This should be possible using not an ISO (loop/cloop) based filesystem but also an ext2/3/4 filesystem. A short google search showed me http://wiki.ubuntuusers.de/Nur-Lesen_Root-Dateisystem_mit_aufs which is exactly the solution I was looking for. I only had to adopt it on SliTaz.

The Slitaz way is more complicated since I don’t know of a SliTaz package that offers initrd creation functionality so you have to do this all by your own, please follow these  instructions:

  • extract an exisiting initrd (use the one that comes with any SliTaz ISO)  “cat rootfs.gz | lzma -d -c | cpio -i”
  • install aufs kernel module (tazpkg install linux-aufs)
  • remove all module branches from the initrd (rm -rf lib/modules/*)
  • copy all kernel modules of the running kernel to it (cp -ax /lib/modules`uname -r` lib/modules)
  • copy the attached init (see below) into initrd
  • make it executable (chmod 0755 init)
  • repack it (find . -print | cpio -o -H newc | lzma -c –best >../aufsrootfs.gz)
  • modify the bootloader by passing the initrd and adding aufs=tmpfs to the kernel parameters

Init comes with two scripts that allows you to remount the underlying root partition rw. So you’re able to change the content of the filesystem (e.g. for running updates) but beware: If you’ll upgrade the kernel you have to repack the initrd!

Have fun!

This is the init you have to use instead of the existing one:

#! /bin/sh

export aufs

mount -t proc proc /proc
mount -t sysfs sysfs /sys

for x in $(cat /proc/cmdline); do
case $x in
root=*)
ROOTNAME=${x#root=}
;;
aufs=*)
aufs=${x#aufs=}
case $aufs in
tmpfs-debug)
aufs=tmpfs
aufsdebug=1
;;
esac
;;
esac
done

echo
echo “root-aufs: Setting up aufs on ${ROOTNAME} as root file system “
echo

modprobe -q aufs || insmod /lib/modules/`uname -r`/kernel/fs/aufs/aufs.ko.gz
if [ $? -ne 0 ]; then
echo    root-aufs error: Failed to load aufs module
exit 0
fi

#make the mount points on the init root file system
mkdir /aufs
mkdir /rw
mkdir /ro

# mount the temp file system and move real root out of the way
mount -t tmpfs aufs-tmpfs /rw
mount ${ROOTNAME} /ro
if [ $? -ne 0 ]; then
echo “root-aufs error: ${ROOTNAME}  failed to move to /ro”
exit 0
fi

mount -t aufs -o dirs=/rw:/ro=ro aufs /aufs
if [ $? -ne 0 ]; then
echo    root-aufs error:      Failed to mount /aufs files system
exit 0
fi

#test for mount points on aufs file system
[  -d /aufs/ro ] || mkdir /aufs/ro
[  -d /aufs/rw ] || mkdir /aufs/rw

# the real root file system is hidden on /ro of the init file system.  move it to /ro
mount -omove /ro /aufs/ro
if [ $? -ne 0 ]; then
echo    root-aufs error:      Failed to move /ro /aufs/ro
exit 0
fi

# tmpfs file system is hidden on /rw
mount -omove /rw /aufs/rw
if [ $? -ne 0 ]; then
echo    root-aufs error:      Failed to move /rw /aufs/rw
exit 0
fi

#Add the comment block to fstab
cat <<EOF >/aufs/etc/fstab
#
#  $0 has mounted the root file system in ram
#
#  This fstab is in ram and the real fstab can be found /ro/etc/fstab
#  The root file system ‘ / ‘ has been removed.
EOF

#remove root from fstab
cat /aufs/ro/etc/fstab|grep -v ‘ / ‘ >>/aufs/etc/fstab

# add the read only file system to fstab
#ROOTTYPE=$(cat /proc/mounts|grep ${ROOT}|cut -d’ ‘ -f3)
#ROOTOPTIONS=$(cat /proc/mounts|grep ${ROOT}|cut -d’ ‘ -f4)
#echo ${ROOT} /ro $ROOTTYPE $ROOTOPTIONS 0 0 >>/aufs/etc/fstab

# S22mount on debian systems is not mounting  /ro correctly after boot
# add to rc.local to correct what you see from df
#replace last case of exit with #exit
#cat /aufs/ro/etc/rc.local|sed ‘s/\(.*\)exit/\1\#exit/’ >/aufs/etc/rc.local
#echo mount -f  /ro >>/aufs/etc/rc.local

# add back the root file system. mtab seems to be created by one of the init proceses.
#echo “echo aufs / aufs rw,xino=/rw/.aufs.xino,br:/rw=rw:/ro=ro 0 0 >>/etc/mtab” >>/aufs/etc/rc.local
#echo “echo aufs-tmpfs /rw tmpfs rw 0 0 >>/etc/mtab” >>/aufs/etc/rc.local
#echo exit 0 >>/aufs/etc/rc.local

#fix permissions
chmod 755 /aufs

#build remountrw
echo \#!/bin/sh >/aufs/bin/remountrw
echo mount -o remount,rw ${ROOT} >>/aufs/usr/bin/remountrw
chmod 0700 /aufs/bin/remountrw

#build remountro
echo \#!/bin/sh >/aufs/bin/remountro
echo mount -o remount,ro ${ROOT} >>/aufs/usr/bin/remountro
chmod 0700 /aufs/bin/remountro

umount /sys
umount /proc

# remount ro
mount -oremount,ro /aufs

echo -e “\33[70G[ \33[1;33mOK\33[0;39m ]“
exec /sbin/switch_root /aufs /sbin/init

For reference, this is my grub menu.lst with the old (normal boot) and the new (aufs read only boot) entry:

[...]

title SliTaz GNU/Linux (Kernel 2.6.37-slitaz)
root (hd0,0)
kernel /boot/vmlinuz-2.6.37-slitaz root=/dev/hda1

title SliTaz GNU/Linux (Kernel 2.6.37-slitaz) (AUFS)
root (hd0,0)
kernel /boot/vmlinuz-2.6.37-slitaz root=/dev/hda1 aufs=tmpfs
initrd /boot/aufsrootfs.gz

Written by Peter Fichtner

March 8, 2011 at 9:58 am

Posted in Linux, MPD

Mini MPD release

with 14 comments

As described in http://pfichtner.wordpress.com/2009/10/13/mpd-mini-distro/ I searched a minimalistic distribution to run a MPD that fits on a 32 MB DOM (SSD) of a T-Online Vision S100. I decided to use SliTaz as distribution. It was harder to get it work than I thought at the beginning but I finally solved all problems. The size of the complete system (kernel and initrd) is 11.2 MB only.

I successfully booted my S100s using the following boot mechanisms:

  • PXE using the builtin ethernet adapter
  • PXE using the builtin WiFi adapter (using my kexec environment s100-wifi-boot)
  • directly from the builtin DOM (SSD) using syslinux

Local, ethernet and even WiFi (near to AP) boot times are all around 12 seconds (including mp3 share network mount).

While booting the mp3 media share (NFS) is mounted. The share has to be specified as kernel parameter (mediashare). SMB support is included in the system but this absolutely untested yet.

MPD stores  a bunch of files (actual state like played song, shuffle mode, playlists, etc.). To be able to persist these settings you can specify a kernel parameter named “mpdstate”. I tested it with a local partition (mpdstate=/dev/hda2) and also a NFS share (mpdstate=nfsserver:/path/to/state-dir).

Installation is more than simple, this is configuration file when using PXE boot:

DEFAULT mini-mpd
LABEL mini-mpd

KERNEL path/to/vmlinuz-2.6.30.6-slitaz

# use ethernet adapter
#APPEND initrd=path/to/initrd.img-2.6.30.6-slitaz mediashare=nfsserver:/path/to/mp3s mpdstate=nfsserver:/path/to/state-dir
# use WiFi adapter
APPEND initrd=IMAGES/slitaz/initrd.img-2.6.30.6-slitaz wdev=wlan0 wtype=WPA wessid=yourssid wkey=yourkey mediashare=nfsserver:/path/to/mp3s mpdstate=nfsserver:/path/to/state-dir

Installation to local DOM (SSD) is not more difficult:

  • create a primary partition to hold kernel and initrd (FAT32, type c), size should be 24 MB, so there’s enough space left for the second partition, mark this partiton as active (bootable)
  • create another primary partition to hold the MPD state files (Linux, type 83), the rest of the DOM (8 MB)
  • write the MBR to the DOM (part of the syslinux project)
  • mount first partition, copy kernel and initrd to it and create a syslinux.cfg (see below)
  • umount partition and call syslinux

DEFAULT mini-mpd
PROMPT 0
TIMEOUT 5
LABEL mini-mpd
KERNEL vmlinuz-2.6.30.6-slitaz
# ethernet, remote state
#APPEND initrd=initrd.img-2.6.30.6-slitaz mediashare=nfsserver:/path/to/mp3s mpdstate=nfsserver:/path/to/state-dir
# ethernet, local state
#APPEND initrd=initrd.img-2.6.30.6-slitaz mediashare=nfsserver:/path/to/mp3s mpdstate=/dev/hda2
# WiFi, remote state
APPEND initrd=initrd.img-2.6.30.6-slitaz wdev=wlan0 wtype=WPA wessid=yourssid wkey=yourkey mediashare=nfsserver:/path/to/mp3s mpdstate=nfsserver:/path/to/state-dir
# WiFi, local state,
#APPEND initrd=initrd.img-2.6.30.6-slitaz wdev=wlan0 wtype=WPA wessid=yourssid wkey=yourkey mediashare=nfsserver:/path/to/mp3s mpdstate=/dev/hda2

Both config files (PXE and syslinux) are included in the downloadable archives.

The archives can be downloaded from mini-mpd.dyndns.org as generic x86 version (17 MB) and the special stripped version for the S100 (12 MB).

To keep maintenance as simple as possible you can ssh into your box via user “tux” and password “tux”. Type “su” to get root privileges (guess the password! ;-) ).

Have a lot of fun

[Update 2009-02-01]

The S100 image now supports the standard S100 IR remote (which came bundled with the S100)! This is done by invoking ncmpc on VT2 getting it’s input from an alternate lirc daemon named “inputlirc”. Image size sligtly increased but still is about 12 MB.

Written by Peter Fichtner

January 29, 2010 at 9:05 am

Posted in Linux, MPD

MPD mini distro

with 7 comments

[Update 2010-01-29]

you can download the image, see http://pfichtner.wordpress.com/2010/01/29/mini-mpd-release/

What’s the ideal distro to run a mpd out of the S100′s 32 meg DOM? I don’t want to compile mpd by hand but install it via a package manager.

Let’s take a look:

  • ubuntu: too big (>700 MB)
  • debian: too big
  • Puppy Linux: too big
  • Damn small linux: I failed to get the package management back on the HDD
  • Tiny/Micro Core Linux: Nice base, but mpd not installable as package
  • archlinux: Kernel failed to boot on VirtualBox (known problem)
  • gentoo: I think a “Linux from scratch” needs less initial work than this distro

So there isn’t a distro that fulfills my whishes? Oh yes, there is! I finally found one!

It’s named SliTaz. What’s so special? The core is just about 10 meg and it comes with a very nice small package management. This is the perfect base for the project. but the best thing is: There is a mpd package (and all packages of its dependend libs) available!

Next steps will be:

  • Remove all uneeded packages
  • Turn the rootfs it into a ro (readonly) fs
  • include scripts to connect to WPA2 based AP via WiFi
  • mount the resource holding the mp3s via NFS

[Update 2010-01-21]

I did have some problems to get sound working (SliTaz 2.0 does not support the builtin WiFi adapter and SliTaz 2.2 has a known sound problem). I finally solved it.

Everything is working fine including the following:

  • Ethernet and WiFi connection
  • Sound
  • MPD
  • NFS mount of the MP3 share

Boot time (including DHCP/mount of two NFS shares) is 11 seconds.

I’m sure I will release an image the next days. The preferred way to boot it will be PXE (initrd) from an NFS/HTTP share or from the builtin IDE port (installed DOM/SSD module). The image (2.2 MB kernel excluded) is actual 15 MB (unstripped) / 9.7 MB (stripped) only.

[Update 2010-01-29]

you can download the image, see http://pfichtner.wordpress.com/2010/01/29/mini-mpd-release/

http://www.slitaz.org/SliTAZ

Written by Peter Fichtner

October 13, 2009 at 11:57 am

Posted in Linux, MPD

Tagged with , ,

Follow

Get every new post delivered to your Inbox.