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