functions-mountdisk.sh revision 211730
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 211730 2010-08-24 06:11:46Z 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" ;;
127211730Simp        UFS+J) mount_partition ${PART}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
128211730Simp        ZFS) mount_partition ${PART} ${PARTFS} ${PARTMNT} ;;
129211730Simp        *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
130209513Simp      esac
131209513Simp    fi
132211730Simp  done
133209513Simp
134211730Simp  # Now that we've mounted "/" lets do any other remaining mount-points
135211730Simp  ##################################################################
136211730Simp  for PART in `ls ${PARTDIR}`
137211730Simp  do
138211730Simp    if [ ! -e "/dev/${PART}" ]
139211730Simp    then
140211730Simp      exit_err "ERROR: The partition ${PART} does not exist. Failure in bsdlabel?"
141211730Simp    fi 
142209513Simp     
143211730Simp    PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`"
144211730Simp    PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`"
145211730Simp    PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`"
146209513Simp
147211730Simp    if [ "${PARTENC}" = "ON" ]
148211730Simp    then
149211730Simp      EXT=".eli"
150211730Simp    else
151211730Simp      EXT=""
152211730Simp    fi
153209513Simp
154211730Simp    # Check if we've found "/" again, don't need to mount it twice
155211730Simp    echo "$PARTMNT" | grep "/," >/dev/null
156211730Simp    if [ "$?" != "0" -a "$PARTMNT" != "/" ]
157211730Simp    then
158209513Simp       case ${PARTFS} in
159211730Simp         UFS) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
160211730Simp         UFS+S) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;;
161211730Simp         UFS+J) mount_partition ${PART}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
162211730Simp         ZFS) mount_partition ${PART} ${PARTFS} ${PARTMNT} ;;
163211730Simp         SWAP)
164211730Simp		   # Lets enable this swap now
165211730Simp           if [ "$PARTENC" = "ON" ]
166211730Simp           then
167211730Simp             echo_log "Enabling encrypted swap on /dev/${PART}"
168211730Simp             rc_halt "geli onetime -d -e 3des ${PART}"
169211730Simp             sleep 5
170211730Simp             rc_halt "swapon /dev/${PART}.eli"
171211730Simp           else
172211730Simp             echo_log "swapon ${PART}"
173211730Simp             sleep 5
174211730Simp             rc_halt "swapon /dev/${PART}"
175211730Simp            fi
176211730Simp            ;;
177209513Simp          *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
178211730Simp      esac
179211730Simp    fi
180211730Simp  done
181209513Simp};
182