3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Functions which unmount all mounted disk filesystems
32 # Unmount all mounted partitions under specified dir
36 _umntdirs=`mount | sort -r | grep "on $_udir" | cut -d ' ' -f 3`
43 # Script that adds our gmirror devices for syncing
48 for DISK in `ls ${MIRRORCFGDIR}`
50 MIRRORDISK="`cat ${DISK} | cut -d ':' -f 1`"
51 MIRRORBAL="`cat ${DISK} | cut -d ':' -f 2`"
52 MIRRORNAME="`cat ${DISK} | cut -d ':' -f 3`"
54 # Start the mirroring service
55 rc_nohalt "gmirror forget ${MIRRORNAME}"
56 rc_halt "gmirror insert ${MIRRORNAME} ${MIRRORDISK}"
62 # Unmounts all our mounted file-systems
63 unmount_all_filesystems()
65 # Copy the logfile to disk before we unmount
66 cp ${LOGOUT} ${FSMNT}/root/pc-sysinstall.log
69 # Start by unmounting any ZFS partitions
72 # Lets read our partition list, and unmount each
73 ##################################################################
74 for PART in `ls ${PARTDIR}`
76 PARTDEV=`echo $PART | sed 's|-|/|g'`
77 PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
78 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
79 PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
80 PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d '#' -f 4`"
82 if [ "${PARTENC}" = "ON" ]
89 if [ "${PARTFS}" = "SWAP" ]
91 rc_nohalt "swapoff ${PARTDEV}${EXT}"
94 # Check if we've found "/", and unmount that last
95 if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
97 rc_halt "umount -f ${PARTDEV}${EXT}"
99 # Re-check if we are missing a label for this device and create it again if so
100 if [ ! -e "/dev/label/${PARTLABEL}" ]
103 UFS) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
104 UFS+S) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
105 UFS+SUJ) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
106 UFS+J) glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal ;;
112 # Check if we've found "/" and make sure the label exists
113 if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ]
115 if [ ! -e "/dev/label/${PARTLABEL}" ]
118 UFS) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
119 UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
120 UFS+SUJ) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
121 UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal" ;;
128 # Last lets the /mnt partition
129 #########################################################
130 rc_nohalt "umount -f ${FSMNT}"
132 # If are using a ZFS on "/" set it to legacy
133 if [ ! -z "${FOUNDZFSROOT}" ]
135 rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}"
138 # If we need to relabel "/" do it now
139 if [ ! -z "${ROOTRELABEL}" ]
145 rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null
147 # Check if we need to run any gmirror syncing
148 ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null
151 # Lets start syncing now
157 # Unmounts any filesystems after a failure
158 unmount_all_filesystems_failure()
162 # if we did a fresh install, start unmounting
163 if [ "${INSTALLMODE}" = "fresh" ]
166 # Lets read our partition list, and unmount each
167 ##################################################################
168 if [ -d "${PARTDIR}" ]
170 for PART in `ls ${PARTDIR}`
172 PARTDEV=`echo $PART | sed 's|-|/|g'`
173 PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
174 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
175 PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
177 if [ "${PARTFS}" = "SWAP" ]
179 if [ "${PARTENC}" = "ON" ]
181 swapoff ${PARTDEV}.eli >/dev/null 2>/dev/null
183 swapoff ${PARTDEV} >/dev/null 2>/dev/null
187 # Check if we've found "/" again, don't need to mount it twice
188 if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
190 umount -f ${PARTDEV} >/dev/null 2>/dev/null
191 umount -f ${FSMNT}${PARTMNT} >/dev/null 2>/dev/null
195 # Last lets the /mnt partition
196 #########################################################
197 umount -f ${FSMNT} >/dev/null 2>/dev/null
201 # We are doing a upgrade, try unmounting any of these filesystems
202 chroot ${FSMNT} /sbin/umount -a >/dev/null 2>/dev/null
203 umount -f ${FSMNT}/usr >/dev/null 2>/dev/null
204 umount -f ${FSMNT}/dev >/dev/null 2>/dev/null
205 umount -f ${FSMNT} >/dev/null 2>/dev/null
206 sh ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null
210 umount ${CDMNT} >/dev/null 2>/dev/null