| 1 |
# Copyright 1999-2011 Gentoo Foundation
|
| 2 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/mount-boot.eclass,v 1.17 2009/10/09 20:57:08 vapier Exp $
|
| 4 |
#
|
| 5 |
# This eclass is really only useful for bootloaders.
|
| 6 |
#
|
| 7 |
# If the live system has a separate /boot partition configured, then this
|
| 8 |
# function tries to ensure that it's mounted in rw mode, exiting with an
|
| 9 |
# error if it cant. It does nothing if /boot isn't a separate partition.
|
| 10 |
#
|
| 11 |
# MAINTAINER: base-system@gentoo.org
|
| 12 |
|
| 13 |
EXPORT_FUNCTIONS pkg_preinst pkg_postinst pkg_prerm pkg_postrm
|
| 14 |
|
| 15 |
mount-boot_mount_boot_partition() {
|
| 16 |
if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
|
| 17 |
return
|
| 18 |
else
|
| 19 |
elog
|
| 20 |
elog "To avoid automounting and auto(un)installing with /boot,"
|
| 21 |
elog "just export the DONT_MOUNT_BOOT variable."
|
| 22 |
elog
|
| 23 |
fi
|
| 24 |
|
| 25 |
# note that /dev/BOOT is in the Gentoo default /etc/fstab file
|
| 26 |
local fstabstate=$(awk '!/^#|^[[:blank:]]+#|^\/dev\/BOOT/ {print $2}' /etc/fstab | egrep "^/boot$" )
|
| 27 |
local procstate=$(awk '$2 ~ /^\/boot$/ {print $2}' /proc/mounts)
|
| 28 |
local proc_ro=$(awk '{ print $2 " ," $4 "," }' /proc/mounts | sed -n '/\/boot .*,ro,/p')
|
| 29 |
|
| 30 |
if [ -n "${fstabstate}" ] && [ -n "${procstate}" ]; then
|
| 31 |
if [ -n "${proc_ro}" ]; then
|
| 32 |
einfo
|
| 33 |
einfo "Your boot partition, detected as being mounted as /boot, is read-only."
|
| 34 |
einfo "Remounting it in read-write mode ..."
|
| 35 |
einfo
|
| 36 |
mount -o remount,rw /boot
|
| 37 |
if [ "$?" -ne 0 ]; then
|
| 38 |
eerror
|
| 39 |
eerror "Unable to remount in rw mode. Please do it manually!"
|
| 40 |
eerror
|
| 41 |
die "Can't remount in rw mode. Please do it manually!"
|
| 42 |
fi
|
| 43 |
touch /boot/.e.remount
|
| 44 |
else
|
| 45 |
einfo
|
| 46 |
einfo "Your boot partition was detected as being mounted as /boot."
|
| 47 |
einfo "Files will be installed there for ${PN} to function correctly."
|
| 48 |
einfo
|
| 49 |
fi
|
| 50 |
elif [ -n "${fstabstate}" ] && [ -z "${procstate}" ]; then
|
| 51 |
mount /boot -o rw
|
| 52 |
if [ "$?" -eq 0 ]; then
|
| 53 |
einfo
|
| 54 |
einfo "Your boot partition was not mounted as /boot, but portage"
|
| 55 |
einfo "was able to mount it without additional intervention."
|
| 56 |
einfo "Files will be installed there for ${PN} to function correctly."
|
| 57 |
einfo
|
| 58 |
else
|
| 59 |
eerror
|
| 60 |
eerror "Cannot automatically mount your /boot partition."
|
| 61 |
eerror "Your boot partition has to be mounted rw before the installation"
|
| 62 |
eerror "can continue. ${PN} needs to install important files there."
|
| 63 |
eerror
|
| 64 |
die "Please mount your /boot partition manually!"
|
| 65 |
fi
|
| 66 |
touch /boot/.e.mount
|
| 67 |
else
|
| 68 |
einfo
|
| 69 |
einfo "Assuming you do not have a separate /boot partition."
|
| 70 |
einfo
|
| 71 |
fi
|
| 72 |
}
|
| 73 |
|
| 74 |
mount-boot_pkg_preinst() {
|
| 75 |
mount-boot_mount_boot_partition
|
| 76 |
}
|
| 77 |
|
| 78 |
mount-boot_pkg_prerm() {
|
| 79 |
touch "${ROOT}"/boot/.keep 2>/dev/null
|
| 80 |
mount-boot_mount_boot_partition
|
| 81 |
touch "${ROOT}"/boot/.keep 2>/dev/null
|
| 82 |
}
|
| 83 |
|
| 84 |
mount-boot_umount_boot_partition() {
|
| 85 |
if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
|
| 86 |
return
|
| 87 |
fi
|
| 88 |
|
| 89 |
if [ -e /boot/.e.remount ] ; then
|
| 90 |
einfo
|
| 91 |
einfo "Automatically remounting /boot as ro"
|
| 92 |
einfo
|
| 93 |
rm -f /boot/.e.remount
|
| 94 |
mount -o remount,ro /boot
|
| 95 |
elif [ -e /boot/.e.mount ] ; then
|
| 96 |
einfo
|
| 97 |
einfo "Automatically unmounting /boot"
|
| 98 |
einfo
|
| 99 |
rm -f /boot/.e.mount
|
| 100 |
umount /boot
|
| 101 |
fi
|
| 102 |
}
|
| 103 |
|
| 104 |
mount-boot_pkg_postinst() {
|
| 105 |
mount-boot_umount_boot_partition
|
| 106 |
}
|
| 107 |
|
| 108 |
mount-boot_pkg_postrm() {
|
| 109 |
mount-boot_umount_boot_partition
|
| 110 |
}
|