File: mount2dir

package info (click to toggle)
fai 3.1.8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,144 kB
  • ctags: 164
  • sloc: sh: 3,410; perl: 1,780; makefile: 113
file content (93 lines) | stat: -rwxr-xr-x 3,011 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /bin/bash

# $Id: mount2dir 4230 2007-02-07 21:36:53Z lange $
#*********************************************************************
#
# mount2dir -- mount partitions to a directory using a fstab file
#
# This script is part of FAI (Fully Automatic Installation)
# (c) 2001-2007 by Thomas Lange, lange@informatik.uni-koeln.de
# Universitaet zu Koeln
#
#*********************************************************************
# 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 2 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.
# 
# A copy of the GNU General Public License is available as
# `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html.  You
# can also obtain it by writing to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#*********************************************************************

# examples:
# mount new created partitions to /tmp/target
# mount2dir /tmp/target /tmp/fstab 1
#
# root filesystem already mounted. Found a fstab inside. Now mount
# the remaining partitons
# mount2dir $target $target/etc/fstab 0 ro
#
# TODO: option parsing with getopts, option for also mounting nfs directories
# matching a certain server name

target=$1 # where to mount
fstab=$2
fscheck=$3 # make fsck if 1
moptions=$4 # if set, use only this mount option (mostly -r)

# exit if too few parameters given
[ "$fstab" ] || {
    echo "Too few parameters."
    echo "Usage: mount2dir targetdir fstab [ fscheck mopt ]"
    exit 1
}

[ -f $fstab ] || {
    echo "No fstab file $fstab found."
    exit 2
}

(
while read device mountpoint fstype mopt dummy; do

    case $mopt in
	*noauto*) continue ;;
    esac

    [ "$mountpoint" == "none" ]  && continue
    [ "$fstype" == "swap" ]  && continue
    [ "$fstype" == "proc" ]  && continue
    [ "$fstype" == "usbfs" ]  && continue
    [ "$fstype" == "sysfs" ]  && continue
    [ "$fstype" == "tmpfs" ]  && continue
    [ "$fstype" == "devpts" ]  && continue

    case $device in
	""|\#*) continue ;;

	/dev/*)

	    # overwrite mount options
	    mopt="-o $mopt"
	    [ "$moptions" ] && mopt="-o $moptions"
	    [ -d $target/$mountpoint ] || mkdir -p $target$mountpoint
	    if [ $debug ]; then
		echo "Mounting $device to $target$mountpoint type: $fstype opt: $mopt"
	    else
		[ $verbose ] && echo "Mounting $device to $target$mountpoint"
	    fi
	    # should we fsck the partition first?
	    [ "$fscheck" = 1 ] && fsck -nt $fstype $device
	    mount -t $fstype -o noatime $mopt $device $target$mountpoint
    esac
done

) < $fstab