-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake-stick.sh
executable file
·99 lines (78 loc) · 3.02 KB
/
make-stick.sh
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
#! /bin/sh
# make-stick.sh: adds what's needed to boot the system from a chosen stick
# It should not erase anything from the system (but you should make sure that you have enough room on the key)
# Testing user ID
uid=$(/usr/bin/id -u)
if [ $uid != "0" ] ; then
echo "Please make sure to become root before running me" 2>&1 ;
exit 1
fi
set -ex
### Initial checkups
if [ -e basesystem.sqh ] ; then
echo "Base system found, fine."
else
echo "XXX Unable to fine the base system (basesystem.sqh). Please use make-base.sh first"
exit 1
fi
if [ -e initrd.gz ] ; then
echo "initrd found, fine."
else
echo "XXX Unable to fine the initrd.gz. Please use make-base.sh first"
exit 1
fi
echo "XXX Pick the right stick to use"
STICKS=`ls -l /dev/disk/by-id/ | grep " usb-" | awk '{print $11}' | sed -e 's|^.*\(sd.\)[0-9]*|\1|' | sort -u`
BUTTON="stop"
echo -n > /tmp/USB_message
echo "Stop: Stop the stick creation right away">> /tmp/USB_message
#echo "fake: make a disk image instead of using a real disk">> /tmp/USB_message
for s in $STICKS ; do
unset STICK_NAME
STICK_NAME=`ls -l /dev/disk/by-id/ | grep "$s\$" | sed -e 's/^.*usb-\([^_]*_[^_]*_[^_]*\)_.*$/\1/'`
unset STICK_SIZE
STICK_SIZE=`cat /sys/block/$s/size`
BLOCS=`cat /sys/block/$s/queue/hw_sector_size`
STICK_SIZE=`expr $STICK_SIZE \* $BLOCS / 1000000`
TYPE="$s: USB stick $STICK_NAME ($STICK_SIZE Mbytes)"
BUTTON=$BUTTON","$s
echo $TYPE >> /tmp/USB_message
done
echo >> /tmp/USB_message
echo "Clic on the stick to use:" >> /tmp/USB_message
CHOSEN_STICK=`xmessage -center -print -file /tmp/USB_message -buttons $BUTTON || true` # FIXME: I don't like ignoring the return value here
rm /tmp/USB_message
if [ "$CHOSEN_STICK" = "stop" ] ; then
exit 1
fi
STICK=/dev/$CHOSEN_STICK
PART=${STICK}1
echo "XXX Copy the data onto the stick $CHOSEN_STICK"
umount mountpoint 2>/dev/null|| true
rm -rf mountpoint
mkdir mountpoint
mount $PART mountpoint
if [ ! -e mountpoint/boot ] ; then
mkdir mountpoint/boot
fi
if [ -e mountpoint/boot/basesystem.sqh ] ; then
echo "The base system already exists, do not copy it again (to save time)"
else
cp basesystem.sqh mountpoint/boot
fi
cp initrd.gz mountpoint/boot
#echo "XXX Install grub onto the stick"
#echo "(if it fails with the message 'Your embedding area is unusually small. core.img won't fit in it', try starting gparted to reduce the size of the partition by one Mb, placed at the begining of the disk. One day, that will be automated)"
# http://ubuntuforums.org/archive/index.php/t-1528529.html
# grub-install --boot-directory=mountpoint/boot $STICK
echo "XXX Write Stick Master Boot Record"
dd conv=notrunc bs=440 count=1 if=mbr.bin of=$STICK
echo "XXX Set boot flag to first partition"
parted $STICK set 1 boot on
echo "XXX Install syslinux onto the stick"
syslinux -i $PART
echo "XXX Give me a kernel and with an initrd, I will boot the whole world"
cp chroot/vmlinuz mountpoint/boot
echo "XXX We also need a config file for syslinux because we can't writing links on vfat fs"
cp syslinux.cfg mountpoint
umount mountpoint