42 |
local grubopts |
local grubopts |
43 |
local OLD_IFS |
local OLD_IFS |
44 |
local grubconf="/boot/grub/grub.conf" |
local grubconf="/boot/grub/grub.conf" |
45 |
|
local grub2conf="/boot/grub/grub.cfg" |
46 |
|
local pass |
47 |
|
|
48 |
KERNEL_IMAGE="$1" |
KERNEL_IMAGE="$1" |
49 |
KERNEL_DESCRIPTION="$2" |
KERNEL_DESCRIPTION="$2" |
57 |
|
|
58 |
[ -z "${KERNEL_DESCRIPTION}" ] && KERNEL_DESCRIPTION="${KERNEL_IMAGE}" |
[ -z "${KERNEL_DESCRIPTION}" ] && KERNEL_DESCRIPTION="${KERNEL_IMAGE}" |
59 |
|
|
|
if [ ! -f ${grubconf} ] |
|
|
then |
|
|
echo "${grubconf} not found" |
|
|
return 1 |
|
|
fi |
|
|
|
|
|
# first of all get the first rootfs instance |
|
|
for i in $(< ${grubconf}) |
|
|
do |
|
|
rootfs="$(echo ${i} | grep root=)" |
|
|
[[ -n ${rootfs} ]] && break |
|
|
done |
|
|
|
|
|
# then get the grub-root |
|
|
OLD_IFS="$IFS" |
|
|
IFS=$'\n' |
|
|
for i in $(< ${grubconf}) |
|
|
do |
|
|
grubroot="$(echo ${i} | grep 'root (' | cut -d' ' -f2)" |
|
|
[[ -n ${grubroot} ]] && break |
|
|
done |
|
|
IFS="${OLD_IFS}" |
|
|
|
|
60 |
# check for special hardware |
# check for special hardware |
61 |
if [[ -x $(which hwinfo) ]] |
if [[ -x $(which hwinfo) ]] |
62 |
then |
then |
68 |
fi |
fi |
69 |
fi |
fi |
70 |
|
|
71 |
# fix description |
# grub2 |
72 |
: > ${grubconf} |
if [[ -x /sbin/grub-mkconfig ]] |
73 |
echo "default 0" >> ${grubconf} |
then |
74 |
echo "timeout 3" >> ${grubconf} |
# create a device.map |
75 |
# using roots current password |
if [[ ! -f /boot/grub/device.map ]] |
76 |
echo "password --md5 $(cat /etc/shadow | grep root | cut -d: -f2)" >> ${grubconf} |
then |
77 |
echo >> ${grubconf} |
grub-mkdevicemap |
78 |
echo "# normal boot" >> ${grubconf} |
fi |
79 |
echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf} |
|
80 |
echo "root ${grubroot}" >> ${grubconf} |
# needed by grub-mkconfig on the first run |
81 |
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts}" >> ${grubconf} |
if [[ ! -f /boot/grub/video.lst ]] |
82 |
echo >> ${grubconf} |
then |
83 |
echo "# admin boots" >> ${grubconf} |
install -m0644 /$(mlibdir)/grub/*/video.lst /boot/grub/video.lst |
84 |
echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf} |
fi |
85 |
echo "lock" >> ${grubconf} |
|
86 |
echo "root ${grubroot}" >> ${grubconf} |
# fix grubconfig for special devices |
87 |
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} hardware-auto-detection" >> ${grubconf} |
if [[ -n ${grubopts} ]] |
88 |
echo >> ${grubconf} |
then |
89 |
echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf} |
sed -i "s:^\(export GRUB_CMDLINE_LINUX=\).*:\1\"${grubopts}\":" /etc/conf.d/grub |
90 |
echo "lock" >> ${grubconf} |
fi |
91 |
echo "root ${grubroot}" >> ${grubconf} |
|
92 |
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} alx-reset-settings" >> ${grubconf} |
# update grub.cfg |
93 |
|
LC_ALL=C grub-mkconfig -o ${grub2conf} |
94 |
|
|
95 |
|
# install bootloader to disk |
96 |
|
#local bootpartition="$(df -h /boot |(read; awk '{print $1; exit}'))" |
97 |
|
local bootdisk |
98 |
|
bootdisk="$(grub-probe --target=drive /boot | sed 's:(\(.*\),.*):(\1):')" |
99 |
|
|
100 |
|
# Generate core.img, but don't let it be installed in boot sector |
101 |
|
grub-install --no-floppy "${bootdisk}" |
102 |
|
|
103 |
|
# grub legacy |
104 |
|
else |
105 |
|
|
106 |
|
if [ ! -f ${grubconf} ] |
107 |
|
then |
108 |
|
echo "${grubconf} not found" |
109 |
|
return 1 |
110 |
|
fi |
111 |
|
|
112 |
|
# first of all get the first rootfs instance |
113 |
|
for i in $(< ${grubconf}) |
114 |
|
do |
115 |
|
rootfs="$(echo ${i} | grep root=)" |
116 |
|
[[ -n ${rootfs} ]] && break |
117 |
|
done |
118 |
|
|
119 |
|
# then get the grub-root |
120 |
|
OLD_IFS="$IFS" |
121 |
|
IFS=$'\n' |
122 |
|
for i in $(< ${grubconf}) |
123 |
|
do |
124 |
|
grubroot="$(echo ${i} | grep 'root (' | cut -d' ' -f2)" |
125 |
|
[[ -n ${grubroot} ]] && break |
126 |
|
done |
127 |
|
IFS="${OLD_IFS}" |
128 |
|
|
129 |
|
# fix description |
130 |
|
: > ${grubconf} |
131 |
|
echo "default 0" >> ${grubconf} |
132 |
|
echo "timeout 3" >> ${grubconf} |
133 |
|
# using roots current password if one was set |
134 |
|
pass="$(grep '^root:' /etc/shadow | cut -d: -f2)" |
135 |
|
# or fallback to a default password |
136 |
|
[[ -z ${pass} ]] && pass="$1$oc/rCMuc$ZodLQSj6N5zYIJtOBg.RT/" |
137 |
|
echo "password --md5 ${pass}" >> ${grubconf} |
138 |
|
echo >> ${grubconf} |
139 |
|
echo "# normal boot" >> ${grubconf} |
140 |
|
echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf} |
141 |
|
echo "root ${grubroot}" >> ${grubconf} |
142 |
|
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts}" >> ${grubconf} |
143 |
|
echo >> ${grubconf} |
144 |
|
echo "# admin boots" >> ${grubconf} |
145 |
|
echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf} |
146 |
|
echo "lock" >> ${grubconf} |
147 |
|
echo "root ${grubroot}" >> ${grubconf} |
148 |
|
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} hardware-auto-detection" >> ${grubconf} |
149 |
|
echo >> ${grubconf} |
150 |
|
echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf} |
151 |
|
echo "lock" >> ${grubconf} |
152 |
|
echo "root ${grubroot}" >> ${grubconf} |
153 |
|
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} alx-reset-settings" >> ${grubconf} |
154 |
|
fi |
155 |
} |
} |
156 |
|
|
157 |
## compat |
## compat |