Skip to content

Commit 7d58e73

Browse files
committed
Update - Added dockerfile
1 parent 0cf0faa commit 7d58e73

File tree

2 files changed

+143
-1
lines changed

2 files changed

+143
-1
lines changed

dockerfiles/kbuilder/Dockerfile

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,98 @@ CMD /bin/bash
3535

3636

3737
# -----------------------------------------------------------------------------
38+
# git clone -b v5.15 --depth=1 https://github.com/torvalds/linux
39+
# git clone -b 1_36_0 --depth=1 https://github.com/mirror/busybox
40+
3841
# --- docker build ---
3942
# docker build -t kbuilder --build-arg UID=$(id -u) --build-arg GID=$(id -g) .
4043

4144
# --- run daemon mode ---
42-
# docker run -it -d --name kbuilder_con --mount type=bind,src=/xxx,dst=/yyy kbuilder
45+
# docker run -it -d --name kbuilder_con \
46+
# --mount type=bind,src=/path/to/linux,dst=/home/builder/linux \
47+
# --mount type=bind,src=/path/to/busybox,dst=/home/builder/busybox \
48+
# kbuilder
4349

4450
# docker exec -it kbuilder_con /bin/bash
4551
# docker exec -it -u builder -w /home/builder kbuilder_con /bin/bash
4652

53+
# --- build kernel ---
54+
# cd linux
55+
# make defconfig
56+
# make menuconfig
57+
# Kernel hacking -> [*] Kernel debugging
58+
# Kernel hacking -> Compile-time checks and compiler options -> [*] Compile the kernel with debug info
59+
# Processor type and features -> [ ] EFI runtime service support
60+
# -> [ ] Build a relocatable kernel
61+
# time make -j $(nproc)
62+
63+
# --- create compile_commands.json at host ---
64+
# cd linux
65+
# ./scripts/clang-tools/gen_compile_commands.py
66+
# or
67+
# ./scripts/gen_compile_commands.py
68+
69+
# --- if need build busybox ---
70+
# cd busybox
71+
# make defconfig
72+
# make menuconfig
73+
# Settings -> [*] Build static binary (no shared libs)
74+
# make
75+
# make install
76+
77+
# --- create initramfs (busybox simple) at host ---
78+
# mkdir -p ramfs/{proc,bin,sbin,dev,sys}
79+
# cd ramfs/bin
80+
# curl -LOks https://busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox
81+
# chmod 755 ./busybox
82+
# ln -s busybox sh
83+
# ln -s busybox mount
84+
# cd ../sbin
85+
# cat <<EOF > init
86+
# > #!/bin/sh
87+
# > mount -t proc none /proc
88+
# > mount -t sysfs none /sys
89+
# > exec /bin/sh
90+
# > EOF
91+
# chmod 755 init
92+
# cd ../dev
93+
# sudo mknod console c 5 1
94+
# sudo mknod null c 1 3
95+
# cd ..
96+
# find ./ | cpio -o -H newc | gzip > initramfs.img
97+
98+
# --- launch qemu at host ---
99+
# qemu-system-x86_64 -kernel /path/to/bzImage -initrd /path/to/initramfs.img -append "console=ttyS0 rdinit=/sbin/init" -nographic
100+
# finish -> ctrl+a x
101+
102+
# --- create initramfs (busybox full) at host ---
103+
# mkdir -p ramfs/{proc,dev,sys,run,etc/init.d}
104+
# cp -pr /path/to/busybox/_install/* ramfs/
105+
# cd ramfs/dev
106+
# sudo mknod console c 5 1
107+
# sudo mknod null c 1 3
108+
# sudo mknod -m 666 tty c 5 0
109+
# sudo mknod ram b 1 0
110+
# cd ../etc/init.d
111+
# cat <<EOF > rcS
112+
# > #!/bin/sh
113+
# > mount -v --bind /dev /dev
114+
# > mount -v --bind /dev/pts /dev/pts
115+
# > mount -vt proc proc /proc
116+
# > mount -vt sysfs sysfs /sys
117+
# > mount -vt tmpfs tmpfs /run
118+
# > /sbin/mdev -s
119+
# > EOF
120+
# chmod 755 rcS
121+
# cd ../..
122+
# find ./ | cpio -o -H newc | gzip > initramfs.img
123+
124+
# --- launch qemu + gdb at host ---
125+
# qemu-system-x86_64 -kernel /path/to/bzImage -initrd /path/to/initramfs.img -append "console=ttyS0 rdinit=/sbin/init root=/dev/ram" -nographic -gdb tcp::12345 -S
126+
# gdb
127+
# target remote localhost:12345
128+
# symbol-file /path/to/linux/vmlinux
129+
# directory /path/to/linux
130+
# b start_kernel
131+
# layout split
132+
# c

dockerfiles/libcbuilder/Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
FROM ubuntu:22.04
2+
3+
ENV DEBIAN_FRONTEND noninteractive
4+
5+
RUN apt-get update && apt-get install -y \
6+
curl \
7+
vim \
8+
tmux \
9+
sudo \
10+
bear \
11+
git
12+
13+
RUN apt-get install -y bison build-essential gawk gettext openssl python3 texinfo wget
14+
15+
RUN echo root:root | chpasswd
16+
17+
# add user
18+
ARG UID=1000
19+
ARG GID=1000
20+
ARG USER=builder
21+
ARG GROUP=builder
22+
ARG PASS=builder
23+
RUN groupadd -g $GID ${GROUP} && \
24+
useradd -m -s /bin/bash -u ${UID} -g ${GID} -G sudo ${USER} && \
25+
echo ${USER}:${PASS} | chpasswd
26+
27+
# switch user
28+
USER ${USER}
29+
WORKDIR /home/${USER}
30+
31+
ENV GIT_SSL_NO_VERIFY 1
32+
33+
CMD /bin/bash
34+
35+
36+
# -----------------------------------------------------------------------------
37+
# git clone -b glibc-2.37 --depth=1 https://sourceware.org/git/glibc.git
38+
39+
# --- docker build ---
40+
# docker build -t libcbuilder --build-arg UID=$(id -u) --build-arg GID=$(id -g) .
41+
42+
# --- run daemon mode ---
43+
# docker run -it -d --name libcbuilder_con --mount type=bind,src=/path/to/glibc,dst=/home/builder/glibc libcbuilder
44+
45+
# docker exec -it libcbuilder_con /bin/bash
46+
# docker exec -it -u builder -w /home/builder libcbuilder_con /bin/bash
47+
48+
# --- build ---
49+
# mkdir -p glibc/build
50+
# cd glibc/build
51+
# ../configure --prefix="$(pwd)/out" --libdir="$(pwd)/out/lib" --libexecdir="$(pwd)/out/lib" --enable-multi-arch --enable-stack-protector=strong
52+
# make
53+
# --- create compile_commands.json for host ---
54+
# bear -- make
55+
# sed -i -e 's/\/home\/builder\/glibc/\/home\/user\/path\/to\/glibc/g' compile_commands.json
56+
# mv compile_commands.json ../

0 commit comments

Comments
 (0)