functions-unmount.sh revision 211730
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 211730 2010-08-24 06:11:46Z 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+J) glabel label ${PARTLABEL} /dev/${PART}${EXT}.journal ;; 103 *) ;; 104 esac 105 fi 106 fi 107 108 # Check if we've found "/" and make sure the label exists 109 if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ] 110 then 111 if [ ! -e "/dev/label/${PARTLABEL}" ] 112 then 113 case ${PARTFS} in 114 UFS) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}" ;; 115 UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}" ;; 116 UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}.journal" ;; 117 *) ;; 118 esac 119 fi 120 fi 121 done 122 123 # Last lets the /mnt partition 124 ######################################################### 125 rc_nohalt "umount -f ${FSMNT}" 126 127 # If are using a ZFS on "/" set it to legacy 128 if [ ! -z "${FOUNDZFSROOT}" ] 129 then 130 rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}" 131 fi 132 133 # If we need to relabel "/" do it now 134 if [ ! -z "${ROOTRELABEL}" ] 135 then 136 ${ROOTRELABEL} 137 fi 138 139 # Unmount our CDMNT 140 rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null 141 142 # Check if we need to run any gmirror syncing 143 ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null 144 if [ "$?" = "0" ] 145 then 146 # Lets start syncing now 147 start_gmirror_sync 148 fi 149 150}; 151 152# Unmounts any filesystems after a failure 153unmount_all_filesystems_failure() 154{ 155 cd / 156 157 # if we did a fresh install, start unmounting 158 if [ "${INSTALLMODE}" = "fresh" ] 159 then 160 161 # Lets read our partition list, and unmount each 162 ################################################################## 163 if [ -d "${PARTDIR}" ] 164 then 165 for PART in `ls ${PARTDIR}` 166 do 167 168 PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`" 169 PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`" 170 PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`" 171 172 #if [ "${PARTFS}" = "SWAP" ] 173 #then 174 # if [ "${PARTENC}" = "ON" ] 175 # then 176 # rc_nohalt "swapoff /dev/${PART}.eli" 177 # else 178 # rc_nohalt "swapoff /dev/${PART}" 179 # fi 180 #fi 181 182 # Check if we've found "/" again, don't need to mount it twice 183 if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ] 184 then 185 rc_nohalt "umount -f /dev/${PART}" 186 rc_nohalt "umount -f ${FSMNT}${PARTMNT}" 187 fi 188 done 189 190 # Last lets the /mnt partition 191 ######################################################### 192 rc_nohalt "umount -f ${FSMNT}" 193 194 fi 195 else 196 # We are doing a upgrade, try unmounting any of these filesystems 197 chroot ${FSMNT} /sbin/umount -a >>${LOGOUT} >>${LOGOUT} 198 umount -f ${FSMNT}/usr >>${LOGOUT} 2>>${LOGOUT} 199 umount -f ${FSMNT}/dev >>${LOGOUT} 2>>${LOGOUT} 200 umount -f ${FSMNT} >>${LOGOUT} 2>>${LOGOUT} 201 rc_nohalt "sh ${TMPDIR}/.upgrade-unmount" 202 fi 203 204 # Unmount our CDMNT 205 rc_nohalt "umount ${CDMNT}" 206 207}; 208