-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller
executable file
·86 lines (69 loc) · 1.47 KB
/
installer
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
#!/bin/sh
set -euo pipefail
get_partition_name(){
sgdisk -i "$2" "$1" | awk -F"'" '/Partition name/ {print $2}'
}
check_disk(){
[ "$(get_partition_name "$1" "1")" = "EFI System Partition" ] || return 1
[ "$(get_partition_name "$1" "2")" = "Linux /boot" ] || return 1
[ "$(get_partition_name "$1" "3")" = "Linux Data" ] || return 1
}
partition_disk(){
sgdisk -og "$1" \
-n 1:2048:411647 -c 1:"EFI System Partition" -t 1:ef00 \
-n 2:411647:823295 -c 2:"Linux /boot" -t 2:8300 \
--attributes=2:set:2 \
-n 3 -c 3:"Linux Data" -t 3:8e00 \
"$1"
sgdisk -p "$1"
format_boot "$1"
format_data "$1"
}
grow_disk(){
sgdisk -e "$1"
}
format_data(){
mkfs.ext4 -L DATA "$1"3
}
format_boot(){
mkfs.ext4 -L BOOT "$1"2
}
check_boot(){
[ -d /boot ] || mkdir /boot
mount LABEL=BOOT /boot || (
format_boot "$1"
mount LABEL=BOOT /boot
)
extlinux --install "/boot"
cat /share/syslinux/gptmbr.bin > "$1"
write_syslinuxcfg
}
write_syslinuxcfg(){
mkdir -p /boot/syslinux
cat <<dog >/boot/syslinux/syslinux.cfg
PROMPT 1
DEFAULT primary
TIMEOUT 30
LABEL primary
KERNEL /primary
LABEL backup
KERNEL /backup
dog
}
copy_files(){
mv /boot/primary /boot/backup || true
cp primary /boot/primary
}
if [ -z "$1" ]; then
echo "Usage: $0 <device>"
fi
echo "Checking disk for partitions"
check_disk "$1" || partition_disk "$1"
#grow_disk "$1"
echo "Checking boot partition"
check_boot "$1"
echo "Copying OS files"
copy_files "$1"
umount /boot
echo "Mounting data"
mount LABEL=DATA /data || true