functions-unmount.sh revision 209513
1209513Simp#!/bin/sh 2209513Simp#- 3209513Simp# Copyright (c) 2010 iX Systems, Inc. All rights reserved. 4209513Simp# 5209513Simp# Redistribution and use in source and binary forms, with or without 6209513Simp# modification, are permitted provided that the following conditions 7209513Simp# are met: 8209513Simp# 1. Redistributions of source code must retain the above copyright 9209513Simp# notice, this list of conditions and the following disclaimer. 10209513Simp# 2. Redistributions in binary form must reproduce the above copyright 11209513Simp# notice, this list of conditions and the following disclaimer in the 12209513Simp# documentation and/or other materials provided with the distribution. 13209513Simp# 14209513Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15209513Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16209513Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17209513Simp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18209513Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19209513Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20209513Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21209513Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22209513Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23209513Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24209513Simp# SUCH DAMAGE. 25209513Simp# 26209513Simp# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-unmount.sh 209513 2010-06-24 22:21:47Z imp $ 27209513Simp 28209513Simp# Functions which unmount all mounted disk filesystems 29209513Simp 30209513Simp# Unmount all mounted partitions under specified dir 31209513Simpumount_all_dir() { 32209513Simp _udir="$1" 33209513Simp _umntdirs=`mount | sort -r | grep "on $_udir" | cut -d ' ' -f 3` 34209513Simp for _ud in $_umntdirs 35209513Simp do 36209513Simp umount -f ${_ud} 37209513Simp done 38209513Simp} 39209513Simp 40209513Simp# Script that adds our gmirror devices for syncing 41209513Simpstart_gmirror_sync() 42209513Simp{ 43209513Simp 44209513Simp cd ${MIRRORCFGDIR} 45209513Simp for DISK in `ls *` 46209513Simp do 47209513Simp MIRRORDISK="`cat ${DISK} | cut -d ':' -f 1`" 48209513Simp MIRRORBAL="`cat ${DISK} | cut -d ':' -f 2`" 49209513Simp MIRRORNAME="`cat ${DISK} | cut -d ':' -f 3`" 50209513Simp 51209513Simp # Start the mirroring service 52209513Simp rc_halt "gmirror insert ${MIRRORNAME} /dev/${MIRRORDISK}" 53209513Simp 54209513Simp done 55209513Simp 56209513Simp}; 57209513Simp 58209513Simp# Unmounts all our mounted file-systems 59209513Simpunmount_all_filesystems() 60209513Simp{ 61209513Simp # Copy the logfile to disk before we unmount 62209513Simp cp ${LOGOUT} ${FSMNT}/root/pc-sysinstall.log 63209513Simp cd / 64209513Simp 65209513Simp # Start by unmounting any ZFS partitions 66209513Simp zfs_cleanup_unmount 67209513Simp 68209513Simp # Lets read our partition list, and unmount each 69209513Simp ################################################################## 70209513Simp for PART in `ls ${PARTDIR}` 71209513Simp do 72209513Simp 73209513Simp PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`" 74209513Simp PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`" 75209513Simp PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`" 76209513Simp PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d ':' -f 4`" 77209513Simp 78209513Simp if [ "${PARTENC}" = "ON" ] 79209513Simp then 80209513Simp EXT=".eli" 81209513Simp else 82209513Simp EXT="" 83209513Simp fi 84209513Simp 85209513Simp #if [ "${PARTFS}" = "SWAP" ] 86209513Simp #then 87209513Simp # rc_nohalt "swapoff /dev/${PART}${EXT}" 88209513Simp #fi 89209513Simp 90209513Simp # Check if we've found "/", and unmount that last 91209513Simp if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ] 92209513Simp then 93209513Simp rc_halt "umount -f /dev/${PART}${EXT}" 94209513Simp 95209513Simp # Re-check if we are missing a label for this device and create it again if so 96209513Simp if [ ! -e "/dev/label/${PARTLABEL}" ] 97209513Simp then 98209513Simp case ${PARTFS} in 99209513Simp UFS) glabel label ${PARTLABEL} /dev/${PART}${EXT} ;; 100209513Simp UFS+S) glabel label ${PARTLABEL} /dev/${PART}${EXT} ;; 101209513Simp UFS+J) glabel label ${PARTLABEL} /dev/${PART}${EXT}.journal ;; 102209513Simp *) ;; 103209513Simp esac 104209513Simp fi 105209513Simp fi 106209513Simp 107209513Simp # Check if we've found "/" and make sure the label exists 108209513Simp if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ] 109209513Simp then 110209513Simp if [ ! -e "/dev/label/${PARTLABEL}" ] 111209513Simp then 112209513Simp case ${PARTFS} in 113209513Simp UFS) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}" ;; 114209513Simp UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}" ;; 115209513Simp UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} /dev/${PART}${EXT}.journal" ;; 116209513Simp *) ;; 117209513Simp esac 118209513Simp fi 119209513Simp fi 120209513Simp done 121209513Simp 122209513Simp # Last lets the /mnt partition 123209513Simp ######################################################### 124209513Simp rc_nohalt "umount -f ${FSMNT}" 125209513Simp 126209513Simp # If are using a ZFS on "/" set it to legacy 127209513Simp if [ ! -z "${FOUNDZFSROOT}" ] 128209513Simp then 129209513Simp rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}" 130209513Simp fi 131209513Simp 132209513Simp # If we need to relabel "/" do it now 133209513Simp if [ ! -z "${ROOTRELABEL}" ] 134209513Simp then 135209513Simp ${ROOTRELABEL} 136209513Simp fi 137209513Simp 138209513Simp # Unmount our CDMNT 139209513Simp rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null 140209513Simp 141209513Simp # Check if we need to run any gmirror syncing 142209513Simp ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null 143209513Simp if [ "$?" = "0" ] 144209513Simp then 145209513Simp # Lets start syncing now 146209513Simp start_gmirror_sync 147209513Simp fi 148209513Simp 149209513Simp}; 150209513Simp 151209513Simp# Unmounts any filesystems after a failure 152209513Simpunmount_all_filesystems_failure() 153209513Simp{ 154209513Simp cd / 155209513Simp 156209513Simp # if we did a fresh install, start unmounting 157209513Simp if [ "${INSTALLMODE}" = "fresh" ] 158209513Simp then 159209513Simp 160209513Simp # Lets read our partition list, and unmount each 161209513Simp ################################################################## 162209513Simp if [ -d "${PARTDIR}" ] 163209513Simp then 164209513Simp for PART in `ls ${PARTDIR}` 165209513Simp do 166209513Simp 167209513Simp PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`" 168209513Simp PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`" 169209513Simp PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`" 170209513Simp 171209513Simp #if [ "${PARTFS}" = "SWAP" ] 172209513Simp #then 173209513Simp # if [ "${PARTENC}" = "ON" ] 174209513Simp # then 175209513Simp # rc_nohalt "swapoff /dev/${PART}.eli" 176209513Simp # else 177209513Simp # rc_nohalt "swapoff /dev/${PART}" 178209513Simp # fi 179209513Simp #fi 180209513Simp 181209513Simp # Check if we've found "/" again, don't need to mount it twice 182209513Simp if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ] 183209513Simp then 184209513Simp rc_nohalt "umount -f /dev/${PART}" 185209513Simp rc_nohalt "umount -f ${FSMNT}${PARTMNT}" 186209513Simp fi 187209513Simp done 188209513Simp 189209513Simp # Last lets the /mnt partition 190209513Simp ######################################################### 191209513Simp rc_nohalt "umount -f ${FSMNT}" 192209513Simp 193209513Simp fi 194209513Simp else 195209513Simp # We are doing a upgrade, try unmounting any of these filesystems 196209513Simp chroot ${FSMNT} /sbin/umount -a >>${LOGOUT} >>${LOGOUT} 197209513Simp umount -f ${FSMNT}/usr >>${LOGOUT} 2>>${LOGOUT} 198209513Simp umount -f ${FSMNT}/dev >>${LOGOUT} 2>>${LOGOUT} 199209513Simp umount -f ${FSMNT} >>${LOGOUT} 2>>${LOGOUT} 200209513Simp rc_nohalt "sh ${TMPDIR}/.upgrade-unmount" 201209513Simp fi 202209513Simp 203209513Simp # Unmount our CDMNT 204209513Simp rc_nohalt "umount ${CDMNT}" 205209513Simp 206209513Simp}; 207