Skip to content

Commit 15164a1

Browse files
committed
Add script to create ubuntu debootstrap rootfs
1 parent 9b78ea0 commit 15164a1

File tree

7 files changed

+63
-10
lines changed

7 files changed

+63
-10
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ jobs:
115115
matrix:
116116
kernel: [{ack: 0, version: 5.10.y}, {ack: 0, version: 5.15.y}, {ack: 0, version: 6.1.y}, {ack: 1, version: android13-5.10-lts}]
117117
arch: [arm64, x86_64]
118+
timeout-minutes: 20
118119
runs-on: ubuntu-22.04
119120
env:
120121
ACK: ${{ matrix.kernel.ack }}
@@ -125,15 +126,19 @@ jobs:
125126
- name: Download all workflow run artifacts
126127
uses: actions/download-artifact@v3
127128

129+
- name: Install common dependencies
130+
shell: bash
131+
run: sudo apt update && sudo apt install -y debootstrap
132+
128133
- name: Install x86_64 dependencies
129134
if: ${{ matrix.arch == 'x86_64' }}
130135
shell: bash
131-
run: sudo apt update && sudo apt install -y qemu-system-x86
136+
run: sudo apt install -y qemu-system-x86
132137

133138
- name: Install arm64 dependencies
134139
if: ${{ matrix.arch == 'arm64' }}
135140
shell: bash
136-
run: sudo apt update && sudo apt install -y qemu-system-arm
141+
run: sudo apt install -y qemu-system-arm qemu-user-static binfmt-support
137142

138143
- name: Get real kernel version
139144
run: |
@@ -175,26 +180,26 @@ jobs:
175180
176181
- name: Initialize rootfs and initramfs
177182
run: |
183+
set -x
178184
make rootfs-init
179-
ROOTFS=./alpine-${{ matrix.arch }} make rootfs-init
185+
ROOTFS=./alpine-${{ matrix.arch }}.img make rootfs-init
180186
181-
make cpio
182-
ROOTFS_DIR=./rootfs/alpine-${{ matrix.arch }} make cpio
187+
scripts/ubuntu_debootstrap.sh jammy ${{ matrix.arch }}
188+
SUDO=1 ROOTFS_DIR=./rootfs/ubuntu-jammy-${{ matrix.arch }} CPIO_FILE=ubuntu-jammy-${{ matrix.arch }}.cpio.gz make rootfs-overlay
183189
184190
- name: Setup shared/init.sh
185191
run: |
186192
mkdir shared
187193
echo poweroff > shared/init.sh
188194
chmod +x shared/init.sh
189195
190-
- run: ls -lR
191-
192196
- name: Run kernel
193197
run: |
194198
QEMU_KERNEL_IMAGE=./kernel-image/$IMAGE_NAME make run
195-
QEMU_KERNEL_IMAGE=./kernel-image/$IMAGE_NAME ROOTFS=./rootfs-${{ matrix.arch }} make run
199+
QEMU_KERNEL_IMAGE=./kernel-image/$IMAGE_NAME ROOTFS=./rootfs/ubuntu-jammy-${{ matrix.arch }}.img make run
196200
QEMU_KERNEL_IMAGE=./kernel-image/$IMAGE_NAME INITRD=1 make run
197-
QEMU_KERNEL_IMAGE=./kernel-image/$IMAGE_NAME CPU=2 MEM=2048M QEMU_EXTRA_ARGS="" QEMU_EXTRA_KERNEL_CMDLINE="nokaslr" make run
201+
QEMU_KERNEL_IMAGE=./kernel-image/$IMAGE_NAME INITRD=./ubuntu-jammy-${{ matrix.arch }}.cpio.gz make run
202+
QEMU_KERNEL_IMAGE=./kernel-image/$IMAGE_NAME CPU=2 MEM=2048M QEMU_EXTRA_ARGS="" QEMU_EXTRA_KERNEL_CMDLINE="nokaslr" ROOTFS=./alpine-${{ matrix.arch }}.img make run
198203
199204
- name: Upload rootfs artifact
200205
uses: actions/upload-artifact@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/rootfs/*.img
22
/rootfs/*.cpio.gz
33
/rootfs/alpine-*/
4+
/rootfs/ubuntu-*/
45

56
/toolchain
67
/shared

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The only supported host OS is Ubuntu 22.04, things may or may not work on any ot
77
First install the dependencies and clone the project:
88
```bash
99
sudo apt update
10-
sudo apt install -y bc bison build-essential flex git libelf-dev libssl-dev ncurses-dev qemu qemu-system-x86 qemu-system-arm llvm clang clang-tools lld lz4 binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu pahole
10+
sudo apt install -y bc bison build-essential flex git libelf-dev libssl-dev ncurses-dev gdb gdb-multiarch qemu qemu-system-x86 qemu-system-arm qemu-user-static binfmt-support llvm clang clang-tools lld lz4 binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu pahole dwarves
1111
git clone --recursive https://github.com/gsingh93/linux-exploit-dev-env
1212
cd linux-exploit-dev-env
1313
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/systemd/system/setup.service
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[Service]
2+
Type=simple
3+
ExecStart=
4+
ExecStart=-/sbin/agetty --autologin root --noclear %I 38400 linux
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Documentation=man:systemd-sysv-generator(8)
3+
SourcePath=/etc/init.d/setup
4+
Description=Linux Exploit Dev Environment Setup
5+
6+
[Service]
7+
Type=forking
8+
Restart=no
9+
TimeoutSec=5min
10+
IgnoreSIGPIPE=no
11+
KillMode=process
12+
GuessMainPID=no
13+
RemainAfterExit=yes
14+
SuccessExitStatus=5 6
15+
ExecStart=/etc/init.d/setup start
16+
ExecStop=/etc/init.d/setup stop
17+
18+
[Install]
19+
WantedBy=multi-user.target

scripts/ubuntu_debootstrap.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
5+
CWD=$(dirname -- "$0")
6+
ROOT_DIR="$(realpath ${CWD}/..)"
7+
8+
NAME="${1:-jammy}"
9+
ARCH="${2:-x86_64}"
10+
11+
DIR="${ROOT_DIR}/rootfs/ubuntu-${NAME}-${ARCH}"
12+
13+
if [[ "$ARCH" == x86_64 ]]; then
14+
ARCH=amd64
15+
elif [[ "$ARCH" != arm64 ]]; then
16+
echo "usage: $0 [NAME] [x86_64 | arm64]"
17+
exit 1
18+
fi
19+
20+
mkdir -p $DIR
21+
sudo debootstrap --arch $ARCH $NAME $DIR
22+
23+
echo "Ubuntu ${NAME} debootstrap installed in ${DIR}"

0 commit comments

Comments
 (0)