diff options
author | Sebastian Schmelzer | 2011-05-04 18:11:19 +0200 |
---|---|---|
committer | Sebastian Schmelzer | 2011-05-04 18:11:19 +0200 |
commit | ade0d1f264970b404de66142d830b07a4ce43ddc (patch) | |
tree | 6f80e2df7863a598666272b116e37e4c6139f62e | |
parent | fix for small, single partition usb sticks (diff) | |
download | usb-boot-stick-ade0d1f264970b404de66142d830b07a4ce43ddc.tar.gz usb-boot-stick-ade0d1f264970b404de66142d830b07a4ce43ddc.tar.xz usb-boot-stick-ade0d1f264970b404de66142d830b07a4ce43ddc.zip |
pbmtk v1
-rwxr-xr-x | create-installer | 13 | ||||
-rw-r--r-- | inc/functions.common.sh | 71 | ||||
-rw-r--r-- | inc/functions.create-installer.sh | 119 | ||||
-rw-r--r-- | inc/functions.iso.sh | 123 | ||||
-rw-r--r-- | inc/functions.usb.sh | 203 | ||||
-rwxr-xr-x | install-usb | 1 | ||||
-rwxr-xr-x | installer/tpl/installer.tpl.sh | 5 | ||||
-rwxr-xr-x | pbmtk | 65 |
8 files changed, 596 insertions, 4 deletions
diff --git a/create-installer b/create-installer index 50075f9..0bd5038 100755 --- a/create-installer +++ b/create-installer @@ -1,4 +1,17 @@ #!/bin/bash +# ----------------------------------------------------------------------------- +# Copyright (c) 2011 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# PreBoot USB stick preparation utility +# ----------------------------------------------------------------------------- ROOT_DIR=$(dirname $(readlink -f $0)) diff --git a/inc/functions.common.sh b/inc/functions.common.sh new file mode 100644 index 0000000..75586c2 --- /dev/null +++ b/inc/functions.common.sh @@ -0,0 +1,71 @@ +SYSLINUX=${ROOT_DIR}/contrib/syslinux/latest +PATH="${ROOT_DIR}/bin/:$PATH" + +QUIET="0" + +banner () { + + echo -e "\t __ __ __ " + echo -e "\t.-----.| |--.--------.| |_| |--." + echo -e "\t| _ || _ | || _| < " + echo -e "\t| __||_____|__|__|__||____|__|__|" + echo -e "\t|__| " + echo -e "\t ** OpenSLX Project // 2011 **" + echo -e "\t http://lab.openslx.org/" + echo -e "" + +} + +set_quiet () { + if [ "x$DEBUG" != "x1" -a "x$QUIET" != "x1" ]; then + exec 6>&1 > $LOG_DIR/stdout.log + exec 2> $LOG_DIR/stderr.log + QUIET="1" + fi +} + +unset_quiet () { + if [ "x$QUIET" = "x1" ]; then + exec 1>&6 6>&- + exec 2>&- + QUIET="0" + fi +} + + +pinfo () { + unset_quiet + echo -e "[info] $1" + set_quiet +} +perror () { + unset_quiet + echo -e "[error] $1" + set_quiet +} +pecho () { + unset_quiet + echo -e "[user] $1" + set_quiet +} +pechon () { + unset_quiet + echo -e -n "[user] $1" + set_quiet +} + +getopt_start () { + + GETOPT_TEMP=`getopt -o $SHORT_OPTS --long $LONG_OPTS \ + -n "$SELF" -- "$@"` + + if [ $? != 0 ] ; then + perror "Unknown option(s).\n" + print_usage + exit 1 + fi +} + +run_global_checks () { + : +}
\ No newline at end of file diff --git a/inc/functions.create-installer.sh b/inc/functions.create-installer.sh new file mode 100644 index 0000000..c323439 --- /dev/null +++ b/inc/functions.create-installer.sh @@ -0,0 +1,119 @@ +SHORT_OPTS=":vfdhi" +LONG_OPTS="version,force,debug,iso,help" + +KERNEL="kernel-preboot-latest" +INITRAMFS="initramfs-default" +PBSI=$ROOT_DIR/installer/pbstick-installer + +LOG_DIR="/tmp/pbmtk" + +run_module_checks () { + + if [ ! -z $1 ]; then + perror "Too many parameters. \n" + print_usage + exit 1 + fi + + if [ -z $(which uuencode) ]; then + perror "'uuencode' is missing (if you are on a debian/ubuntu system: apt-get install sharutils)" + exit 1 + fi +} + +init_params () { + FORCE=0 + DEBUG=0 +} + +print_usage() { + echo "Usage: $(basename $SELF) installer [OPTIONS]" + echo -e " -d --debug \t give more debug output" + echo -e " -i --iso \t include code for ISO generation" + echo -e " -f --force \t don't ask questions" + echo -e " -h --help \t print help" + echo -e " -v --version \t print version information" +} + +read_params() { + getopt_start $@ + + eval set -- "$GETOPT_TEMP" + + while true ; do + case "$1" in + -v|--version) + echo "OpenSLX PreBoot .. ($VERSION - $VDATE)." + exit 0 + ;; + -h|--help) + print_usage + exit 0 + ;; + -i|--iso) pinfo "ISO mode not yet finished .. skipping."; shift ;; + -f|--force) pinfo "Disable user-interaction."; FORCE=1; shift ;; + -d|--debug) pinfo "Enabled debugmode."; DEBUG=1; unset_quiet; shift ;; + --) shift ; break ;; + *) perror "Internal error!" ; exit 1 ;; + esac + done +} + +pre_start_cleanup () { + pinfo "Cleanup installer tmp." + rm -rfv $ROOT_DIR/installer/tmp + rm -fv $ROOT_DIR/installer/stick-payload.tar.bz2 +} + +setup_dir_structure () { + pinfo "Create dir structure." + mkdir -p $ROOT_DIR/installer/tmp/share \ + $ROOT_DIR/installer/tmp/bin \ + $ROOT_DIR/installer/tmp/boot +} + +copy_files () { + pinfo "Copy required files." + cp -fv $SYSLINUX/mbr/mbr.bin $ROOT_DIR/installer/tmp/share + cp -fv $SYSLINUX/linux/syslinux $ROOT_DIR/installer/tmp/bin + + cp -fv $ROOT_DIR/build/$KERNEL $ROOT_DIR/installer/tmp/boot/kernel + + cp -fv $ROOT_DIR/build/$INITRAMFS $ROOT_DIR/installer/tmp/boot/initramfs + + cp -fv $SYSLINUX/com32/menu/menu.c32 $ROOT_DIR/installer/tmp/boot/ + cp -fv $SYSLINUX/com32/menu/vesamenu.c32 $ROOT_DIR/installer/tmp/boot/ + cp -fv $ROOT_DIR/config/extlinux/* $ROOT_DIR/installer/tmp/boot/ + mv -v $ROOT_DIR/installer/tmp/boot/extlinux.conf $ROOT_DIR/installer/tmp/boot/syslinux.cfg + +} + +create_payload () { + pinfo "Create payload." + cd $ROOT_DIR/installer/tmp/ + tar cjfv ../stick-payload.tar.bz2 * + cd $ROOT_DIR +} + +create_installer () { + pinfo "Complete installer." + cat $ROOT_DIR/installer/tpl/installer.tpl.sh > $PBSI + echo "PAYLOAD:" >> $PBSI + cat $ROOT_DIR/installer/stick-payload.tar.bz2 | uuencode - >> $PBSI + chmod +rx $PBSI +} + + +run () { + set_quiet + + pre_start_cleanup + setup_dir_structure + copy_files + create_payload + create_installer + + unset_quiet + + pinfo "FINISHED: Installer can be found here: $PBSI!" +}
\ No newline at end of file diff --git a/inc/functions.iso.sh b/inc/functions.iso.sh new file mode 100644 index 0000000..3fdece8 --- /dev/null +++ b/inc/functions.iso.sh @@ -0,0 +1,123 @@ +SHORT_OPTS=":vfdh" +LONG_OPTS="version,force,debug,help" + +KERNEL="kernel-preboot-latest" +INITRAMFS="initramfs-default" + +LOG_DIR="/tmp/pbmtk" +TMP_DIR=/tmp/openslx-iso + + +run_module_checks () { + + if [ ! -z $1 ]; then + perror "Too many parameters. \n" + print_usage + exit 1 + fi + + if [ -z $(which genisoimage) ]; then + perror "'genisoimage' is missing (if you are on a debian/ubuntu system: apt-get install genisoimage)" + exit 1 + fi +} + +init_params () { + FORCE=0 + DEBUG=0 +} + +print_usage() { + echo "Usage: $(basename $SELF) iso [OPTIONS]" + echo -e " -d --debug \t give more debug output" + echo -e " -f --force \t don't ask questions" + echo -e " -h --help \t print help" + echo -e " -v --version \t print version information" +} + +read_params() { + getopt_start $@ + + eval set -- "$GETOPT_TEMP" + + while true ; do + case "$1" in + -v|--version) + echo "OpenSLX PreBoot .. ($VERSION - $VDATE)." + exit 0 + ;; + -h|--help) + print_usage + exit 0 + ;; + -f|--force) pinfo "Disable user-interaction."; FORCE=1; shift ;; + -d|--debug) pinfo "Enabled debugmode."; DEBUG=1; unset_quiet; shift ;; + --) shift ; break ;; + *) perror "Internal error!" ; exit 1 ;; + esac + done +} + +pre_start_cleanup () { + pinfo "Cleanup installer tmp." + rm -rfv $TMP_DIR +} + +setup_dir_structure () { + pinfo "Create dir structure." + mkdir -p $TMP_DIR/isolinux +} + +copy_files () { + pinfo "Copy required files." + cp -v $ROOT_DIR/build/kernel-preboot-latest $TMP_DIR/isolinux/kernel + + cp -v $ROOT_DIR/build/initramfs-default $TMP_DIR/isolinux/initramfs + + cp -v $SYSLINUX/com32/menu/menu.c32 $TMP_DIR/isolinux/ + cp -v $SYSLINUX/com32/menu/vesamenu.c32 $TMP_DIR/isolinux/ + + # exchange this for another theme + cp -v ${ROOT_DIR}/config/extlinux/pbs2.png $TMP_DIR/isolinux/ + sed -e "s,USB,ISO," $ROOT_DIR/config/extlinux/extlinux.conf \ + > $TMP_DIR/isolinux/isolinux.cfg + + cp -v ${SYSLINUX}/core/isolinux.bin $TMP_DIR/isolinux/ + + # create an autorun.inf file + echo -en "icon=\boot\openslx.ico,0\r\nlabel=OpenSLX PreBoot Linux\r\n" \ + > $TMP_DIR/autorun.inf + cp ${ROOT_DIR}/COPYING $TMP_DIR/copying.txt + +} + + +create_iso () { + pinfo "Create ISO." + + genisoimage \ + -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 \ + -r -J -l -boot-info-table -hide-list config/hide.conf \ + -abstract /tmp/openslx-iso/isolinux/info.txt -relaxed-filenames \ + -biblio /tmp/openslx-iso/isolinux/info.txt -publisher "OpenSLX GmbH" \ + -p "OpenSLX Project, http://lab.openslx.org, info@openslx.org" \ + -V "OpenSLX PreBoot Linux ISO Image" -input-charset iso8859-1 \ + -volset "PreBoot Linux of the OpenSLX Project" -joliet-long \ + -copyright /tmp/openslx-iso/copying.txt \ + -o $ROOT_DIR/openslx.iso $TMP_DIR + +} + + +run () { + set_quiet + + pre_start_cleanup + setup_dir_structure + copy_files + create_iso + + unset_quiet + + pinfo "FINISHED: ISO can be found here: $ROOT_DIR/openslx.iso!" +}
\ No newline at end of file diff --git a/inc/functions.usb.sh b/inc/functions.usb.sh new file mode 100644 index 0000000..47ccbd4 --- /dev/null +++ b/inc/functions.usb.sh @@ -0,0 +1,203 @@ +SHORT_OPTS=":vfdhs" +LONG_OPTS="version,force,sudo,debug,help" + +KERNEL="kernel-preboot-latest" +INITRAMFS="initramfs-default" + +LOG_DIR="/tmp/pbmtk" + +run_module_checks () { + + if [ "x$SUDO" != "x1" -a $(whoami) != "root" ]; then + perror "You should be root or use '--sudo' switch." + exit 1; + fi + + if [ ! -z $1 ]; then + perror "Too many parameters. \n" + print_usage + exit 1 + fi + + if [ -z $OUT_DEV ]; then + perror "No output device specified.\n" + print_usage + exit 1 + fi + + if [ ! -e "/dev/$OUT_DEV" ]; then + perror "There is no /dev/${OUT_DEV}." + exit 1 + fi + +# if [ -z $(which uuencode) ]; then +# perror "'uuencode' is missing (if you are on a debian/ubuntu system: apt-get install sharutils)" +# exit 1 +# fi +} + +init_params () { + FORCE=0 + DEBUG=0 + SUDO=0 +} + +print_usage() { + echo "Usage: $(basename $SELF) usb [OPTIONS] DEVICE" + echo -e " -d --debug \t give more debug output" + echo -e " -f --force \t don't ask questions" + echo -e " -s --sudo \t use sudo instead of requesting uid=0" + echo -e " -h --help \t print help" + echo -e " -v --version \t print version information" + echo "DEVICE is the device used by the usb stick (e.g. \"sdX\" for /dev/sdX)." +} + +read_params() { + getopt_start $@ + + eval set -- "$GETOPT_TEMP" + + while true ; do + case "$1" in + -v|--version) + echo "OpenSLX PreBoot USB stick installer ($VERSION - $VDATE)." + exit 0 + ;; + -h|--help) + print_usage + exit 0 + ;; + -f|--force) pinfo "Disable user-interaction."; FORCE=1; shift ;; + -d|--debug) pinfo "Enabled debugmode."; DEBUG=1; unset_quiet; shift ;; + -s|--sudo) pinfo "Enabled usage of sudo."; SUDO=1; shift ;; + --) shift ; break ;; + *) perror "Internal error!" ; exit 1 ;; + esac + done + + OUT_DEV=$1 + shift + + [ "x$SUDO" = "x1" ] && SUDOCMD="sudo" +} + +ask_user () { + unset_quiet + if [ "x$FORCE" != "x1" ]; then + pinfo "Device \"/dev/${OUT_DEV}\" will be repartitioned and formatted." + pechon "Do you really want to proceed? Then type in 'yes' or 'no' (default: 'no'): " + read cont + [ "x${cont}" != "xyes" ] && exit 1 + fi + set_quiet +} + +umount_dev () { + pinfo "Make sure stick is unmounted." + for i in 1 2 3 4 5 6 7 8 9; do + $SUDOCMD umount /dev/${OUT_DEV}$i &> /dev/null + done +} + +create_partitions () { + pinfo "Create partitions on stick." + # get the total size of the device + DISKSIZE=$($SUDOCMD sfdisk -s /dev/${OUT_DEV} 2>/dev/null || echo 0) + DISKSIZE=$((${DISKSIZE}/1024)) + + # get the size of boot stuff and calculate the left over free space on device + KSIZE=$(ls -l ${ROOT_DIR}/build/${KERNEL}|awk '{print $5}') + ISIZE=$(ls -l ${ROOT_DIR}/build/${INITRAMFS}|awk '{print $5}') + IMAGESIZE=$(((${KSIZE}+${ISIZE}+6000000)/1048576)) + FREE=$((${DISKSIZE}-${IMAGESIZE})) + + if [ $IMAGESIZE -lt 16 ]; then + perror "Calculated image size too small, something went wrong probably ($IMAGESIZE MB)." + fi + + # create bootable vfat at the end of the device if big enough, otherwise use + # the entire device + if [ ${FREE} -ge 50 ] ; then + MAIN_DEV="/dev/${OUT_DEV}2" + HOME_DEV="/dev/${OUT_DEV}1" + $SUDOCMD sfdisk /dev/${OUT_DEV} -uM << EOF +,${FREE},L, +,,6,* +EOF + else + MAIN_DEV="/dev/${OUT_DEV}1" + HOME_DEV="" + $SUDOCMD sfdisk /dev/${OUT_DEV} << EOF +,,6,* +EOF + fi + + sync +} + +create_fs () { + pinfo "Create bootable MBR and filesystems." + # copy mbr to stick + $SUDOCMD dd bs=440 count=1 conv=notrunc if=${SYSLINUX}/mbr/mbr.bin of=/dev/${OUT_DEV} + + # create filesystems on newly createt partitions + $SUDOCMD mkfs.vfat -F 16 -n pbstick ${MAIN_DEV} + [ ! -z ${HOME_DEV} ] && $SUDOCMD mkfs.ext2 -L pbstick-home ${HOME_DEV} +} + +mount_stick () { + pinfo "Mounting stick." + $SUDOCMD mkdir -p /media/openslx-stick + $SUDOCMD mount ${MAIN_DEV} /media/openslx-stick + + if [ ! -z ${HOME_DEV} ]; then + $SUDOCMD mkdir -p /media/openslx-stick-usrhome + $SUDOCMD mount ${HOME_DEV} /media/openslx-stick-usrhome + fi + + $SUDOCMD mkdir -p /media/openslx-stick/boot +} + +copy_files () { + pinfo "Copy files to stick." + $SUDOCMD cp -v ${ROOT_DIR}/build/${KERNEL} /media/openslx-stick/boot/kernel + + $SUDOCMD cp -v ${ROOT_DIR}/build/${INITRAMFS} /media/openslx-stick/boot/initramfs + + $SUDOCMD cp -v ${SYSLINUX}/com32/menu/menu.c32 /media/openslx-stick/boot/ + $SUDOCMD cp -v ${SYSLINUX}/com32/menu/vesamenu.c32 /media/openslx-stick/boot/ + + $SUDOCMD cp -v ${ROOT_DIR}/config/extlinux/* /media/openslx-stick/boot + $SUDOCMD mv /media/openslx-stick/boot/extlinux.conf /media/openslx-stick/boot/syslinux.cfg +} + +umount_stick () { + pinfo "Unmount stick (it can take some time to sync)." + $SUDOCMD umount /media/openslx-stick + [ ! -z ${HOME_DEV} ] && $SUDOCMD umount /media/openslx-stick-usrhome + + $SUDOCMD rm -rf /media/openslx-stick* +} + +run_syslinux () { + pinfo "Complete syslinux installation." + echo "${SYSLINUX}/linux/syslinux --install -d /boot -f ${MAIN_DEV}" + $SUDOCMD ${SYSLINUX}/linux/syslinux --install -d /boot -f ${MAIN_DEV} +} + +run () { + set_quiet + + ask_user + umount_dev + create_partitions + create_fs + mount_stick + copy_files + umount_stick + run_syslinux + + unset_quiet + + pinfo "FINISHED: You can unplug the stick now!" +} diff --git a/install-usb b/install-usb index 3ad2a62..65838bc 100755 --- a/install-usb +++ b/install-usb @@ -94,7 +94,6 @@ fi mkdir -p /media/openslx-stick /media/openslx-stick-usrhome -sync if [ "x$NO_USRHOME" != "xtrue" ]; then mount /dev/${OUT_DEV}2 /media/openslx-stick diff --git a/installer/tpl/installer.tpl.sh b/installer/tpl/installer.tpl.sh index 0e5c83b..15ef6ce 100755 --- a/installer/tpl/installer.tpl.sh +++ b/installer/tpl/installer.tpl.sh @@ -179,7 +179,6 @@ fi mkdir -p /media/openslx-stick /media/openslx-stick-usrhome -sync if [ "x$NO_USRHOME" != "xtrue" ]; then mount /dev/${OUT_DEV}2 /media/openslx-stick @@ -190,9 +189,9 @@ fi mkdir -p /media/openslx-stick/boot -cp -v $TMP_DIR/boot/* /media/openslx-stick/boot/ $DEBUG_OUT +cp -v $TMP_DIR/boot/* /media/openslx-stick/boot/ -umount /media/openslx-stick $DEBUG_OUT +umount /media/openslx-stick umount /media/openslx-stick-usrhome $DEBUG_OUT rm -rf /media/openslx-stick* $DEBUG_OUT @@ -0,0 +1,65 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Copyright (c) 2011 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# PreBoot Media ToolKit +# ----------------------------------------------------------------------------- + +ROOT_DIR=$(dirname $(readlink -f $0)) +SELF=$(readlink -f $0) + +SUBMODULE=$1 +shift + +. $ROOT_DIR/inc/functions.common.sh + +print_module_usage() { + echo "Toolkit for creating PreBoot Media for OpenSLX NG (pbmtk)" + echo "Usage: $(basename $SELF) MODULE [OPTIONS]" + echo "Modules:" + echo -e " env \t fetch, update, recreate kernel/initramfs" + echo -e " iso \t create preboot isos" + echo -e " usb \t create preboot usb sticks" + echo -e " installer \t create self-extracting installers" + echo "For more help run: $(basename $SELF) MODULE --help" +} + +banner + +if [ "x$SUBMODULE" = "xenv" ]; then + echo -e "Module: ENV" +elif [ "x$SUBMODULE" = "xiso" ]; then + echo -e "Module: PreBoot-ISO Creator" + . $ROOT_DIR/inc/functions.iso.sh +elif [ "x$SUBMODULE" = "xusb" ]; then + echo -e "Module: PreBoot-USB-Stick Creator" + . $ROOT_DIR/inc/functions.usb.sh +elif [ "x$SUBMODULE" = "xinstaller" ]; then + echo -e "Module: PreBoot-Media Installer Creator" + . $ROOT_DIR/inc/functions.create-installer.sh +elif [ "x$SUBMODULE" = "x--version" -o "x$SUBMODULE" = "x-v" ]; then + echo -e "Module: Version" + exit 1 +else + print_module_usage +fi + +init_params + +mkdir -p $LOG_DIR/ + +run_global_checks + +read_params $@ + +run_module_checks + +run |