From 5dadd81481352fe8dfc24c1865c263c2934201ef Mon Sep 17 00:00:00 2001 From: Dirk von Suchodoletz Date: Sat, 30 Apr 2011 17:17:01 +0200 Subject: Version of usb-stick creator which puts the bootable partition to the end. --- install-usb | 64 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/install-usb b/install-usb index cfccfda..01c57cd 100755 --- a/install-usb +++ b/install-usb @@ -1,4 +1,18 @@ #!/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)) @@ -8,11 +22,6 @@ if [ $(whoami) != "root" ]; then fi OUT_DEV=$1 -SYSLINUX=${ROOT_DIR}/contrib/syslinux/latest - -PATH="$PATH:${ROOT_DIR}/bin/" - -[ ! -f ${SYSLINUX}/Makefile ] && env.setup-syslinux.sh if [ -z $OUT_DEV ]; then echo "no dev" @@ -23,18 +32,38 @@ for i in 1 2 3 4 5 6 7 8 9; do umount /dev/${OUT_DEV}$i &> /dev/null done +SYSLINUX=${ROOT_DIR}/contrib/syslinux/latest + +PATH="$PATH:${ROOT_DIR}/bin/" + +# create the required stuff (syslinux, kernel, initramfs) +[ ! -f ${SYSLINUX}/Makefile ] && env.setup-syslinux.sh +[ ! -f ${ROOT_DIR}/build/kernel-preboot-latest ] && build.kernel.sh +#[ ! -f ${ROOT_DIR}/build/initramfs-default ] && build.initramfs.sh +build.initramfs.sh + # get the total size of the device DISKSIZE=$(sfdisk -s /dev/${OUT_DEV} 2>/dev/null || echo 0) -# get the size of boot stuff - +# get the size of boot stuff and calculate the left over free space on device +KSIZE=$(ls -l ${ROOT_DIR}/build/kernel-preboot-latest|awk '{print $5}') +ISIZE=$(ls -l ${ROOT_DIR}/build/initramfs-default|awk '{print $5}') +IMAGESIZE=$((${KSIZE}+${ISIZE}+6000000)) +FREE=$((${DISKSIZE}-${IMAGESIZE})) +FREE=$((${FREE}/1048576)) + +# create bootable vfat at the end of the device +sfdisk /dev/${OUT_DEV} -uM << EOF +,${FREE},L, +,,6,* +EOF # create bootable vfat partition with 96cylinders and a ext3 partition for the # rest of the stick -sfdisk /dev/${OUT_DEV} << EOF -,96,6,* -,,L -EOF +#sfdisk /dev/${OUT_DEV} << EOF +#,96,6,* +#,,L +#EOF sync @@ -42,24 +71,21 @@ sync dd bs=440 count=1 conv=notrunc if=${SYSLINUX}/mbr/mbr.bin of=/dev/${OUT_DEV} # create filesystems on newly createt partitions -mkfs.vfat -F 16 -n openslx-stick /dev/${OUT_DEV}1 -mkfs.ext2 -L openslx-usrhome /dev/${OUT_DEV}2 +mkfs.vfat -F 16 -n openslx-stick /dev/${OUT_DEV}2 +mkfs.ext2 -L openslx-usrhome /dev/${OUT_DEV}1 mkdir -p /media/openslx-stick /media/openslx-stick-usrhome sync -mount /dev/${OUT_DEV}1 /media/openslx-stick -mount /dev/${OUT_DEV}2 /media/openslx-stick-usrhome +mount /dev/${OUT_DEV}2 /media/openslx-stick +mount /dev/${OUT_DEV}1 /media/openslx-stick-usrhome mkdir -p /media/openslx-stick/boot -[ ! -f ${ROOT_DIR}/build/kernel-preboot-latest ] && build.kernel.sh cp -v ${ROOT_DIR}/build/kernel-preboot-latest /media/openslx-stick/boot/kernel -#[ ! -f ${ROOT_DIR}/build/initramfs-default ] && build.initramfs.sh -build.initramfs.sh cp -v ${ROOT_DIR}/build/initramfs-default /media/openslx-stick/boot/init cp -v ${SYSLINUX}/com32/menu/menu.c32 /media/openslx-stick/boot/ @@ -72,5 +98,5 @@ sync umount /media/openslx-stick umount /media/openslx-stick-usrhome -${SYSLINUX}/linux/syslinux --install -d /boot -f /dev/${OUT_DEV}1 +${SYSLINUX}/linux/syslinux --install -d /boot -f /dev/${OUT_DEV}2 -- cgit v1.2.3-55-g7522