# Bind mount /dev
mount --bind /dev ${MOUNTPOINT}/dev
+# Bind mount /proc
+mount --bind /proc ${MOUNTPOINT}/proc
+
+# Bind mount /sys
+mount --bind /sys ${MOUNTPOINT}/sys
+
# Backup old mtab
mv ${MOUNTPOINT}/etc/mtab ${MOUNTPOINT}/etc/mtab.orig
#cat /proc/self/mounts | grep -E '^(/dev/m|devtmpfs)' | perl -pne 's%/media(/?)%$1%' | sort | uniq > /media/etc/mtab
perl -pne "/^(devtmpfs \\/dev|\\/dev\\/(md|dm|mapper))/ || undef \$_; s%${MOUNTPOINT}/?%/%" /proc/self/mounts > ${MOUNTPOINT}/etc/mtab
-# Backup old device.map
-mv ${MOUNTPOINT}/boot/grub/device.map ${MOUNTPOINT}/boot/grub/device.map.orig
-
-# Install grub
-for i in $LOOPB $LOOPA; do
- # Create new device map
- echo "(hd0) $i" > ${MOUNTPOINT}/boot/grub/device.map
-
- # Fix grub
- #XXX: e2fs_stage1_5 is 20 sectors embedded, but it fail with gpt
- #XXX: we use install command directly instead of setup (hd0) because it fail with loop
- cat << EOF | chroot ${MOUNTPOINT} grub --device-map=/boot/grub/device.map
-root (hd0,0)
-install --stage2=/boot/grub/stage2 /grub/stage1 (hd0) /grub/stage2 p /grub/menu.lst
-EOF
-done
+# Extract last kernel version
+KVER=`chroot ${MOUNTPOINT} rpm -qa | perl -pne '/kernel-server-latest/||undef $_;s%^kernel-(server)-latest-([^-]+)-(.+)$%\2-\1-\3%'`
-# Restore old device.map
-mv -f ${MOUNTPOINT}/boot/grub/device.map.orig ${MOUNTPOINT}/boot/grub/device.map
+# Retrieve mdboot and mddata uuids
+MDBOOTUUID=`mdadm --detail /dev/md/${MDBOOT} | perl -pne '/UUID\s:\s/||undef $_;s/^\s+UUID\s:\s//'`
+MDDATAUUID=`mdadm --detail /dev/md/${MDDATA} | perl -pne '/UUID\s:\s/||undef $_;s/^\s+UUID\s:\s//'`
-# Bind mount /proc
-mount --bind /proc ${MOUNTPOINT}/proc
+# Regenerate initrd
+#XXX: request a non hostonly to get all kernel modules
+#XXX: provide devices uuid to have md and luks ready
+#XXX: force crypttab presence, mandatory to unlocking
+#XXX: you may add ip=dhcp rd.neednet=1 for debug purpose
+chroot ${MOUNTPOINT} dracut -f -N --fstab --hostonly-cmdline --kernel-cmdline 'rd.luks.uuid='$LUKSDATAUUID' rd.md.uuid='$MDBOOTUUID' rd.md.uuid='$MDDATAUUID -I /etc/crypttab /boot/initrd-${KVER}.img ${KVER}
-# Bind mount /sys
-mount --bind /sys ${MOUNTPOINT}/sys
+# Generate grub config
+chroot ${MOUNTPOINT} grub2-mkconfig -o /boot/grub2/grub.cfg
-# Extract last kernel version
-KVER=`chroot ${MOUNTPOINT} rpm -qa | perl -pne '/kernel-server-latest/||undef $_;s%^kernel-(server)-latest-([^-]+)-(.+)$%\2-\1-\3%'`
-# Regenerate initrd
-#XXX: force non hostonly else it don't store commandline : rd.luks.uuid rd.md.uuid ip=dhcp rd.neednet=1
-DRACUT_SKIP_FORCED_NON_HOSTONLY=1 chroot ${MOUNTPOINT} mkinitrd -f /boot/initrd-${KVER}.img ${KVER}
+# Install grub
+for i in $LOOPB $LOOPA; do
+ chroot ${MOUNTPOINT} grub2-install $i
+done
# Umount dev
umount ${MOUNTPOINT}/sys
# Reset mtab
mv -f ${MOUNTPOINT}/etc/mtab.orig ${MOUNTPOINT}/etc/mtab
+# Umount mysql
+umount ${MOUNTPOINT}/var/lib/mysql
+
+# Umount mail
+umount ${MOUNTPOINT}/var/spool/mail
+
+# Umount home
+umount ${MOUNTPOINT}/home
+
# Umount boot
umount ${MOUNTPOINT}/boot