-
Notifications
You must be signed in to change notification settings - Fork 4
/
node_init.sh
executable file
·79 lines (58 loc) · 1.46 KB
/
node_init.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
#!/bin/bash
set -e
BOOTDIR_PATH=`readlink -f $1`
NODE=$2
UHUBCTL="uhubctl -l 1-1"
RPIBOOT=rpiboot
if [ ! -e $BOOTDIR_PATH ]; then
echo "Missing boot dir path"
exit 255
fi
if [ -z "$NODE" ]; then
echo "Must specify node number"
exit 255
fi
BOOT_MNTPT=/tmp/boot$NODE
ROOT_MNTPT=/tmp/root$NODE
rm -rf $BOOT_MNTPT
mkdir $BOOT_MNTPT
rm -rf $ROOT_MNTPT
mkdir $ROOT_MNTPT
echo "---Cycling power"
$UHUBCTL -r 4 -p $NODE -a cycle
echo "---Putting node ${NODE} into USB MSD mode"
$RPIBOOT
sleep 10
DISKDEV=`ls -1 /dev/disk/by-path/*usb-[0-9]:[0-9].${NODE}*:0`
echo "---Checking ${DISKDEV}"
if [ ! -L $DISKDEV ]; then
echo "Could not find mass storage device"
exit 255
fi
echo -e ",524288,0xC\n,+,L" | sfdisk $DISKDEV
sync
# tell the kernel that the partitions have changed
partx ${DISKDEV}
# need to wait for the symlinks to update
sleep 10
sfdisk -l $DISKDEV
sleep 1
ls -l /dev/disk/by-path
mkdosfs ${DISKDEV}-part1
mkfs.ext4 -F ${DISKDEV}-part2
mount ${DISKDEV}-part1 $BOOT_MNTPT
mount ${DISKDEV}-part2 $ROOT_MNTPT
echo "---Untarring boot partition"
tar -C $BOOT_MNTPT -xzf $BOOTDIR_PATH/bootfs.tar.gz
echo "---Untarring root partition"
tar -C $ROOT_MNTPT -xzf $BOOTDIR_PATH/rootfs.tar.gz
echo "---Fixup hostname for node${NODE}"
sed -i -e "s/raspberrypi/node${NODE}/g" $ROOT_MNTPT/etc/hosts
echo "node${NODE}" > $ROOT_MNTPT/etc/hostname
echo "---Unmounting filesystems"
umount $BOOT_MNTPT
umount $ROOT_MNTPT
rmdir $BOOT_MNTPT
rmdir $ROOT_MNTPT
sync
echo "---Done"