source: src-sh/pc-sysinstall/backend/functions-unmount.sh @ 754b73a5

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 754b73a5 was 754b73a5, checked in by Kris Moore <kris@…>, 17 months ago

Be more verbose when we do unmounting / cleanup of installs

Don't try to umount the CDMNT variable when not installing from it

  • Property mode set to 100755
File size: 6.7 KB
Line 
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: head/usr.sbin/pc-sysinstall/backend/functions-unmount.sh 232899 2012-03-12 21:32:43Z jpaetzel $
27
28# Functions which unmount all mounted disk filesystems
29
30# Unmount all mounted partitions under specified dir
31umount_all_dir()
32{
33  _udir="$1"
34  _umntdirs=`mount | sort -r | grep "on $_udir" | cut -d ' ' -f 3`
35  for _ud in $_umntdirs
36  do
37    echo_log "Unmounting: ${_ud}"
38    sleep 5
39    umount -f ${_ud} 
40  done
41}
42
43# Script that adds our gmirror devices for syncing
44start_gmirror_sync()
45{
46
47  cd ${MIRRORCFGDIR}
48  for DISK in `ls ${MIRRORCFGDIR}`
49  do
50    MIRRORDISK="`cat ${DISK} | cut -d ':' -f 1`"
51    MIRRORBAL="`cat ${DISK} | cut -d ':' -f 2`"
52    MIRRORNAME="`cat ${DISK} | cut -d ':' -f 3`"
53   
54    # Start the mirroring service
55    rc_nohalt "gmirror forget ${MIRRORNAME}"
56    rc_halt "gmirror insert ${MIRRORNAME} ${MIRRORDISK}"
57
58  done
59
60};
61
62# Unmounts all our mounted file-systems
63unmount_all_filesystems()
64{
65  # Copy the logfile to disk before we unmount
66  cp ${LOGOUT} ${FSMNT}/root/pc-sysinstall.log
67  cd /
68
69  # Start by unmounting any ZFS partitions
70  zfs_cleanup_unmount
71
72  # Lets read our partition list, and unmount each
73  ##################################################################
74  for PART in `ls ${PARTDIR}`
75  do
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`"
81
82    if [ "${PARTENC}" = "ON" ]
83    then
84      EXT=".eli"
85    else
86      EXT=""
87    fi
88
89    if [ "${PARTFS}" = "SWAP" ]
90    then
91      rc_nohalt "swapoff ${PARTDEV}${EXT}"
92    fi
93
94    # Check if we've found "/", and unmount that last
95    if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
96    then
97      echo_log "Unmounting: ${PARTDEV}${EXT}"
98      rc_halt "umount -f ${PARTDEV}${EXT}"
99
100      # Re-check if we are missing a label for this device and create it again if so
101      if [ ! -e "/dev/label/${PARTLABEL}" ]
102      then
103        case ${PARTFS} in
104          UFS) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
105          UFS+S) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
106          UFS+SUJ) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
107          UFS+J) glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal ;;
108          *) ;;
109        esac
110      fi
111    fi
112
113    # Check if we've found "/" and make sure the label exists
114    if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ]
115    then
116      if [ ! -e "/dev/label/${PARTLABEL}" ]
117      then
118        case ${PARTFS} in
119          UFS) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
120          UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
121          UFS+SUJ) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
122          UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal" ;;
123          *) ;;
124        esac
125      fi
126    fi
127  done
128
129  # Last lets the /mnt partition
130  #########################################################
131  echo_log "Unmounting: ${FSMNT}"
132  rc_nohalt "umount -f ${FSMNT}"
133
134   # If are using a ZFS on "/" set it to legacy
135  if [ ! -z "${FOUNDZFSROOT}" ]
136  then
137    rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}"
138  fi
139
140  # If we need to relabel "/" do it now
141  if [ ! -z "${ROOTRELABEL}" ]
142  then
143    ${ROOTRELABEL}
144  fi
145
146  # Check if we need to unmount a media
147  case $INSTALLMEDIUM in
148     dvd|usb) echo_log "Unmounting DVD/USB media: ${CDMNT}"
149              sleep 5
150              rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null
151              ;;
152           *) ;;
153  esac
154
155  # Check if we need to run any gmirror syncing
156  ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null
157  if [ $? -eq 0 ]
158  then
159    # Lets start syncing now
160    start_gmirror_sync
161  fi
162
163};
164
165# Unmounts any filesystems after a failure
166unmount_all_filesystems_failure()
167{
168  cd /
169
170  # if we did a fresh install, start unmounting
171  if [ "${INSTALLMODE}" = "fresh" ]
172  then
173
174    # Lets read our partition list, and unmount each
175    ##################################################################
176    if [ -d "${PARTDIR}" ]
177    then
178    for PART in `ls ${PARTDIR}`
179    do
180      PARTDEV=`echo $PART | sed 's|-|/|g'` 
181      PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
182      PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
183      PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
184
185      if [ "${PARTFS}" = "SWAP" ]
186      then
187        if [ "${PARTENC}" = "ON" ]
188        then
189          swapoff ${PARTDEV}.eli >/dev/null 2>/dev/null
190        else
191          swapoff ${PARTDEV} >/dev/null 2>/dev/null
192        fi
193      fi
194
195      # Check if we've found "/" again, don't need to mount it twice
196      if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
197      then
198        umount -f ${PARTDEV} >/dev/null 2>/dev/null
199        umount -f ${FSMNT}${PARTMNT} >/dev/null 2>/dev/null
200      fi
201    done
202
203    # Last lets the /mnt partition
204    #########################################################
205    umount -f ${FSMNT} >/dev/null 2>/dev/null
206
207   fi
208  else
209    # We are doing a upgrade, try unmounting any of these filesystems
210    chroot ${FSMNT} /sbin/umount -a >/dev/null 2>/dev/null
211    umount -f ${FSMNT}/usr >/dev/null 2>/dev/null
212    umount -f ${FSMNT}/dev >/dev/null 2>/dev/null
213    umount -f ${FSMNT} >/dev/null 2>/dev/null
214    sh ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null
215  fi
216   
217  # Unmount our CDMNT
218  umount ${CDMNT} >/dev/null 2>/dev/null
219
220};
Note: See TracBrowser for help on using the repository browser.