]> Raphaƫl G. Git Repositories - distgen/blob - lib/boot.sh
021a3841d1ff25421cce3086bfa1a735909b958c
[distgen] / lib / boot.sh
1 #! /bin/sh -e
2
3 # Bind mount /dev
4 mount --bind /dev ${MOUNTPOINT}/dev
5
6 # Backup old mtab
7 mv ${MOUNTPOINT}/etc/mtab ${MOUNTPOINT}/etc/mtab.orig
8
9 # Create new mtab
10 #cat /proc/self/mounts | grep -E '^(/dev/m|devtmpfs)' | perl -pne 's%/media(/?)%$1%' | sort | uniq > /media/etc/mtab
11 perl -pne "/^(devtmpfs \\/dev|\\/dev\\/(md|dm|mapper))/ || undef \$_; s%${MOUNTPOINT}/?%/%" /proc/self/mounts > ${MOUNTPOINT}/etc/mtab
12
13 # Backup old device.map
14 mv ${MOUNTPOINT}/boot/grub/device.map ${MOUNTPOINT}/boot/grub/device.map.orig
15
16 # Install grub
17 for i in $LOOPB $LOOPA; do
18 # Create new device map
19 echo "(hd0) $i" > ${MOUNTPOINT}/boot/grub/device.map
20
21 # Fix grub
22 #XXX: e2fs_stage1_5 is 20 sectors embedded, but it fail with gpt
23 #XXX: we use install command directly instead of setup (hd0) because it fail with loop
24 cat << EOF | chroot ${MOUNTPOINT} grub --device-map=/boot/grub/device.map
25 root (hd0,0)
26 install --stage2=/boot/grub/stage2 /grub/stage1 (hd0) /grub/stage2 p /grub/menu.lst
27 EOF
28 done
29
30 # Restore old device.map
31 mv -f ${MOUNTPOINT}/boot/grub/device.map.orig ${MOUNTPOINT}/boot/grub/device.map
32
33 # Bind mount /proc
34 mount --bind /proc ${MOUNTPOINT}/proc
35
36 # Bind mount /sys
37 mount --bind /sys ${MOUNTPOINT}/sys
38
39 # Extract last kernel version
40 KVER=`chroot ${MOUNTPOINT} rpm -qa | perl -pne '/kernel-server-latest/||undef $_;s%^kernel-(server)-latest-([^-]+)-(.+)$%\2-\1-\3%'`
41 # Regenerate initrd
42 #XXX: force non hostonly else it don't store commandline : rd.luks.uuid rd.md.uuid ip=dhcp rd.neednet=1
43 DRACUT_SKIP_FORCED_NON_HOSTONLY=1 chroot ${MOUNTPOINT} mkinitrd -f /boot/initrd-${KVER}.img ${KVER}
44
45 # Umount dev
46 umount ${MOUNTPOINT}/sys
47
48 # Umount dev
49 umount ${MOUNTPOINT}/proc
50
51 # Umount dev
52 umount ${MOUNTPOINT}/dev
53
54 # Reset mtab
55 mv -f ${MOUNTPOINT}/etc/mtab.orig ${MOUNTPOINT}/etc/mtab
56
57 # Umount boot
58 umount ${MOUNTPOINT}/boot