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 # First make sure we create the mount point
61 if [ ! -d "${FSMNT}${ZMNT}" ] ; then
62 mkdir -p ${FSMNT}${ZMNT} >>${LOGOUT} 2>>${LOGOUT}
65 if [ "${ZMNT}" = "/" ] ; then
69 echo_log "zfs create -p ${ZPOOLNAME}${ZNAME}"
70 rc_halt "zfs create -p ${ZPOOLNAME}${ZNAME}"
73 rc_halt "zfs set mountpoint=${FSMNT}${ZNAME} ${ZPOOLNAME}${ZNAME}"
75 # Disable atime for this zfs partition, speed increase
76 rc_nohalt "zfs set atime=off ${ZPOOLNAME}${ZNAME}"
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}" ]
84 mkdir -p ${FSMNT}${MNTPOINT} >>${LOGOUT} 2>>${LOGOUT}
87 echo_log "mount ${MNTFLAGS} ${PART} -> ${FSMNT}${MNTPOINT}"
89 rc_halt "mount ${MNTFLAGS} ${PART} ${FSMNT}${MNTPOINT}"
94 # Mounts all the new file systems to prepare for installation
95 mount_all_filesystems()
97 # Make sure our mount point exists
98 mkdir -p ${FSMNT} >/dev/null 2>/dev/null
100 # First lets find and mount the / partition
101 #########################################################
102 for PART in `ls ${PARTDIR}`
104 PARTDEV=`echo $PART | sed 's|-|/|g'`
105 if [ ! -e "${PARTDEV}" ]
107 exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
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`"
114 if [ "${PARTENC}" = "ON" ]
121 # Check for root partition for mounting, including ZFS "/,/usr" type
122 echo "$PARTMNT" | grep "/," >/dev/null
123 if [ "$?" = "0" -o "$PARTMNT" = "/" ]
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" ;;
137 # Now that we've mounted "/" lets do any other remaining mount-points
138 ##################################################################
139 for PART in `ls ${PARTDIR}`
141 PARTDEV=`echo $PART | sed 's|-|/|g'`
142 if [ ! -e "${PARTDEV}" ]
144 exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
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`"
151 if [ "${PARTENC}" = "ON" ]
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" != "/" ]
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} ;;
169 # Lets enable this swap now
170 if [ "$PARTENC" = "ON" ]
172 echo_log "Enabling encrypted swap on ${PARTDEV}"
173 rc_halt "geli onetime -d -e 3des ${PARTDEV}"
175 rc_halt "swapon ${PARTDEV}.eli"
177 echo_log "swapon ${PARTDEV}"
179 rc_halt "swapon ${PARTDEV}"
183 if [ ! -d "${PARTMNT}" ]
185 mkdir -p "${PARTMNT}"
187 mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT}
189 *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;