diff options
author | Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> | 2009-10-21 00:21:58 -0300 |
---|---|---|
committer | Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> | 2009-10-21 00:46:39 -0300 |
commit | db1dde541c09927eb5f9bc1240a867d92e084cd9 (patch) | |
tree | 775b4386ae25a0fcbf9f638f7bc1e0c436d28d15 /archiso | |
parent | c801829c615a49bf484b4be792d2f5c3aad4fe8a (diff) | |
download | archiso32-db1dde541c09927eb5f9bc1240a867d92e084cd9.tar.xz |
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 <vmlinuz386@yahoo.com.ar>
Diffstat (limited to 'archiso')
-rwxr-xr-x | archiso/mkarchiso | 48 |
1 files changed, 29 insertions, 19 deletions
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 |