-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·147 lines (116 loc) · 3.67 KB
/
build.sh
File metadata and controls
executable file
·147 lines (116 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh
# Kernel, BusyBox, and musl Toolchain Versions and URLs
KERNEL_VERSION="5.4.295"
KERNEL_URL="https://github.com/danielsboringfloppy/linux-$KERNEL_VERSION.git"
TOYBOX_VERSION="0.8.13"
TOYBOX_URL="https://github.com/landley/toybox.git"
MUSL_TOOLCHAIN_URL="https://musl.cc/i486-linux-musl-cross.tgz"
# Directories
BUILD_ROOT_DIR=$(pwd)
CONFIG_DIR="./configs"
CONFIG_FILE="$CONFIG_DIR/linux.config"
BUILD_DIR="$BUILD_ROOT_DIR/build"
TOOLCHAIN_DIR="$BUILD_DIR/toolchain"
ROOTFS_DIR="$BUILD_DIR/rootfs" # Root filesystem directory
FLOPPY_IMG="$BUILD_DIR/floppy.img" # Virtual floppy disk image file
MNT_DIR="$BUILD_DIR/mnt" # Temporary mount directory for the floppy
SYSLINUX_CFG="$MNT_DIR/syslinux.cfg" # Syslinux configuration file path
set -xe
# Function to download and extract Linux kernel
download_kernel() {
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" || exit 1
cd linux-$KERNEL_VERSION || git clone $KERNEL_URL
}
# Function to download and extract BusyBox
download_toybox() {
cd "$BUILD_DIR" || exit 1
cd toybox || git clone $TOYBOX_URL -b $TOYBOX_VERSION
}
# Function to download and extract musl toolchain
download_toolchain() {
mkdir -p "$TOOLCHAIN_DIR"
cd "$TOOLCHAIN_DIR" || exit 1
wget -c "$MUSL_TOOLCHAIN_URL" -O "i486-linux-musl-cross.tgz"
tar xf "i486-linux-musl-cross.tgz"
}
# Function to copy kernel config
copy_config() {
cp "$1" "$2"
}
# Function to build Linux kernel
build_kernel() {
cd "$BUILD_DIR/linux-$KERNEL_VERSION" || exit 1
make dbf_pentium_defconfig
make -j"$(nproc)"
}
# Function to build BusyBox using musl toolchain
build_toybox() {
cd "$BUILD_DIR/toybox" || exit 1
# Set up the cross-compilation environment
export CROSS_COMPILE="$TOOLCHAIN_DIR/i486-linux-musl-cross/bin/i486-linux-musl-"
CROSS_COMPILE=$CROSS_COMPILE LDFLAGS="--static" make defconfig
make -j"$(nproc)"
PREFIX=$ROOTFS_DIR make install
}
# Function to create the root filesystem structure
setup_rootfs() {
mkdir -p "$ROOTFS_DIR"
cd "$ROOTFS_DIR" || exit 1
mkdir -p bin dev etc sbin usr lib proc sys
cd -
}
setup_init() {
cp -a "$BUILD_ROOT_DIR/init/." "$ROOTFS_DIR/"
}
# Function to create CPIO archive of the root filesystem
create_cpio_archive() {
cd "$ROOTFS_DIR" || exit 1
find . | cpio -o -H newc | gzip > "$BUILD_DIR/rootfs.cpio.xz"
}
# Function to create and format a virtual floppy image in FAT32
create_floppy_image() {
# Size of floppy image in bytes (1.44MB)
FLOPPY_SIZE=$((1440 * 1024))
# Create a blank floppy image
dd if=/dev/zero of="$FLOPPY_IMG" bs=512 count=$((FLOPPY_SIZE / 512))
mkfs.fat -F 12 "$FLOPPY_IMG"
}
# Function to install Syslinux bootloader on the floppy image
install_syslinux() {
mkdir -p "$MNT_DIR"
# Mount the floppy image
sudo mount -o loop "$FLOPPY_IMG" "$MNT_DIR"
# Create Syslinux configuration file
sudo bash -c "cat > $SYSLINUX_CFG" <<EOF
DEFAULT linux
LABEL linux
KERNEL /bzImage
APPEND initrd=/rootfs.cpio.xz
EOF
# Unmount the floppy image
sudo umount "$MNT_DIR"
sudo syslinux --install "$FLOPPY_IMG"
}
# Function to mount the floppy image and copy the kernel and rootfs to it
copy_files_to_floppy() {
mkdir -p "$MNT_DIR"
# Mount the floppy image
sudo mount -o loop "$FLOPPY_IMG" "$MNT_DIR"
sudo cp "$BUILD_DIR/linux-$KERNEL_VERSION/arch/x86/boot/bzImage" "$MNT_DIR/bzImage"
sudo cp "$BUILD_DIR/rootfs.cpio.xz" "$MNT_DIR/rootfs.cpio.xz"
# Unmount the floppy image
sudo umount "$MNT_DIR"
}
# Main execution
download_toolchain
download_kernel
build_kernel
download_toybox
build_toybox
setup_rootfs
setup_init
create_cpio_archive
create_floppy_image
copy_files_to_floppy
install_syslinux