[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] grub support for usb-hdd images



Pls consider the following patches implementing grub support when creating usb-hdd disk images.

The second patch introduces some additional modifications preventing the parted errors, but requires parted to support disk images directly. I wonder if this is available in all systems live-helper supports.

Best regards

Luigi
diff -U 3 -d -r -N -x .svn -- HEAD/functions/defaults.sh Patched/functions/defaults.sh
--- HEAD/functions/defaults.sh	2010-01-21 17:39:15.000000000 +0100
+++ Patched/functions/defaults.sh	2010-01-20 17:38:28.000000000 +0100
@@ -1039,7 +1039,7 @@
 	then
 		# grub or yaboot + usb-hdd
 		case "${LH_BOOTLOADER}" in
-			grub|yaboot)
+			grub2|yaboot)
 				Echo_error "You have selected a combination of bootloader and image type that is currently not supported by live-helper. Please use either another bootloader or a different image type."
 				exit 1
 				;;
diff -U 3 -d -r -N -x .svn -- HEAD/helpers/lh_binary_usb-hdd Patched/helpers/lh_binary_usb-hdd
--- HEAD/helpers/lh_binary_usb-hdd	2010-01-21 17:38:53.000000000 +0100
+++ Patched/helpers/lh_binary_usb-hdd	2010-01-22 17:16:05.000000000 +0100
@@ -147,6 +147,7 @@
 		Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
 		Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
 		Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
+		Chroot chroot "parted -s ${FREELO} mkfs 1 ${PARTITION_TYPE}" || true
 
 		if [ "${LH_BOOTLOADER}" = "syslinux" ]
 		then
@@ -159,6 +160,7 @@
 		parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100% || true
 		parted -s ${FREELO} set 1 boot on || true
 		parted -s ${FREELO} set 1 lba off || true
+		parted -s ${FREELO} mkfs 1 ${PARTITION_TYPE} || true
 
 		if [ "${LH_BOOTLOADER}" = "syslinux" ]
 		then
@@ -175,28 +177,18 @@
 
 case "${LH_BINARY_FILESYSTEM}" in
 	ext2|ext3)
-		MKFS="${LH_BINARY_FILESYSTEM}"
-		MKFS_OPTIONS="-L DEBIAN_LIVE -m 0"
-		;;
-
-	fat16)
-		MKFS="vfat"
-		MKFS_OPTIONS="-F 16 -n DEBIAN_LIVE"
-		;;
-
-	fat32)
-		MKFS="vfat"
-		MKFS_OPTIONS="-F 32 -n DEBIAN_LIVE"
-		;;
-esac
-
-case "${LH_CHROOT_BUILD}" in
-	true)
-		Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
+		e2label $FREELO DEBIAN_LIVE
 		;;
 
-	false)
-		mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}
+	fat*)
+		if [ -f ~/.mtoolsrc ]; then
+			cp ~/.mtoolsrc ~/.mtoolsrc.ori
+		fi
+		echo mtools_skip_check=1 >> ~/.mtoolsrc
+		mlabel -i $FREELO ::DEBIAN_LIVE
+		if [ -f ~/.mtoolsrc.ori ]; then
+			mv ~/.mtoolsrc.ori ~/.mtoolsrc
+		fi
 		;;
 esac
 
@@ -209,38 +201,6 @@
 mkdir -p chroot/binary.tmp
 ${LH_ROOT_COMMAND} mount ${FREELO} chroot/binary.tmp
 cp -r -T ${CP_OPTIONS} binary/ chroot/binary.tmp
-
-FIXME()
-{
-if [ "${LH_BOOTLOADER}" = "grub" ]
-then
-
-cat > chroot/grub.sh << EOF
-cd binary.tmp
-grub --batch << EOM
-find /live/vmlinuz
-EOM
-EOF
-
-	rootpartition="$(Chroot chroot 'sh grub.sh' 2>/dev/null | grep -A 1 'find /live/vmlinuz' | grep -v 'find /live/vmlinuz')"
-	usbdev="$(echo $rootpartition | sed -e 's|,[[:digit:]]||')"
-	echo "Root partition is $rootpartition, device is: $usbdev"
-
-	echo "WAITING..." && read WAIT
-
-#cat > chroot/grub.sh << EOF
-#grub --batch << EOM
-#root $rootpartition
-#setup $usbdev
-#EOM
-#EOF
-
-#Chroot chroot "sh grub.sh"
-
-	rm -f chroot/grub.sh
-fi
-}
-
 ${LH_ROOT_COMMAND} umount chroot/binary.tmp
 rmdir chroot/binary.tmp
 
