#!/bin/sh -e # # /etc/initramfs-tools/scripts/init-bottom/rootaufs # # Copyright 2009 Shamim Mohamed. Derived from root-aufs, which is # Copyright 2008 Nicholas A. Schembri State College PA USA. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. # # Thank you Voyage Linux, http://voyage.hk/ # Env. variables used: # ROOT : /dev/disk/by-uuid/nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn # rootmnt : /root if [ "$1" = "prereqs" ]; then exit 0 fi for x in $(cat /proc/cmdline); do case "$x" in aufs=*) aufs=${x#aufs=} ;; esac done if [ "$aufs" != "tmpfs" ]; then # Nothing to do exit 0 fi if ! modprobe -q aufs; then echo "No aufs module, ABORT!" exit 0 fi # Make the mount points mkdir /aufs /rw /ro # Mount the temp file system and move the real root out of the way mount -t tmpfs aufs-tmpfs /rw mount --move ${rootmnt} /ro mount -t aufs -o dirs=/rw:/ro=ro aufs /aufs # Make mount points on aufs file system mkdir -p /aufs/ro /aufs/rw # Move the real root to /ro and tmpfs to /rw mount --move /ro /aufs/ro mount --move /rw /aufs/rw # Construct a fake fstab for the tmpfs. Start with the original # and remove the root entry; construct an entry for the the aufs root. egrep -v ' / | swap |tmpfs' /aufs/ro/etc/fstab >/aufs/etc/fstab ROOTENT=$(grep ${ROOT} /proc/mounts | awk '{printf "%s %s\n", $3, $4}') echo ${ROOT} /ro $ROOTENT 0 0 >>/aufs/etc/fstab mount --move /aufs ${rootmnt} exit 0