1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: mount-boot.eclass
6 # base-system@gentoo.org
7 # @BLURB: functions for packages that install files into /boot
9 # This eclass is really only useful for bootloaders.
11 # If the live system has a separate /boot partition configured, then this
12 # function tries to ensure that it's mounted in rw mode, exiting with an
13 # error if it can't. It does nothing if /boot isn't a separate partition.
15 EXPORT_FUNCTIONS pkg_pretend pkg_preinst pkg_postinst pkg_prerm pkg_postrm
17 # @FUNCTION: mount-boot_disabled
20 # Detect whether the current environment/build settings are such that we do not
21 # want to mess with any mounts.
22 mount-boot_is_disabled() {
23 # Since this eclass only deals with /boot, skip things when ROOT is active.
24 if [[ "${ROOT:-/}" != "/" ]] ; then
28 # If we're only building a package, then there's no need to check things.
29 if [[ "${MERGE_TYPE}" == "buildonly" ]] ; then
33 # The user wants us to leave things be.
34 if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
38 # OK, we want to handle things ourselves.
42 # @FUNCTION: mount-boot_check_status
45 # Figure out what kind of work we need to do in order to have /boot be sane.
47 # 0 - Do nothing at all!
48 # 1 - It's mounted, but is currently ro, so need to remount rw.
49 # 2 - It's not mounted, so need to mount it rw.
50 mount-boot_check_status() {
51 # Get out fast if possible.
52 mount-boot_is_disabled && return 0
54 # note that /dev/BOOT is in the Gentoo default /etc/fstab file
55 local fstabstate=$(awk '!/^#|^[[:blank:]]+#|^\/dev\/BOOT/ {print $2}' /etc/fstab | egrep "^/boot$" )
56 local procstate=$(awk '$2 ~ /^\/boot$/ {print $2}' /proc/mounts)
57 local proc_ro=$(awk '{ print $2 " ," $4 "," }' /proc/mounts | sed -n '/\/boot .*,ro,/p')
59 if [ -n "${fstabstate}" ] && [ -n "${procstate}" ] ; then
60 if [ -n "${proc_ro}" ] ; then
62 einfo "Your boot partition, detected as being mounted at /boot, is read-only."
63 einfo "It will be remounted in read-write mode temporarily."
67 einfo "Your boot partition was detected as being mounted at /boot."
68 einfo "Files will be installed there for ${PN} to function correctly."
71 elif [ -n "${fstabstate}" ] && [ -z "${procstate}" ] ; then
73 einfo "Your boot partition was not mounted at /boot, so it will be automounted for you."
74 einfo "Files will be installed there for ${PN} to function correctly."
78 einfo "Assuming you do not have a separate /boot partition."
83 mount-boot_pkg_pretend() {
84 # Get out fast if possible.
85 mount-boot_is_disabled && return 0
87 elog "To avoid automounting and auto(un)installing with /boot,"
88 elog "just export the DONT_MOUNT_BOOT variable."
89 mount-boot_check_status
92 mount-boot_mount_boot_partition() {
93 mount-boot_check_status
98 mount -o remount,rw /boot
99 if [ $? -ne 0 ] ; then
101 eerror "Unable to remount in rw mode. Please do it manually!"
102 die "Can't remount in rw mode. Please do it manually!"
104 touch /boot/.e.remount
108 if [ $? -ne 0 ] ; then
110 eerror "Cannot automatically mount your /boot partition."
111 eerror "Your boot partition has to be mounted rw before the installation"
112 eerror "can continue. ${PN} needs to install important files there."
113 die "Please mount your /boot partition manually!"
120 mount-boot_pkg_preinst() {
121 # Handle older EAPIs.
123 [0-3]) mount-boot_pkg_pretend ;;
126 mount-boot_mount_boot_partition
129 mount-boot_pkg_prerm() {
130 touch "${ROOT}"/boot/.keep 2>/dev/null
131 mount-boot_mount_boot_partition
132 touch "${ROOT}"/boot/.keep 2>/dev/null
135 mount-boot_umount_boot_partition() {
136 # Get out fast if possible.
137 mount-boot_is_disabled && return 0
139 if [ -e /boot/.e.remount ] ; then
140 einfo "Automatically remounting /boot as ro as it was previously."
141 rm -f /boot/.e.remount
142 mount -o remount,ro /boot
143 elif [ -e /boot/.e.mount ] ; then
144 einfo "Automatically unmounting /boot as it was previously."
150 mount-boot_pkg_postinst() {
151 mount-boot_umount_boot_partition
154 mount-boot_pkg_postrm() {
155 mount-boot_umount_boot_partition