summaryrefslogblamecommitdiffstats
path: root/install-usb
blob: 65838bc33ac606895c36f4e194667e99bd566589 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
           













                                                                               








                                     
 
                        

                                                                          


          




                                                            



                                        

                                            
                             






                                                                   

                                                           
                              
 


                                                                             
                                                  
                                  
 



                                                                            


           
    
                 



                               
 

                                                                              



                              



                   
                                                                            

                                                





                                                    


                                                          
 





                                                     


                                  
 
                                                                              
 
                                                                             
 

                                                                    
 
                                                             
                                                                                  


                           

                                   

                            




                                                                   
 
#!/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 "[Error] No output device specified."
    echo "Usage $0 [devicename of usb-stick] (e.g. \"sdc\" for /dev/sdc)."
    exit 1
fi

echo "device ${OUT_DEV} will be repartitioned and formatted"
echo -n "type 'cont' to proceed: "
read cont
[ "x${cont}" != "xcont" ] && exit 1

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="${ROOT_DIR}/bin/:$PATH"

# 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)
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-preboot-latest|awk '{print $5}')
ISIZE=$(ls -l ${ROOT_DIR}/build/initramfs-default|awk '{print $5}')
IMAGESIZE=$(((${KSIZE}+${ISIZE}+6000000)/1048576))
FREE=$((${DISKSIZE}-${IMAGESIZE}))

# create bootable vfat at the end of the device if big enough, otherwise use
# the entire device
if [ ${FREE} -ge 50 ] ; then
  sfdisk /dev/${OUT_DEV} -uM << EOF
,${FREE},L,
,,6,*
EOF
else
  NO_USRHOME=true
  sfdisk /dev/${OUT_DEV} << EOF
,,6,*
EOF
fi

# 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
if [ "x$NO_USRHOME" != "xtrue" ]; then
  mkfs.vfat -F 16 -n  openslx-stick /dev/${OUT_DEV}2
  mkfs.ext2 -L openslx-usrhome /dev/${OUT_DEV}1
else
  mkfs.vfat -F 16 -n  openslx-stick /dev/${OUT_DEV}1
fi

mkdir -p /media/openslx-stick /media/openslx-stick-usrhome


if [ "x$NO_USRHOME" != "xtrue" ]; then
  mount /dev/${OUT_DEV}2 /media/openslx-stick
  mount /dev/${OUT_DEV}1 /media/openslx-stick-usrhome
else
  mount /dev/${OUT_DEV}1 /media/openslx-stick
fi

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/initramfs

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

rm -rf /media/openslx-stick*

if [ "x$NO_USRHOME" != "xtrue" ]; then
  ${SYSLINUX}/linux/syslinux --install -d /boot -f /dev/${OUT_DEV}2
else
  ${SYSLINUX}/linux/syslinux --install -d /boot -f /dev/${OUT_DEV}1
fi