#!/bin/bash # ---------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # wrote this file. As long as you retain this notice you # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a beer in return. # ---------------------------------------------------------------------------- # mk_dreamplug_rootfs # # Runs multistrap and readies the resultinf root filesystem so that it silently completes package configuration on the first boot-up. # This has been tailored for the DreamPlug, and tested. # It might be possible to use it on the Sheeva and GuruPlug by pushing another kernel, but it hasn't been tested that way. Use it at your own risk. # # Based on http://gnesis.crysol.org/es/node/1384 and on http://plugcomputer.org/plugforum/index.php?topic=878.0 # # 2011-05-14: first release # 2011-05-15: tweaks to reduce flash writes # 2011-05-16: added non-free rep and libertas-firmware package # target=/media/disk target=/media/disk hostname='dreamspark' rootpasswd='password' #kernelimage=http://dreamplug.googlecode.com/files/uImage #kernelmodules=http://dreamplug.googlecode.com/files/linux-2.6.33.6.tar.bz2 kernelimage=http://www.newit.co.uk/kernels/Dreamplug/Dreamplug-prerelease/uImage kernelmodules=http://www.newit.co.uk/kernels/Dreamplug/Dreamplug-prerelease/Modules.tar.gz tmpdir=/tmp/multistrap_temp mkdir -p $tmpdir wget -c $kernelimage --output-document="$tmpdir/uImage" wget -c $kernelmodules --output-document="$tmpdir/linux.tar.gz" rm -rf $target/* # Do we have any downloaded packages from previous runs? # This uses disk space in the host system, but greatly reduces the time when running this script several times in a row. mkdir -p $target/var/cache/apt/ cp -r $tmpdir/aptcache/* $target/var/cache/apt/ echo "Multistrapping..." multistrap -f multistrap.conf --no-auth -d $target echo "Moving downloaded packages" mkdir -p $tmpdir/aptcache/ cp -r $target/var/cache/apt/* $tmpdir/aptcache/ echo "Unpacking kernel modules..." mkdir -p $target/lib/modules/ tar -C $target/lib/ -zxvf $tmpdir/linux.tar.gz | tail # Until udev is configured and run for the first time, dev nodes won't be created, but we need some basic ones for spawning a console (console) and creating RSA keys for SSH (urandom). echo "Creating basic device nodes" mknod $target/dev/console c 5 1 mknod $target/dev/random c 1 8 mknod $target/dev/urandom c 1 9 mknod $target/dev/null c 1 3 mknod $target/dev/ptmx c 5 2 # Basic fstab & mtab.. echo "Setting up basic fstab & mtab" echo " rootfs / rootfs relatime,rw 0 0 proc /proc proc none 0 0 sys /sys sysfs none 0 0 none /dev/pts devpts defaults 0 0 tmpfs /tmp tmpfs rw,nosuid,nodev 0 0 " > $target/etc/fstab touch $target/etc/mtab # Set up hostname echo "Setting up hostname, initial root password, /etc/network/interfaces, nameservers, persistent-net-generator rules" echo $hostname > $target/etc/hostname # The root password is "password" - that thing down there is the hash. The first-boot script should change the password, but currently does not :-( echo "root:Npge08pfz4wuk:0:0:root:/root:/bin/bash" > $target/etc/passwd echo "root:Npge08pfz4wuk:0:" > $target/etc/group # Crear /etc/network/interfaces echo "# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 iface eth0 inet dhcp allow-hotplug eth1 iface eth1 inet dhcp " > $target/etc/network/interfaces # Setup nameserver (use OpenDNS by default) echo "nameserver 208.67.222.222 nameserver 208.67.220.220" > $target/etc/resolv.conf # Touch the net generator udev so that eth0 won't be reassigned in case the user # changes the MAC address - this may happen if you change the rootfs between plugs. touch $target/etc/udev/rules.d/75-persistent-net-generator.rules # Yo dawg! I heard you like scripts, so I put a script in ya script so you can script while you script! # ... so here we'll generate a second stage script which will be run when the plug boots up for the first time # It will: # * configure all packages silently # * configure inittab to spawn a console on the serial port (JTAG) # * delete the script and reboot echo "Setting up first-boot script" echo " # Lets blink the leds during the first boot, just for fun. mount sys /sys -t sysfs echo \"heartbeat\" > /sys/class/leds/guruplug\:green\:wmode/trigger # AP echo \"heartbeat\" > /sys/class/leds/guruplug\:red\:wmode/trigger # Wifi echo \"heartbeat\" > /sys/class/leds/guruplug\:green\:health/trigger # BT echo \"heartbeat\" > /sys/class/leds/guruplug\:red\:health/trigger # Poweron ?? (doesnt work) echo \"Deleting old inittab\" rm /etc/inittab echo \"Preconfiguring dash - else dash and bash will be left in a broken state\" /var/lib/dpkg/info/dash.preinst install echo \"Configuring all packages\" export DEBIAN_FRONTEND=noninteractive dpkg --configure -a # By default, spawn a console on the serial port echo \"Adding a getty on the serial port\" echo \"T0:12345:respawn:/sbin/getty -L ttyS0 115200 vt100\" >> /etc/inittab echo \"Running depmod\" depmod echo \"Setting new root password\" echo -e \"$rootpasswd\\n$rootpasswd\\n\" | /usr/bin/passwd root echo \"Tweaks to reduce flash writes as per http://www.plugcomputer.org/plugwiki/index.php/Reduce_Flash_Writes\" echo \" # Reduce writes to flash drives vm.laptop_mode=5 vm.swappiness=0 vm.dirty_writeback_centisecs=1500 vm.dirty_expire_centisecs=1500 \" >> /etc/sysctl.conf echo \"Deleting this very same script\" rm -f /install.sh echo \"Syncing filesystem just in case something didn't get written\" sync echo \"Reboot time!\" # echo 0 > /sys/class/leds/guruplug\:green\:health/brightness # BT # echo 0 > /sys/class/leds/guruplug\:green\:wmode/brightness # AP # echo 0 > /sys/class/leds/guruplug\:red\:wmode/brightness # Wifi # echo 0 > /sys/class/leds/guruplug\:red\:health/brightness # Poweron ?? reboot -d -f -i -p " > cat > $target/install.sh chmod 755 $target/install.sh echo "Enabling first-boot script" echo " # The default runlevel. id:2:initdefault: T0:12345:wait:/install.sh -L ttyS0 115200 vt100 # T0:12345:respawn:/sbin/getty -L ttyS0 115200 vt100 " > $target/etc/inittab echo "Syncing..." sync echo "Finished. You may now copy the rootfs to the plug."