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

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

Make pc-sysinstall aware of a possible beadm.install custom version
to use when installing with GRUB boot-loader

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