[PATCH] Fix corruption of usb images by live-build caused by trying to modify flags in partition table when image is mounted with offset
Hello,
As described on Daniel's blog[1], a regression was introduced into live-build that caused the usb images created by live-build to be corrupted. I've determined that the corruption was caused by live-build modifying flags in the partition table while the image is still mounted with an offset. Please accept this patch which updates the lb_binary_usb helper to modify the flags with a properly configured loop mount as well as apply the fix that caused the regression to lb_source_usb (but without the problem fixed here of course).
[1] http://blog.daniel-baumann.ch/2011/07/13#20110713_debian-live-6.0.2-images
Cheers,
--
Cody A.W. Somerville
Release Engineer
Foundations Team
Custom Engineering Solutions Group
Canonical OEM Services
Phone: +1 781 850 2087
Cell: +1 613 401 5141
Fax: +1 613 687 7368
Email: cody.somerville@canonical.com
=== modified file 'scripts/build/lb_binary_usb'
--- scripts/build/lb_binary_usb 2011-03-21 19:52:50 +0000
+++ scripts/build/lb_binary_usb 2011-07-19 19:12:21 +0000
@@ -190,16 +190,10 @@
case "${LB_BUILD_WITH_CHROOT}" in
true)
Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
-
- Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
- Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
;;
false)
mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}
-
- parted -s ${FREELO} set 1 boot on || true
- parted -s ${FREELO} set 1 lba off || true
;;
esac
@@ -265,6 +259,24 @@
echo "!!! The above error/warning messages can be ignored !!!"
+FREELO="$(${LB_LOSETUP} -f)"
+Losetup "${FREELO}" chroot/binary.img 0
+
+case "${LB_BUILD_WITH_CHROOT}" in
+ true)
+ Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
+ Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
+ ;;
+
+ false)
+ parted -s "${FREELO}" set 1 boot on || true
+ parted -s "${FREELO}" set 1 lba off || true
+ ;;
+esac
+
+sleep 1
+${LB_LOSETUP} -d ${FREELO}
+
if [ -n "${MAKEDEV}" ]
then
rm -rf chroot/dev
=== modified file 'scripts/build/lb_source_usb'
--- scripts/build/lb_source_usb 2011-03-09 18:20:42 +0000
+++ scripts/build/lb_source_usb 2011-07-19 19:12:21 +0000
@@ -93,7 +93,6 @@
Losetup $FREELO source.img 0
Chroot chroot "parted -s ${FREELO} mklabel msdos" || true
Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
-Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
sleep 1
${LB_LOSETUP} -d ${FREELO}
@@ -127,6 +126,12 @@
${LB_LOSETUP} -d ${FREELO}
Echo_warning "!!! The above error/warning messages can be ignored !!!"
+FREELO="$(${LB_LOSETUP} -f)"
+Losetup "$FREELO" source.img 0
+Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
+sleep 1
+${LB_LOSETUP} -d ${FREELO}
+
if [ -n "${MAKEDEV}" ]
then
rm -rf chroot/dev
Reply to: