Build a basic Linux kernel and ramdisk that can start in QEMU.
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
old/
|
||||
tmp/
|
||||
artifacts/
|
||||
24
docker/Dockerfile.kernel
Normal file
24
docker/Dockerfile.kernel
Normal file
@@ -0,0 +1,24 @@
|
||||
FROM fedora:latest
|
||||
ENV KERNEL_VERSION=5.10.3
|
||||
|
||||
RUN dnf install -y \
|
||||
bc \
|
||||
bison \
|
||||
clang \
|
||||
cpio \
|
||||
curl \
|
||||
diffutils \
|
||||
elfutils-libelf-devel \
|
||||
findutils \
|
||||
flex \
|
||||
hostname \
|
||||
make \
|
||||
ncurses-devel \
|
||||
patch \
|
||||
xz
|
||||
|
||||
RUN mkdir -p /build/ramfs
|
||||
RUN curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-${KERNEL_VERSION}.tar.xz | tar xJC /build
|
||||
RUN mv /build/linux* /build/kernel
|
||||
COPY buildramfs.sh /build/ramfs/buildramfs.sh
|
||||
COPY lam.config /build/kernel/.config
|
||||
40
docker/buildramfs.sh
Executable file
40
docker/buildramfs.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
ARCH="x86_64"
|
||||
BB_VER="1.31.0"
|
||||
|
||||
# Dirs
|
||||
mkdir -p root
|
||||
cd root
|
||||
mkdir -p bin dev etc lib mnt proc sbin sys tmp var
|
||||
cd -
|
||||
|
||||
# Utils
|
||||
if [ ! -f "root/bin/busybox" ]; then
|
||||
curl -L "https://www.busybox.net/downloads/binaries/${BB_VER}-defconfig-multiarch-musl/busybox-${ARCH}" >root/bin/busybox
|
||||
fi
|
||||
cd root/bin
|
||||
chmod +x busybox
|
||||
ln -s busybox mount
|
||||
ln -s busybox sh
|
||||
cd -
|
||||
|
||||
# Init process
|
||||
|
||||
cat >>root/init << EOF
|
||||
#!/bin/busybox sh
|
||||
/bin/busybox --install -s /bin
|
||||
mount -t devtmpfs devtmpfs /dev
|
||||
mount -t proc proc /proc
|
||||
mount -t sysfs sysfs /sys
|
||||
mount -t tmpfs tmpfs /tmp
|
||||
setsid cttyhack sh
|
||||
exec /bin/sh
|
||||
EOF
|
||||
chmod +x root/init
|
||||
|
||||
# initramfs creation
|
||||
|
||||
cd root
|
||||
find . | cpio -ov --format=newc | gzip -9 >../initramfs
|
||||
cd -
|
||||
1717
docker/lam.config
Normal file
1717
docker/lam.config
Normal file
File diff suppressed because it is too large
Load Diff
4
scripts/build-kernel.sh
Executable file
4
scripts/build-kernel.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p artifacts/kernel
|
||||
docker run --rm -v "$(pwd)/artifacts/kernel:/build/artifacts" lam-kernel bash -c "make -j2 -C /build/kernel && cp /build/kernel/arch/x86/boot/bzImage /build/artifacts/"
|
||||
4
scripts/build-ramfs.sh
Executable file
4
scripts/build-ramfs.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p artifacts/ramdisk
|
||||
docker run --rm -v "$(pwd)/artifacts/ramdisk:/build/artifacts" lam-kernel bash -c "cd /build/ramfs && ./buildramfs.sh && cp initramfs /build/artifacts/initramfs.cpio.gz"
|
||||
9
scripts/run.sh
Executable file
9
scripts/run.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
qemu-system-x86_64 \
|
||||
-kernel artifacts/kernel/bzImage \
|
||||
-initrd artifacts/ramdisk/initramfs.cpio.gz \
|
||||
-nographic \
|
||||
-serial mon:stdio \
|
||||
-no-reboot \
|
||||
-append "console=ttyS0"
|
||||
Reference in New Issue
Block a user