-
Notifications
You must be signed in to change notification settings - Fork 41
/
create-grub-dir.sh
executable file
·73 lines (57 loc) · 2.4 KB
/
create-grub-dir.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Filename: create-grub-dir.sh
# Purpose: generate core.img and according files for templates/boot/grub/
# Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2 or any later version.
# Latest change: Thu Mar 11 14:25:15 CET 2010 [mika]
################################################################################
# This script is very hackish due to the way the grub directory has to be
# generated. :-/ The script is meant to be executed on a Debian system that
# matches the grub version, otherwise the execution of grub-mkimage *might* fail.
# So if you want to use a recent Grub version make sure you execute this script
# on an up2date Debian/unstable system.
################################################################################
set -e
if [ -z "$1" ] ; then
echo "Usage: $0 <grub-version>">&2
echo "Usage example: $0 1.98-1">&2
exit 1
fi
if [ -d grub ] ; then
echo "Directory 'grub' exists in current working directory already, will not continue.">&2
exit 1
fi
GRUB="$1"
oldpwd=$(pwd)
ARCH=$(dpkg --print-architecture)
if ! [ -f "grub-pc_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-common_${GRUB}_${ARCH}.deb" ] ; then
wget http://cdn.debian.net/debian/pool/main/g/grub2/grub-pc_"${GRUB}"_${ARCH}.deb
wget http://cdn.debian.net/debian/pool/main/g/grub2/grub-common_"${GRUB}"_${ARCH}.deb
fi
if ! [ -f "grub-pc_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-common_${GRUB}_${ARCH}.deb" ] ; then
echo "Error reading grub files version $GRUB - exiting.">&2
exit 1
fi
GRUBDIR=$(mktemp -d)
echo "Using temporary directory $GRUBDIR"
cd "$GRUBDIR"
mkdir -p grub
ar x "${oldpwd}"/"grub-pc_${GRUB}_${ARCH}.deb"
tar xzf data.tar.gz
ar x "${oldpwd}"/"grub-common_${GRUB}_${ARCH}.deb"
tar xzf data.tar.gz
if ./usr/bin/grub-mkimage --help | grep -q -- --format ; then
./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o core.img biosdisk iso9660 --format=i386-pc
else
./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o core.img biosdisk iso9660
fi
for a in usr/lib/grub/*-pc/{*.mod,efiemu??.o,command.lst,moddep.lst,fs.lst,handler.lst,parttool.lst}; do \
[[ -e $a ]] && cp $a grub/
done
mv core.img grub/
cd "$oldpwd"
mv "${GRUBDIR}"/grub .
rm -rf "$GRUBDIR"
echo "Generated new grub boot directory 'grub'."
## END OF FILE #################################################################