@@ -20,6 +20,7 @@ RELEASE=trixie
2020FEATURE=minimal
2121SEEK=2047
2222PERF=false
23+ IN_DOCKER=false
2324
2425# Display help function
2526display_help () {
@@ -77,66 +78,10 @@ if [ $PERF = "true" ] && [ -z ${KERNEL+x} ]; then
7778fi
7879
7980# If full feature is chosen, install more packages
80- if [ $FEATURE = " full" ]; then
81+ if [ " $FEATURE " = " full" ]; then
8182 PREINSTALL_PKGS=$PREINSTALL_PKGS " ," $ADD_PACKAGE
8283fi
8384
84- sudo rm -rf $DIR
85- mkdir -p $DIR
86- sudo debootstrap --include=$PREINSTALL_PKGS $RELEASE $DIR
85+ source ./debootstrap.sh
86+ source ./configure.sh
8787
88- # Set some defaults and enable promtless ssh to the machine for root.
89- sudo sed -i ' /^root/ { s/:x:/::/ }' $DIR /etc/passwd
90- echo ' T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100' | sudo tee -a $DIR /etc/inittab
91- printf ' \nauto eth0\niface eth0 inet dhcp\n' | sudo tee -a $DIR /etc/network/interfaces
92- echo ' /dev/root / ext4 defaults 0 0' | sudo tee -a $DIR /etc/fstab
93- echo ' debugfs /sys/kernel/debug debugfs defaults 0 0' | sudo tee -a $DIR /etc/fstab
94- # echo 'securityfs /sys/kernel/security securityfs defaults 0 0' | sudo tee -a $DIR/etc/fstab
95- # echo 'configfs /sys/kernel/config/ configfs defaults 0 0' | sudo tee -a $DIR/etc/fstab
96- echo ' binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0' | sudo tee -a $DIR /etc/fstab
97- echo " kernel.printk = 7 4 1 3" | sudo tee -a $DIR /etc/sysctl.conf
98- echo ' debug.exception-trace = 0' | sudo tee -a $DIR /etc/sysctl.conf
99- echo " net.core.bpf_jit_enable = 1" | sudo tee -a $DIR /etc/sysctl.conf
100- echo " net.core.bpf_jit_kallsyms = 1" | sudo tee -a $DIR /etc/sysctl.conf
101- echo " net.core.bpf_jit_harden = 0" | sudo tee -a $DIR /etc/sysctl.conf
102- echo " kernel.softlockup_all_cpu_backtrace = 1" | sudo tee -a $DIR /etc/sysctl.conf
103- echo " kernel.kptr_restrict = 0" | sudo tee -a $DIR /etc/sysctl.conf
104- echo " kernel.watchdog_thresh = 60" | sudo tee -a $DIR /etc/sysctl.conf
105- echo " net.ipv4.ping_group_range = 0 65535" | sudo tee -a $DIR /etc/sysctl.conf
106- echo -en " 127.0.0.1\tlocalhost\n" | sudo tee $DIR /etc/hosts
107- echo " nameserver 8.8.8.8" | sudo tee -a $DIR /etc/resolve.conf
108- echo " pwn" | sudo tee $DIR /etc/hostname
109-
110- # Add perf support
111- if [ $PERF = " true" ]; then
112- cp -r $KERNEL $DIR /tmp/
113- sudo chroot $DIR /bin/bash -c " apt-get update; apt-get install -y flex bison python-dev libelf-dev libunwind8-dev libaudit-dev libslang2-dev libperl-dev binutils-dev liblzma-dev libnuma-dev"
114- sudo chroot $DIR /bin/bash -c " cd /tmp/linux/tools/perf/; make"
115- sudo chroot $DIR /bin/bash -c " cp /tmp/linux/tools/perf/perf /usr/bin/"
116- rm -r $DIR /tmp/linux
117- fi
118-
119- # create a default user called user
120- echo " user::1000:1000:user:/home/user:/bin/bash" | sudo tee -a $DIR /etc/passwd
121- echo " user:x:1000:" | sudo tee -a $DIR /etc/group
122- sudo mkdir -p $DIR /home/user/.ssh
123- sudo chown -R 1000:1000 $DIR /home/user
124-
125- # install python3
126- sudo chroot $DIR /bin/bash -c " apt-get update"
127- sudo chroot $DIR /bin/bash -c " apt-get install -y python3 && ln -s /usr/bin/python3 /usr/bin/python"
128-
129- # create ssh key and save it
130- ssh-keygen -f $RELEASE .id_rsa -t rsa -N ' '
131- sudo mkdir -p $DIR /root/.ssh/
132- cat $RELEASE .id_rsa.pub | sudo tee $DIR /root/.ssh/authorized_keys
133- cat $RELEASE .id_rsa.pub | sudo tee $DIR /home/user/.ssh/authorized_keys
134- sudo chown -R 1000:1000 $DIR /home/user
135-
136- # Build a disk image
137- dd if=/dev/zero of=$RELEASE .img bs=1M seek=$SEEK count=1
138- sudo mkfs.ext4 -F $RELEASE .img
139- sudo mkdir -p /mnt/$DIR
140- sudo mount -o loop $RELEASE .img /mnt/$DIR
141- sudo cp -a $DIR /. /mnt/$DIR /.
142- sudo umount /mnt/$DIR
0 commit comments