[PATCH olpc-os-builder 09/14] sd_card_image: clean up calculations, rely on dmsetup + kpartx
Sascha Silbe
silbe at activitycentral.com
Thu Mar 17 11:21:23 EDT 2011
sd_card_image previously used two mismatching C/H/S geometries internally.
The impact on the output was minimal (the image file might have been slightly
larger than necessary) because most of the actually used values were
hardcoded, but it was rather confusing.
By replacing the loop device offset magic with dmsetup and kpartx we can
avoid doing some of the more problematic calculations. It also makes it
easier to add grub support (for testing the image inside a VM).
The partition layout is slightly altered to start the root device at 128MB
(power-of-2 boundary) instead of at 132MB, reducing boot from 64MB to 60MB.
Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
modules/sd_card_image/image.50.makefs.sh | 59 ++++++++++++++++--------------
1 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/modules/sd_card_image/image.50.makefs.sh b/modules/sd_card_image/image.50.makefs.sh
index c9ed3b8..9b6118b 100644
--- a/modules/sd_card_image/image.50.makefs.sh
+++ b/modules/sd_card_image/image.50.makefs.sh
@@ -4,9 +4,13 @@
. $OOB__shlib
versioned_fs=$(read_config base versioned_fs)
buildnr=$(read_buildnr)
-BLOCK_SIZE=512
-NUM_HEADS=16
-NUM_SECTORS_PER_TRACK=62
+BOOT_START_MB=4
+ROOT_START_MB=64
+BLOCK_SIZE_BYTE=512
+NUM_HEADS=64
+NUM_SECTORS_PER_TRACK=32
+
+CYLINDER_SIZE_BYTE=$(($NUM_SECTORS_PER_TRACK * $NUM_HEADS * $BLOCK_SIZE_BYTE))
# FIXME trap signals and cleanup
# FIXME check that traps due to errors are caught
@@ -25,38 +29,38 @@ make_image()
local disk_size=${vals%,*}
local ext=
expr index "$vals" ',' &>/dev/null && ext=${vals#*,}
- echo "Making image of size $disk_size"
+ echo "Making image for SD card of size $disk_size"
echo "Create disk and partitions..."
- local num_blocks=$(($disk_size / $BLOCK_SIZE))
- local num_cylinders=$(($num_blocks / $NUM_HEADS / $NUM_SECTORS_PER_TRACK))
- local image_size=$(($num_cylinders * $NUM_HEADS * $NUM_SECTORS_PER_TRACK * $BLOCK_SIZE))
- local os_part1_begin=$(($NUM_SECTORS_PER_TRACK * $BLOCK_SIZE))
+ local num_blocks=$(($disk_size / $BLOCK_SIZE_BYTE))
+ local num_cylinders=$(($num_blocks * $BLOCK_SIZE_BYTE / $CYLINDER_SIZE_BYTE))
+ local image_size_byte=$(($num_cylinders * $CYLINDER_SIZE_BYTE))
+ local os_part1_begin_sector=$(($BOOT_START_MB * 1024 * 1024 / 512))
+ local os_part2_begin_sector=$(($ROOT_START_MB * 1024 * 1024 / 512))
[ -z "$ext" ] && ext="zd"
local img=$intermediatesdir/$(image_name).$ext.disk.img
- dd if=/dev/zero of=$img bs=$BLOCK_SIZE count=0 seek=$(($image_size / $BLOCK_SIZE))
- /sbin/sfdisk -S 32 -H 32 --force -uS $img <<EOF
-8192,131072,83,*
-139264,,,
-EOF
- local img_sectors=$(sfdisk -uS -l $img | grep img2 | awk '{print $4}')
- echo "(1 losetup error is normal here)"
- losetup -d /dev/loop6 || :
- losetup -o $((8192 * $BLOCK_SIZE)) --sizelimit $((131072 * $BLOCK_SIZE)) /dev/loop6 $img
- 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
+ dd if=/dev/zero of=$img bs=$BLOCK_SIZE_BYTE count=0 seek=$(($image_size_byte / $BLOCK_SIZE_BYTE))
+ /sbin/sfdisk -S $NUM_SECTORS_PER_TRACK -H $NUM_HEADS --force -uS $img <<-EOF
+ $os_part1_begin_sectors,$(($os_part2_begin_sector - $os_part1_begin_sector)),83,*
+ $os_part2_begin_sectors,,83,
+ EOF
+
+ local loop_dev=$(losetup --show -f $img)
+ local dm_name=sdcardtmp$$
+
+ stat --format="0 $(($image_size_byte / 512)) linear %t:%T 0" $loop_dev | dmsetup create $dm_name
+ kpartx -a -p p /dev/mapper/$dm_name
echo "Create filesystems..."
- mke2fs -O dir_index,^resize_inode -L Boot -F /dev/loop6
- mount /dev/loop6 $BOOT
+ mke2fs -O dir_index,^resize_inode -L Boot -F /dev/mapper/${dm_name}p1
+ mount /dev/mapper/${dm_name}p1 $BOOT
- mkfs.ext4 -O dir_index,^huge_file -E resize=8G -m1 -L OLPCRoot /dev/loop7
- tune2fs -o journal_data_ordered /dev/loop7
- mount /dev/loop7 $ROOT
+ mkfs.ext4 -O dir_index,^huge_file -E resize=8G -m1 -L OLPCRoot /dev/mapper/${dm_name}p2
+ tune2fs -o journal_data_ordered /dev/mapper/${dm_name}p2
+ mount /dev/mapper/${dm_name}p2 $ROOT
echo "Copy in root filesystem..."
cp -a $fsmount/* $ROOT
@@ -89,8 +93,9 @@ EOF
umount $ROOT
umount $BOOT
- losetup -d /dev/loop6 || :
- losetup -d /dev/loop7 || :
+ kpartx -d -p p /dev/mapper/$dm_name
+ dmsetup remove $dm_name
+ losetup -d $loop_dev
# FIXME: any value to running e2fsck now? maybe with -D ?
}
--
1.7.4.1
More information about the Devel
mailing list