diff options
Diffstat (limited to 'abs/core-testing/linhes-live/bin/gen_fstab')
-rwxr-xr-x | abs/core-testing/linhes-live/bin/gen_fstab | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/abs/core-testing/linhes-live/bin/gen_fstab b/abs/core-testing/linhes-live/bin/gen_fstab new file mode 100755 index 0000000..db36546 --- /dev/null +++ b/abs/core-testing/linhes-live/bin/gen_fstab @@ -0,0 +1,122 @@ +#! /bin/sh +# +# gen_fstab - make new fstab for larch live system based on detected devices +# +# Author: Michael Towers <gradgrind[at]online[dot]de> +# +# This file is part of the larch project. +# +# larch 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 2 of the License, or +# (at your option) any later version. +# +# larch 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 larch; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +#---------------------------------------------------------------------------- +# 2007.12.17 + +# Note that the results are, by default, not copied into place +# They end up here: +DEST="/tmp/fstab" +MNT="/tmp/mnt" + +# However, passing '-l' as command-line option will install them. +# The old fstab will then be backed up to fstab~. +LOAD="" +if [ "$1" = "-l" ]; then LOAD="-l"; fi + +if [ -n "$( df | grep " ${MNT}" )" ]; then + echo "ERROR: Mounted filesystem at/within ${MNT}" + exit 1 +fi +mkdir -p ${MNT} +rm -rf ${MNT}/* + +tmpfile="/tmp/fstab2" +: >${tmpfile} + +echo "# fstab generated by gen_fstab" >${DEST} +echo "#<file system> <dir> <type> <options> <dump> <pass>" >>${DEST} +echo >>${DEST} + +echo "none /dev/pts devpts defaults 0 0" >>${DEST} +echo "none /dev/shm tmpfs defaults 0 0" >>${DEST} +echo >>${DEST} + +# Get all other partitions +sfdisk -d | grep "^/dev/" | sed "s|\(.*\):.*Id=\(..\).*|\1 \2|" | \ + while read dev id; do + # Ignore if id is "Extended" or "LVM", these are not usable partitions + if [ "${id}" = "5" -o "${id}" = "8e" ]; then continue; fi + # See if swap + if [ "${id}" = "82" ]; then + printf "%-12s %-12s %-8s defaults,noatime 0 0\n" \ + ${dev} swap swap >>${DEST} + continue + fi + removable="" + part=$( basename ${dev} ) + if [ $( cat /sys/block/${part:0:3}/removable 2>/dev/null ) -ne 0 ]; then + removable="_rmv" + fi + mountdir=${part}${removable} + printf "%-12s %-12s %-8s user,noauto,noatime 0 0\n" \ + ${dev} /mnt/${mountdir} auto >>${tmpfile} + mkdir -p ${MNT}/${mountdir} + done + +# LVM +for lvmd in $( ls /dev/mapper 2>/dev/null | grep -v control ); do + printf "%-30s %-22s %-8s user,noauto,noatime 0 0\n" \ + /dev/mapper/${lvmd} /mnt/${lvmd} auto >>${tmpfile} + mkdir -p ${MNT}/${lvmd} +done + +echo >>${DEST} +cat ${tmpfile} >>${DEST} +rm ${tmpfile} +echo >>${DEST} + +# CD devices +for dev in $( cat /proc/sys/dev/cdrom/info 2>/dev/null | head -n 3 | \ + tail -n 1 | cut -d ":" -f 2 ); do + mountdir="${dev}_cd" + mkdir ${MNT}/${mountdir} + printf "%-12s %-12s %-8s user,noauto,exec,unhide 0 0\n" \ + /dev/${dev} /mnt/${mountdir} auto >>${DEST} +done + +echo >>${DEST} +echo "# This would do for a floppy" >>${DEST} +echo "#/dev/fd0 /mnt/floppy vfat,ext2 rw,user,noauto 0 0" >>${DEST} +echo "# + mkdir /mnt/floppy" >>${DEST} +echo >>${DEST} +echo "# E.g. for USB storage:" >>${DEST} +echo "#/dev/sdb1 /mnt/usb auto rw,user,noauto 0 0" >>${DEST} +echo "# + mkdir /mnt/usb" >>${DEST} + +if [ -n "${LOAD}" ]; then + # test if the script is started by root user. If not, exit + if [ $UID -ne 0 ]; then + echo "Only root can run ${APP}"; exit 1 + fi + + cp -b ${DEST} /etc/fstab + # Delete removeable mount points which are not currently mounted + for m in $( ls /mnt | grep ^[hs]d ); do + if [ -z "$( df | grep " /mnt/${m}$" )" ]; then + rmdir /mnt/${m} + fi + done + for m in $( ls ${MNT} ); do + mkdir -p /mnt/${m} + done +fi |