diff --git a/src/experimental/glibc-busybox/01_get_kernel.sh b/src/experimental/glibc-busybox/01_get_kernel.sh index 0d79b79a1..266664da9 100755 --- a/src/experimental/glibc-busybox/01_get_kernel.sh +++ b/src/experimental/glibc-busybox/01_get_kernel.sh @@ -1,23 +1,23 @@ #!/bin/sh -# Grab everything after the '=' character +# Grab everything after the '=' character. DOWNLOAD_URL=$(grep -i KERNEL_SOURCE_URL .config | cut -f2 -d'=') -# Grab everything after the last '/' character +# Grab everything after the last '/' character. ARCHIVE_FILE=${DOWNLOAD_URL##*/} cd source -# Downloading kernel file -# -c option allows the download to resume +# Downloading kernel file. +# -c option allows the download to resume. wget -c $DOWNLOAD_URL -# Delete folder with previously extracted kernel +# 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' +# Extract kernel to folder 'work/kernel'. +# Full path will be something like 'work/kernel/linux-4.4.6'. tar -xvf $ARCHIVE_FILE -C ../work/kernel cd .. diff --git a/src/experimental/glibc-busybox/02_build_kernel.sh b/src/experimental/glibc-busybox/02_build_kernel.sh index c5543e5fc..65ebe9f75 100755 --- a/src/experimental/glibc-busybox/02_build_kernel.sh +++ b/src/experimental/glibc-busybox/02_build_kernel.sh @@ -2,24 +2,25 @@ cd work/kernel -# Change to the first directory ls finds, e.g. 'linux-3.18.6' +# Change to the first directory ls finds, e.g. 'linux-4.4.6'. cd $(ls -d *) -# Cleans up the kernel sources, including configuration files +# Cleans up the kernel sources, including configuration files. make mrproper -# Create a default configuration file for the kernel +# Create default configuration file for the kernel. make defconfig -# Changes the name of the system +# Changes the name of the system to 'minimal'. 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 +# 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) -# Install kernel headers in "./usr" (this is not "/usr") which are used later. +# Install kernel headers in './usr' (this is not '/usr') which are used later +# when we build and configure the GNU C library (glibc). make headers_install cd ../../.. diff --git a/src/experimental/glibc-busybox/03_get_glibc.sh b/src/experimental/glibc-busybox/03_get_glibc.sh index a68d3edcb..06bebf2a7 100755 --- a/src/experimental/glibc-busybox/03_get_glibc.sh +++ b/src/experimental/glibc-busybox/03_get_glibc.sh @@ -1,23 +1,23 @@ #!/bin/sh -# Grab everything after the '=' character +# Grab everything after the '=' character. DOWNLOAD_URL=$(grep -i GLIBC_SOURCE_URL .config | cut -f2 -d'=') -# Grab everything after the last '/' character +# Grab everything after the last '/' character. ARCHIVE_FILE=${DOWNLOAD_URL##*/} cd source -# Downloading musl file -# -c option allows the download to resume +# Downloading glibc file. +# -c option allows the download to resume. wget -c $DOWNLOAD_URL -# Delete folder with previously extracted glibc +# Delete folder with previously extracted glibc. rm -rf ../work/glibc mkdir ../work/glibc -# Extract glibc to folder 'work/glibc' -# Full path will be something like 'work/glibc/glibc-1.1.11' +# Extract glibc to folder 'work/glibc'. +# Full path will be something like 'work/glibc/glibc-2.23'. tar -xvf $ARCHIVE_FILE -C ../work/glibc cd .. diff --git a/src/experimental/glibc-busybox/04_build_glibc.sh b/src/experimental/glibc-busybox/04_build_glibc.sh index 008caad52..9cf0b7910 100755 --- a/src/experimental/glibc-busybox/04_build_glibc.sh +++ b/src/experimental/glibc-busybox/04_build_glibc.sh @@ -1,5 +1,6 @@ #!/bin/sh +# Find the kernel build directory. cd work/kernel cd $(ls -d *) WORK_KERNEL_DIR=$(pwd) @@ -7,29 +8,32 @@ cd ../../.. cd work/glibc -# Change to the first directory ls finds, e.g. 'glibc-2.22' +# Change to the first directory ls finds, e.g. 'glibc-2.23'. cd $(ls -d *) +# Prepare working area, e.g. 'work/glibc/glibc-2.23/glibc_objects'. rm -rf ./glibc_objects mkdir glibc_objects +# Prepare installation area, e.g. 'work/glibc/glibc-2.23/glibc_installed'. rm -rf ./glibc_installed mkdir glibc_installed cd glibc_installed GLIBC_INSTALLED=$(pwd) +# All glibc work is done from the working area. cd ../glibc_objects -../configure --prefix= --with-headers=$WORK_KERNEL_DIR/usr/include --disable-werror -#../configure --prefix=$GLIBC_INSTALLED --with-headers=$WORK_KERNEL_DIR/usr/include --enable-static-ns --disable-werror -#../configure --prefix=$GLIBC_INSTALLED --with-headers=$WORK_KERNEL_DIR/usr/include --disable-werror +# glibc is configured to use the root folder (--prefix=) and as result all libraries +# will be installed in '/lib'. Kernel headers are taken from our already prepared +# kernel header area (see 02_build_kernel.sh). +../configure --prefix= --with-headers=$WORK_KERNEL_DIR/usr/include --disable-werror + +# Compile glibc with optimization for "parallel jobs" = "number of processors". make -j $(grep ^processor /proc/cpuinfo | wc -l) -#set DESTDIR=$GLIBC_INSTALLED -#export DESTDIR +# Install glibc in the installation area, e.g. 'work/glibc/glibc-2.23/glibc_installed'. make install DESTDIR=$GLIBC_INSTALLED -j $(grep ^processor /proc/cpuinfo | wc -l) -#unset DESTDIR - cd ../../.. diff --git a/src/experimental/glibc-busybox/05_prepare_glibc.sh b/src/experimental/glibc-busybox/05_prepare_glibc.sh index dd01e774a..9b18f0ec9 100755 --- a/src/experimental/glibc-busybox/05_prepare_glibc.sh +++ b/src/experimental/glibc-busybox/05_prepare_glibc.sh @@ -1,5 +1,6 @@ #!/bin/sh +# Find the kernel build directory. cd work/kernel cd $(ls -d *) WORK_KERNEL_DIR=$(pwd) @@ -12,6 +13,26 @@ cd $(ls -d *) cd glibc_installed +# Create custom 'usr' area and link it with some of the kernel header directories. +# BusyBox compilation process uses these linked directories. The following +# directories are affected: +# +# usr (glibc) +# | +# +--include (glibc) +# | | +# | +--asm (kernel) +# | | +# | +--asm-generic (kernel) +# | | +# | +--asm-generic (kernel) +# | | +# | +--linux (kernel) +# | | +# | +--mtd (kernel) +# | +# +--lib (glibc) + mkdir -p usr cd usr @@ -37,28 +58,3 @@ ln -s $WORK_KERNEL_DIR/usr/include/mtd mtd cd ../../../.. -exit 0 - -unlink musl-ar 2>/dev/null -ln -s `which ar` musl-ar - -unlink musl-strip 2>/dev/null -ln -s `which strip` musl-strip - -unlink linux 2>/dev/null -ln -s /usr/include/linux linux - -unlink mtd 2>/dev/null -ln -s /usr/include/mtd mtd - -if [ -d /usr/include/asm ] -then - unlink asm 2>/dev/null - ln -s /usr/include/asm asm -else - unlink asm 2>/dev/null - ln -s /usr/include/asm-generic asm -fi - -unlink asm-generic 2>/dev/null -ln -s /usr/include/asm-generic asm-generic diff --git a/src/experimental/glibc-busybox/06_get_busybox.sh b/src/experimental/glibc-busybox/06_get_busybox.sh index 672bb5841..ef7cd387c 100755 --- a/src/experimental/glibc-busybox/06_get_busybox.sh +++ b/src/experimental/glibc-busybox/06_get_busybox.sh @@ -1,23 +1,23 @@ #!/bin/sh -# Grab everything after the '=' character +# Grab everything after the '=' character. DOWNLOAD_URL=$(grep -i BUSYBOX_SOURCE_URL .config | cut -f2 -d'=') -# Grab everything after the last '/' character +# Grab everything after the last '/' character. ARCHIVE_FILE=${DOWNLOAD_URL##*/} cd source -# Downloading busybox source -# -c option allows the download to resume +# Downloading busybox source. +# -c option allows the download to resume. wget -c $DOWNLOAD_URL -# Delete folder with previously extracted busybox +# 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' +# Extract busybox to folder 'busybox'. +# Full path will be something like 'work/busybox/busybox-1.24.2'. tar -xvf $ARCHIVE_FILE -C ../work/busybox cd .. diff --git a/src/experimental/glibc-busybox/07_build_busybox.sh b/src/experimental/glibc-busybox/07_build_busybox.sh index ff7373300..672217139 100755 --- a/src/experimental/glibc-busybox/07_build_busybox.sh +++ b/src/experimental/glibc-busybox/07_build_busybox.sh @@ -1,57 +1,40 @@ #!/bin/sh +# Find the glibc installation area. cd work/glibc cd $(ls -d *) cd glibc_installed GLIBC_INSTALLED=$(pwd) - cd ../../../.. cd work/busybox -# Change to the first directory ls finds, e.g. 'busybox-1.23.1' +# Change to the first directory ls finds, e.g. 'busybox-1.24.2'. cd $(ls -d *) -#PATH_BACKUP=$PATH -#PATH=$GLIBC_INSTALLED:$PATH - -# Remove previously generated artifacts +# Remove previously generated artifacts. make distclean -# Create a default configuration file +# Create default configuration file. make defconfig -# Change the configuration, so that busybox is statically compiled -# You could do this manually with 'make menuconfig' -# -# Uncomment for static build. -# -#sed -i "s/.*CONFIG_STATIC.*/CONFIG_STATIC=y/" .config - +# This variable holds the full path to the glibc installation area as quoted string. +# All back slashes are escaped (/ => \/) in order to keep the 'sed' command stable. GLIBC_INSTALLED_ESCAPED=$(echo \"$GLIBC_INSTALLED\" | sed 's/\//\\\//g') -#echo $GLIBC_INSTALLED_ESCAPED -#exit 0 - -# Uncomment after some tests -# +# Now we tell BusyBox to use the glibc installation area. sed -i "s/.*CONFIG_SYSROOT.*/CONFIG_SYSROOT=$GLIBC_INSTALLED_ESCAPED/" .config -#exit 0 - -#sed -i "s/.*CONFIG_CROSS_COMPILER_PREFIX.*/CONFIG_CROSS_COMPILER_PREFIX=\"uclibc-\"/" .config -#sed -i "s/.*CONFIG_IFPLUGD.*/CONFIG_IFPLUGD=n/" .config +# The 'inetd' applet fails to compile because we use the glibc installation area as +# main pointer to the kernel headers (see 05_prepare_glibc.sh) and some headers are +# not resolved. The easiest solution is to ignore this particular applet. sed -i "s/.*CONFIG_INETD.*/CONFIG_INETD=n/" .config -#sed -i "s/.*CONFIG_FEATURE_WTMP.*/CONFIG_FEATURE_WTMP=n/" .config -# Compile busybox with optimization for "parallel jobs" = "number of processors" +# 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 +# Create the symlinks for busybox. The file 'busybox.links' is used for this. make install -#PATH=$PATH_BACKUP - cd ../../.. diff --git a/src/experimental/glibc-busybox/08_generate_rootfs.sh b/src/experimental/glibc-busybox/08_generate_rootfs.sh index e230b3bfe..7164ce640 100755 --- a/src/experimental/glibc-busybox/08_generate_rootfs.sh +++ b/src/experimental/glibc-busybox/08_generate_rootfs.sh @@ -1,5 +1,6 @@ #!/bin/sh +# Find the glibc installation area. cd work/glibc cd $(ls -d *) cd glibc_installed @@ -12,13 +13,15 @@ cd work rm -rf rootfs cd busybox + +# Change to the first directory ls finds, e.g. 'busybox-1.24.2'. cd $(ls -d *) -# Copy all BusyBox generated stuff to the location of our "initramfs" folder. +# 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. +# Remove 'linuxrc' which is used when we boot in 'RAM disk' mode. rm -f linuxrc # Create root FS folders. @@ -31,13 +34,13 @@ mkdir src mkdir sys mkdir tmp -# "1" means that only the owner of a file/directory (or root) can remove it. +# '1' means that only the owner of particular file/directory 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 +# 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 @@ -57,7 +60,7 @@ EOF chmod +x bootscript.sh -# The script "/etc/rc.dhcp" is automatically invoked for each network device. +# The script '/etc/rc.dhcp' is automatically invoked for each network device. cat > rc.dhcp << EOF #!/bin/sh @@ -71,14 +74,14 @@ EOF chmod +x rc.dhcp -# DNS resolving is done by using Google's public DNS servers +# 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 +# The file '/etc/welcome.txt' is displayed on every boot of the system in each # available terminal. cat > welcome.txt << EOF @@ -90,7 +93,7 @@ cat > welcome.txt << EOF EOF -# The file "/etc/inittab" contains the configuration which defines how the +# 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 @@ -110,8 +113,8 @@ EOF cd .. -# The "/init" script passes the execution to "/sbin/init" which in turn looks -# for the configuration file "/etc/inittab". +# The '/init' script passes the execution to '/sbin/init' which in turn looks +# for the configuration file '/etc/inittab'. cat > init << EOF #!/bin/sh @@ -121,7 +124,7 @@ EOF chmod +x init -# Copy all source files to "/src". Note that the scripts won't work there. +# Copy all source files to '/src'. Note that the scripts won't work there. cp ../../*.sh src cp ../../.config src cp ../../*.txt src @@ -129,16 +132,23 @@ chmod +rx src/*.sh chmod +r src/.config chmod +r src/*.txt -# Copy the necessary 'glibc' libraries for proper DNS resolving. +# Copy all necessary 'glibc' libraries to '/lib' BEGIN. + +# This is the dynamic loader. The file name is different for 32-bit and 64-bit machines. +cp $GLIBC_INSTALLED/lib/ld-linux* ./lib + +# BusyBox has direct dependencies on these libraries. cp $GLIBC_INSTALLED/lib/libm.so.6 ./lib cp $GLIBC_INSTALLED/lib/libc.so.6 ./lib -cp $GLIBC_INSTALLED/lib/ld-linux* ./lib + +# These libraries are necessary for the DNS resolving. cp $GLIBC_INSTALLED/lib/libresolv.so.2 ./lib cp $GLIBC_INSTALLED/lib/libnss_dns.so.2 ./lib - -# Make sure x86_64 binaries can be loaded (for 64bit machines). +# Make sure the dynamic loader is visible on 64-bit machines. ln -s lib lib64 +# Copy all necessary 'glibc' libraries to '/lib' END. + cd ../.. diff --git a/src/experimental/glibc-busybox/09_pack_rootfs.sh b/src/experimental/glibc-busybox/09_pack_rootfs.sh index 678d9d2e4..020d0fc42 100755 --- a/src/experimental/glibc-busybox/09_pack_rootfs.sh +++ b/src/experimental/glibc-busybox/09_pack_rootfs.sh @@ -2,12 +2,12 @@ cd work -# Remove the old initramfs archive if it exists. +# Remove the old 'initramfs' archive if it exists. rm -f rootfs.cpio.gz cd rootfs -# Packs the current folder structure in "cpio.gz" archive. +# Packs the current 'initramfs' folder structure in 'cpio.gz' archive. find . | cpio -R root:root -H newc -o | gzip > ../rootfs.cpio.gz cd ../.. diff --git a/src/experimental/glibc-busybox/10_generate_iso.sh b/src/experimental/glibc-busybox/10_generate_iso.sh index f4a39b763..42a83eaa9 100755 --- a/src/experimental/glibc-busybox/10_generate_iso.sh +++ b/src/experimental/glibc-busybox/10_generate_iso.sh @@ -1,14 +1,18 @@ #!/bin/sh +# Find the kernel build directory. cd work/kernel cd $(ls -d *) WORK_KERNEL_DIR=$(pwd) cd ../../.. +# Remove the old ISO file if it exists. rm -f minimal_linux_live.iso + +# Remove the old ISO generation area if it exists. rm -rf work/isoimage -# This is the root folder of the ISO image +# This is the root folder of the ISO image. mkdir work/isoimage cd work/isoimage @@ -24,13 +28,13 @@ for i in lib lib64 share end ; do if [ $i = end ]; then exit 1; fi; done -# Now we copy the kernel +# Now we copy the kernel. cp $WORK_KERNEL_DIR/arch/x86/boot/bzImage ./kernel.bz -# Now we copy the root file system +# Now we copy the root file system. cp ../rootfs.cpio.gz ./rootfs.gz -# Copy all source files to "/src". Note that the scripts won't work there. +# Copy all source files to '/src'. Note that the scripts won't work there. mkdir src cp ../../*.sh src cp ../../.config src @@ -39,16 +43,16 @@ chmod +rx src/*.sh chmod +r src/.config chmod +r src/*.txt -# Create ISOLINUX configuration file +# Create ISOLINUX configuration file. echo 'default kernel.bz initrd=rootfs.gz' > ./isolinux.cfg -# Now we generate the ISO image file +# Now we generate the ISO image file. genisoimage -J -r -o ../minimal_linux_live.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table ./ -# This allows the ISO image to be bootable if it is burned on USB flash drive +# This allows the ISO image to be bootable if it is burned on USB flash drive. isohybrid ../minimal_linux_live.iso 2>/dev/null || true -# Copy the ISO image to the root project folder +# Copy the ISO image to the root project folder. cp ../minimal_linux_live.iso ../../ cd ../.. diff --git a/src/experimental/glibc-busybox/build_minimal_linux_live.sh b/src/experimental/glibc-busybox/build_minimal_linux_live.sh index fbfd5892c..dff5db4c4 100755 --- a/src/experimental/glibc-busybox/build_minimal_linux_live.sh +++ b/src/experimental/glibc-busybox/build_minimal_linux_live.sh @@ -3,9 +3,9 @@ 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 03_get_glibc.sh +sh 04_build_glibc.sh +sh 05_prepare_glibc.sh sh 06_get_busybox.sh sh 07_build_busybox.sh sh 08_generate_rootfs.sh