On Fri, Oct 26, 2007 at 12:47:36AM +0200, Daniel Hess wrote: > Maybe be could bindmount subdirds to the directory we bindmount later on > top of /etc, than we don't need to copy the whole thing. Was easier written than done. It got a bit longer and uglier than I thought, but it works. May I have comments before I do something like commit it to the svn please? :) Greetings Daniel
#!/bin/sh
### BEGIN INIT INFO
# Provides: ltsp_local_mount
# Required-Start:
# Required-Stop:
# Should-Start:
# Default-Start: 3
# Default-Stop:
# Short-Description: Make local devices (u)mountable by user
# Description: Takes care, that /etc/mtab is writeable, so that
# users can mount and umount local and static devices
# like cdroms.
### END INIT INFO
test -f /etc/default/ltsp-client-setup && . /etc/default/ltsp-client-setup
case "$1" in
start)
# make /etc writeable
cd $tmpfs_dir
# mount /etc subtree from nfs
mkdir etc-nfs
eval $(sed -ns 's#^\([^ ]*\) / nfs \([^ ]*\) .*#mount \1/etc etc-nfs -o\2#p' /proc/mounts)
# make etc-rw a mointpoint to move it later
mkdir etc-rw
mount -t tmpfs -o mode=0755 tmpfs etc-rw
# bindmount dirs and files
for i in $(find etc-nfs/ -maxdepth 1 -mindepth 1 -type d | sed 's#^etc-nfs\/##'); do
mkdir "etc-rw/$i"
mount --bind "etc-nfs/$i" "etc-rw/$i"
done
for i in $(find etc-nfs/ -maxdepth 1 -type f | sed 's#^etc-nfs\/##'); do
touch "etc-rw/$i"
mount --bind "etc-nfs/$i" "etc-rw/$i"
done
# copy the rest
for i in $(find etc-nfs/ -maxdepth 1 ! -type f ! -type d ! -name mtab | sed 's#^etc-nfs\/##'); do
cp -a "etc-nfs/$i" "etc-rw/$i"
done
# move old bindmounts
for i in $(grep '^[^ ]* \/etc' /proc/mounts | cut -d' ' -f2); do
mount --move "$i" "etc-rw$(echo $i | sed 's#/etc##')"
done
# move new /etc over /etc
mount --move $tmpfs_dir/etc-rw /etc
# create writeable mtab
cp /proc/mounts /etc/mtab
# create cdrom entry in fstab and mountpoint under /media
if [ -b /dev/cdrom ]; then
echo "/dev/cdrom /media/cdrom0 udf,iso9660 user,auto 0 0" >>/etc/fstab
mkdir /media/cdrom0 && ln -s /media/cdrom0 /media/cdrom
fi
if [ -b /dev/cdrom?* ]; then
for CDDEV in $(ls /dev/cdrom?*); do
echo "/dev/${CDDEV} /media/${CDDEV} udf,iso9660 user,auto 0 0" >>/etc/fstab
mkdir /media/${CDDEV}
done
fi
;;
*) exit 0 ;;
esac
exit 0
Attachment:
signature.asc
Description: Digital signature