+# update device map if possible
+if [ "x$GRUB2" = "xno" ]; then
+ # Grub1 part
+ if [ -f "$device_map" ]; then
+ mv -f "$device_map" "$device_map.old"
+ fi
+ grub --batch --no-floppy --device-map="$device_map" <<'EOF' >/dev/null 2>&1
+quit
+EOF
+ if [ ! -s "$device_map" ]; then
+ if [ -f "$device_map.old" ]; then
+ mv -f "$device_map.old" "$device_map"
+ fi
+
+ else
+ rm -f "$device_map.old"
+ fi
+else
+ # Grub2 part
+ grub-mkdevicemap --no-floppy
+ grub-install --no-floppy --grub-setup=/bin/true "$(grub-probe -t drive /boot/grub)" >/dev/null 2>&1
+fi
+echo -n " grub3"
+
+# import GRUB helper functions (again, updated device map)
+. /usr/share/kernel-2.6-cn/grub-functions.sh
+
+if [ "x$GRUB2" = "xno" ]; then
+ # Grub1 part
+ # get install device (0x80 BIOS device)
+ install_device=$(grep '^(hd0)' "$device_map" | \
+ sed -e 's%[^[:space:]]*[[:space:]]*\([^[:space:]]*\)%\1%')
+ if [ -z "$install_device" ]; then
+ echo "."
+ echo "CN: FATAL ERROR while detecting boot disk!"
+ echo "CN: Do not reboot your server and report this to OTRS immediately!"
+ exit 1
+ fi
+
+ # oops, install device is a symlink...
+ if [ -h "$install_device" ]; then
+ install_device_resolved=$(resolve_symlink "$install_device")
+ if [ -z "$install_device_resolved" ]; then
+ install_device_resolved="$install_device"
+ fi
+
+ # try to fix device map with symlink resolved device
+ if [ "x$install_device_resolved" != "x$install_device" ]; then
+ cp_check_and_sed '^\(hd0\)' \
+ "s;^(hd0).*;(hd0) $install_device_resolved;" "$device_map" \
+ || true
+ fi
+ fi
+else
+ # Grub2 part
+ install_device="(hd0)"
+fi
+echo -n " grub4"
+
+# install GRUB loader
+# this will work for both Grub1 and Grub2
+if ! grub-install --no-floppy "$install_device" >/dev/null 2>&1; then