functions-mountdisk.sh revision 232899
1209513Simp#!/bin/sh 2209513Simp#- 3209552Simp# Copyright (c) 2010 iXsystems, Inc. All rights reserved. 4209513Simp# 5209513Simp# Redistribution and use in source and binary forms, with or without 6209513Simp# modification, are permitted provided that the following conditions 7209513Simp# are met: 8209513Simp# 1. Redistributions of source code must retain the above copyright 9209513Simp# notice, this list of conditions and the following disclaimer. 10209513Simp# 2. Redistributions in binary form must reproduce the above copyright 11209513Simp# notice, this list of conditions and the following disclaimer in the 12209513Simp# documentation and/or other materials provided with the distribution. 13209513Simp# 14209513Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15209513Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16209513Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17209513Simp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18209513Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19209513Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20209513Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21209513Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22209513Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23209513Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24209513Simp# SUCH DAMAGE. 25209513Simp# 26209513Simp# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh 232899 2012-03-12 21:32:43Z jpaetzel $ 27209513Simp 28209513Simp# Functions related mounting the newly formatted disk partitions 29209513Simp 30209513Simp# Mounts all the specified partition to the mount-point 31209513Simpmount_partition() 32209513Simp{ 33209513Simp if [ -z "${1}" -o -z "${2}" -o -z "${3}" ] 34209513Simp then 35209513Simp exit_err "ERROR: Missing arguments for mount_partition" 36209513Simp fi 37209513Simp 38209513Simp PART="${1}" 39209513Simp PARTFS="${2}" 40209513Simp MNTPOINT="${3}" 41209513Simp MNTFLAGS="${4}" 42209513Simp 43209513Simp # Setup the MNTOPTS 44209513Simp if [ -z "${MNTOPTS}" ] 45209513Simp then 46209513Simp MNTFLAGS="-o rw" 47209513Simp else 48209513Simp MNTFLAGS="-o rw,${MNTFLAGS}" 49209513Simp fi 50209513Simp 51209513Simp 52209513Simp #We are on ZFS, lets setup this mount-point 53209513Simp if [ "${PARTFS}" = "ZFS" ] 54209513Simp then 55211730Simp ZPOOLNAME=$(get_zpool_name "${PART}") 56209513Simp 57211730Simp # Check if we have multiple zfs mounts specified 58211730Simp for ZMNT in `echo ${MNTPOINT} | sed 's|,| |g'` 59211730Simp do 60232899Sjpaetzel # Check for any ZFS specific mount options 61232899Sjpaetzel ZMNTOPTS="`echo $ZMNT | cut -d '(' -f 2 | cut -d ')' -f 1`" 62232899Sjpaetzel if [ "$ZMNTOPTS" = "$ZMNT" ] ; then ZMNTOPTS="" ; fi 63232899Sjpaetzel 64232899Sjpaetzel # Reset ZMNT with options removed 65232899Sjpaetzel ZMNT="`echo $ZMNT | cut -d '(' -f 1`" 66232899Sjpaetzel 67211730Simp # First make sure we create the mount point 68211730Simp if [ ! -d "${FSMNT}${ZMNT}" ] ; then 69211730Simp mkdir -p ${FSMNT}${ZMNT} >>${LOGOUT} 2>>${LOGOUT} 70211730Simp fi 71209513Simp 72232899Sjpaetzel # Check for any volsize args 73232899Sjpaetzel zcopt="" 74232899Sjpaetzel for ZOPT in `echo $ZMNTOPTS | sed 's/|/ /g'` 75232899Sjpaetzel do 76232899Sjpaetzel echo "$ZOPT" | grep -q volsize 77232899Sjpaetzel if [ $? -eq 0 ] ; then 78232899Sjpaetzel volsize=`echo $ZOPT | cut -d '=' -f 2` 79232899Sjpaetzel zcopt="-V $volsize" 80232899Sjpaetzel fi 81232899Sjpaetzel done 82232899Sjpaetzel 83211730Simp if [ "${ZMNT}" = "/" ] ; then 84211730Simp ZNAME="" 85211730Simp else 86211730Simp ZNAME="${ZMNT}" 87232899Sjpaetzel echo_log "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}" 88232899Sjpaetzel rc_halt "zfs create $zcopt -p ${ZPOOLNAME}${ZNAME}" 89211730Simp fi 90211730Simp sleep 2 91232899Sjpaetzel if [ -z "$zcopt" ] ; then 92232899Sjpaetzel rc_halt "zfs set mountpoint=${FSMNT}${ZNAME} ${ZPOOLNAME}${ZNAME}" 93232899Sjpaetzel fi 94209513Simp 95232899Sjpaetzel # If no ZFS options, we can skip 96232899Sjpaetzel if [ -z "$ZMNTOPTS" ] ; then continue ; fi 97209513Simp 98232899Sjpaetzel # Parse any ZFS options now 99232899Sjpaetzel for ZOPT in `echo $ZMNTOPTS | sed 's/|/ /g'` 100232899Sjpaetzel do 101232899Sjpaetzel echo "$ZOPT" | grep -q volsize 102232899Sjpaetzel if [ $? -eq 0 ] ; then continue ; fi 103232899Sjpaetzel rc_halt "zfs set $ZOPT ${ZPOOLNAME}${ZNAME}" 104232899Sjpaetzel done 105232899Sjpaetzel done # End of adding ZFS mounts 106232899Sjpaetzel 107209513Simp else 108211730Simp # If we are not on ZFS, lets do the mount now 109209513Simp # First make sure we create the mount point 110209513Simp if [ ! -d "${FSMNT}${MNTPOINT}" ] 111209513Simp then 112209513Simp mkdir -p ${FSMNT}${MNTPOINT} >>${LOGOUT} 2>>${LOGOUT} 113209513Simp fi 114209513Simp 115220909Sjpaetzel echo_log "mount ${MNTFLAGS} ${PART} -> ${FSMNT}${MNTPOINT}" 116209513Simp sleep 2 117220909Sjpaetzel rc_halt "mount ${MNTFLAGS} ${PART} ${FSMNT}${MNTPOINT}" 118209513Simp fi 119209513Simp 120209513Simp}; 121209513Simp 122209513Simp# Mounts all the new file systems to prepare for installation 123209513Simpmount_all_filesystems() 124209513Simp{ 125211730Simp # Make sure our mount point exists 126211730Simp mkdir -p ${FSMNT} >/dev/null 2>/dev/null 127209513Simp 128211730Simp # First lets find and mount the / partition 129211730Simp ######################################################### 130211730Simp for PART in `ls ${PARTDIR}` 131211730Simp do 132220909Sjpaetzel PARTDEV=`echo $PART | sed 's|-|/|g'` 133220909Sjpaetzel if [ ! -e "${PARTDEV}" ] 134211730Simp then 135220909Sjpaetzel exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?" 136211730Simp fi 137209513Simp 138232899Sjpaetzel PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" 139232899Sjpaetzel PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" 140232899Sjpaetzel PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" 141209513Simp 142209513Simp if [ "${PARTENC}" = "ON" ] 143209513Simp then 144209513Simp EXT=".eli" 145209513Simp else 146209513Simp EXT="" 147209513Simp fi 148209513Simp 149209513Simp # Check for root partition for mounting, including ZFS "/,/usr" type 150209513Simp echo "$PARTMNT" | grep "/," >/dev/null 151209513Simp if [ "$?" = "0" -o "$PARTMNT" = "/" ] 152209513Simp then 153209513Simp case ${PARTFS} in 154220909Sjpaetzel UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 155220909Sjpaetzel UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 156220909Sjpaetzel UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 157220909Sjpaetzel UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;; 158220909Sjpaetzel ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;; 159220909Sjpaetzel IMAGE) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;; 160211730Simp *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; 161209513Simp esac 162209513Simp fi 163211730Simp done 164209513Simp 165211730Simp # Now that we've mounted "/" lets do any other remaining mount-points 166211730Simp ################################################################## 167211730Simp for PART in `ls ${PARTDIR}` 168211730Simp do 169220909Sjpaetzel PARTDEV=`echo $PART | sed 's|-|/|g'` 170220909Sjpaetzel if [ ! -e "${PARTDEV}" ] 171211730Simp then 172220909Sjpaetzel exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?" 173211730Simp fi 174209513Simp 175232899Sjpaetzel PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`" 176232899Sjpaetzel PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`" 177232899Sjpaetzel PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`" 178209513Simp 179211730Simp if [ "${PARTENC}" = "ON" ] 180211730Simp then 181211730Simp EXT=".eli" 182211730Simp else 183211730Simp EXT="" 184211730Simp fi 185209513Simp 186211730Simp # Check if we've found "/" again, don't need to mount it twice 187211730Simp echo "$PARTMNT" | grep "/," >/dev/null 188211730Simp if [ "$?" != "0" -a "$PARTMNT" != "/" ] 189211730Simp then 190209513Simp case ${PARTFS} in 191220909Sjpaetzel UFS) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 192220909Sjpaetzel UFS+S) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 193220909Sjpaetzel UFS+SUJ) mount_partition ${PARTDEV}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 194220909Sjpaetzel UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;; 195220909Sjpaetzel ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;; 196211730Simp SWAP) 197211730Simp # Lets enable this swap now 198211730Simp if [ "$PARTENC" = "ON" ] 199211730Simp then 200220909Sjpaetzel echo_log "Enabling encrypted swap on ${PARTDEV}" 201220909Sjpaetzel rc_halt "geli onetime -d -e 3des ${PARTDEV}" 202211730Simp sleep 5 203220909Sjpaetzel rc_halt "swapon ${PARTDEV}.eli" 204211730Simp else 205220909Sjpaetzel echo_log "swapon ${PARTDEV}" 206211730Simp sleep 5 207220909Sjpaetzel rc_halt "swapon ${PARTDEV}" 208211730Simp fi 209211730Simp ;; 210213650Simp IMAGE) 211213650Simp if [ ! -d "${PARTMNT}" ] 212213650Simp then 213213650Simp mkdir -p "${PARTMNT}" 214213650Simp fi 215220909Sjpaetzel mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} 216213650Simp ;; 217213650Simp *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; 218211730Simp esac 219211730Simp fi 220211730Simp done 221209513Simp}; 222