-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkcascade
executable file
·109 lines (87 loc) · 2.98 KB
/
mkcascade
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
#!/bin/sh
set -e
REPO_ROOT_DIR=$(dirname "$SCRIPT")
TARGET_DIR=$REPO_ROOT_DIR/target
STAGE3_DIR=/var/stage3
CASCADE_DIR=/var/cascade
HD_PATH=$TARGET_DIR/kernel-hd
if [ ! -f $TARGET_DIR/rootfs.tar.gz ]; then
mkdir -p $TARGET_DIR
URL=https://distfiles.gentoo.org/releases/amd64/autobuilds/20240602T164858Z/stage3-amd64-openrc-20240602T164858Z.tar.xz
wget -O $TARGET_DIR/rootfs.tar.gz $URL
unset URL
fi
if [ ! -d $STAGE3_DIR/bin ]; then
mkdir -p $STAGE3_DIR
tar xpf $TARGET_DIR/rootfs.tar.gz --xattrs-include='*.*' --numeric-owner -C $STAGE3_DIR
echo "nameserver 8.8.8.8" > $STAGE3_DIR/etc/resolv.conf
mount --rbind /dev $STAGE3_DIR/dev
mount --make-rslave $STAGE3_DIR/dev
mount -t proc /proc $STAGE3_DIR/proc
mount --rbind /sys $STAGE3_DIR/sys
mount --make-rslave $STAGE3_DIR/sys
# We just use a regular directory for /tmp
# and delete it below.
#
# This doesn't align with the Gentoo guide
# but it seems to work.
mkdir -p /tmp
# Gentoo docs specifying mounting /run, but
# we skip that because configs end up being
# saved here and we want to copy it to the
# final disk image, so we don't want anything
# from the underlying host machine included.
# Copy in the Cascade ebuild repo
#
# For now we put this in tmp because we need
# to first create the local repo and then
# copy these in with the appropriate permissions.
cp -r ebuild $STAGE3_DIR/tmp/
echo "
#!/bin/sh
set -e
# Really we should uncomment this rather than
# add a new line..
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
# This assumes that there aren't any other USE flags
# set by default.
echo 'USE="dracut"' >> /etc/portage/make.conf
echo 'ACCEPT_KEYWORDS="~amd64"' >> /etc/portage/make.conf
echo 'ACCEPT_LICENSE="*"' >> /etc/portage/make.conf
emerge-webrsync
source /etc/profile
# Install the Linux kernel.
emerge sys-kernel/gentoo-kernel-bin
# Add a local repository
emerge app-eselect/eselect-repository
eselect repository create cascade
mv /tmp/ebuild/* /var/db/repos/cascade
rm -r /tmp/ebuild
chown -R portage:portage /var/db/repos/cascade
# Install our patched version of xattr, so it doesn't attempt
# to follow symlinks and break uutils coreutils.
emerge --update sys-apps/install-xattr::cascade
# Replace GNU coreutils with uutils coreutils.
emerge --update sys-apps/coreutils::cascade
# Enable ttys0
sed -i '/ttyS0/s/^#//' etc/inittab
" > $STAGE3_DIR/setup
chmod +x $STAGE3_DIR/setup
chroot $STAGE3_DIR /setup
rm $STAGE3_DIR/setup
# Make disk image
dd if=/dev/zero of=$HD_PATH bs=1M count=10000
# Set owner back to user so they can start qemu without sudo
chown $SUDO_USER:$SUDO_USER $HD_PATH
TMP_MNT=/mnt/cascade
mkdir -p $TMP_MNT
mkfs.ext4 $HD_PATH
mount $HD_PATH $TMP_MNT
cp -r $STAGE3_DIR/{bin,boot,etc,home,lib,lib64,media,opt,root,run,sbin,usr,var} $TMP_MNT
mkdir $TMP_MNT/{dev,proc,sys}
# Create blank root password
passwd --root $TMP_MNT root -d
umount $TMP_MNT
unset TMP_MNT
fi