Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-boot/systemrescuecd-x86-grub/, sys-boot/systemrescuecd-x86-grub/files/
Date: Fri, 05 Jul 2019 20:31:45
Message-Id: 1562358684.9b308815f37859def7fc4cb4466b27c8213496e6.mgorny@gentoo
1 commit: 9b308815f37859def7fc4cb4466b27c8213496e6
2 Author: Reinis Danne <rei4dan <AT> gmail <DOT> com>
3 AuthorDate: Sat Mar 9 12:39:45 2019 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Fri Jul 5 20:31:24 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9b308815
7
8 sys-boot/systemrescuecd-x86-grub: Update for 6
9
10 SystemRescueCD starting from version 6 is based on Arch and the way it
11 is booted changed.
12
13 Rewrite to:
14 - Support SystemRescueCD versions 5 and 6.
15
16 - Create menu entries for all versions found.
17
18 - Add option to copy the newest ISO to /boot if there is enough free
19 space. Helpful if / becomes unaccessible while /boot is on a separate
20 partition.
21
22 - Add a menu entry for persistent boot (version 6 only). Will put data
23 on the same disk, where the current ISO resides, in
24 "/persistent_sysresccd-${version}/x86_64".
25
26 Signed-off-by: Reinis Danne <rei4dan <AT> gmail.com>
27 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
28
29 .../files/systemrescuecd.default-2 | 33 +++++
30 .../files/systemrescuecd.grub-2 | 146 +++++++++++++++++++++
31 .../systemrescuecd-x86-grub-0.2.ebuild | 31 +++++
32 3 files changed, 210 insertions(+)
33
34 diff --git a/sys-boot/systemrescuecd-x86-grub/files/systemrescuecd.default-2 b/sys-boot/systemrescuecd-x86-grub/files/systemrescuecd.default-2
35 new file mode 100644
36 index 00000000000..941622bfc3b
37 --- /dev/null
38 +++ b/sys-boot/systemrescuecd-x86-grub/files/systemrescuecd.default-2
39 @@ -0,0 +1,33 @@
40 +# Here you can set custom bootoptions for the SystemRescueCD
41 +#
42 +# For SystemRescueCD version 6.x:
43 +#
44 +# You can add in a space separated list:
45 +# setkmap=xx: set keyboard layout for terminal
46 +# copytoram: load the ISO fully in memory
47 +# requires 2GB of memory to cache the system
48 +#
49 +# For SystemRescueCD version 5.x:
50 +#
51 +# You can add for example in a space separated list:
52 +# setkmap=xx: which defines the keymap to load (example: setkmap=de)
53 +# dostartx: load the X.Org graphical environment and launch Xfce
54 +# docache: causes the iso file to be fully loaded into memory
55 +# this requires 400MB of memory to cache everything
56 +# doload=xxx: loads needed kernel modules (example: doload=3c59x,e1000)
57 +# noload=xxx: prevents loading kernel modules
58 +# nomodeset: do not load the Kernel-Mode-Setting video driver
59 +#
60 +# Example:
61 +# SRCD_BOOTOPTIONS="setkmap=de docache dostartx"
62 +#
63 +# For all available bootoptions see:
64 +# http://www.sysresccd.org/Sysresccd-manual-en_Booting_the_CD-ROM
65 +#
66 +# Note:
67 +# After changing this, you must update your grub configuration file, to take effect
68 +
69 +SRCD_BOOTOPTIONS=""
70 +
71 +# Copy ISO to /boot if there is enough space
72 +#COPY_SRCD_TO_BOOT="yes"
73
74 diff --git a/sys-boot/systemrescuecd-x86-grub/files/systemrescuecd.grub-2 b/sys-boot/systemrescuecd-x86-grub/files/systemrescuecd.grub-2
75 new file mode 100755
76 index 00000000000..26857d23e90
77 --- /dev/null
78 +++ b/sys-boot/systemrescuecd-x86-grub/files/systemrescuecd.grub-2
79 @@ -0,0 +1,146 @@
80 +#!/bin/sh
81 +# Copyright 1999-2019 Gentoo Authors
82 +# Distributed under the terms of the GNU General Public License v2
83 +
84 +. /usr/share/grub/grub-mkconfig_lib
85 +
86 +if [ -r /etc/default/systemrescuecd ] ; then
87 + . /etc/default/systemrescuecd
88 +fi
89 +
90 +COPY_SRCD_TO_BOOT=${COPY_SRCD_TO_BOOT:-no}
91 +
92 +bootdir="/boot"
93 +installdir="/usr/share/systemrescuecd"
94 +
95 +isorex='^(/.*/)?systemrescuecd-.*[.]iso$'
96 +
97 +# Path of the link to the newest ISO, created by ebuild
98 +srcd="${installdir}/systemrescuecd-x86-newest.iso"
99 +
100 +# Extract ISO version
101 +isovsed() {
102 + sed -E 's|^.*systemrescuecd(-x86)?-||;s|.iso$||'
103 +}
104 +
105 +# Find ISOs in a given directory
106 +isofind() {
107 + find "${1}" -maxdepth 1 -type f -regextype egrep -regex ${isorex}
108 +}
109 +
110 +# Copy ISO to boot partition
111 +copy_srcd_iso() {
112 + if [ ! -f "${bootdir}/"$(basename "${1}") ]; then
113 + if [ $(df -k --output=avail "${bootdir}" | tail -1) -gt $(du -k "${1}" | cut -f 1) ]; then
114 + cp "${1}" "${bootdir}/"
115 + else
116 + # Before complaining, check if the installed ISO is actually newer
117 + if $(printf '%s\n' $(isofind "${bootdir}" | isovsed | sort -V) $(echo "${1}" | isovsed) | sort -VC); then
118 + gettext_printf "Error: Not enough free disk space on ${bootdir}!\n" >&2
119 + gettext_printf "Error: Failed to copy the new iso!\n" >&2
120 + fi
121 + fi
122 + fi
123 +}
124 +
125 +write_srcd() {
126 + cat <<EOF
127 + menuentry "${longname} [${1}] (Copy to RAM${bootops}" --class rescue {
128 +${grub_string}
129 + set gfxpayload=keep
130 + set isofile=${path}
131 + loopback loop \${isofile}
132 + linux (loop)/sysresccd/boot/x86_64/vmlinuz archisobasedir=sysresccd img_loop=\${isofile} img_dev=${diskuuid} copytoram ${SRCD_BOOTOPTIONS}
133 + initrd (loop)/sysresccd/boot/intel_ucode.img (loop)/sysresccd/boot/amd_ucode.img (loop)/sysresccd/boot/x86_64/sysresccd.img
134 + }
135 + menuentry "${longname} [${1}] (Copy to RAM with persistence${bootops}" --class rescue {
136 +${grub_string}
137 + set gfxpayload=keep
138 + set isofile=${path}
139 + loopback loop \${isofile}
140 + linux (loop)/sysresccd/boot/x86_64/vmlinuz archisobasedir=sysresccd img_loop=\${isofile} img_dev=${diskuuid} cow_device=${diskuuid} cow_directory=/persistent_sysresccd-${1}/x86_64 copytoram ${SRCD_BOOTOPTIONS}
141 + initrd (loop)/sysresccd/boot/intel_ucode.img (loop)/sysresccd/boot/amd_ucode.img (loop)/sysresccd/boot/x86_64/sysresccd.img
142 + }
143 + menuentry "${longname} [${1}] (Minimal${bootops}" --class rescue {
144 +${grub_string}
145 + set gfxpayload=keep
146 + set isofile=${path}
147 + loopback loop \${isofile}
148 + linux (loop)/sysresccd/boot/x86_64/vmlinuz archisobasedir=sysresccd img_loop=\${isofile} img_dev=${diskuuid} ${SRCD_BOOTOPTIONS}
149 + initrd (loop)/sysresccd/boot/intel_ucode.img (loop)/sysresccd/boot/amd_ucode.img (loop)/sysresccd/boot/x86_64/sysresccd.img
150 + }
151 +EOF
152 +}
153 +
154 +write_srcd_5() {
155 + cat <<EOF
156 + menuentry "${longname} [${1}] (64bit${bootops}" --class rescue {
157 +${grub_string}
158 + set isofile=${path}
159 + loopback loop \${isofile}
160 + linux (loop)/isolinux/rescue64 ${SRCD_BOOTOPTIONS} isoloop=\${isofile}
161 + initrd (loop)/isolinux/initram.igz
162 + }
163 + menuentry "${longname} [${1}] (32bit${bootops}" --class rescue {
164 +${grub_string}
165 + set isofile=${path}
166 + loopback loop \${isofile}
167 + linux (loop)/isolinux/rescue32 ${SRCD_BOOTOPTIONS} isoloop=\${isofile}
168 + initrd (loop)/isolinux/initram.igz
169 + }
170 +EOF
171 +}
172 +
173 +# Get v5 ISOs
174 +# Use: isogrep5 [-v]
175 +# -v invert match
176 +isogrep5() {
177 + ls -rv "${isopref}"/systemrescuecd-*.iso | grep ${1} -e '-x86-5'
178 +}
179 +
180 +write_srcd_submenu() {
181 + # Start submenu
182 + echo "submenu \"${longname}\" --class submenu {"
183 +
184 + # Make sure to reverse-sort by version
185 + for iso in $(isogrep5 -v; isogrep5); do
186 + path=$(make_system_path_relative_to_its_root "${iso}")
187 + gettext_printf " image: ${iso}\n" >&2
188 + if $(printf '%s\n' "6.0.0" $(echo ${iso} | isovsed) | sort -VC); then
189 + write_srcd $(echo ${iso} | isovsed)
190 + else
191 + write_srcd_5 $(echo ${iso} | isovsed)
192 + fi
193 + done
194 +
195 + # End submenu
196 + echo "}"
197 +}
198 +
199 +bootops=")"
200 +
201 +if [ ! -z "${SRCD_BOOTOPTIONS}" ]; then
202 + bootops=" with bootoptions)"
203 +fi
204 +
205 +if [ "${COPY_SRCD_TO_BOOT}" = yes ]; then
206 + srcd=$(realpath "${srcd}")
207 + copy_srcd_iso "${srcd}"
208 +fi
209 +
210 +# Build menu entries
211 +for isopref in ${bootdir} ${installdir}; do
212 + # Make sure there are any ISOs
213 + ls "${isopref}" | grep -E -q -e "${isorex}" || continue
214 +
215 + diskuuid=/dev/disk/by-uuid/$(${grub_probe} --target=fs_uuid "${isopref}")
216 + device=$(${grub_probe} --target=device "${isopref}")
217 + label=$(${grub_probe} --target=fs_label "${isopref}")
218 + [ "${label}" = "(null)" ] && label=${device}
219 + grub_string=$(prepare_grub_to_access_device "${device}" | grub_add_tab | grub_add_tab)
220 + longname="SystemRescueCD on ${label}"
221 +
222 + gettext_printf "Found %s on %s\n" "${longname}" "${device}" >&2
223 +
224 + write_srcd_submenu
225 +done
226
227 diff --git a/sys-boot/systemrescuecd-x86-grub/systemrescuecd-x86-grub-0.2.ebuild b/sys-boot/systemrescuecd-x86-grub/systemrescuecd-x86-grub-0.2.ebuild
228 new file mode 100644
229 index 00000000000..76daeb7ece1
230 --- /dev/null
231 +++ b/sys-boot/systemrescuecd-x86-grub/systemrescuecd-x86-grub-0.2.ebuild
232 @@ -0,0 +1,31 @@
233 +# Copyright 1999-2019 Gentoo Authors
234 +# Distributed under the terms of the GNU General Public License v2
235 +
236 +EAPI=7
237 +
238 +DESCRIPTION="Grub menu entries for the .iso image of systemrescuecd-x86"
239 +HOMEPAGE="http://www.sysresccd.org/"
240 +SRC_URI=""
241 +
242 +LICENSE="GPL-2"
243 +SLOT=0
244 +KEYWORDS="~amd64 ~x86"
245 +
246 +S="${WORKDIR}"
247 +
248 +RDEPEND="app-admin/systemrescuecd-x86
249 + sys-boot/grub"
250 +
251 +src_install() {
252 + exeinto /etc/grub.d
253 + newexe "${FILESDIR}"/systemrescuecd.grub-2 39_systemrescuecd
254 +
255 + insinto /etc/default
256 + newins "${FILESDIR}"/systemrescuecd.default-2 systemrescuecd
257 +}
258 +
259 +pkg_postinst() {
260 + elog "To add the menu entries for systemrescuecd to grub, you should now run"
261 + elog " grub-mkconfig -o /boot/grub/grub.cfg"
262 + elog "You can set custom bootoptions in /etc/default/systemrescuecd"
263 +}