@@ -260,6 +220,36 @@
 sleep 1
 ${LH_LOSETUP} -d ${FREELO}
 
+if [ "${LH_BOOTLOADER}" = "grub" ]
+then
+	case "${LH_CHROOT_BUILD}" in
+		true)
+			cat > chroot/grub.sh << EOF
+
+grub --device-map=/dev/null --batch << EOM
+device (hd0) binary.img
+root (hd0,0)
+setup (hd0)
+quit
+EOM
+EOF
+
+			Chroot chroot "sh grub.sh"
+
+			rm -f chroot/grub.sh
+			;;
+
+		false)
+			${LH_ROOT_COMMAND} grub --device-map=/dev/null --batch << EOM
+device (hd0) chroot/binary.img
+root (hd0,0)
+setup (hd0)
+quit
+EOM
+			;;
+	esac
+fi
+
 echo "!!! The above error/warning messages can be ignored !!!"
 
 if [ -n "${MAKEDEV}" ]
diff -U 3 -d -r -N -x .svn -- HEAD/functions/defaults.sh Patched/functions/defaults.sh
--- HEAD/functions/defaults.sh	2010-01-21 17:39:15.000000000 +0100
+++ Patched/functions/defaults.sh	2010-01-20 17:38:28.000000000 +0100
@@ -1039,7 +1039,7 @@
 	then
 		# grub or yaboot + usb-hdd
 		case "${LH_BOOTLOADER}" in
-			grub|yaboot)
+			grub2|yaboot)
 				Echo_error "You have selected a combination of bootloader and image type that is currently not supported by live-helper. Please use either another bootloader or a different image type."
 				exit 1
 				;;
diff -U 3 -d -r -N -x .svn -- HEAD/helpers/lh_binary_usb-hdd Patched/helpers/lh_binary_usb-hdd
--- HEAD/helpers/lh_binary_usb-hdd	2010-01-21 17:38:53.000000000 +0100
+++ Patched/helpers/lh_binary_usb-hdd	2010-01-22 17:25:24.000000000 +0100
@@ -105,17 +105,6 @@
 DU_DIM="$(du -ms binary | cut -f1)"
 REAL_DIM="$(Calculate_partition_size ${DU_DIM} ${LH_BINARY_FILESYSTEM})"
 dd if=/dev/zero of=chroot/binary.img bs=1024k count=0 seek=${REAL_DIM}
-FREELO="$(${LH_LOSETUP} -f)"
-if [ ! -b chroot/${FREELO} ]
-then
-	MAKEDEV="true"
-
-	mv chroot/dev chroot/dev.tmp
-	find /dev | cpio -dmpu chroot
-fi
-
-echo "!!! The following error/warning messages can be ignored !!!"
-Losetup $FREELO chroot/binary.img 0
 
 case "${LH_ARCHITECTURE}" in
 	sparc)
@@ -143,60 +132,57 @@
 
 case "${LH_CHROOT_BUILD}" in
 	true)
-		Chroot chroot "parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE}" || true
-		Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
-		Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
-		Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
-
-		if [ "${LH_BOOTLOADER}" = "syslinux" ]
-		then
-			dd if=chroot/usr/lib/syslinux/mbr.bin of=${FREELO} bs=440 count=1
-		fi
+		Chroot chroot "parted -s binary.img mklabel ${PARTITION_TABLE_TYPE}" || true
+		Chroot chroot "parted -s binary.img mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
+		Chroot chroot "parted -s binary.img set 1 boot on" || true
+		Chroot chroot "parted -s binary.img set 1 lba off" || true
+		Chroot chroot "parted -s binary.img mkfs 1 ${PARTITION_TYPE}" || true
 		;;
 
 	false)
-		parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE} || true
-		parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100% || true
-		parted -s ${FREELO} set 1 boot on || true
-		parted -s ${FREELO} set 1 lba off || true
+		parted -s chroot/binary.img mklabel ${PARTITION_TABLE_TYPE} || true
+		parted -s chroot/binary.img mkpart primary ${PARTITION_TYPE} 0.0 100% || true
+		parted -s chroot/binary.img set 1 boot on || true
+		parted -s chroot/binary.img set 1 lba off || true
+		parted -s chroot/binary.img mkfs 1 ${PARTITION_TYPE} || true
+		;;
+esac
 
