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