functions-mountdisk.sh revision 213650
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 213650 2010-10-09 08:52:09Z imp $ 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 60211730Simp # First make sure we create the mount point 61211730Simp if [ ! -d "${FSMNT}${ZMNT}" ] ; then 62211730Simp mkdir -p ${FSMNT}${ZMNT} >>${LOGOUT} 2>>${LOGOUT} 63211730Simp fi 64209513Simp 65211730Simp if [ "${ZMNT}" = "/" ] ; then 66211730Simp ZNAME="" 67211730Simp else 68211730Simp ZNAME="${ZMNT}" 69211730Simp echo_log "zfs create -p ${ZPOOLNAME}${ZNAME}" 70211730Simp rc_halt "zfs create -p ${ZPOOLNAME}${ZNAME}" 71211730Simp fi 72211730Simp sleep 2 73211730Simp rc_halt "zfs set mountpoint=${FSMNT}${ZNAME} ${ZPOOLNAME}${ZNAME}" 74209513Simp 75211730Simp # Disable atime for this zfs partition, speed increase 76211730Simp rc_nohalt "zfs set atime=off ${ZPOOLNAME}${ZNAME}" 77211730Simp done 78209513Simp 79209513Simp else 80211730Simp # If we are not on ZFS, lets do the mount now 81209513Simp # First make sure we create the mount point 82209513Simp if [ ! -d "${FSMNT}${MNTPOINT}" ] 83209513Simp then 84209513Simp mkdir -p ${FSMNT}${MNTPOINT} >>${LOGOUT} 2>>${LOGOUT} 85209513Simp fi 86209513Simp 87209513Simp echo_log "mount ${MNTFLAGS} /dev/${PART} -> ${FSMNT}${MNTPOINT}" 88209513Simp sleep 2 89209513Simp rc_halt "mount ${MNTFLAGS} /dev/${PART} ${FSMNT}${MNTPOINT}" 90209513Simp fi 91209513Simp 92209513Simp}; 93209513Simp 94209513Simp# Mounts all the new file systems to prepare for installation 95209513Simpmount_all_filesystems() 96209513Simp{ 97211730Simp # Make sure our mount point exists 98211730Simp mkdir -p ${FSMNT} >/dev/null 2>/dev/null 99209513Simp 100211730Simp # First lets find and mount the / partition 101211730Simp ######################################################### 102211730Simp for PART in `ls ${PARTDIR}` 103211730Simp do 104211730Simp if [ ! -e "/dev/${PART}" ] 105211730Simp then 106211730Simp exit_err "ERROR: The partition ${PART} does not exist. Failure in bsdlabel?" 107211730Simp fi 108209513Simp 109209513Simp PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`" 110209513Simp PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`" 111209513Simp PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`" 112209513Simp 113209513Simp if [ "${PARTENC}" = "ON" ] 114209513Simp then 115209513Simp EXT=".eli" 116209513Simp else 117209513Simp EXT="" 118209513Simp fi 119209513Simp 120209513Simp # Check for root partition for mounting, including ZFS "/,/usr" type 121209513Simp echo "$PARTMNT" | grep "/," >/dev/null 122209513Simp if [ "$?" = "0" -o "$PARTMNT" = "/" ] 123209513Simp then 124209513Simp case ${PARTFS} in 125211730Simp UFS) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 126211730Simp UFS+S) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 127213647Simp UFS+SUJ) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 128211730Simp UFS+J) mount_partition ${PART}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;; 129211730Simp ZFS) mount_partition ${PART} ${PARTFS} ${PARTMNT} ;; 130213650Simp IMAGE) mount_partition ${PART} ${PARTFS} ${PARTMNT} ;; 131211730Simp *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; 132209513Simp esac 133209513Simp fi 134211730Simp done 135209513Simp 136211730Simp # Now that we've mounted "/" lets do any other remaining mount-points 137211730Simp ################################################################## 138211730Simp for PART in `ls ${PARTDIR}` 139211730Simp do 140211730Simp if [ ! -e "/dev/${PART}" ] 141211730Simp then 142211730Simp exit_err "ERROR: The partition ${PART} does not exist. Failure in bsdlabel?" 143211730Simp fi 144209513Simp 145211730Simp PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`" 146211730Simp PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`" 147211730Simp PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`" 148209513Simp 149211730Simp if [ "${PARTENC}" = "ON" ] 150211730Simp then 151211730Simp EXT=".eli" 152211730Simp else 153211730Simp EXT="" 154211730Simp fi 155209513Simp 156211730Simp # Check if we've found "/" again, don't need to mount it twice 157211730Simp echo "$PARTMNT" | grep "/," >/dev/null 158211730Simp if [ "$?" != "0" -a "$PARTMNT" != "/" ] 159211730Simp then 160209513Simp case ${PARTFS} in 161211730Simp UFS) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 162211730Simp UFS+S) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 163213647Simp UFS+SUJ) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; 164211730Simp UFS+J) mount_partition ${PART}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;; 165211730Simp ZFS) mount_partition ${PART} ${PARTFS} ${PARTMNT} ;; 166211730Simp SWAP) 167211730Simp # Lets enable this swap now 168211730Simp if [ "$PARTENC" = "ON" ] 169211730Simp then 170211730Simp echo_log "Enabling encrypted swap on /dev/${PART}" 171211730Simp rc_halt "geli onetime -d -e 3des ${PART}" 172211730Simp sleep 5 173211730Simp rc_halt "swapon /dev/${PART}.eli" 174211730Simp else 175211730Simp echo_log "swapon ${PART}" 176211730Simp sleep 5 177211730Simp rc_halt "swapon /dev/${PART}" 178211730Simp fi 179211730Simp ;; 180213650Simp IMAGE) 181213650Simp if [ ! -d "${PARTMNT}" ] 182213650Simp then 183213650Simp mkdir -p "${PARTMNT}" 184213650Simp fi 185213650Simp mount_partition ${PART} ${PARTFS} ${PARTMNT} 186213650Simp ;; 187213650Simp *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; 188211730Simp esac 189211730Simp fi 190211730Simp done 191209513Simp}; 192