blob: 01c57cdd894dd4787db80948f315e2ecbf81567b (
plain) (
tree)
|
|
#!/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))
if [ $(whoami) != "root" ]; then
echo "you should be root"
exit 1;
fi
OUT_DEV=$1
if [ -z $OUT_DEV ]; then
echo "no dev"
exit 1
fi
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 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
sync
# copy mbr to stick
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}2
mkfs.ext2 -L openslx-usrhome /dev/${OUT_DEV}1
mkdir -p /media/openslx-stick /media/openslx-stick-usrhome
sync
mount /dev/${OUT_DEV}2 /media/openslx-stick
mount /dev/${OUT_DEV}1 /media/openslx-stick-usrhome
mkdir -p /media/openslx-stick/boot
cp -v ${ROOT_DIR}/build/kernel-preboot-latest /media/openslx-stick/boot/kernel
cp -v ${ROOT_DIR}/build/initramfs-default /media/openslx-stick/boot/init
cp -v ${SYSLINUX}/com32/menu/menu.c32 /media/openslx-stick/boot/
cp -v ${SYSLINUX}/com32/menu/vesamenu.c32 /media/openslx-stick/boot/
cp -v ${ROOT_DIR}/config/extlinux/* /media/openslx-stick/boot
mv /media/openslx-stick/boot/extlinux.conf /media/openslx-stick/boot/syslinux.cfg
sync
umount /media/openslx-stick
umount /media/openslx-stick-usrhome
${SYSLINUX}/linux/syslinux --install -d /boot -f /dev/${OUT_DEV}2
|