-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85de59d
Showing
9 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Minimal boot linux coreutils bash glibc | ||
|
||
![qemu showing boot into minimal linux](./img/boot-qemu-example.png) | ||
|
||
Goal is to have mimimal but realistic node with network capabilities build in (`ip`) and bootstrapped (similar to [alpine's netbot](https://boot.alpinelinux.org/) ([example](https://github.com/KarmaComputing/server-bootstrap/blob/494089caa2c88bbf37a739aa96561231d5847be5/.github/workflows/build-alpine-netboot-image-zfs.yml#L1))). [Clearlinux](https://github.com/clearlinux/distribution) is interesting. This is using glibc over musl (which alpine uses). | ||
|
||
|
||
## The process in a nutshell | ||
|
||
- Given a built linux kernel (e.g. `vmlinuz-lts`) | ||
- Clone and build all the various packages you want | ||
- Write an `init` script | ||
- Build all the binaries + `init` script into a initramfs | ||
- Run/boot with qemu | ||
|
||
|
||
|
||
TODO: add [iproute2](https://github.com/iproute2/iproute2) for minimal routing. | ||
|
||
## Things you need to build | ||
|
||
- git clone & build GNU `bash` is in it's own repo | ||
- git clone & build coreutils (`ls` , `date` , `touch` etc(`mount` is not in here- who knew) | ||
- To get `mount` you need to build util-linux https://en.wikipedia.org/wiki/Util-linux | ||
- is `ls` failing, did you forget to include `/usr/lib/x86_64-linux-gnu/libcap.so.2`? See `mkchroot.sh` helper from https://landley.net/writing/rootfs-programming.html | ||
|
||
- Don't forget to `mount` linux virtual filesystems (oh wait, did you forget to build util-linux into your init? | ||
|
||
Example built rootfs: | ||
``` | ||
ls -lh rootfs.cpio.gz | ||
-rw-rw-r-- 1 chris chris 16M Dec 8 23:40 rootfs.cpio.gz | ||
``` | ||
|
||
# What does this repo not include (yet) | ||
|
||
- Full clone/compile instructions | ||
- Automated ci | ||
|
||
### How do I build statically coreutils, do I even need to? | ||
|
||
See https://lists.gnu.org/archive/html/coreutils/2019-04/msg00001.html | ||
|
||
## `ls` , `cat` and `date` etc won't run without libc! | ||
|
||
git clone https://sourceware.org/git/glibc.git | ||
|
||
# Reading | ||
See also | ||
|
||
https://wiki.gentoo.org/wiki/Custom_Initramfs | ||
https://unix.stackexchange.com/a/305406 | ||
https://landley.net/writing/rootfs-howto.html | ||
https://landley.net/writing/rootfs-programming.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -exu | ||
|
||
./create-init.sh | ||
./build-rootfs.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
INITAL_WORKING_DIR=$PWD | ||
|
||
cd coreutils | ||
git checkout v9.5 | ||
./bootstrap | ||
./configure LDFLAGS="-static" | ||
make | ||
find src/ -executable -maxdepth 1 | ||
|
||
|
||
cd $INITAL_WORKING_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
set -xu | ||
|
||
SCRATCH_SPACE_DIR=$1 | ||
|
||
INITAL_WORKING_DIR=$PWD | ||
|
||
git clone https://sourceware.org/git/glibc.git | ||
cd glibc | ||
git checkout release/2.40/master | ||
mkdir glibc-build | ||
cd glibc-build | ||
mkdir out | ||
../configure --prefix=$(pwd)/out | ||
make | ||
make install | ||
|
||
# Copy built libc objects/files over into scratch space | ||
cp -r -n ./out/* $SCRATCH_SPACE_DIR | ||
|
||
cd $INITAL_WORKING_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
cd scratch-space | ||
|
||
find . | cpio -o -H newc | gzip > ../rootfs.cpio.gz | ||
|
||
cd - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
echo "#!/usr/bin/bash" > scratch-space/init | ||
echo "exec /usr/bin/bash" >> scratch-space/init | ||
chmod +x scratch-space/init | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
# Credit: | ||
# https://landley.net/writing/rootfs-programming.html | ||
|
||
function mkchroot | ||
{ | ||
[ $# -lt 2 ] && return | ||
|
||
dest=$1 | ||
shift | ||
for i in "$@" | ||
do | ||
# Get an absolute path for the file | ||
[ "${i:0:1}" == "/" ] || i=$(which $i) | ||
# Skip files that already exist at target. | ||
[ -f "$dest/$i" ] && continue | ||
if [ -e "$i" ] | ||
then | ||
# Create destination path | ||
d=`echo "$i" | grep -o '.*/'` && | ||
mkdir -p "$dest/$d" && | ||
# Copy file | ||
cat "$i" > "$dest/$i" && | ||
chmod +x "$dest/$i" | ||
else | ||
echo "Not found: $i" | ||
fi | ||
# Recursively copy shared libraries' shared libraries. | ||
mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ') | ||
done | ||
} | ||
|
||
mkchroot "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
qemu-system-x86_64 -kernel vmlinuz-lts -initrd rootfs.cpio.gz --append "init=/usr/bin/init" |