source: src-sh/pc-sysinstall/backend/functions-unmount.sh @ 88e7386

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

Save the logfile after we stamp GRUB

  • Property mode set to 100755
File size: 8.0 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  cd /
66
67  # Check if we need to setup GRUB
68  if [ -e "${TMPDIR}/.grub-install" ] ; then setup_grub; fi
69
70  # Copy the logfile to disk before we unmount
71  cp ${LOGOUT} ${FSMNT}/root/pc-sysinstall.log
72
73  # Start by unmounting any ZFS partitions
74  zfs_cleanup_unmount
75
76  # Lets read our partition list, and unmount each
77  ##################################################################
78  for PART in `ls ${PARTDIR}`
79  do
80    PARTDEV=`echo $PART | sed 's|-|/|g'`   
81    PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
82    PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
83    PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
84    PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d '#' -f 4`"
85
86    if [ "${PARTENC}" = "ON" ]
87    then
88      EXT=".eli"
89    else
90      EXT=""
91    fi
92
93    if [ "${PARTFS}" = "SWAP" ]
94    then
95      rc_nohalt "swapoff ${PARTDEV}${EXT}"
96    fi
97
98    # Check if we've found "/", and unmount that last
99    if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
100    then
101      echo_log "Unmounting: ${PARTDEV}${EXT}"
102      rc_halt "umount -f ${PARTDEV}${EXT}"
103
104      # Re-check if we are missing a label for this device and create it again if so
105      if [ ! -e "/dev/label/${PARTLABEL}" ]
106      then
107        case ${PARTFS} in
108          UFS) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
109          UFS+S) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
110          UFS+SUJ) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;;
111          UFS+J) glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal ;;
112          *) ;;
113        esac
114      fi
115    fi
116
117    # Check if we've found "/" and make sure the label exists
118    if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ]
119    then
120      if [ ! -e "/dev/label/${PARTLABEL}" ]
121      then
122        case ${PARTFS} in
123          UFS) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
124          UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
125          UFS+SUJ) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;;
126          UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal" ;;
127          *) ;;
128        esac
129      fi
130    fi
131  done
132
133  # Last lets the /mnt partition
134  #########################################################
135  echo_log "Unmounting: ${FSMNT}"
136  rc_nohalt "umount -f ${FSMNT}"
137
138   # If are using a ZFS on "/" set it to legacy
139  if [ ! -z "${FOUNDZFSROOT}" ]
140  then
141    rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}"
142  fi
143
144  # If we need to relabel "/" do it now
145  if [ ! -z "${ROOTRELABEL}" ]
146  then
147    ${ROOTRELABEL}
148  fi
149
150  # Check if we need to unmount a media
151  case $INSTALLMEDIUM in
152     dvd|usb) echo_log "Unmounting DVD/USB media: ${CDMNT}"
153              sleep 5
154              rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null
155              ;;
156           *) ;;
157  esac
158
159  # Check if we need to run any gmirror syncing
160  ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null
161  if [ $? -eq 0 ]
162  then
163    # Lets start syncing now
164    start_gmirror_sync
165  fi
166
167};
168
169# Unmounts any filesystems after a failure
170unmount_all_filesystems_failure()
171{
172  cd /
173
174  # if we did a fresh install, start unmounting
175  if [ "${INSTALLMODE}" = "fresh" ]
176  then
177
178    # Lets read our partition list, and unmount each
179    ##################################################################
180    if [ -d "${PARTDIR}" ]
181    then
182    for PART in `ls ${PARTDIR}`
183    do
184      PARTDEV=`echo $PART | sed 's|-|/|g'` 
185      PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
186      PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
187      PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
188
189      if [ "${PARTFS}" = "SWAP" ]
190      then
191        if [ "${PARTENC}" = "ON" ]
192        then
193          swapoff ${PARTDEV}.eli >/dev/null 2>/dev/null
194        else
195          swapoff ${PARTDEV} >/dev/null 2>/dev/null
196        fi
197      fi
198
199      # Check if we've found "/" again, don't need to mount it twice
200      if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ]
201      then
202        umount -f ${PARTDEV} >/dev/null 2>/dev/null
203        umount -f ${FSMNT}${PARTMNT} >/dev/null 2>/dev/null
204      fi
205    done
206
207    # Last lets the /mnt partition
208    #########################################################
209    umount -f ${FSMNT} >/dev/null 2>/dev/null
210
211   fi
212  else
213    # We are doing a upgrade, try unmounting any of these filesystems
214    chroot ${FSMNT} /sbin/umount -a >/dev/null 2>/dev/null
215    umount -f ${FSMNT}/usr >/dev/null 2>/dev/null
216    umount -f ${FSMNT}/dev >/dev/null 2>/dev/null
217    umount -f ${FSMNT} >/dev/null 2>/dev/null
218    sh ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null
219  fi
220   
221  # Unmount our CDMNT
222  umount ${CDMNT} >/dev/null 2>/dev/null
223
224};
225
226# Script which stamps grub on the specified disks
227setup_grub() 
228{
229  # Mount devfs
230  rc_halt "mount -t devfs devfs ${FSMNT}/dev"
231
232  # Check for a custom beadm.install to copy before we run grub
233  if [ -e "/root/beadm.install" ] ; then
234     rc_halt "cp /root/beadm.install ${FSMNT}/root/beadm.install"
235     rc_halt "chmod 755 ${FSMNT}/root/beadm.install"
236  fi
237
238  # Make sure to copy zpool.cache first
239  rc_nohalt "cp /boot/zfs/zpool.cache ${FSMNT}/boot/zfs/"
240
241  # Copy the hostid so that our zfs cache works
242  rc_nohalt "cp /etc/hostid ${FSMNT}/etc/hostid"
243
244  # Read through our list and stamp grub for each device
245  while read line
246  do
247    # Make sure we have a /dev in front of the disk name
248    echo $line | grep -q '/dev/'
249    if [ $? -eq 0 ] ; then
250      gDisk="$line"
251    else
252      gDisk="/dev/$line"
253    fi
254
255    # Stamp GRUB now
256    rc_halt "chroot ${FSMNT} grub-install --force $gDisk"
257  done < ${TMPDIR}/.grub-install
258
259  # Make sure we re-create the default grub.cfg
260  rc_halt "chroot ${FSMNT} grub-mkconfig -o /boot/grub/grub.cfg"
261
262  # Sleep and cleanup
263  if [ -e "${FSMNT}/root/beadm.install" ] ; then
264     rc_halt "rm ${FSMNT}/root/beadm.install"
265  fi
266  sleep 5
267  rc_halt "umount ${FSMNT}/dev"
268};
Note: See TracBrowser for help on using the repository browser.