1
|
#!/bin/sh
|
2
|
#-
|
3
|
# Copyright (c) 2010 iXsystems, Inc. All rights reserved.
|
4
|
#
|
5
|
# Redistribution and use in source and binary forms, with or without
|
6
|
# modification, are permitted provided that the following conditions
|
7
|
# are met:
|
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.
|
13
|
#
|
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
|
24
|
# SUCH DAMAGE.
|
25
|
#
|
26
|
# $FreeBSD: src/usr.sbin/pc-sysinstall/backend/functions-unmount.sh,v 1.2 2010/06/27 16:46:11 imp Exp $
|
27
|
|
28
|
# Functions which unmount all mounted disk filesystems
|
29
|
|
30
|
# Unmount all mounted partitions under specified dir
|
31
|
umount_all_dir() {
|
32
|
_udir="$1"
|
33
|
_umntdirs=`mount | sort -r | grep "on $_udir" | cut -d ' ' -f 3`
|
34
|
for _ud in $_umntdirs
|
35
|
do
|
36
|
umount -f ${_ud}
|
37
|
done
|
38
|
}
|
39
|
|
40
|
# Script that adds our gmirror devices for syncing
|
41
|
start_gmirror_sync()
|
42
|
{
|
43
|
|
44
|
cd ${MIRRORCFGDIR}
|
45
|
for DISK in `ls *`
|
46
|
do
|
47
|
MIRRORDISK="`cat ${DISK} | cut -d ':' -f 1`"
|
48
|
MIRRORBAL="`cat ${DISK} | cut -d ':' -f 2`"
|
49
|
MIRRORNAME="`cat ${DISK} | cut -d ':' -f 3`"
|
50
|
|
51
|
# Start the mirroring service
|
52
|
rc_halt "gmirror insert ${MIRRORNAME} /dev/${MIRRORDISK}"
|
53
|
|
54
|
done
|
55
|
|
56
|
};
|
57
|
|
58
|
# Unmounts all our mounted file-systems
|
59
|
unmount_all_filesystems()
|
60
|
{
|
61
|
# Copy the logfile to disk before we unmount
|
62
|
cp ${LOGOUT} ${FSMNT}/root/pc-sysinstall.log
|
63
|
cd /
|
64
|
|
65
|
# Start by unmounting any ZFS partitions
|
66
|
zfs_cleanup_unmount
|
67
|
|
68
|
# Lets read our partition list, and unmount each
|
69
|
##################################################################
|
70
|
for PART in `ls ${PARTDIR}`
|
71
|
do
|
72
|
|
73
|
PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`"
|
74
|
PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`"
|
75
|
PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`"
|
76
|
PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d ':' -f 4`"
|
77
|
|
78
|
if [ "${PARTENC}" = "ON" ]
|
79
|
then
|
80
|
EXT=".eli"
|
81
|
else
|
82
|
EXT=""
|
83
|
fi
|
84
|
|
85
|
#if [ "${PARTFS}" = "SWAP" ]
|
86
|
#then
|
87
|
# rc_nohalt "swapoff /dev/${PART}${EXT}"
|
88
|
#fi
|
89
|
|
90
|
# Check if we've found "/", and unmount that last
|
91
|
if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
|
92
|
then
|
93
|
#rc_halt "umount -f /dev/${PART}${EXT}"
|
94
|
|
95
|
# Re-check if we are missing a label for this device and create it again if so
|
96
|
if [ ! -e "/dev/label/${PARTLABEL}" ]
|
97
|
then
|
98
|
case ${PARTFS} in
|
99
|
UFS) glabel label ${PARTLABEL} /dev/${PART}${EXT} ;;
|
100
|
UFS+S) glabel label ${PARTLABEL} /dev/${PART}${EXT} ;;
|
101
|
UFS+J) glabel label ${PARTLABEL} /dev/${PART}${EXT}.journal ;;
|
102
|
*) ;;
|
103
|
esac
|
104
|
fi
|
105
|
fi
|
106
|
|
107
|
# Check if we've found "/" and make sure the label exists
|
108
|
if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ]
|
109
|
then
|
110
|
if [ ! -e "/dev/label/${PARTLABEL}" ]
|
111
|
then
|
112
|
case ${PARTFS} in
|
113
|
UFS) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}" ;;
|
114
|
UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}" ;;
|
115
|
UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}.journal" ;;
|
116
|
*) ;;
|
117
|
esac
|
118
|
fi
|
119
|
fi
|
120
|
done
|
121
|
|
122
|
# Last lets the /mnt partition
|
123
|
#########################################################
|
124
|
#rc_nohalt "umount -f ${FSMNT}"
|
125
|
|
126
|
# If are using a ZFS on "/" set it to legacy
|
127
|
if [ ! -z "${FOUNDZFSROOT}" ]
|
128
|
then
|
129
|
rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}"
|
130
|
fi
|
131
|
|
132
|
# If we need to relabel "/" do it now
|
133
|
if [ ! -z "${ROOTRELABEL}" ]
|
134
|
then
|
135
|
${ROOTRELABEL}
|
136
|
fi
|
137
|
|
138
|
# Unmount our CDMNT
|
139
|
#rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null
|
140
|
|
141
|
# Check if we need to run any gmirror syncing
|
142
|
ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null
|
143
|
if [ "$?" = "0" ]
|
144
|
then
|
145
|
# Lets start syncing now
|
146
|
start_gmirror_sync
|
147
|
fi
|
148
|
|
149
|
};
|
150
|
|
151
|
# Unmounts any filesystems after a failure
|
152
|
unmount_all_filesystems_failure()
|
153
|
{
|
154
|
cd /
|
155
|
|
156
|
# if we did a fresh install, start unmounting
|
157
|
if [ "${INSTALLMODE}" = "fresh" ]
|
158
|
then
|
159
|
|
160
|
# Lets read our partition list, and unmount each
|
161
|
##################################################################
|
162
|
if [ -d "${PARTDIR}" ]
|
163
|
then
|
164
|
for PART in `ls ${PARTDIR}`
|
165
|
do
|
166
|
|
167
|
PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`"
|
168
|
PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`"
|
169
|
PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`"
|
170
|
|
171
|
#if [ "${PARTFS}" = "SWAP" ]
|
172
|
#then
|
173
|
# if [ "${PARTENC}" = "ON" ]
|
174
|
# then
|
175
|
# rc_nohalt "swapoff /dev/${PART}.eli"
|
176
|
# else
|
177
|
# rc_nohalt "swapoff /dev/${PART}"
|
178
|
# fi
|
179
|
#fi
|
180
|
|
181
|
# Check if we've found "/" again, don't need to mount it twice
|
182
|
if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
|
183
|
then
|
184
|
#rc_nohalt "umount -f /dev/${PART}"
|
185
|
#rc_nohalt "umount -f ${FSMNT}${PARTMNT}"
|
186
|
fi
|
187
|
done
|
188
|
|
189
|
# Last lets the /mnt partition
|
190
|
#########################################################
|
191
|
#rc_nohalt "umount -f ${FSMNT}"
|
192
|
|
193
|
fi
|
194
|
else
|
195
|
# We are doing a upgrade, try unmounting any of these filesystems
|
196
|
chroot ${FSMNT} /sbin/umount -a >>${LOGOUT} >>${LOGOUT}
|
197
|
umount -f ${FSMNT}/usr >>${LOGOUT} 2>>${LOGOUT}
|
198
|
umount -f ${FSMNT}/dev >>${LOGOUT} 2>>${LOGOUT}
|
199
|
umount -f ${FSMNT} >>${LOGOUT} 2>>${LOGOUT}
|
200
|
rc_nohalt "sh ${TMPDIR}/.upgrade-unmount"
|
201
|
fi
|
202
|
|
203
|
# Unmount our CDMNT
|
204
|
#rc_nohalt "umount ${CDMNT}"
|
205
|
|
206
|
};
|