- # install a kernel image
- echo -e "do_symlinks = yes\nlink_in_boot = yes\ndo_initrd = yes" > etc/kernel-img.conf &&
- chroot . apt-get install linux-image-2.6-amd64
-
+ # install a kernel image
+ cat > etc/kernel-img.conf << EOF &&
+do_symlinks = yes
+link_in_boot = yes
+do_initrd = yes
+EOF
+ chroot . apt-get install linux-image-2.6-amd64 &&
+ cat >> etc/kernel-img.conf << EOF
+postinst_hook = /usr/sbin/update-grub
+postrm_hook = /usr/sbin/update-grub
+EOF
+ else
+ cat > etc/kernel-img.conf << EOF &&
+do_symlinks = no
+do_initrd = yes
+EOF
+ chroot . apt-get install linux-image-2.6-amd64 &&
+ cat >> etc/kernel-img.conf << EOF
+postinst_hook = update-grub
+postrm_hook = update-grub
+EOF
+ chroot . apt-get install grub2 &&
+ cp -av $dev_root dev/ &&
+ echo "(hd0) /dev/`basename $dev_root`" > boot/grub/device.map &&
+ chroot . grub-install /dev/"`basename $dev_root`" &&
+ sed -i -e 's/^#GRUB_TERMINAL=console/GRUB_TERMINAL=console/' etc/default/grub &&
+ chroot . update-grub &&
+ rm -v dev/"`basename $dev_root`" boot/grub/device.map &&
+ sed -i -e "s#dev/`basename $dev_root`#dev/vda#g" boot/grub/grub.cfg
+ fi