1 |
commit: 09bfa95d154e09442f43e948c7b2823f27bf700c |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Nov 28 23:40:58 2011 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Nov 28 23:40:58 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/hardened-dev.git;a=commit;h=09bfa95d |
7 |
|
8 |
sys-boot/grub: workaround for no xattr support in portage's movefile.py |
9 |
|
10 |
--- |
11 |
HOWTO.txt | 28 ++-- |
12 |
sys-boot/grub/ChangeLog | 2 + |
13 |
sys-boot/grub/files/grub.conf.gentoo | 16 ++ |
14 |
sys-boot/grub/grub-0.97-r11.ebuild | 292 ++++++++++++++++++++++++++++++++++ |
15 |
sys-boot/grub/metadata.xml | 13 ++ |
16 |
5 files changed, 341 insertions(+), 10 deletions(-) |
17 |
|
18 |
diff --git a/HOWTO.txt b/HOWTO.txt |
19 |
index 8408ef4..b88816e 100644 |
20 |
--- a/HOWTO.txt |
21 |
+++ b/HOWTO.txt |
22 |
@@ -37,25 +37,34 @@ The goodies are in a branch of the hardened-development overlay: |
23 |
git checkout XT_PAX # switch branches |
24 |
git pull origin XT_PAX # and pull |
25 |
|
26 |
-2. We need to override portage's pax-utils.eclass with the overlay's eclass. |
27 |
+2. We need to override portage's pax-utils.eclass with the overlay's eclass, and |
28 |
+make sure that we've added extended attribute support to our use flags: |
29 |
|
30 |
-cat << EOF >> /etc/portage/repos.conf |
31 |
-[DEFAULT] |
32 |
-eclass-overrides = hardened-dev |
33 |
-EOF |
34 |
+ cat << EOF >> /etc/portage/repos.conf |
35 |
+ [DEFAULT] |
36 |
+ eclass-overrides = hardened-dev |
37 |
+ EOF |
38 |
+ |
39 |
+ echo "USE=\"\${USE} xattr\"" >> /etc/make.conf |
40 |
+ |
41 |
+There is still a problem with portage preserving xattrs, so the eclass's pax-mark |
42 |
+only works when called from pkg_postinst(), but we're working on fixing this! That's |
43 |
+what our hacked up grub does in the next step. |
44 |
|
45 |
3. Now let's emerge the stuff we'll need later: |
46 |
|
47 |
emerge =sys-devel/binutils-2.21.1-r2 \ # these are all masked so |
48 |
=sys-kernel/xtpax-sources-3.1.1 \ # we'll have to unmask them |
49 |
=sys-apps/elfix-0.3.2 \ |
50 |
+ =sys-boot/grub-0.97-r11 \ |
51 |
--autounmask-write |
52 |
|
53 |
etc-update # accept changes the changes |
54 |
|
55 |
emerge =sys-devel/binutils-2.21.1-r2 \ # these are unmasked, so emerge |
56 |
=sys-kernel/xtpax-sources-3.1.1 \ |
57 |
- =sys-apps/elfix-0.3.2 |
58 |
+ =sys-apps/elfix-0.3.2 \ |
59 |
+ =sys-boot/grub-0.97-r11 \ |
60 |
|
61 |
source /etc/profile # for binutils, if we keep using |
62 |
# the same shell |
63 |
@@ -144,15 +153,14 @@ you want to use. I also recommend xattr support on tmpfs: |
64 |
... |
65 |
|
66 |
3. Compile the kernel and boot. If you didn't install grub on the MBR before the |
67 |
-migration, do so now, but be extra careful to make sure it was properly pax marked |
68 |
-before runnign it from the command line. paxctl-ng -v /sbin/grub should give |
69 |
+migration, do so now. Make sure it was properly pax marked before running it from |
70 |
+the command line. paxctl-ng -v /sbin/grub should give |
71 |
|
72 |
/sbin/grub: |
73 |
PT_PAX: not found |
74 |
XT_PAX: --me-x |
75 |
|
76 |
-If it doesn't that may be because the eclass didn't properly pax mark it! Do so |
77 |
-manually if need be: |
78 |
+If it doesn't, then manually mark it using: |
79 |
|
80 |
paxctl-ng -cv /sbin/grub # To create the XT_PAX field |
81 |
paxctl-ng -mexv /sbin/grub # To properly mark it |
82 |
|
83 |
diff --git a/sys-boot/grub/ChangeLog b/sys-boot/grub/ChangeLog |
84 |
new file mode 100644 |
85 |
index 0000000..139597f |
86 |
--- /dev/null |
87 |
+++ b/sys-boot/grub/ChangeLog |
88 |
@@ -0,0 +1,2 @@ |
89 |
+ |
90 |
+ |
91 |
|
92 |
diff --git a/sys-boot/grub/files/grub.conf.gentoo b/sys-boot/grub/files/grub.conf.gentoo |
93 |
new file mode 100644 |
94 |
index 0000000..0027099 |
95 |
--- /dev/null |
96 |
+++ b/sys-boot/grub/files/grub.conf.gentoo |
97 |
@@ -0,0 +1,16 @@ |
98 |
+# This is a sample grub.conf for use with Genkernel, per the Gentoo handbook |
99 |
+# http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=10#doc_chap2 |
100 |
+# If you are not using Genkernel and you need help creating this file, you |
101 |
+# should consult the handbook. Alternatively, consult the grub.conf.sample that |
102 |
+# is included with the Grub documentation. |
103 |
+ |
104 |
+default 0 |
105 |
+timeout 30 |
106 |
+#splashimage=(hd0,0)/boot/grub/splash.xpm.gz |
107 |
+ |
108 |
+#title Gentoo Linux 2.6.24-r5 |
109 |
+#root (hd0,0) |
110 |
+#kernel /boot/kernel-genkernel-x86-2.6.24-gentoo-r5 root=/dev/ram0 real_root=/dev/sda3 |
111 |
+#initrd /boot/initramfs-genkernel-x86-2.6.24-gentoo-r5 |
112 |
+ |
113 |
+# vim:ft=conf: |
114 |
|
115 |
diff --git a/sys-boot/grub/grub-0.97-r11.ebuild b/sys-boot/grub/grub-0.97-r11.ebuild |
116 |
new file mode 100644 |
117 |
index 0000000..9bc167d |
118 |
--- /dev/null |
119 |
+++ b/sys-boot/grub/grub-0.97-r11.ebuild |
120 |
@@ -0,0 +1,292 @@ |
121 |
+# Copyright 1999-2011 Gentoo Foundation |
122 |
+# Distributed under the terms of the GNU General Public License v2 |
123 |
+# $Header: /var/cvsroot/gentoo-x86/sys-boot/grub/grub-0.97-r10.ebuild,v 1.11 2011/09/10 02:33:59 dirtyepic Exp $ |
124 |
+ |
125 |
+# XXX: we need to review menu.lst vs grub.conf handling. We've been converting |
126 |
+# all systems to grub.conf (and symlinking menu.lst to grub.conf), but |
127 |
+# we never updated any of the source code (it still all wants menu.lst), |
128 |
+# and there is no indication that upstream is making the transition. |
129 |
+ |
130 |
+# If you need to roll a new grub-static distfile, here is how. |
131 |
+# - Robin H. Johnson <robbat2@g.o> - 29 Nov 2010 |
132 |
+# USE='static -ncurses -netboot -custom-cflags' \ |
133 |
+# GRUB_STATIC_PACKAGE_BUILDING=1 ebuild \ |
134 |
+# grub-${PVR}.ebuild package && \ |
135 |
+# cp -f ${PKGDIR}/${CAT}/${PF}.tbz2 ${DISTDIR}/grub-static-${PVR}.tar.bz2 |
136 |
+ |
137 |
+inherit mount-boot eutils flag-o-matic toolchain-funcs autotools linux-info pax-utils |
138 |
+ |
139 |
+PATCHVER="1.11" # Should match the revision ideally |
140 |
+DESCRIPTION="GNU GRUB Legacy boot loader" |
141 |
+HOMEPAGE="http://www.gnu.org/software/grub/" |
142 |
+SRC_URI="mirror://gentoo/${P}.tar.gz |
143 |
+ ftp://alpha.gnu.org/gnu/${PN}/${P}.tar.gz |
144 |
+ mirror://gentoo/splash.xpm.gz |
145 |
+ mirror://gentoo/${P}-patches-${PATCHVER}.tar.bz2" |
146 |
+ |
147 |
+LICENSE="GPL-2" |
148 |
+SLOT="0" |
149 |
+KEYWORDS="~amd64 ~x86" |
150 |
+IUSE="custom-cflags ncurses netboot static" |
151 |
+ |
152 |
+RDEPEND="ncurses? ( |
153 |
+ >=sys-libs/ncurses-5.2-r5 |
154 |
+ amd64? ( app-emulation/emul-linux-x86-baselibs ) |
155 |
+ )" |
156 |
+DEPEND="${RDEPEND}" |
157 |
+ |
158 |
+pkg_setup() { |
159 |
+ local arch="$(tc-arch)" |
160 |
+ case ${arch} in |
161 |
+ amd64) CONFIG_CHECK='~IA32_EMULATION' check_extra_config ;; |
162 |
+ esac |
163 |
+} |
164 |
+ |
165 |
+src_unpack() { |
166 |
+ unpack ${A} |
167 |
+ cd "${S}" |
168 |
+ |
169 |
+ # patch breaks booting for some people #111885 |
170 |
+ rm "${WORKDIR}"/patch/400_*reiser4* |
171 |
+ |
172 |
+ # Grub will not handle a kernel larger than EXTENDED_MEMSIZE Mb as |
173 |
+ # discovered in bug 160801. We can change this, however, using larger values |
174 |
+ # for this variable means that Grub needs more memory to run and boot. For a |
175 |
+ # kernel of size N, Grub needs (N+1)*2. Advanced users should set a custom |
176 |
+ # value in make.conf, it is possible to make kernels ~16Mb in size, but it |
177 |
+ # needs the kitchen sink built-in. |
178 |
+ local t="custom" |
179 |
+ if [[ -z ${GRUB_MAX_KERNEL_SIZE} ]] ; then |
180 |
+ case $(tc-arch) in |
181 |
+ amd64) GRUB_MAX_KERNEL_SIZE=9 ;; |
182 |
+ x86) GRUB_MAX_KERNEL_SIZE=5 ;; |
183 |
+ esac |
184 |
+ t="default" |
185 |
+ fi |
186 |
+ einfo "Grub will support the ${t} maximum kernel size of ${GRUB_MAX_KERNEL_SIZE} Mb (GRUB_MAX_KERNEL_SIZE)" |
187 |
+ |
188 |
+ sed -i \ |
189 |
+ -e "/^#define.*EXTENDED_MEMSIZE/s,3,${GRUB_MAX_KERNEL_SIZE},g" \ |
190 |
+ "${S}"/grub/asmstub.c \ |
191 |
+ || die "Failed to hack memory size" |
192 |
+ |
193 |
+ if [[ -n ${PATCHVER} ]] ; then |
194 |
+ EPATCH_SUFFIX="patch" |
195 |
+ epatch "${WORKDIR}"/patch |
196 |
+ eautoreconf |
197 |
+ fi |
198 |
+} |
199 |
+ |
200 |
+src_compile() { |
201 |
+ filter-flags -fPIE #168834 |
202 |
+ |
203 |
+ use amd64 && multilib_toolchain_setup x86 |
204 |
+ |
205 |
+ unset BLOCK_SIZE #73499 |
206 |
+ |
207 |
+ ### i686-specific code in the boot loader is a bad idea; disabling to ensure |
208 |
+ ### at least some compatibility if the hard drive is moved to an older or |
209 |
+ ### incompatible system. |
210 |
+ |
211 |
+ # grub-0.95 added -fno-stack-protector detection, to disable ssp for stage2, |
212 |
+ # but the objcopy's (faulty) test fails if -fstack-protector is default. |
213 |
+ # create a cache telling configure that objcopy is ok, and add -C to econf |
214 |
+ # to make use of the cache. |
215 |
+ # |
216 |
+ # CFLAGS has to be undefined running econf, else -fno-stack-protector detection fails. |
217 |
+ # STAGE2_CFLAGS is not allowed to be used on emake command-line, it overwrites |
218 |
+ # -fno-stack-protector detected by configure, removed from netboot's emake. |
219 |
+ use custom-cflags || unset CFLAGS |
220 |
+ |
221 |
+ export grub_cv_prog_objcopy_absolute=yes #79734 |
222 |
+ use static && append-ldflags -static |
223 |
+ |
224 |
+ # Per bug 216625, the emul packages do not provide .a libs for performing |
225 |
+ # suitable static linking |
226 |
+ if use amd64 && use static ; then |
227 |
+ if [ -z "${GRUB_STATIC_PACKAGE_BUILDING}" ]; then |
228 |
+ die "You must use the grub-static package if you want a static Grub on amd64!" |
229 |
+ else |
230 |
+ eerror "You have set GRUB_STATIC_PACKAGE_BUILDING. This" |
231 |
+ eerror "is specifically intended for building the tarballs for the" |
232 |
+ eerror "grub-static package via USE='static -ncurses'." |
233 |
+ eerror "All bets are now off." |
234 |
+ ebeep 10 |
235 |
+ fi |
236 |
+ fi |
237 |
+ |
238 |
+ # build the net-bootable grub first, but only if "netboot" is set |
239 |
+ if use netboot ; then |
240 |
+ econf \ |
241 |
+ --libdir=/lib \ |
242 |
+ --datadir=/usr/lib/grub \ |
243 |
+ --exec-prefix=/ \ |
244 |
+ --disable-auto-linux-mem-opt \ |
245 |
+ --enable-diskless \ |
246 |
+ --enable-{3c{5{03,07,09,29,95},90x},cs89x0,davicom,depca,eepro{,100}} \ |
247 |
+ --enable-{epic100,exos205,ni5210,lance,ne2100,ni{50,65}10,natsemi} \ |
248 |
+ --enable-{ne,ns8390,wd,otulip,rtl8139,sis900,sk-g16,smc9000,tiara} \ |
249 |
+ --enable-{tulip,via-rhine,w89c840} || die "netboot econf failed" |
250 |
+ |
251 |
+ emake w89c840_o_CFLAGS="-O" || die "making netboot stuff" |
252 |
+ |
253 |
+ mv -f stage2/{nbgrub,pxegrub} "${S}"/ |
254 |
+ mv -f stage2/stage2 stage2/stage2.netboot |
255 |
+ |
256 |
+ make clean || die "make clean failed" |
257 |
+ fi |
258 |
+ |
259 |
+ # Now build the regular grub |
260 |
+ # Note that FFS and UFS2 support are broken for now - stage1_5 files too big |
261 |
+ econf \ |
262 |
+ --libdir=/lib \ |
263 |
+ --datadir=/usr/lib/grub \ |
264 |
+ --exec-prefix=/ \ |
265 |
+ --disable-auto-linux-mem-opt \ |
266 |
+ $(use_with ncurses curses) \ |
267 |
+ || die "econf failed" |
268 |
+ |
269 |
+ # sanity check due to common failure |
270 |
+ use ncurses && ! grep -qs "HAVE_LIBCURSES.*1" config.h && die "USE=ncurses but curses not found" |
271 |
+ |
272 |
+ emake || die "making regular stuff" |
273 |
+} |
274 |
+ |
275 |
+src_test() { |
276 |
+ # non-default block size also give false pass/fails. |
277 |
+ unset BLOCK_SIZE |
278 |
+ make check || die "make check failed" |
279 |
+} |
280 |
+ |
281 |
+src_install() { |
282 |
+ emake DESTDIR="${D}" install || die |
283 |
+ if use netboot ; then |
284 |
+ exeinto /usr/lib/grub/${CHOST} |
285 |
+ doexe nbgrub pxegrub stage2/stage2.netboot || die "netboot install" |
286 |
+ fi |
287 |
+ |
288 |
+ dodoc AUTHORS BUGS ChangeLog NEWS README THANKS TODO |
289 |
+ newdoc docs/menu.lst grub.conf.sample |
290 |
+ dodoc "${FILESDIR}"/grub.conf.gentoo |
291 |
+ prepalldocs |
292 |
+ |
293 |
+ [ -n "${GRUB_STATIC_PACKAGE_BUILDING}" ] && \ |
294 |
+ mv \ |
295 |
+ "${D}"/usr/share/doc/${PF} \ |
296 |
+ "${D}"/usr/share/doc/grub-static-${PF/grub-} |
297 |
+ |
298 |
+ insinto /usr/share/grub |
299 |
+ doins "${DISTDIR}"/splash.xpm.gz |
300 |
+} |
301 |
+ |
302 |
+setup_boot_dir() { |
303 |
+ local boot_dir=$1 |
304 |
+ local dir=${boot_dir} |
305 |
+ |
306 |
+ mkdir -p "${dir}" |
307 |
+ [[ ! -L ${dir}/boot ]] && ln -s . "${dir}/boot" |
308 |
+ dir="${dir}/grub" |
309 |
+ if [[ ! -e ${dir} ]] ; then |
310 |
+ mkdir "${dir}" || die "${dir} does not exist!" |
311 |
+ fi |
312 |
+ |
313 |
+ # change menu.lst to grub.conf |
314 |
+ if [[ ! -e ${dir}/grub.conf ]] && [[ -e ${dir}/menu.lst ]] ; then |
315 |
+ mv -f "${dir}"/menu.lst "${dir}"/grub.conf |
316 |
+ ewarn |
317 |
+ ewarn "*** IMPORTANT NOTE: menu.lst has been renamed to grub.conf" |
318 |
+ ewarn |
319 |
+ fi |
320 |
+ |
321 |
+ if [[ ! -e ${dir}/menu.lst ]]; then |
322 |
+ einfo "Linking from new grub.conf name to menu.lst" |
323 |
+ ln -snf grub.conf "${dir}"/menu.lst |
324 |
+ fi |
325 |
+ |
326 |
+ if [[ -e ${dir}/stage2 ]] ; then |
327 |
+ mv "${dir}"/stage2{,.old} |
328 |
+ ewarn "*** IMPORTANT NOTE: you must run grub and install" |
329 |
+ ewarn "the new version's stage1 to your MBR. Until you do," |
330 |
+ ewarn "stage1 and stage2 will still be the old version, but" |
331 |
+ ewarn "later stages will be the new version, which could" |
332 |
+ ewarn "cause problems such as an unbootable system." |
333 |
+ ewarn "This means you must use either grub-install or perform" |
334 |
+ ewarn "root/setup manually! For more help, see the handbook:" |
335 |
+ ewarn "http://www.gentoo.org/doc/en/handbook/handbook-${ARCH}.xml?part=1&chap=10#grub-install-auto" |
336 |
+ ebeep |
337 |
+ fi |
338 |
+ |
339 |
+ einfo "Copying files from /lib/grub, /usr/lib/grub and /usr/share/grub to ${dir}" |
340 |
+ for x in \ |
341 |
+ "${ROOT}"/lib*/grub/*/* \ |
342 |
+ "${ROOT}"/usr/lib*/grub/*/* \ |
343 |
+ "${ROOT}"/usr/share/grub/* ; do |
344 |
+ [[ -f ${x} ]] && cp -p "${x}" "${dir}"/ |
345 |
+ done |
346 |
+ |
347 |
+ if [[ ! -e ${dir}/grub.conf ]] ; then |
348 |
+ s="${ROOT}/usr/share/doc/${PF}/grub.conf.gentoo" |
349 |
+ [[ -e "${s}" ]] && cat "${s}" >${dir}/grub.conf |
350 |
+ [[ -e "${s}.gz" ]] && zcat "${s}.gz" >${dir}/grub.conf |
351 |
+ [[ -e "${s}.bz2" ]] && bzcat "${s}.bz2" >${dir}/grub.conf |
352 |
+ fi |
353 |
+ |
354 |
+ # Per bug 218599, we support grub.conf.install for users that want to run a |
355 |
+ # specific set of Grub setup commands rather than the default ones. |
356 |
+ grub_config=${dir}/grub.conf.install |
357 |
+ [[ -e ${grub_config} ]] || grub_config=${dir}/grub.conf |
358 |
+ if [[ -e ${grub_config} ]] ; then |
359 |
+ egrep \ |
360 |
+ -v '^[[:space:]]*(#|$|default|fallback|initrd|password|splashimage|timeout|title)' \ |
361 |
+ "${grub_config}" | \ |
362 |
+ /sbin/grub --batch \ |
363 |
+ --device-map="${dir}"/device.map \ |
364 |
+ > /dev/null |
365 |
+ fi |
366 |
+ |
367 |
+ # the grub default commands silently piss themselves if |
368 |
+ # the default file does not exist ahead of time |
369 |
+ if [[ ! -e ${dir}/default ]] ; then |
370 |
+ grub-set-default --root-directory="${boot_dir}" default |
371 |
+ fi |
372 |
+ einfo "Grub has been installed to ${boot_dir} successfully." |
373 |
+} |
374 |
+ |
375 |
+pkg_postinst() { |
376 |
+ mount-boot_mount_boot_partition |
377 |
+ |
378 |
+ # bug 330745 |
379 |
+ # must be pax-marked before setup_boot_dir |
380 |
+ pax-mark -m "${D}"/sbin/grub |
381 |
+ |
382 |
+ if [[ -n ${DONT_MOUNT_BOOT} ]]; then |
383 |
+ elog "WARNING: you have DONT_MOUNT_BOOT in effect, so you must apply" |
384 |
+ elog "the following instructions for your /boot!" |
385 |
+ elog "Neglecting to do so may cause your system to fail to boot!" |
386 |
+ elog |
387 |
+ else |
388 |
+ setup_boot_dir "${ROOT}"/boot |
389 |
+ # Trailing output because if this is run from pkg_postinst, it gets mixed into |
390 |
+ # the other output. |
391 |
+ einfo "" |
392 |
+ fi |
393 |
+ elog "To interactively install grub files to another device such as a USB" |
394 |
+ elog "stick, just run the following and specify the directory as prompted:" |
395 |
+ elog " emerge --config =${PF}" |
396 |
+ elog "Alternately, you can export GRUB_ALT_INSTALLDIR=/path/to/use to tell" |
397 |
+ elog "grub where to install in a non-interactive way." |
398 |
+ |
399 |
+ # needs to be after we call setup_boot_dir |
400 |
+ mount-boot_pkg_postinst |
401 |
+} |
402 |
+ |
403 |
+pkg_config() { |
404 |
+ local dir |
405 |
+ if [ ! -d "${GRUB_ALT_INSTALLDIR}" ]; then |
406 |
+ einfo "Enter the directory where you want to setup grub:" |
407 |
+ read dir |
408 |
+ else |
409 |
+ dir="${GRUB_ALT_INSTALLDIR}" |
410 |
+ fi |
411 |
+ setup_boot_dir "${dir}" |
412 |
+} |
413 |
|
414 |
diff --git a/sys-boot/grub/metadata.xml b/sys-boot/grub/metadata.xml |
415 |
new file mode 100644 |
416 |
index 0000000..dca555e |
417 |
--- /dev/null |
418 |
+++ b/sys-boot/grub/metadata.xml |
419 |
@@ -0,0 +1,13 @@ |
420 |
+<?xml version="1.0" encoding="UTF-8"?> |
421 |
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> |
422 |
+<pkgmetadata> |
423 |
+<herd>base-system</herd> |
424 |
+<use> |
425 |
+ <flag name='device-mapper'> |
426 |
+ Enable support for <pkg>sys-fs/device-mapper</pkg> |
427 |
+ </flag> |
428 |
+ <flag name='efiemu'> |
429 |
+ Build and install the efiemu runtimes |
430 |
+ </flag> |
431 |
+</use> |
432 |
+</pkgmetadata> |