]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / usr.sbin / pc-sysinstall / backend / functions-mountdisk.sh
1 #!/bin/sh
2 #-
3 # Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 # SUCH DAMAGE.
25 #
26 # $FreeBSD$
27
28 # Functions related mounting the newly formatted disk partitions
29
30 # Mounts all the specified partition to the mount-point
31 mount_partition()
32 {
33   if [ -z "${1}" -o -z "${2}" -o -z "${3}" ]
34   then
35     exit_err "ERROR: Missing arguments for mount_partition"
36   fi
37
38   PART="${1}"
39   PARTFS="${2}"
40   MNTPOINT="${3}"
41   MNTFLAGS="${4}"
42
43   # Setup the MNTOPTS
44   if [ -z "${MNTOPTS}" ]
45   then
46     MNTFLAGS="-o rw"
47   else
48     MNTFLAGS="-o rw,${MNTFLAGS}"
49   fi
50
51
52   #We are on ZFS, lets setup this mount-point
53   if [ "${PARTFS}" = "ZFS" ]
54   then
55     ZPOOLNAME=$(get_zpool_name "${PART}")
56
57     # Check if we have multiple zfs mounts specified
58     for ZMNT in `echo ${MNTPOINT} | sed 's|,| |g'`
59     do
60       # First make sure we create the mount point
61       if [ ! -d "${FSMNT}${ZMNT}" ] ; then
62         mkdir -p ${FSMNT}${ZMNT} >>${LOGOUT} 2>>${LOGOUT}
63       fi
64
65       if [ "${ZMNT}" = "/" ] ; then
66         ZNAME=""
67       else
68         ZNAME="${ZMNT}"
69         echo_log "zfs create -p ${ZPOOLNAME}${ZNAME}"
70         rc_halt "zfs create -p ${ZPOOLNAME}${ZNAME}"
71       fi
72       sleep 2
73       rc_halt "zfs set mountpoint=${FSMNT}${ZNAME} ${ZPOOLNAME}${ZNAME}"
74
75       # Disable atime for this zfs partition, speed increase
76       rc_nohalt "zfs set atime=off ${ZPOOLNAME}${ZNAME}"
77     done 
78
79   else
80     # If we are not on ZFS, lets do the mount now
81     # First make sure we create the mount point
82     if [ ! -d "${FSMNT}${MNTPOINT}" ]
83     then
84       mkdir -p ${FSMNT}${MNTPOINT} >>${LOGOUT} 2>>${LOGOUT}
85     fi
86
87     echo_log "mount ${MNTFLAGS} ${PART} -> ${FSMNT}${MNTPOINT}"
88     sleep 2
89     rc_halt "mount ${MNTFLAGS} ${PART} ${FSMNT}${MNTPOINT}"
90   fi
91
92 };
93
94 # Mounts all the new file systems to prepare for installation
95 mount_all_filesystems()
96 {
97   # Make sure our mount point exists
98   mkdir -p ${FSMNT} >/dev/null 2>/dev/null
99
100   # First lets find and mount the / partition
101   #########################################################
102   for PART in `ls ${PARTDIR}`
103   do
104     PARTDEV=`echo $PART | sed 's|-|/|g'` 
105     if [ ! -e "${PARTDEV}" ]
106     then
107       exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
108     fi 
109
110     PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`"
111     PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`"
112     PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`"
113
114     if [ "${PARTENC}" = "ON" ]
115     then
116       EXT=".eli"
117     else
118       EXT=""
119     fi
120
121     # Check for root partition for mounting, including ZFS "/,/usr" type 
122     echo "$PARTMNT" | grep "/," >/dev/null
123     if [ "$?" = "0" -o "$PARTMNT" = "/" ]
124     then
125       case ${PARTFS} in
126         UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
127         UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
128         UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
129         UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
130         ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
131         IMAGE) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
132         *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
133       esac
134     fi
135   done
136
137   # Now that we've mounted "/" lets do any other remaining mount-points
138   ##################################################################
139   for PART in `ls ${PARTDIR}`
140   do
141     PARTDEV=`echo $PART | sed 's|-|/|g'`
142     if [ ! -e "${PARTDEV}" ]
143     then
144       exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
145     fi 
146      
147     PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`"
148     PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`"
149     PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`"
150
151     if [ "${PARTENC}" = "ON" ]
152     then
153       EXT=".eli"
154     else
155       EXT=""
156     fi
157
158     # Check if we've found "/" again, don't need to mount it twice
159     echo "$PARTMNT" | grep "/," >/dev/null
160     if [ "$?" != "0" -a "$PARTMNT" != "/" ]
161     then
162        case ${PARTFS} in
163          UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
164          UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
165          UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
166          UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
167          ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
168          SWAP)
169                    # Lets enable this swap now
170            if [ "$PARTENC" = "ON" ]
171            then
172              echo_log "Enabling encrypted swap on ${PARTDEV}"
173              rc_halt "geli onetime -d -e 3des ${PARTDEV}"
174              sleep 5
175              rc_halt "swapon ${PARTDEV}.eli"
176            else
177              echo_log "swapon ${PARTDEV}"
178              sleep 5
179              rc_halt "swapon ${PARTDEV}"
180             fi
181             ;;
182          IMAGE)
183            if [ ! -d "${PARTMNT}" ]
184            then
185              mkdir -p "${PARTMNT}" 
186            fi 
187            mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT}
188            ;;
189          *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
190       esac
191     fi
192   done
193 };