-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimal-root.sh
executable file
·105 lines (80 loc) · 3.32 KB
/
minimal-root.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
#!/bin/bash
set -eE
trap 'echo Error: in $0 on line $LINENO' ERR
if [ "$(id -u)" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
attach_MOUNTPOINT() {
local MOUNTPOINT="$1"
if [ ! -c /dev/mem ]; then
mknod -m 660 /dev/mem c 1 1
chown root:kmem /dev/mem
fi
mount dev-live -t devtmpfs "$MOUNTPOINT/dev"
mount devpts-live -t devpts -o nodev,nosuid "$MOUNTPOINT/dev/pts"
mount proc-live -t proc "$MOUNTPOINT/proc"
mount sysfs-live -t sysfs "$MOUNTPOINT/sys"
mount securityfs -t securityfs "$MOUNTPOINT/sys/kernel/security"
mount -t cgroup2 none "$MOUNTPOINT/sys/fs/cgroup"
mount -t tmpfs none "$MOUNTPOINT/tmp"
mount -t tmpfs none "$MOUNTPOINT/var/lib/apt/lists"
mount -t tmpfs none "$MOUNTPOINT/var/cache/apt"
}
detach_MOUNTPOINT() {
# Reverse the operations from setup_MOUNTPOINT
local MOUNTPOINT
MOUNTPOINT=$(realpath "$1")
# ensure we have exactly one trailing slash, and escape all slashes for awk
MOUNTPOINT_match=$(echo "$MOUNTPOINT" | sed -e's,/$,,; s,/,\\/,g;')'\/'
# sort -r ensures that deeper MOUNTPOINTs are unmounted first
awk </proc/self/mounts "\$2 ~ /$MOUNTPOINT_match/ { print \$2 }" | LC_ALL=C sort -r | while IFS= read -r submount; do
mount --make-private "$submount"
umount "$submount"
done
}
export RELASE_NAME="Ubuntu 24.10 (Oracular Oriole)"
export RELASE_VERSION="24.10"
export PROJECT=ubuntu-cpc
export SUITE=oracular
export FLAVOR=server
export ARCH=arm64
export IMAGEFORMAT=none
export IMAGE_TARGETS=none
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
export LC_ALL=C
export LC_CTYPE=C
export LANGUAGE=C
export LANG=C
export SYSROOT=aarch64
# Create a stock root directory and populate it with debootstrap.
mkdir $SYSROOT
debootstrap --arch=$ARCH oracular $SYSROOT "http://ports.ubuntu.com/ubuntu-ports"
# Attach sysroot.
attach_MOUNTPOINT $SYSROOT
# Update, Upgrade, Add repositories.
chroot $SYSROOT apt update
chroot $SYSROOT apt -y upgrade
chroot $SYSROOT apt -y dist-upgrade
chroot $SYSROOT apt -y install apt-utils software-properties-common python3-launchpadlib
chroot $SYSROOT add-apt-repository -y universe # Solves some unmet dependencies.
chroot $SYSROOT add-apt-repository -y multiverse # This one as well.
chroot $SYSROOT apt-add-repository -y restricted # Yep, this one too.
chroot $SYSROOT add-apt-repository -y ppa:jjriek/rockchip # We need Joshua's repo.
chroot $SYSROOT add-apt-repository -y ppa:oibaf/graphics-drivers # We need the upstream mesa repo.
chroot $SYSROOT apt update
chroot $SYSROOT apt -y upgrade
chroot $SYSROOT apt -y install ubuntu-server-rockchip u-boot-orangepi-5-plus u-boot-tools u-boot-menu \
linux-firmware cloud-initramfs-growroot grub-efi-arm64 initramfs-tools
7z x linux-rockchip-6.13-rc6_arm64.zip -O$SYSROOT/tmp/kernel
chroot $SYSROOT /bin/bash -c "dpkg -i /tmp/kernel/linux-*6.13*.deb"
chroot $SYSROOT update-initramfs -u
# Get every things clean.
chroot $SYSROOT apt -y autoremove
chroot $SYSROOT apt autoclean
chroot $SYSROOT apt clean
# Detach the sysroot.
detach_MOUNTPOINT $SYSROOT
# Package the minimal sysroot.
(cd $SYSROOT && tar -p -c --sort=name --xattrs ./*) | xz -3 -T0 > "ubuntu-${RELASE_VERSION}-preinstalled-${FLAVOR}-arm64.rootfs.tar.xz"