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 which unmount all mounted disk filesystems
30 # Unmount all mounted partitions under specified dir
34 _umntdirs=`mount | sort -r | grep "on $_udir" | cut -d ' ' -f 3`
41 # Script that adds our gmirror devices for syncing
46 for DISK in `ls ${MIRRORCFGDIR}`
48 MIRRORDISK="`cat ${DISK} | cut -d ':' -f 1`"
49 MIRRORBAL="`cat ${DISK} | cut -d ':' -f 2`"
50 MIRRORNAME="`cat ${DISK} | cut -d ':' -f 3`"
52 # Start the mirroring service
53 rc_nohalt "gmirror forget ${MIRRORNAME}"
54 rc_halt "gmirror insert ${MIRRORNAME} ${MIRRORDISK}"
60 # Unmounts all our mounted file-systems
61 unmount_all_filesystems()
63 # Copy the logfile to disk before we unmount
64 cp ${LOGOUT} ${FSMNT}/root/pc-sysinstall.log
67 # Start by unmounting any ZFS partitions
70 # Lets read our partition list, and unmount each
71 ##################################################################
72 for PART in `ls ${PARTDIR}`
74 PARTDEV=`echo $PART | sed 's|-|/|g'`
75 PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
76 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
77 PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
78 PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d '#' -f 4`"
80 if [ "${PARTENC}" = "ON" ]
87 if [ "${PARTFS}" = "SWAP" ]
89 rc_nohalt "swapoff ${PARTDEV}${EXT}"
92 # Check if we've found "/", and unmount that last
93 if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
95 rc_halt "umount -f ${PARTDEV}${EXT}"
97 # Re-check if we are missing a label for this device and create it again if so
98 if [ ! -e "/dev/label/${PARTLABEL}" ]
101 UFS) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
102 UFS+S) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
103 UFS+SUJ) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
104 UFS+J) glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal ;;
110 # Check if we've found "/" and make sure the label exists
111 if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ]
113 if [ ! -e "/dev/label/${PARTLABEL}" ]
116 UFS) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
117 UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
118 UFS+SUJ) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
119 UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal" ;;
126 # Last lets the /mnt partition
127 #########################################################
128 rc_nohalt "umount -f ${FSMNT}"
130 # If are using a ZFS on "/" set it to legacy
131 if [ ! -z "${FOUNDZFSROOT}" ]
133 rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}"
136 # If we need to relabel "/" do it now
137 if [ ! -z "${ROOTRELABEL}" ]
143 rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null
145 # Check if we need to run any gmirror syncing
146 ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null
149 # Lets start syncing now
155 # Unmounts any filesystems after a failure
156 unmount_all_filesystems_failure()
160 # if we did a fresh install, start unmounting
161 if [ "${INSTALLMODE}" = "fresh" ]
164 # Lets read our partition list, and unmount each
165 ##################################################################
166 if [ -d "${PARTDIR}" ]
168 for PART in `ls ${PARTDIR}`
170 PARTDEV=`echo $PART | sed 's|-|/|g'`
171 PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
172 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
173 PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
175 if [ "${PARTFS}" = "SWAP" ]
177 if [ "${PARTENC}" = "ON" ]
179 swapoff ${PARTDEV}.eli >/dev/null 2>/dev/null
181 swapoff ${PARTDEV} >/dev/null 2>/dev/null
185 # Check if we've found "/" again, don't need to mount it twice
186 if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
188 umount -f ${PARTDEV} >/dev/null 2>/dev/null
189 umount -f ${FSMNT}${PARTMNT} >/dev/null 2>/dev/null
193 # Last lets the /mnt partition
194 #########################################################
195 umount -f ${FSMNT} >/dev/null 2>/dev/null
199 # We are doing a upgrade, try unmounting any of these filesystems
200 chroot ${FSMNT} /sbin/umount -a >/dev/null 2>/dev/null
201 umount -f ${FSMNT}/usr >/dev/null 2>/dev/null
202 umount -f ${FSMNT}/dev >/dev/null 2>/dev/null
203 umount -f ${FSMNT} >/dev/null 2>/dev/null
204 sh ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null
208 umount ${CDMNT} >/dev/null 2>/dev/null