From db1dde541c09927eb5f9bc1240a867d92e084cd9 Mon Sep 17 00:00:00 2001 From: Gerardo Exequiel Pozzi Date: Wed, 21 Oct 2009 00:21:58 -0300 Subject: Fix how mkarchiso makes usb image The current implementation in how partition is created for ext2 img it looks a bit bad. This patch makes the partition in more standarized way, respecting cylinder alignement: * The size of resulting image will be in cylinder multiple ~8MB. * Use fdisk instead of sfdisk (sfdisk write some bad information) * Make the result image in one pass, instead of concatenating. Also the advantage is that with this can add another partitions without any issues in the usb-flash-drive with this .img. For example of current situation: qemu-system-x86_64 -hda archlinux-avr.toolchain.img -serial stdio --------------------------------------------------------------------- [root@avr ~]# fdisk /dev/sda Command (m for help): p Disk /dev/sda: 223 MB, 223974400 bytes 59 heads, 41 sectors/track, 180 cylinders Units = cylinders of 2419 * 512 = 1238528 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sda1 * 1 181 218693+ 83 Linux Partition 1 has different physical/logical beginnings (non-Linux?): phys=(0, 1, 1) logical=(0, 1, 23) Partition 1 has different physical/logical endings: phys=(27, 58, 41) logical=(180, 49, 21) Command (m for help): v Partition 1 has different physical/logical beginnings (non-Linux?): phys=(0, 1, 1) logical=(0, 1, 23) Partition 1 has different physical/logical endings: phys=(27, 58, 41) logical=(180, 49, 21) Partition 1: previous sectors 437449 disagrees with total 67731 62 unallocated 512-byte sectors Command (m for help): --------------------------------------------------------------------- qemu-system-x86_64 -hda archlinux-avr.toolchain-fix.img -serial stdio --------------------------------------------------------------------- [root@avr ~]# fdisk /dev/sda Command (m for help): p Disk /dev/sda: 230 MB, 230307840 bytes 255 heads, 63 sectors/track, 28 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x5c94ca4f Device Boot Start End Blocks Id System /dev/sda1 * 1 28 224878+ 83 Linux Command (m for help): v 62 unallocated 512-byte sectors --------------------------------------------------------------------- Signed-off-by: Gerardo Exequiel Pozzi --- archiso/mkarchiso | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'archiso/mkarchiso') diff --git a/archiso/mkarchiso b/archiso/mkarchiso index 7b706ca..b6d0f54 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -261,39 +261,49 @@ command_iso () { command_usb () { _imgcommon - - fsimg="${imgname}.part1" + + modprobe -q loop + + # Calculate cylinder size in bytes + CYL_SIZE=$((255*63*512)) + + # First partition offset + PART_OFFSET=$((63*512)) # ext2 overhead's upper bound is 6%, empirically tested up to 1GB rootsize=$(du -bs "${work_dir}/iso" | cut -f1) - imgsz=$(( (${rootsize}*106)/100/512 + 1)) # image size in sectors + imgsz=$(( (${rootsize}*106)/100/${CYL_SIZE} + 1 )) # image size in cylinders + + # Get next free loop device + devloop=$(losetup -f) # create the filesystem image file - dd if=/dev/zero of="$fsimg" bs=512 count="$imgsz" + dd if=/dev/zero of="$imgname" bs="$CYL_SIZE" count="$imgsz" + + # Setup a loop device, and skip the first 63 sectors + losetup "$devloop" -o "$PART_OFFSET" "$imgname" # create a filesystem on the image - mke2fs -m 0 -F -L "${LABEL}" "$fsimg" + mke2fs -m 0 -F -L "${LABEL}" "$devloop" # mount the filesystem and copy data - modprobe loop TMPDIR=$(mktemp -d archiso-usbXXXXXX) - mount -o loop "$fsimg" "$TMPDIR" + mount "$devloop" "$TMPDIR" cp -a "${work_dir}"/iso/* "$TMPDIR" - umount "$TMPDIR" + umount -d "$TMPDIR" rm -rf "$TMPDIR" - # add sectors 0-62, then glue together - dd if=/dev/zero of="${imgname}" bs=512 count=63 - cat "$fsimg" >> "${imgname}" - rm "$fsimg" - # create a partition table - # if this looks like voodoo, it's because it is - sfdisk -uS -f "${imgname}" << EOF -63,$imgsz,83,* -0,0,00 -0,0,00 -0,0,00 + fdisk -C "$imgsz" -H 255 -S 63 "$imgname" << EOF +n +p +1 + + +a +1 +p +w EOF # install grub on the image -- cgit v1.2.3-70-g09d2