-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkrootfs.sh
executable file
·190 lines (157 loc) · 6.51 KB
/
mkrootfs.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env bash
set -euo pipefail
MODEL=${MODEL:-pioneer} # pioneer, pisces
DEVICE=/dev/loop100
CHROOT_TARGET=rootfs
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
ROOT_IMG=revyos-${MODEL}-${TIMESTAMP}.img
# == kernel variables ==
KERNEL_pioneer="linux-headers-6.6.56-pioneer linux-image-6.6.56-pioneer"
KERNEL_pisces="linux-headers-6.6.56-pisces linux-image-6.6.56-pisces"
KERNEL=$(eval echo '$'"KERNEL_${MODEL}")
# == packages ==
BASE_TOOLS="binutils file tree sudo bash-completion u-boot-menu initramfs-tools openssh-server network-manager dnsmasq-base libpam-systemd ppp wireless-regdb wpasupplicant libengine-pkcs11-openssl iptables systemd-timesyncd vim usbutils libgles2 parted"
XFCE_DESKTOP="xorg xfce4 desktop-base lightdm xfce4-terminal tango-icon-theme xfce4-notifyd xfce4-power-manager network-manager-gnome xfce4-goodies pulseaudio alsa-utils dbus-user-session rtkit pavucontrol thunar-volman eject gvfs gvfs-backends udisks2 dosfstools e2fsprogs e2fsprogs libblockdev-crypto2 ntfs-3g polkitd exfat-fuse "
GNOME_DESKTOP="gnome-core avahi-daemon desktop-base file-roller gnome-tweaks gstreamer1.0-libav gstreamer1.0-plugins-ugly libgsf-bin libproxy1-plugin-networkmanager network-manager-gnome"
KDE_DESKTOP="kde-plasma-desktop"
BENCHMARK_TOOLS="glmark2 mesa-utils vulkan-tools iperf3 stress-ng"
#FONTS="fonts-crosextra-caladea fonts-crosextra-carlito fonts-dejavu fonts-liberation fonts-liberation2 fonts-linuxlibertine fonts-noto-core fonts-noto-cjk fonts-noto-extra fonts-noto-mono fonts-noto-ui-core fonts-sil-gentium-basic"
FONTS="fonts-noto-core fonts-noto-cjk fonts-noto-mono fonts-noto-ui-core"
INCLUDE_APPS="firefox vlc gimp gimp-data-extras gimp-plugin-registry gimp-gmic chromium"
EXTRA_TOOLS="i2c-tools net-tools ethtool"
LIBREOFFICE="libreoffice-base \
libreoffice-calc \
libreoffice-core \
libreoffice-draw \
libreoffice-impress \
libreoffice-math \
libreoffice-report-builder-bin \
libreoffice-writer \
libreoffice-nlpsolver \
libreoffice-report-builder \
libreoffice-script-provider-bsh \
libreoffice-script-provider-js \
libreoffice-script-provider-python \
libreoffice-sdbc-mysql \
libreoffice-sdbc-postgresql \
libreoffice-wiki-publisher \
"
DOCKER="docker.io apparmor ca-certificates cgroupfs-mount git needrestart xz-utils"
ADDONS="initramfs-tools firmware-amd-graphics firmware-realtek"
machine_info() {
uname -a
echo $(nproc)
lscpu
whoami
env
fdisk -l
df -h
}
init() {
# Init out folder & rootfs
mkdir -p rootfs
apt update
# create flash image
fallocate -l 7G $ROOT_IMG
}
install_deps() {
apt install -y gdisk dosfstools g++-12-riscv64-linux-gnu build-essential \
libncurses-dev gawk flex bison openssl libssl-dev \
dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf mkbootimg \
fakeroot genext2fs genisoimage libconfuse-dev mtd-utils mtools qemu-utils squashfs-tools \
device-tree-compiler rauc u-boot-tools f2fs-tools swig mmdebstrap parted
}
qemu_setup() {
apt install -y binfmt-support qemu-user-static curl wget
update-binfmts --display
}
img_setup() {
losetup -P "${DEVICE}" $ROOT_IMG
parted -s -a optimal -- "${DEVICE}" mktable msdos
parted -s -a optimal -- "${DEVICE}" mkpart primary fat32 0% 256MiB
parted -s -a optimal -- "${DEVICE}" mkpart primary ext4 256MiB 1280MiB
parted -s -a optimal -- "${DEVICE}" mkpart primary ext4 1280MiB 100%
partprobe "${DEVICE}"
mkfs.vfat "${DEVICE}p1" -n EFI
mkfs.ext4 -F -L revyos-boot "${DEVICE}p2"
mkfs.ext4 -F -L revyos-root "${DEVICE}p3"
mount "${DEVICE}p3" rootfs
mkdir -p rootfs/boot
mount "${DEVICE}p2" rootfs/boot
mkdir -p rootfs/boot/efi
mount "${DEVICE}p1" rootfs/boot/efi
}
make_rootfs() {
mmdebstrap --architectures=riscv64 \
--skip=check/empty \
--include="ca-certificates debian-ports-archive-keyring revyos-keyring locales dosfstools \
$BASE_TOOLS $XFCE_DESKTOP $BENCHMARK_TOOLS $FONTS $INCLUDE_APPS $EXTRA_TOOLS $LIBREOFFICE $ADDONS" \
sid "$CHROOT_TARGET" \
"deb [trusted=yes] https://mirror.iscas.ac.cn/revyos/revyos-addons/ revyos-addons main" \
"deb [trusted=yes] https://mirror.iscas.ac.cn/revyos/revyos-kernels/ revyos-kernels main" \
"deb [trusted=yes] https://mirror.iscas.ac.cn/revyos/revyos-base/ sid main contrib non-free non-free-firmware"
}
after_mkrootfs() {
# Set up fstab
cat > "$CHROOT_TARGET"/etc/fstab << EOF
LABEL=revyos-root / ext4 defaults,noatime,x-systemd.device-timeout=300s,x-systemd.mount-timeout=300s 0 0
LABEL=revyos-boot /boot ext4 defaults,noatime,x-systemd.device-timeout=300s,x-systemd.mount-timeout=300s 0 0
LABEL=EFI /boot/efi vfat defaults,noatime,x-systemd.device-timeout=300s,x-systemd.mount-timeout=300s 0 0
EOF
sudo chroot $CHROOT_TARGET /bin/bash << EOF
# apt update
apt update
# Add user
useradd -m -s /bin/bash -G adm,sudo debian
echo 'debian:debian' | chpasswd
# Change hostname
echo revyos-${MODEL} > /etc/hostname
echo 127.0.1.1 revyos-${MODEL} >> /etc/hosts
# Disable iperf3
systemctl disable iperf3
# Set default timezone to Asia/Shanghai
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo "Asia/Shanghai" > /etc/timezone
exit
EOF
# Add timestamp file in /etc
if [ ! -f revyos-release ]; then
echo "$TIMESTAMP" > rootfs/etc/revyos-release
else
cp -v revyos-release rootfs/etc/revyos-release
fi
# clean up source.list
cat > $CHROOT_TARGET/etc/apt/sources.list << EOF
deb https://mirror.iscas.ac.cn/revyos/revyos-addons/ revyos-addons main
deb https://mirror.iscas.ac.cn/revyos/revyos-kernels/ revyos-kernels main
deb https://mirror.iscas.ac.cn/revyos/revyos-base/ sid main contrib non-free non-free-firmware
EOF
# remove openssh keys
rm -v $CHROOT_TARGET/etc/ssh/ssh_host_*
cp -rvp addons/etc/systemd/system/firstboot.service $CHROOT_TARGET/etc/systemd/system/
cp -rvp addons/opt/firstboot.sh $CHROOT_TARGET/opt/
chroot "$CHROOT_TARGET" sh -c "systemctl enable firstboot"
# Add update-u-boot config
cat > $CHROOT_TARGET/etc/default/u-boot << EOF
U_BOOT_PROMPT="2"
U_BOOT_MENU_LABEL="RevyOS GNU/Linux"
U_BOOT_PARAMETERS="console=ttyS0,115200 root=LABEL=revyos-root rootfstype=ext4 rootwait rw earlycon hide_v0p7_ext selinux=0 LANG=en_US.UTF-8"
U_BOOT_ROOT="root=LABEL=revyos-root"
EOF
# Install kernel
sudo chroot $CHROOT_TARGET /bin/bash << EOF
apt install -y $KERNEL
u-boot-update
EOF
# clean source
rm -vrf $CHROOT_TARGET/var/lib/apt/lists/*
umount -l "$CHROOT_TARGET"
}
machine_info
init
install_deps
qemu_setup
img_setup
make_rootfs
after_mkrootfs
losetup -d "${DEVICE}"