From 16af9c68f4900785c94a0cd3e65dfb44e81d4aff Mon Sep 17 00:00:00 2001 From: Andres Salomon Date: Sat, 30 May 2009 02:55:03 -0400 Subject: [PATCH] mkext3: pull partition info and image size from fstab This allows different image types to have different partition layouts and sizes.. Signed-off-by: Andres Salomon --- mkext3.sh | 170 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 106 insertions(+), 64 deletions(-) diff --git a/mkext3.sh b/mkext3.sh index d723f9f..37cec99 100755 --- a/mkext3.sh +++ b/mkext3.sh @@ -16,8 +16,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -ROOT_SIZE="1998" -IMG_LABEL="DebXO" IMG_NAME="" ROOT_DIR="" @@ -49,41 +47,19 @@ detach_loop() losetup -d "$1" } -# @img - fs image to mount -# @type - fs type to mount -# @offset - if the image is partitioned, the offset to mount at -# -# sets $MOUNT_POINT with the path of the newly created (and mounted) dir -mk_mount() -{ - img="$1" - type="$2" - offset="$3" - - if [ "$offset" != "" ]; then - offset=",offset=$offset" - fi - - MOUNT_POINT=$(mktemp) - rm -f $MOUNT_POINT - mkdir $MOUNT_POINT - - mount "$img" "$MOUNT_POINT" -o loop$offset -t "$type" -} - -# @mntpt - directory to umount and delete -rm_mount() -{ - umount "$1" - rmdir "$1" -} - # @img - image name to create -# @size - image size create_bootable_img() { img="$1" - size="$2" + + # get the total size by summing all the partition sizes (listed in fstab comments) + partition_sizes=`grep '^LABEL=' configs/${CONFIG_TYPE}/fstab-ext3 | \ + sed 's/.*#[[:space:]]\+\([0-9]\+\)$/\1/' | xargs echo | tr ' ' +` + size=$(($partition_sizes)) + + # there's some partition overhead; pad the image so that parted doesn't whine + overhead=`echo | awk "{ printf(\"%d\n\", 0.014 * $size); }"` + size=$((size + overhead)) # first, create a sparse image minus_size=$(($size * 6 / 100)) @@ -92,7 +68,13 @@ create_bootable_img() # fill in the partition table parted -s "$img" "mklabel msdos" - parted -s "$img" "mkpart primary ext2 0 -1" + prior=0 + grep '^LABEL=' configs/${CONFIG_TYPE}/fstab-ext3 | \ + sed 's/.*#[[:space:]]\+\([0-9]\+\)$/\1/' | while read s; do + end=$((prior + s)) + parted -s "$img" "mkpart primary ext2 $prior $end" + prior=$end + done parted -s "$img" "set 1 boot on" } @@ -111,12 +93,21 @@ grub_install() default 0 timeout 5 color cyan/blue white/blue - -title $IMG_LABEL +EOF + label=`sed -ne 's/^LABEL=\(.\+\)[[:space:]]\+\/[[:space:]]\+.*/\1/p' configs/${CONFIG_TYPE}/fstab-ext3` + prefix= + grep -q ' ${mntpt}/boot ' /proc/mounts && prefix=/boot + for kern in ${mntpt}/boot/vmlinuz-*; do + v=$(basename $kern | sed 's/vmlinuz-//') + cat >>${mntpt}/boot/grub/menu.lst<] " 1>&2 echo "" 1>&2 echo "Options:" 1>&2 - echo " -l