From 130ffa2cec787cdeacdba5a15b3ae7a7d9a296b6 Mon Sep 17 00:00:00 2001 From: Ivan Davidov Date: Sat, 19 Sep 2015 00:36:37 +0300 Subject: [PATCH] Reorganized the 'experimental' folder. Added 'experimental/musl' whish solves the DNS resolving issue. This should be optimized to use the newly downloaded kernel headers (if possible). --- .gitignore | 10 +- src/experimental/musl/.config | 18 +++ src/experimental/musl/00_prepare.sh | 8 ++ src/experimental/musl/01_get_kernel.sh | 24 ++++ src/experimental/musl/02_build_kernel.sh | 23 ++++ src/experimental/musl/03_get_musl.sh | 24 ++++ src/experimental/musl/04_build_musl.sh | 18 +++ src/experimental/musl/05_prepare_musl.sh | 62 +++++++++ src/experimental/musl/06_get_busybox.sh | 24 ++++ src/experimental/musl/07_build_busybox.sh | 41 ++++++ src/experimental/musl/08_generate_rootfs.sh | 123 ++++++++++++++++++ .../09_pack_rootfs.sh} | 0 .../10_generate_iso.sh} | 0 .../musl/build_minimal_linux_live.sh | 14 ++ src/experimental/{ => musl}/qemu32.sh | 0 src/experimental/{ => musl}/qemu64.sh | 0 src/experimental/{ => toybox}/.config | 0 src/experimental/{ => toybox}/0_prepare.sh | 0 src/experimental/{ => toybox}/1_get_kernel.sh | 0 .../{ => toybox}/2_build_kernel.sh | 0 src/experimental/{ => toybox}/3_get_toybox.sh | 0 .../{ => toybox}/4_build_toybox.sh | 0 .../{ => toybox}/5_generate_rootfs.sh | 0 src/experimental/toybox/6_pack_rootfs.sh | 14 ++ src/experimental/toybox/7_generate_iso.sh | 19 +++ .../{ => toybox}/build_minimal_linux_live.sh | 0 src/experimental/toybox/qemu32.sh | 4 + src/experimental/toybox/qemu64.sh | 4 + 28 files changed, 427 insertions(+), 3 deletions(-) create mode 100644 src/experimental/musl/.config create mode 100755 src/experimental/musl/00_prepare.sh create mode 100755 src/experimental/musl/01_get_kernel.sh create mode 100755 src/experimental/musl/02_build_kernel.sh create mode 100755 src/experimental/musl/03_get_musl.sh create mode 100755 src/experimental/musl/04_build_musl.sh create mode 100755 src/experimental/musl/05_prepare_musl.sh create mode 100755 src/experimental/musl/06_get_busybox.sh create mode 100755 src/experimental/musl/07_build_busybox.sh create mode 100755 src/experimental/musl/08_generate_rootfs.sh rename src/experimental/{6_pack_rootfs.sh => musl/09_pack_rootfs.sh} (100%) rename src/experimental/{7_generate_iso.sh => musl/10_generate_iso.sh} (100%) create mode 100755 src/experimental/musl/build_minimal_linux_live.sh rename src/experimental/{ => musl}/qemu32.sh (100%) rename src/experimental/{ => musl}/qemu64.sh (100%) rename src/experimental/{ => toybox}/.config (100%) rename src/experimental/{ => toybox}/0_prepare.sh (100%) rename src/experimental/{ => toybox}/1_get_kernel.sh (100%) rename src/experimental/{ => toybox}/2_build_kernel.sh (100%) rename src/experimental/{ => toybox}/3_get_toybox.sh (100%) rename src/experimental/{ => toybox}/4_build_toybox.sh (100%) rename src/experimental/{ => toybox}/5_generate_rootfs.sh (100%) create mode 100755 src/experimental/toybox/6_pack_rootfs.sh create mode 100755 src/experimental/toybox/7_generate_iso.sh rename src/experimental/{ => toybox}/build_minimal_linux_live.sh (100%) create mode 100755 src/experimental/toybox/qemu32.sh create mode 100755 src/experimental/toybox/qemu64.sh diff --git a/.gitignore b/.gitignore index f2e57909b..fd37997ca 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,11 @@ /src/work/** /src/*.iso -/src/experimental/source/** -/src/experimental/work/** -/src/experimental/*.iso +/src/experimental/toybox/source/** +/src/experimental/toybox/work/** +/src/experimental/toybox/*.iso + +/src/experimental/musl/source/** +/src/experimental/musl/work/** +/src/experimental/musl/*.iso diff --git a/src/experimental/musl/.config b/src/experimental/musl/.config new file mode 100644 index 000000000..f5c193a94 --- /dev/null +++ b/src/experimental/musl/.config @@ -0,0 +1,18 @@ +# You can find the latest Linux kernel source bundles here: +# +# http://kernel.org +# +KERNEL_SOURCE_URL=https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.1.6.tar.xz + +# You can find the latest Musl source bundles here: +# +# http://musl-libc.org +# +MUSL_SOURCE_URL=http://musl-libc.org/releases/musl-1.1.11.tar.gz + +# You can find the latest BusyBox source bundles here: +# +# http://busybox.net +# +BUSYBOX_SOURCE_URL=http://busybox.net/downloads/busybox-1.23.2.tar.bz2 + diff --git a/src/experimental/musl/00_prepare.sh b/src/experimental/musl/00_prepare.sh new file mode 100755 index 000000000..b1f8e4ed3 --- /dev/null +++ b/src/experimental/musl/00_prepare.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +rm -rf work +mkdir work + +# -p stops errors if the directory already exists +mkdir -p source + diff --git a/src/experimental/musl/01_get_kernel.sh b/src/experimental/musl/01_get_kernel.sh new file mode 100755 index 000000000..0d79b79a1 --- /dev/null +++ b/src/experimental/musl/01_get_kernel.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Grab everything after the '=' character +DOWNLOAD_URL=$(grep -i KERNEL_SOURCE_URL .config | cut -f2 -d'=') + +# Grab everything after the last '/' character +ARCHIVE_FILE=${DOWNLOAD_URL##*/} + +cd source + +# Downloading kernel file +# -c option allows the download to resume +wget -c $DOWNLOAD_URL + +# Delete folder with previously extracted kernel +rm -rf ../work/kernel +mkdir ../work/kernel + +# Extract kernel to folder 'work/kernel' +# Full path will be something like 'work/kernel/linux-3.16.1' +tar -xvf $ARCHIVE_FILE -C ../work/kernel + +cd .. + diff --git a/src/experimental/musl/02_build_kernel.sh b/src/experimental/musl/02_build_kernel.sh new file mode 100755 index 000000000..1734a0270 --- /dev/null +++ b/src/experimental/musl/02_build_kernel.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +cd work/kernel + +# Change to the first directory ls finds, e.g. 'linux-3.18.6' +cd $(ls -d *) + +# Cleans up the kernel sources, including configuration files +make mrproper + +# Create a default configuration file for the kernel +make defconfig + +# Changes the name of the system +sed -i "s/.*CONFIG_DEFAULT_HOSTNAME.*/CONFIG_DEFAULT_HOSTNAME=\"minimal\"/" .config + +# Compile the kernel with optimization for "parallel jobs" = "number of processors" +# Good explanation of the different kernels +# http://unix.stackexchange.com/questions/5518/what-is-the-difference-between-the-following-kernel-makefile-terms-vmlinux-vmlinux +make bzImage -j $(grep ^processor /proc/cpuinfo | wc -l) + +cd ../../.. + diff --git a/src/experimental/musl/03_get_musl.sh b/src/experimental/musl/03_get_musl.sh new file mode 100755 index 000000000..b68679278 --- /dev/null +++ b/src/experimental/musl/03_get_musl.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Grab everything after the '=' character +DOWNLOAD_URL=$(grep -i MUSL_SOURCE_URL .config | cut -f2 -d'=') + +# Grab everything after the last '/' character +ARCHIVE_FILE=${DOWNLOAD_URL##*/} + +cd source + +# Downloading musl file +# -c option allows the download to resume +wget -c $DOWNLOAD_URL + +# Delete folder with previously extracted musl +rm -rf ../work/musl +mkdir ../work/musl + +# Extract musl to folder 'work/musl' +# Full path will be something like 'work/musl/musl-1.1.11' +tar -xvf $ARCHIVE_FILE -C ../work/musl + +cd .. + diff --git a/src/experimental/musl/04_build_musl.sh b/src/experimental/musl/04_build_musl.sh new file mode 100755 index 000000000..4195f9666 --- /dev/null +++ b/src/experimental/musl/04_build_musl.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +cd work/musl + +# Change to the first directory ls finds, e.g. 'musl-1.1.11' +cd $(ls -d *) + +make distclean + +mkdir musl-installed +./configure --prefix=$(pwd)/musl-installed + +make -j $(grep ^processor /proc/cpuinfo | wc -l) + +make install -j $(grep ^processor /proc/cpuinfo | wc -l) + +cd ../../.. + diff --git a/src/experimental/musl/05_prepare_musl.sh b/src/experimental/musl/05_prepare_musl.sh new file mode 100755 index 000000000..5d87515bd --- /dev/null +++ b/src/experimental/musl/05_prepare_musl.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +cd work/kernel +cd $(ls -d *) +WORK_KERNEL_DIR=$(pwd) +cd ../../.. + +cd work/musl + +# Change to the first directory ls finds, e.g. 'musl-1.1.11' +cd $(ls -d *) + +cd musl-installed/bin + +unlink musl-ar +ln -s `which ar` musl-ar + +unlink musl-strip +ln -s `which strip` musl-strip + +cd ../include + +# +# Should work with headers from the newly downloaded kernel +# but it diesn't work. Damn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# +#unlink linux +#ln -s $WORK_KERNEL_DIR/include/linux linux +# +#unlink mtd +#ln -s $WORK_KERNEL_DIR/include/linux/mtd mtd +# +#unlink asm +#ln -s $WORK_KERNEL_DIR/include/uapi/asm-generic asm +# +#unlink asm-generic +#ln -s $WORK_KERNEL_DIR/include/uapi/asm-generic asm-generic +# +#unlink uapi +#ln -s $WORK_KERNEL_DIR/include/uapi uapi +# +#unlink uapi +#ln -s $WORK_KERNEL_DIR/include/uapi uapi + +unlink linux +ln -s /usr/include/linux linux + +unlink mtd +ln -s /usr/include/mtd mtd + +if [ -d /usr/include/asm ] +then + unlink asm + ln -s /usr/include/asm asm +else + unlink asm + ln -s /usr/include/asm-generic asm +fi + +unlink asm-generic +ln -s /usr/include/asm-generic asm-generic + diff --git a/src/experimental/musl/06_get_busybox.sh b/src/experimental/musl/06_get_busybox.sh new file mode 100755 index 000000000..672bb5841 --- /dev/null +++ b/src/experimental/musl/06_get_busybox.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Grab everything after the '=' character +DOWNLOAD_URL=$(grep -i BUSYBOX_SOURCE_URL .config | cut -f2 -d'=') + +# Grab everything after the last '/' character +ARCHIVE_FILE=${DOWNLOAD_URL##*/} + +cd source + +# Downloading busybox source +# -c option allows the download to resume +wget -c $DOWNLOAD_URL + +# Delete folder with previously extracted busybox +rm -rf ../work/busybox +mkdir ../work/busybox + +# Extract busybox to folder 'busybox' +# Full path will be something like 'work/busybox/busybox-1.23.1' +tar -xvf $ARCHIVE_FILE -C ../work/busybox + +cd .. + diff --git a/src/experimental/musl/07_build_busybox.sh b/src/experimental/musl/07_build_busybox.sh new file mode 100755 index 000000000..c6bdf8c96 --- /dev/null +++ b/src/experimental/musl/07_build_busybox.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +cd work/musl +cd $(ls -d *) +cd musl-installed +cd bin +MUSL_BIN_DIR=$(pwd) +cd ../../../../.. + +cd work/busybox + +# Change to the first directory ls finds, e.g. 'busybox-1.23.1' +cd $(ls -d *) + +PATH_BACKUP=$PATH +PATH=$MUSL_BIN_DIR:$PATH + +# Remove previously generated artifacts +make distclean + +# Create a default configuration file +make defconfig + +# Change the configuration, so that busybox is statically compiled +# You could do this manually with 'make menuconfig' +sed -i "s/.*CONFIG_STATIC.*/CONFIG_STATIC=y/" .config +sed -i "s/.*CONFIG_CROSS_COMPILER_PREFIX.*/CONFIG_CROSS_COMPILER_PREFIX=\"musl-\"/" .config +sed -i "s/.*CONFIG_IFPLUGD.*/CONFIG_IFPLUGD=n/" .config +sed -i "s/.*CONFIG_INETD.*/CONFIG_INETD=n/" .config + +# Compile busybox with optimization for "parallel jobs" = "number of processors" +make busybox -j $(grep ^processor /proc/cpuinfo | wc -l) + +# Create the symlinks for busybox +# It uses the file 'busybox.links' for this +make install + +PATH=$PATH_BACKUP + +cd ../../.. + diff --git a/src/experimental/musl/08_generate_rootfs.sh b/src/experimental/musl/08_generate_rootfs.sh new file mode 100755 index 000000000..fd57114fa --- /dev/null +++ b/src/experimental/musl/08_generate_rootfs.sh @@ -0,0 +1,123 @@ +#!/bin/sh + +cd work + +rm -rf rootfs + +cd busybox +cd $(ls -d *) + +# Copy all BusyBox generated stuff to the location of our "initramfs" folder. +cp -R _install ../../rootfs +cd ../../rootfs + +# Remove "linuxrc" which is used when we boot in "RAM disk" mode. +rm -f linuxrc + +# Create root FS folders +mkdir dev +mkdir etc +mkdir proc +mkdir root +mkdir src +mkdir sys +mkdir tmp + +# "1" means that only the owner of a file/directory (or root) can remove it. +chmod 1777 tmp + +cd etc + +# The script "/etc/bootscript.sh" is automatically executed as part of the +# "init" proess. We suppress most kernel messages, mount all crytical file +# systems, loop through all available network devices and we configure them +# through DHCP. +cat > bootscript.sh << EOF +#!/bin/sh + +dmesg -n 1 +mount -t devtmpfs none /dev +mount -t proc none /proc +mount -t sysfs none /sys + +for DEVICE in /sys/class/net/* ; do + ip link set \${DEVICE##*/} up + [ \${DEVICE##*/} != lo ] && udhcpc -b -i \${DEVICE##*/} -s /etc/rc.dhcp +done + +EOF + +chmod +x bootscript.sh + +# The script "/etc/rc.dhcp" is automatically invoked for each network device. +cat > rc.dhcp << EOF +#!/bin/sh + +ip addr add \$ip/\$mask dev \$interface + +if [ "\$router" ]; then + ip route add default via \$router dev \$interface +fi + +EOF + +chmod +x rc.dhcp + +# DNS resolving is done by using Google's public DNS servers +cat > resolv.conf << EOF +nameserver 8.8.8.8 +nameserver 8.8.4.4 + +EOF + +# The file "/etc/welcome.txt" is displayed on every boot of the system in each +# available terminal. +cat > welcome.txt << EOF + + ##################################### + # # + # Welcome to "Minimal Linux Live" # + # # + ##################################### + +EOF + +# The file "/etc/inittab" contains the configuration which defines how the +# system will be initialized. Check the following URL for more details: +# http://git.busybox.net/busybox/tree/examples/inittab +cat > inittab << EOF +::sysinit:/etc/bootscript.sh +::restart:/sbin/init +::ctrlaltdel:/sbin/reboot +::once:cat /etc/welcome.txt +::respawn:/bin/cttyhack /bin/sh +tty2::once:cat /etc/welcome.txt +tty2::respawn:/bin/sh +tty3::once:cat /etc/welcome.txt +tty3::respawn:/bin/sh +tty4::once:cat /etc/welcome.txt +tty4::respawn:/bin/sh + +EOF + +cd .. + +# The "/init" script passes the execution to "/sbin/init" which in turn looks +# for the configuration file "/etc/inittab". +cat > init << EOF +#!/bin/sh + +exec /sbin/init + +EOF + +chmod +x init + +# Copy all source files to "/src". Note that the scripts won't work there. +cp ../../*.sh src +cp ../../.config src +chmod +r src/*.sh +chmod +r src/.config + +cd ../.. + diff --git a/src/experimental/6_pack_rootfs.sh b/src/experimental/musl/09_pack_rootfs.sh similarity index 100% rename from src/experimental/6_pack_rootfs.sh rename to src/experimental/musl/09_pack_rootfs.sh diff --git a/src/experimental/7_generate_iso.sh b/src/experimental/musl/10_generate_iso.sh similarity index 100% rename from src/experimental/7_generate_iso.sh rename to src/experimental/musl/10_generate_iso.sh diff --git a/src/experimental/musl/build_minimal_linux_live.sh b/src/experimental/musl/build_minimal_linux_live.sh new file mode 100755 index 000000000..fbfd5892c --- /dev/null +++ b/src/experimental/musl/build_minimal_linux_live.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +sh 00_prepare.sh +sh 01_get_kernel.sh +sh 02_build_kernel.sh +sh 03_get_musl.sh +sh 04_build_musl.sh +sh 05_prepare_musl.sh +sh 06_get_busybox.sh +sh 07_build_busybox.sh +sh 08_generate_rootfs.sh +sh 09_pack_rootfs.sh +sh 10_generate_iso.sh + diff --git a/src/experimental/qemu32.sh b/src/experimental/musl/qemu32.sh similarity index 100% rename from src/experimental/qemu32.sh rename to src/experimental/musl/qemu32.sh diff --git a/src/experimental/qemu64.sh b/src/experimental/musl/qemu64.sh similarity index 100% rename from src/experimental/qemu64.sh rename to src/experimental/musl/qemu64.sh diff --git a/src/experimental/.config b/src/experimental/toybox/.config similarity index 100% rename from src/experimental/.config rename to src/experimental/toybox/.config diff --git a/src/experimental/0_prepare.sh b/src/experimental/toybox/0_prepare.sh similarity index 100% rename from src/experimental/0_prepare.sh rename to src/experimental/toybox/0_prepare.sh diff --git a/src/experimental/1_get_kernel.sh b/src/experimental/toybox/1_get_kernel.sh similarity index 100% rename from src/experimental/1_get_kernel.sh rename to src/experimental/toybox/1_get_kernel.sh diff --git a/src/experimental/2_build_kernel.sh b/src/experimental/toybox/2_build_kernel.sh similarity index 100% rename from src/experimental/2_build_kernel.sh rename to src/experimental/toybox/2_build_kernel.sh diff --git a/src/experimental/3_get_toybox.sh b/src/experimental/toybox/3_get_toybox.sh similarity index 100% rename from src/experimental/3_get_toybox.sh rename to src/experimental/toybox/3_get_toybox.sh diff --git a/src/experimental/4_build_toybox.sh b/src/experimental/toybox/4_build_toybox.sh similarity index 100% rename from src/experimental/4_build_toybox.sh rename to src/experimental/toybox/4_build_toybox.sh diff --git a/src/experimental/5_generate_rootfs.sh b/src/experimental/toybox/5_generate_rootfs.sh similarity index 100% rename from src/experimental/5_generate_rootfs.sh rename to src/experimental/toybox/5_generate_rootfs.sh diff --git a/src/experimental/toybox/6_pack_rootfs.sh b/src/experimental/toybox/6_pack_rootfs.sh new file mode 100755 index 000000000..f9e16e523 --- /dev/null +++ b/src/experimental/toybox/6_pack_rootfs.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +cd work + +# Remove the old initramfs archive if it exists. +rm -f rootfs.cpio.gz + +cd rootfs + +# Packs the current folder structure in "cpio.gz" archive. +find . | cpio -H newc -o | gzip > ../rootfs.cpio.gz + +cd ../.. + diff --git a/src/experimental/toybox/7_generate_iso.sh b/src/experimental/toybox/7_generate_iso.sh new file mode 100755 index 000000000..38c951585 --- /dev/null +++ b/src/experimental/toybox/7_generate_iso.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +rm -f minimal_linux_live.iso + +cd work/kernel +cd $(ls -d *) + +# Edit Makefile to look for genisoimage instead of mkisofs. This was added as a +# workaround for some "Debian" and "Arch Linux" distributions. In general this +# fix should be harmless. +sed -i 's/mkisofs/genisoimage/g' arch/x86/boot/Makefile + +# Generate the ISO image with optimization for "parallel jobs" = "number of processors" +make isoimage FDINITRD=../../rootfs.cpio.gz -j $(grep ^processor /proc/cpuinfo | wc -l) + +cp arch/x86/boot/image.iso ../../../minimal_linux_live.iso + +cd ../../.. + diff --git a/src/experimental/build_minimal_linux_live.sh b/src/experimental/toybox/build_minimal_linux_live.sh similarity index 100% rename from src/experimental/build_minimal_linux_live.sh rename to src/experimental/toybox/build_minimal_linux_live.sh diff --git a/src/experimental/toybox/qemu32.sh b/src/experimental/toybox/qemu32.sh new file mode 100755 index 000000000..2e4d546c4 --- /dev/null +++ b/src/experimental/toybox/qemu32.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +qemu-system-i386 -cdrom minimal_linux_live.iso + diff --git a/src/experimental/toybox/qemu64.sh b/src/experimental/toybox/qemu64.sh new file mode 100755 index 000000000..8e5174a01 --- /dev/null +++ b/src/experimental/toybox/qemu64.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +qemu-system-x86_64 -cdrom minimal_linux_live.iso +