1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#!/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
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="$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)
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
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
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
rm -rf /media/openslx-stick*
${SYSLINUX}/linux/syslinux --install -d /boot -f /dev/${OUT_DEV}2
|