diff options
author | Aaron Griffin <aaronmgriffin@gmail.com> | 2008-09-06 20:39:35 -0500 |
---|---|---|
committer | Aaron Griffin <aaronmgriffin@gmail.com> | 2008-09-06 20:39:35 -0500 |
commit | 8966351b12bbcf2f8fffbd8c3a4b00e7529349b8 (patch) | |
tree | a54505adcbc029bce687788150df4383e5e936e0 /archiso/mkusbimg | |
parent | 99ed5349b32951fa1ec28cc2ee3caaff83fcd681 (diff) | |
download | archiso32-8966351b12bbcf2f8fffbd8c3a4b00e7529349b8.tar.xz |
Split mkarchiso and configs into logical parts
Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
Diffstat (limited to 'archiso/mkusbimg')
-rwxr-xr-x | archiso/mkusbimg | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/archiso/mkusbimg b/archiso/mkusbimg new file mode 100755 index 0000000..727bb80 --- /dev/null +++ b/archiso/mkusbimg @@ -0,0 +1,78 @@ +#!/bin/bash +# +# mkusbimg - creates a bootable disk image +# Copyright (C) 2008 Simo Leone <simo@archlinux.org> +# +# This program 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 3 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, see <http://www.gnu.org/licenses/>. + +# usage(exitvalue) +# outputs a usage message and exits with value +APPNAME=$(basename "${0}") +usage() +{ + echo "usage: ${APPNAME} <imageroot> <imagefile>" + exit $1 +} + +################################################## + +if [ $# -ne 2 ]; then + usage 1 +fi + +DISKIMG="${2}" +IMGROOT="${1}" +TMPDIR=$(mktemp -d) +FSIMG=$(mktemp) + +# ext2 overhead's upper bound is 6% +# empirically tested up to 1GB +rootsize=$(du -bs ${IMGROOT}|cut -f1) +IMGSZ=$(( (${rootsize}*106)/100/512 + 1)) # image size in sectors + +# create the filesystem image file +dd if=/dev/zero of="$FSIMG" bs=512 count="$IMGSZ" + +# create a filesystem on the image +mke2fs -m 0 -F "$FSIMG" + +# mount the filesystem and copy data +mount -o loop "$FSIMG" "$TMPDIR" +cp -a "$IMGROOT"/* "$TMPDIR" + +# unmount filesystem +umount "$TMPDIR" + +# add sectors 0-62, then glue together +dd if=/dev/zero of="$DISKIMG" bs=512 count=63 +cat "$FSIMG" >> "$DISKIMG" + +# create a partition table +# if this looks like voodoo, it's because it is +sfdisk -uS -f "$DISKIMG" << EOF +63,$IMGSZ,83,* +0,0,00 +0,0,00 +0,0,00 +EOF + +# install grub on the image +grub --no-floppy --batch << EOF +device (hd0) $DISKIMG +root (hd0,0) +setup (hd0) +EOF + +# all done :) +rm -fr "$TMPDIR" "$FSIMG" |