-		if [ "${LH_BOOTLOADER}" = "syslinux" ]
-		then
+if [ "${LH_BOOTLOADER}" = "syslinux" ]
+then
+	FREELO="$(${LH_LOSETUP} -f)"
+	Losetup $FREELO chroot/binary.img 0
+	case "${LH_CHROOT_BUILD}" in
+		true)
+			dd if=chroot/usr/lib/syslinux/mbr.bin of=${FREELO} bs=440 count=1
+		;;
+
+		false)
 			dd if=/usr/lib/syslinux/mbr.bin of=${FREELO} bs=440 count=1
-		fi
 		;;
-esac
+	esac
+	sleep 1
+	${LH_LOSETUP} -d ${FREELO}
+fi
 
-sleep 1
-${LH_LOSETUP} -d ${FREELO}
 
 FREELO="$(${LH_LOSETUP} -f)"
 Losetup $FREELO chroot/binary.img 1
 
 case "${LH_BINARY_FILESYSTEM}" in
 	ext2|ext3)
-		MKFS="${LH_BINARY_FILESYSTEM}"
-		MKFS_OPTIONS="-L DEBIAN_LIVE -m 0"
-		;;
-
-	fat16)
-		MKFS="vfat"
-		MKFS_OPTIONS="-F 16 -n DEBIAN_LIVE"
-		;;
-
-	fat32)
-		MKFS="vfat"
-		MKFS_OPTIONS="-F 32 -n DEBIAN_LIVE"
-		;;
-esac
-
-case "${LH_CHROOT_BUILD}" in
-	true)
-		Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
+		e2label $FREELO DEBIAN_LIVE
 		;;
 
-	false)
-		mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}
+	fat*)
+		if [ -f ~/.mtoolsrc ]; then
+			cp ~/.mtoolsrc ~/.mtoolsrc.ori
+		fi
+		echo mtools_skip_check=1 >> ~/.mtoolsrc
+		mlabel -i $FREELO ::DEBIAN_LIVE
+		if [ -f ~/.mtoolsrc.ori ]; then
+			mv ~/.mtoolsrc.ori ~/.mtoolsrc
+		fi
 		;;
 esac
 
@@ -206,41 +192,12 @@
 		;;
 esac
 
+FREELO="$(${LH_LOSETUP} -f)"
+Losetup $FREELO chroot/binary.img 1
+
 mkdir -p chroot/binary.tmp
 ${LH_ROOT_COMMAND} mount ${FREELO} chroot/binary.tmp
 cp -r -T ${CP_OPTIONS} binary/ chroot/binary.tmp
-
-FIXME()
-{
-if [ "${LH_BOOTLOADER}" = "grub" ]
-then
-
-cat > chroot/grub.sh << EOF
-cd binary.tmp
-grub --batch << EOM
-find /live/vmlinuz
-EOM
-EOF
-
-	rootpartition="$(Chroot chroot 'sh grub.sh' 2>/dev/null | grep -A 1 'find /live/vmlinuz' | grep -v 'find /live/vmlinuz')"
-	usbdev="$(echo $rootpartition | sed -e 's|,[[:digit:]]||')"
-	echo "Root partition is $rootpartition, device is: $usbdev"
-
-	echo "WAITING..." && read WAIT
-
-#cat > chroot/grub.sh << EOF
-#grub --batch << EOM
-#root $rootpartition
-#setup $usbdev
-#EOM
-#EOF
-
-#Chroot chroot "sh grub.sh"
-
-	rm -f chroot/grub.sh
-fi
-}
-
 ${LH_ROOT_COMMAND} umount chroot/binary.tmp
 rmdir chroot/binary.tmp
 
@@ -260,12 +217,34 @@
 sleep 1
 ${LH_LOSETUP} -d ${FREELO}
 
-echo "!!! The above error/warning messages can be ignored !!!"
-
-if [ -n "${MAKEDEV}" ]
+if [ "${LH_BOOTLOADER}" = "grub" ]
 then
-	rm -rf chroot/dev
-	mv chroot/dev.tmp chroot/dev
+	case "${LH_CHROOT_BUILD}" in
+		true)
+			cat > chroot/grub.sh << EOF
+
+grub --device-map=/dev/null --batch << EOM
+device (hd0) binary.img
+root (hd0,0)
+setup (hd0)
+quit
+EOM
+EOF
+
+			Chroot chroot "sh grub.sh"
+
+			rm -f chroot/grub.sh
+			;;
+
+		false)
+			${LH_ROOT_COMMAND} grub --device-map=/dev/null --batch << EOM
+device (hd0) chroot/binary.img
+root (hd0,0)
+setup (hd0)
+quit
+EOM
+			;;
+	esac
 fi
 
 mv chroot/binary.img ./

Reply to: