-
Notifications
You must be signed in to change notification settings - Fork 7
/
create_partitions.sh
executable file
·107 lines (86 loc) · 2.32 KB
/
create_partitions.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
100
101
102
103
104
105
106
107
#!/usr/bin/bash
# Copyright (c) 2023 Kim Hendrikse
export USER="$(getent passwd 1000|cut -d: -f1)"
cd /
# Conditional, not mounted for bullseye, already mounted for bookworm
if ! findmnt /proc ; then
mount -t proc proc /proc
fi
mount -t tmpfs inittemp /mnt
/home/"$USER"/sbts-bin/get_min_files.sh | sort -u |cpio -pudmv mnt
cd mnt
mkdir mnt proc sys dev run tmp
cp /home/"$USER"/sbts-bin/partitions /mnt/tmp
pivot_root . mnt
exec chroot . /usr/bin/bash -c "$(cat <<EOF
cd /
mount --move /mnt/proc /proc
mount --move /mnt/dev /dev
# Extra for bookworm
if findmnt /mnt/sys ; then
mount --move /mnt/sys /sys
fi
if findmnt /mnt/run ; then
mount --move /mnt/run /run
fi
# Unmount so it can be shrunk
umount /mnt
e2fsck -fy /dev/mmcblk0p2
resize2fs -f -M /dev/mmcblk0p2
fdisk /dev/mmcblk0 < /tmp/partitions
resize2fs -f /dev/mmcblk0p2
/usr/sbin/mkfs.ext4 /dev/mmcblk0p5
/usr/sbin/mkfs.ext4 /dev/mmcblk0p6
e2label /dev/mmcblk0p5 SbtsConfig
e2label /dev/mmcblk0p6 SbtsDisk
mkswap /dev/mmcblk0p3
mkdir /tmp/mnt
mount /dev/mmcblk0p6 /tmp/mnt
mkdir /tmp/mnt/log
mkdir /tmp/mnt/tmp
mkdir /tmp/mnt/"$(cat /etc/hostname)"
chown 1000:1000 /tmp/mnt/log
chown 1000:1000 /tmp/mnt/tmp
chown 1000:1000 /tmp/mnt/"$(cat /etc/hostname)"
umount /tmp/mnt
# Pivot back
cd /
mount /dev/mmcblk0p2 /mnt
cd mnt
mkdir home/"$USER"/config
mkdir home/"$USER"/disk
pivot_root . mnt
exec chroot . /usr/bin/bash -c "$( cat <<END
cd /
mount --move /mnt/proc /proc
mount --move /mnt/dev /dev
if findmnt /mnt/sys ; then
mount --move /mnt/sys /sys
fi
if findmnt /mnt/run ; then
mount --move /mnt/run /run
fi
umount /mnt
mount /dev/mmcblk0p1 /mnt
perl -pi -e 's% init.*\$% init=/sbin/overlayRoot.sh%' /mnt/cmdline.txt
umount /mnt
chown 1000:1000 /home/\"$USER/config\"
chown 1000:1000 /home/\"$USER/disk\"
rm /home/\"$USER\"/sbts-bin/create_partitions.sh
#if ! grep bullseye /etc/os-release > /dev/null ; then
if [ "" ] ; then
echo \"Put back /sbin/init to \$(cat /home/$USER/sbts-bin/init_location)\"
rm -f /sbin/init
ln -s \"\$(cat /home/$USER/sbts-bin/init_location)\" /sbin/init
else
if [ -f /boot/firmware/cmdline.txt ] ; then
perl -pi -e 's% init=.*\$% init=/sbin/overlayRoot.sh%' /boot/firmware/cmdline.txt
fi
perl -pi -e 's% init=.*\$% init=/sbin/overlayRoot.sh%' /boot/cmdline.txt
fi
banner FINISHED
exec /sbin/init
END
)"
EOF
)"