1 # Copyright 1999-2019 Gentoo Authors
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.
17 *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
20 EXPORT_FUNCTIONS pkg_pretend pkg_preinst pkg_postinst pkg_prerm pkg_postrm
22 # @FUNCTION: mount-boot_is_disabled
25 # Detect whether the current environment/build settings are such that we do not
26 # want to mess with any mounts.
27 mount-boot_is_disabled() {
28 # Since this eclass only deals with /boot, skip things when EROOT is active.
29 if [[ ${EROOT:-/} != / ]] ; then
33 # If we're only building a package, then there's no need to check things.
34 if [[ ${MERGE_TYPE} == buildonly ]] ; then
38 # The user wants us to leave things be.
39 if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
43 # OK, we want to handle things ourselves.
47 # @FUNCTION: mount-boot_check_status
50 # Check if /boot is sane, i.e., mounted as read-write if on a separate
51 # partition. Die if conditions are not fulfilled.
52 mount-boot_check_status() {
53 # Get out fast if possible.
54 mount-boot_is_disabled && return
56 # note that /dev/BOOT is in the Gentoo default /etc/fstab file
57 local fstabstate=$(awk '!/^[[:blank:]]*#|^\/dev\/BOOT/ && $2 == "/boot" \
58 { print 1; exit }' /etc/fstab || die "awk failed")
60 if [[ -z ${fstabstate} ]] ; then
61 einfo "Assuming you do not have a separate /boot partition."
65 local procstate=$(awk '$2 == "/boot" \
66 { print gensub(/^(.*,)?(ro|rw)(,.*)?$/, "\\2", 1, $4); exit }' \
67 /proc/mounts || die "awk failed")
69 if [[ -z ${procstate} ]] ; then
70 eerror "Your boot partition is not mounted at /boot."
71 eerror "Please mount it and retry."
72 die "/boot not mounted"
75 if [[ ${procstate} == ro ]] ; then
76 eerror "Your boot partition, detected as being mounted at /boot," \
78 eerror "Please remount it as read-write and retry."
79 die "/boot mounted read-only"
82 einfo "Your boot partition was detected as being mounted at /boot."
83 einfo "Files will be installed there for ${PN} to function correctly."
86 mount-boot_pkg_pretend() {
87 mount-boot_check_status
90 mount-boot_pkg_preinst() {
91 mount-boot_check_status
94 mount-boot_pkg_prerm() {
95 mount-boot_check_status
97 if [[ -z ${EPREFIX} ]] \
98 && ! ( shopt -s failglob; : "${EROOT}"/boot/.keep* ) 2>/dev/null
100 # Create a .keep file, in case it is shadowed at the mount point
101 touch "${EROOT}"/boot/.keep 2>/dev/null
105 # No-op phases for backwards compatibility
106 mount-boot_pkg_postinst() { :; }
108 mount-boot_pkg_postrm() { :; }