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
84 # If creating ZFS / dataset, give it name that beadm works with
87 echo_log "zfs create $zcopt -p ${ZPOOLNAME}/ROOT"
88 rc_halt "zfs create $zcopt -p ${ZPOOLNAME}/ROOT"
89 echo_log "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}"
90 rc_halt "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}"
94 echo_log "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}"
95 rc_halt "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}"
98 if [ -z "$zcopt" ] ; then
99 rc_halt "zfs set mountpoint=${FSMNT}${ZMKMNT} ${ZPOOLNAME}${ZNAME}"
102 # Do we need to make this / zfs dataset bootable?
103 if [ "$ZMNT" = "/" ] ; then
104 echo_log "Stamping ${ZPOOLNAME}/ROOT/default as bootfs"
105 rc_halt "zpool set bootfs=${ZPOOLNAME}/ROOT/default ${ZPOOLNAME}"
108 # Do we need to make this /boot zfs dataset bootable?
109 if [ "$ZMNT" = "/boot" ] ; then
110 echo_log "Stamping ${ZPOOLNAME}${ZMNT} as bootfs"
111 rc_halt "zpool set bootfs=${ZPOOLNAME}${ZMNT} ${ZPOOLNAME}"
114 # If no ZFS options, we can skip
115 if [ -z "$ZMNTOPTS" ] ; then continue ; fi
117 # Parse any ZFS options now
118 for ZOPT in `echo $ZMNTOPTS | sed 's/|/ /g'`
120 echo "$ZOPT" | grep -q volsize
121 if [ $? -eq 0 ] ; then continue ; fi
122 rc_halt "zfs set $ZOPT ${ZPOOLNAME}${ZNAME}"
124 done # End of adding ZFS mounts
127 # If we are not on ZFS, lets do the mount now
128 # First make sure we create the mount point
129 if [ ! -d "${FSMNT}${MNTPOINT}" ]
131 mkdir -p ${FSMNT}${MNTPOINT} >>${LOGOUT} 2>>${LOGOUT}
134 echo_log "mount ${MNTFLAGS} ${PART} -> ${FSMNT}${MNTPOINT}"
136 rc_halt "mount ${MNTFLAGS} ${PART} ${FSMNT}${MNTPOINT}"
141 # Mounts all the new file systems to prepare for installation
142 mount_all_filesystems()
144 # Make sure our mount point exists
145 mkdir -p ${FSMNT} >/dev/null 2>/dev/null
147 # First lets find and mount the / partition
148 #########################################################
149 for PART in `ls ${PARTDIR}`
151 PARTDEV=`echo $PART | sed 's|-|/|g'`
152 PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
153 if [ ! -e "${PARTDEV}" -a "${PARTFS}" != "ZFS" ]
155 exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
158 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
159 PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
161 if [ "${PARTENC}" = "ON" ]
168 # Check for root partition for mounting, including ZFS "/,/usr" type
169 echo "$PARTMNT" | grep "/," >/dev/null
170 if [ "$?" = "0" -o "$PARTMNT" = "/" ]
173 UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
174 UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
175 UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
176 UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
177 ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
178 IMAGE) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
179 *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
184 # Now that we've mounted "/" lets do any other remaining mount-points
185 ##################################################################
186 for PART in `ls ${PARTDIR}`
188 PARTDEV=`echo $PART | sed 's|-|/|g'`
189 PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
190 if [ ! -e "${PARTDEV}" -a "${PARTFS}" != "ZFS" ]
192 exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
195 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
196 PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
198 if [ "${PARTENC}" = "ON" ]
205 # Check if we've found "/" again, don't need to mount it twice
206 echo "$PARTMNT" | grep "/," >/dev/null
207 if [ "$?" != "0" -a "$PARTMNT" != "/" ]
210 UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
211 UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
212 UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
213 UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
214 ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
216 # Lets enable this swap now
217 if [ "$PARTENC" = "ON" ]
219 echo_log "Enabling encrypted swap on ${PARTDEV}"
220 rc_halt "geli onetime -d -e 3des ${PARTDEV}"
222 rc_halt "swapon ${PARTDEV}.eli"
224 echo_log "swapon ${PARTDEV}"
226 rc_halt "swapon ${PARTDEV}"
230 if [ ! -d "${PARTMNT}" ]
232 mkdir -p "${PARTMNT}"
234 mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT}
236 *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;