[Dextrose] [PATCH v2 dextrose 2/3] Add support for installing grub

Sascha Silbe silbe at activitycentral.com
Mon Mar 5 13:31:36 EST 2012


Installing a boot loader is a prerequisite for booting the resulting OS
image in a VM or on a regular (i.e. non-XO) x86 PC.

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
 v1->v2: no changes

 modules/base/kspost.10.core.inc              |    3 ---
 modules/sd_card_image/defaults.ini           |    1 +
 modules/sd_card_image/image.50.makefs.sh     |   25 +++++++++++++++++++++++++
 modules/sd_card_image/kspkglist.15.sdcard.sh |   10 ++++++++++
 4 files changed, 36 insertions(+), 3 deletions(-)
 create mode 100644 modules/sd_card_image/kspkglist.15.sdcard.sh

diff --git a/modules/base/kspost.10.core.inc b/modules/base/kspost.10.core.inc
index 9b698f3..81370df 100644
--- a/modules/base/kspost.10.core.inc
+++ b/modules/base/kspost.10.core.inc
@@ -169,9 +169,6 @@ echo "AUTOCREATE_SERVER_KEYS=RSAONLY" >> /etc/sysconfig/sshd
 # this hack can be removed when util-linux-2.20 is included. (#10605)
 echo UTC >> /etc/adjtime

-# not used, takes up a little space
-rm -rf /boot/grub
-
 # files with 000 permissions can't be served by updates.laptop.org (#10843)
 find / -xdev -type f -perm 000 -exec chmod 400 {} +

diff --git a/modules/sd_card_image/defaults.ini b/modules/sd_card_image/defaults.ini
index 75f39f6..bff83fb 100644
--- a/modules/sd_card_image/defaults.ini
+++ b/modules/sd_card_image/defaults.ini
@@ -2,4 +2,5 @@
 keep_disk_image=0
 compress_disk_image=1
 make_zd=1
+install_grub=0

diff --git a/modules/sd_card_image/image.50.makefs.sh b/modules/sd_card_image/image.50.makefs.sh
index 4fdc677..a41518e 100644
--- a/modules/sd_card_image/image.50.makefs.sh
+++ b/modules/sd_card_image/image.50.makefs.sh
@@ -4,6 +4,8 @@
 . $OOB__shlib
 versioned_fs=$(read_config base versioned_fs)
 buildnr=$(read_buildnr)
+install_grub=$(read_config sd_card_image install_grub)
+GRUB_DATA_DIR=/usr/share/grub/i386-redhat
 BLOCK_SIZE=512
 NUM_HEADS=16
 NUM_SECTORS_PER_TRACK=62
@@ -57,6 +59,9 @@ EOF
 	echo "(1 losetup error is normal here)"
 	losetup -d /dev/loop7 || :
 	losetup -o $(((8192 + 131072) * $BLOCK_SIZE)) --sizelimit $(($img_sectors * $BLOCK_SIZE)) /dev/loop7 $img
+	echo "(1 losetup error is normal here)"
+	losetup -d /dev/loop5 || :
+	losetup /dev/loop5 $img

 	echo "Create filesystems..."
 	mkfs.ext4 -O dir_index,^huge_file -E resize=8G -m1 -L OLPCRoot /dev/loop7
@@ -95,8 +100,28 @@ EOF
 		ln -s . $BOOT/boot
 	fi

+	if [ "$install_grub" = 1 ]; then
+		cp "${GRUB_DATA_DIR}"/{stage1,stage2,*stage1_5} $BOOT/grub/
+		ln -s grub.conf $BOOT/grub/menu.lst
+		cat > $BOOT/grub/grub.conf <<-EOF
+			timeout 2
+			default 0
+			root (hd0,0)
+
+			title $(cat "$ROOT"/etc/fedora-release)
+			kernel /$(basename "$BOOT"/vmlinuz-*) root=LABEL=OLPCRoot selinux=0 vga=0x31b
+			initrd /$(basename "$BOOT"/initramfs-*.img)
+		EOF
+		sudo grub --batch --no-floppy <<-EOF
+			device (hd0) /dev/loop5
+			root (hd0,0)
+			setup --stage2=${BOOT}/grub/stage2 --prefix=/grub (hd0)
+		EOF
+	fi
+
 	umount $BOOT
 	umount $ROOT
+	losetup -d /dev/loop5 || :
 	losetup -d /dev/loop6 || :
 	losetup -d /dev/loop7 || :

diff --git a/modules/sd_card_image/kspkglist.15.sdcard.sh b/modules/sd_card_image/kspkglist.15.sdcard.sh
new file mode 100644
index 0000000..e55544f
--- /dev/null
+++ b/modules/sd_card_image/kspkglist.15.sdcard.sh
@@ -0,0 +1,10 @@
+# Licensed under the terms of the GNU GPL v2 or later; see COPYING for details.
+
+. $OOB__shlib
+install_grub=$(read_config sd_card_image install_grub)
+
+if [ "$install_grub" = 1 ]; then
+	echo grub
+else
+	echo -grub
+fi
--
1.7.9



More information about the Dextrose mailing list