functions-mountdisk.sh revision 209513
1209513Simp#!/bin/sh
2209513Simp#-
3209513Simp# Copyright (c) 2010 iX Systems, 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 209513 2010-06-24 22:21:47Z 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
55209513Simp     ZPOOLNAME=$(get_zpool_name "${PART}")
56209513Simp
57209513Simp     # Check if we have multiple zfs mounts specified
58209513Simp     for ZMNT in `echo ${MNTPOINT} | sed 's|,| |g'`
59209513Simp     do
60209513Simp       # First make sure we create the mount point
61209513Simp       if [ ! -d "${FSMNT}${ZMNT}" ] ; then
62209513Simp         mkdir -p ${FSMNT}${ZMNT} >>${LOGOUT} 2>>${LOGOUT}
63209513Simp       fi
64209513Simp
65209513Simp       if [ "${ZMNT}" = "/" ] ; then
66209513Simp         ZNAME=""
67209513Simp       else
68209513Simp         ZNAME="${ZMNT}"
69209513Simp         echo_log "zfs create -p ${ZPOOLNAME}${ZNAME}"
70209513Simp         rc_halt "zfs create -p ${ZPOOLNAME}${ZNAME}"
71209513Simp       fi
72209513Simp       sleep 2
73209513Simp       rc_halt "zfs set mountpoint=${FSMNT}${ZNAME} ${ZPOOLNAME}${ZNAME}"
74209513Simp
75209513Simp       # Disable atime for this zfs partition, speed increase
76209513Simp       rc_nohalt "zfs set atime=off ${ZPOOLNAME}${ZNAME}"
77209513Simp     done 
78209513Simp
79209513Simp  else
80209513Simp  # 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{
97209513Simp   # Make sure our mount point exists
98209513Simp   mkdir -p ${FSMNT} >/dev/null 2>/dev/null
99209513Simp
100209513Simp   # First lets find and mount the / partition
101209513Simp   #########################################################
102209513Simp   for PART in `ls ${PARTDIR}`
103209513Simp   do
104209513Simp     if [ ! -e "/dev/${PART}" ]
105209513Simp     then
106209513Simp       exit_err "ERROR: The partition ${PART} does not exist. Failure in bsdlabel?"
107209513Simp     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
125209513Simp         UFS) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime"
126209513Simp              ;;
127209513Simp       UFS+S) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime"
128209513Simp              ;;
129209513Simp       UFS+J) mount_partition ${PART}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime"
130209513Simp              ;;
131209513Simp         ZFS) mount_partition ${PART} ${PARTFS} ${PARTMNT}
132209513Simp              ;;
133209513Simp           *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
134209513Simp      esac
135209513Simp
136209513Simp    fi
137209513Simp     
138209513Simp   done
139209513Simp
140209513Simp   # Now that we've mounted "/" lets do any other remaining mount-points
141209513Simp   ##################################################################
142209513Simp   for PART in `ls ${PARTDIR}`
143209513Simp   do
144209513Simp     if [ ! -e "/dev/${PART}" ]
145209513Simp     then
146209513Simp       exit_err "ERROR: The partition ${PART} does not exist. Failure in bsdlabel?"
147209513Simp     fi 
148209513Simp     
149209513Simp     PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`"
150209513Simp     PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`"
151209513Simp     PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`"
152209513Simp
153209513Simp     if [ "${PARTENC}" = "ON" ]
154209513Simp     then
155209513Simp       EXT=".eli"
156209513Simp     else
157209513Simp       EXT=""
158209513Simp     fi
159209513Simp
160209513Simp     # Check if we've found "/" again, don't need to mount it twice
161209513Simp     echo "$PARTMNT" | grep "/," >/dev/null
162209513Simp     if [ "$?" != "0" -a "$PARTMNT" != "/" ]
163209513Simp     then
164209513Simp       case ${PARTFS} in
165209513Simp         UFS) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime"
166209513Simp              ;;
167209513Simp       UFS+S) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime"
168209513Simp              ;;
169209513Simp       UFS+J) mount_partition ${PART}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime"
170209513Simp              ;;
171209513Simp         ZFS) mount_partition ${PART} ${PARTFS} ${PARTMNT}
172209513Simp              ;;
173209513Simp        SWAP) # Lets enable this swap now
174209513Simp              if [ "$PARTENC" = "ON" ]
175209513Simp              then
176209513Simp                echo_log "Enabling encrypted swap on /dev/${PART}"
177209513Simp                rc_halt "geli onetime -d -e 3des ${PART}"
178209513Simp                sleep 5
179209513Simp                rc_halt "swapon /dev/${PART}.eli"
180209513Simp              else
181209513Simp                echo_log "swapon ${PART}"
182209513Simp                sleep 5
183209513Simp                rc_halt "swapon /dev/${PART}"
184209513Simp              fi
185209513Simp              ;;
186209513Simp          *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
187209513Simp       esac
188209513Simp     fi
189209513Simp   done
190209513Simp};
191