3 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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
28 # Functions related mounting the newly formatted disk partitions
30 # Mounts all the specified partition to the mount-point
33 if [ -z "${1}" -o -z "${2}" -o -z "${3}" ]
35 exit_err "ERROR: Missing arguments for mount_partition"
44 if [ -z "${MNTOPTS}" ]
48 MNTFLAGS="-o rw,${MNTFLAGS}"
52 #We are on ZFS, lets setup this mount-point
53 if [ "${PARTFS}" = "ZFS" ]
55 ZPOOLNAME=$(get_zpool_name "${PART}")
57 # Check if we have multiple zfs mounts specified
58 for ZMNT in `echo ${MNTPOINT} | sed 's|,| |g'`
60 # Check for any ZFS specific mount options
61 ZMNTOPTS="`echo $ZMNT | cut -d '(' -f 2 | cut -d ')' -f 1`"
62 if [ "$ZMNTOPTS" = "$ZMNT" ] ; then ZMNTOPTS="" ; fi
64 # Reset ZMNT with options removed
65 ZMNT="`echo $ZMNT | cut -d '(' -f 1`"
67 # First make sure we create the mount point
68 if [ ! -d "${FSMNT}${ZMNT}" ] ; then
69 mkdir -p ${FSMNT}${ZMNT} >>${LOGOUT} 2>>${LOGOUT}
72 # Check for any volsize args
74 for ZOPT in `echo $ZMNTOPTS | sed 's/|/ /g'`
76 echo "$ZOPT" | grep -q volsize
77 if [ $? -eq 0 ] ; then
78 volsize=`echo $ZOPT | cut -d '=' -f 2`
83 if [ "${ZMNT}" = "/" ] ; then
87 echo_log "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}"
88 rc_halt "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}"
91 if [ -z "$zcopt" ] ; then
92 rc_halt "zfs set mountpoint=${FSMNT}${ZNAME} ${ZPOOLNAME}${ZNAME}"
95 # If no ZFS options, we can skip
96 if [ -z "$ZMNTOPTS" ] ; then continue ; fi
98 # Parse any ZFS options now
99 for ZOPT in `echo $ZMNTOPTS | sed 's/|/ /g'`
101 echo "$ZOPT" | grep -q volsize
102 if [ $? -eq 0 ] ; then continue ; fi
103 rc_halt "zfs set $ZOPT ${ZPOOLNAME}${ZNAME}"
105 done # End of adding ZFS mounts
108 # If we are not on ZFS, lets do the mount now
109 # First make sure we create the mount point
110 if [ ! -d "${FSMNT}${MNTPOINT}" ]
112 mkdir -p ${FSMNT}${MNTPOINT} >>${LOGOUT} 2>>${LOGOUT}
115 echo_log "mount ${MNTFLAGS} ${PART} -> ${FSMNT}${MNTPOINT}"
117 rc_halt "mount ${MNTFLAGS} ${PART} ${FSMNT}${MNTPOINT}"
122 # Mounts all the new file systems to prepare for installation
123 mount_all_filesystems()
125 # Make sure our mount point exists
126 mkdir -p ${FSMNT} >/dev/null 2>/dev/null
128 # First lets find and mount the / partition
129 #########################################################
130 for PART in `ls ${PARTDIR}`
132 PARTDEV=`echo $PART | sed 's|-|/|g'`
133 if [ ! -e "${PARTDEV}" ]
135 exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
138 PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
139 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
140 PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
142 if [ "${PARTENC}" = "ON" ]
149 # Check for root partition for mounting, including ZFS "/,/usr" type
150 echo "$PARTMNT" | grep "/," >/dev/null
151 if [ "$?" = "0" -o "$PARTMNT" = "/" ]
154 UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
155 UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
156 UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
157 UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
158 ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
159 IMAGE) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
160 *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
165 # Now that we've mounted "/" lets do any other remaining mount-points
166 ##################################################################
167 for PART in `ls ${PARTDIR}`
169 PARTDEV=`echo $PART | sed 's|-|/|g'`
170 if [ ! -e "${PARTDEV}" ]
172 exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
175 PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
176 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
177 PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
179 if [ "${PARTENC}" = "ON" ]
186 # Check if we've found "/" again, don't need to mount it twice
187 echo "$PARTMNT" | grep "/," >/dev/null
188 if [ "$?" != "0" -a "$PARTMNT" != "/" ]
191 UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
192 UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
193 UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
194 UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
195 ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
197 # Lets enable this swap now
198 if [ "$PARTENC" = "ON" ]
200 echo_log "Enabling encrypted swap on ${PARTDEV}"
201 rc_halt "geli onetime -d -e 3des ${PARTDEV}"
203 rc_halt "swapon ${PARTDEV}.eli"
205 echo_log "swapon ${PARTDEV}"
207 rc_halt "swapon ${PARTDEV}"
211 if [ ! -d "${PARTMNT}" ]
213 mkdir -p "${PARTMNT}"
215 mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT}
217 *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;