From: Andres Salomon Date: Tue, 19 Aug 2008 19:42:02 +0000 (-0400) Subject: strip common stuff out of mkext3.sh X-Git-Tag: v0.1~19 X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?p=xodist;a=commitdiff_plain;h=0308aefb96a01181b7c161f59377328d2a795406 strip common stuff out of mkext3.sh Signed-off-by: Andres Salomon --- diff --git a/mkext3.sh b/mkext3.sh new file mode 100755 index 0000000..d08485e --- /dev/null +++ b/mkext3.sh @@ -0,0 +1,223 @@ +#!/bin/sh -e +# +# Copyright © 2008 Andres Salomon +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +IMG_NAME="DebOLPC" +ROOT_SIZE="512" +IMG_LABEL="DebOLPC" +ROOT_DIR="" +CRCIMG="./crcimg.pl" + +. functions.sh + +# @img - fs image to attach loop device to +# @offset - if the image is partitioned, the offset to attach at +# +# sets $LOOP_DEV with the path of the newly attached loop device +attach_loop() +{ + img="$1" + offset="$2" + + LOOP_DEV=$(losetup -f) + + if [ "$offset" != "" ]; then + losetup -o "$offset" "$LOOP_DEV" "$img" + else + losetup "$LOOP_DEV" "$img" + fi +} + +# @dev - the loop device to detach +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 +mk_bootable_img() +{ + img="$1" + size="$2" + + # first, create a sparse image + minus_size=$(($size * 6 / 100)) + size=$(($size - $minus_size)) + dd if=/dev/zero of=$img bs=1M count=1 seek=$(($size - 1)) + + # fill in the partition table + parted -s "$img" "mklabel msdos" + parted -s "$img" "mkpart primary ext2 0 -1" + parted -s "$img" "set 1 boot on" +} + +# @img - image name +# @mntpt - path to mounted root directory +grub_install() +{ + img="$1" + mntpt="$2" + + mkdir -p ${mntpt}/boot/grub + cp /usr/lib/grub/i386-pc/stage[12] ${mntpt}/boot/grub + cp /usr/lib/grub/i386-pc/e2fs_stage1_5 ${mntpt}/boot/grub + + cat >${mntpt}/boot/grub/menu.lst<&2 + echo "Usage: $0 [] " 1>&2 + echo "" 1>&2 + echo "Options:" 1>&2 + echo " -l