diff --git a/src/02_build_kernel.sh b/src/02_build_kernel.sh index c352b2eae..228bd6683 100755 --- a/src/02_build_kernel.sh +++ b/src/02_build_kernel.sh @@ -4,8 +4,8 @@ SRC_DIR=$(pwd) cd work/kernel -# Change to the first directory ls finds, e.g. 'linux-4.4.6'. -cd $(ls -d *) +# Change to the kernel source directory which ls finds, e.g. 'linux-4.4.6'. +cd $(ls -d linux-*) # Cleans up the kernel sources, including configuration files. echo "Preparing kernel work area..." @@ -33,6 +33,12 @@ else # Enable overlay support, e.g. merge ro and rw directories. sed -i "s/.*CONFIG_OVERLAY_FS.*/CONFIG_OVERLAY_FS=y/" .config + + # Step 1 - disable all active kernel compression options (should be only one). + sed -i "s/.*\\(CONFIG_KERNEL_.*\\)=y/\\#\\ \\1 is not set/" .config + + # Step 2 - enable the 'xz' compression option. + sed -i "s/.*CONFIG_KERNEL_XZ.*/CONFIG_KERNEL_XZ=y/" .config fi # Compile the kernel with optimization for 'parallel jobs' = 'number of processors'. @@ -40,7 +46,7 @@ fi # http://unix.stackexchange.com/questions/5518/what-is-the-difference-between-the-following-kernel-makefile-terms-vmlinux-vmlinux echo "Building kernel..." make \ - CFLAGS="-Os -fno-stack-protector -U_FORTIFY_SOURCE" \ + CFLAGS="-Os -s -fno-stack-protector -U_FORTIFY_SOURCE" \ bzImage -j $(grep ^processor /proc/cpuinfo | wc -l) # Install kernel headers in './usr' (this is not '/usr') which are used later diff --git a/src/04_build_glibc.sh b/src/04_build_glibc.sh index ced6095ae..f5152ad60 100755 --- a/src/04_build_glibc.sh +++ b/src/04_build_glibc.sh @@ -2,49 +2,53 @@ # Find the kernel build directory. cd work/kernel -cd $(ls -d *) +cd $(ls -d kernel-*) WORK_KERNEL_DIR=$(pwd) cd ../../.. cd work/glibc -# Change to the first directory ls finds, e.g. 'glibc-2.23'. -cd $(ls -d *) +# Find the glibc source directory, e.g. 'glibc-2.23' and remember it. +cd $(ls -d glibc-*) +GLIBC_SRC=$(pwd) +cd .. -# Prepare working area, e.g. 'work/glibc/glibc-2.23/glibc_objects'. +# Prepare the work area, e.g. 'work/glibc/glibc_objects'. echo "Preparing glibc object area. This may take a while..." -rm -rf ./glibc_objects +rm -rf glibc_objects mkdir glibc_objects -# Prepare install area, e.g. 'work/glibc/glibc-2.23/glibc_installed'. -rm -rf ./glibc_installed +# Prepare the install area, e.g. 'work/glibc/glibc_installed'. +echo "Preparing glibc install area. This may take a while..." +rm -rf glibc_installed mkdir glibc_installed -cd glibc_installed -GLIBC_INSTALLED=$(pwd) -echo "Prepared glibc install area." +GLIBC_INSTALLED=$(pwd)/glibc_installed # All glibc work is done from the working area. -cd ../glibc_objects +cd glibc_objects -# 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). Packages 'gd' and 'selinux' are disabled. +# 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). Packages 'gd' +# and 'selinux' are disabled. echo "Configuring glibc..." -../configure \ +$GLIBC_SRC/configure \ --prefix= \ --with-headers=$WORK_KERNEL_DIR/usr/include \ --without-gd \ --without-selinux \ --disable-werror \ - CFLAGS="-Os -fno-stack-protector -U_FORTIFY_SOURCE" + CFLAGS="-Os -s -fno-stack-protector -U_FORTIFY_SOURCE" # Compile glibc with optimization for "parallel jobs" = "number of processors". echo "Building glibc..." make -j $(grep ^processor /proc/cpuinfo | wc -l) -# Install glibc in the installation area, e.g. 'work/glibc/glibc-2.23/glibc_installed'. +# Install glibc in the installation area, e.g. 'work/glibc/glibc_installed'. echo "Installing glibc..." -make install DESTDIR=$GLIBC_INSTALLED -j $(grep ^processor /proc/cpuinfo | wc -l) +make install \ + DESTDIR=$GLIBC_INSTALLED \ + -j $(grep ^processor /proc/cpuinfo | wc -l) cd ../../.. diff --git a/src/05_prepare_glibc.sh b/src/05_prepare_glibc.sh index 1e90f6f89..d91a3ce21 100755 --- a/src/05_prepare_glibc.sh +++ b/src/05_prepare_glibc.sh @@ -8,10 +8,12 @@ cd ../../.. cd work/glibc -# Change to the first directory ls finds, e.g. 'glibc-2.22' -cd $(ls -d *) +echo "Preparing glibc..." -cd glibc_installed +rm -rf glibc_prepared +cp -r glibc_installed glibc_prepared + +cd glibc_prepared # Create custom 'usr' area and link it with some of the kernel header directories. # BusyBox compilation process uses these linked directories. The following @@ -31,29 +33,17 @@ cd glibc_installed # | # +--lib (glibc) -echo "Preparing glibc..." - mkdir -p usr cd usr -unlink include 2>/dev/null ln -s ../include include - -unlink lib 2>/dev/null ln -s ../lib lib cd ../include -unlink linux 2>/dev/null ln -s $WORK_KERNEL_DIR/usr/include/linux linux - -unlink asm 2>/dev/null ln -s $WORK_KERNEL_DIR/usr/include/asm asm - -unlink asm-generic 2>/dev/null ln -s $WORK_KERNEL_DIR/usr/include/asm-generic asm-generic - -unlink mtd 2>/dev/null ln -s $WORK_KERNEL_DIR/usr/include/mtd mtd cd ../../../.. diff --git a/src/07_build_busybox.sh b/src/07_build_busybox.sh index 301029e23..3dd7c7dd1 100755 --- a/src/07_build_busybox.sh +++ b/src/07_build_busybox.sh @@ -2,20 +2,19 @@ SRC_DIR=$(pwd) -# Find the glibc installation area. -cd work/glibc -cd $(ls -d *) -cd glibc_installed -GLIBC_INSTALLED=$(pwd) -cd ../../../.. +# Remember the glibc installation area. +GLIBC_PREPARED=$(pwd)/work/glibc/glibc_prepared cd work/busybox -# Change to the first directory ls finds, e.g. 'busybox-1.24.2'. -cd $(ls -d *) +# Remove the old BusyBox install area +rm -rf busybox_installed + +# Change to the source directory ls finds, e.g. 'busybox-1.24.2'. +cd $(ls -d busybox-*) # Remove previously generated artifacts. -echo "Preparing BusyBox work area..." +echo "Preparing BusyBox work area. This may take a while..." make distclean # Read the 'USE_PREDEFINED_BUSYBOX_CONFIG' property from '.config' @@ -35,6 +34,9 @@ else echo "Generating default BusyBox configuration..." make defconfig + # Set the installation folder for BusyBox. + #sed -i "s/.*CONFIG_PREFIX.*/CONFIG_PREFIX=\"..\/busybox_installed\"/" .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. @@ -43,20 +45,20 @@ fi # 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') +GLIBC_PREPARED_ESCAPED=$(echo \"$GLIBC_PREPARED\" | sed 's/\//\\\//g') # Now we tell BusyBox to use the glibc installation area. -sed -i "s/.*CONFIG_SYSROOT.*/CONFIG_SYSROOT=$GLIBC_INSTALLED_ESCAPED/" .config +sed -i "s/.*CONFIG_SYSROOT.*/CONFIG_SYSROOT=$GLIBC_PREPARED_ESCAPED/" .config # Compile busybox with optimization for "parallel jobs" = "number of processors". echo "Building BusyBox..." make \ - EXTRA_CFLAGS="-Os -fno-stack-protector -U_FORTIFY_SOURCE" \ + EXTRA_CFLAGS="-Os -s -fno-stack-protector -U_FORTIFY_SOURCE" \ busybox -j $(grep ^processor /proc/cpuinfo | wc -l) # Create the symlinks for busybox. The file 'busybox.links' is used for this. echo "Generating BusyBox based initramfs area..." -make install +make CONFIG_PREFIX="../busybox_installed" install cd ../../.. diff --git a/src/08_generate_rootfs.sh b/src/08_generate_rootfs.sh index 5945828e9..4e4e276be 100755 --- a/src/08_generate_rootfs.sh +++ b/src/08_generate_rootfs.sh @@ -1,30 +1,20 @@ #!/bin/sh -# Find the glibc installation area. -cd work/glibc -cd $(ls -d *) -cd glibc_installed -GLIBC_INSTALLED=$(pwd) - -cd ../../../.. +# Remember the prepared glibc folder. +GLIBC_PREPARED=$(pwd)/work/glibc/glibc_prepared cd work echo "Preparing initramfs work area..." 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. -cp -r _install ../../rootfs +cp -r busybox/busybox_installed rootfs # Copy all rootfs resources to the location of our 'initramfs' folder. -cp -r ../../../08_generate_rootfs/* ../../rootfs +cp -r ../08_generate_rootfs/* rootfs -cd ../../rootfs +cd rootfs # Remove 'linuxrc' which is used when we boot in 'RAM disk' mode. rm -f linuxrc @@ -44,15 +34,15 @@ chmod -R +r **/*.txt # 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 +cp $GLIBC_PREPARED/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_PREPARED/lib/libm.so.6 ./lib +cp $GLIBC_PREPARED/lib/libc.so.6 ./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 +cp $GLIBC_PREPARED/lib/libresolv.so.2 ./lib +cp $GLIBC_PREPARED/lib/libnss_dns.so.2 ./lib # Make sure the dynamic loader is visible on 64-bit machines. ln -s lib lib64 diff --git a/src/09_pack_rootfs.sh b/src/09_pack_rootfs.sh index 8b4094d65..00ce622ee 100755 --- a/src/09_pack_rootfs.sh +++ b/src/09_pack_rootfs.sh @@ -7,9 +7,9 @@ rm -f rootfs.cpio.gz cd rootfs -# Packs the current 'initramfs' folder structure in 'cpio.gz' archive. +# Packs the current 'initramfs' folder structure in 'cpio.xz' archive. echo "Packing initramfs..." -find . | cpio -R root:root -H newc -o | gzip > ../rootfs.cpio.gz +find . | cpio -R root:root -H newc -o | xz --check=none > ../rootfs.cpio.xz cd ../.. diff --git a/src/11_generate_iso.sh b/src/11_generate_iso.sh index d28aea424..e3424cbb0 100755 --- a/src/11_generate_iso.sh +++ b/src/11_generate_iso.sh @@ -32,10 +32,10 @@ cp $WORK_SYSLINUX_DIR/bios/core/isolinux.bin . cp $WORK_SYSLINUX_DIR/bios/com32/elflink/ldlinux/ldlinux.c32 . # Now we copy the kernel. -cp $WORK_KERNEL_DIR/arch/x86/boot/bzImage ./kernel.bz +cp $WORK_KERNEL_DIR/arch/x86/boot/bzImage ./kernel.xz # Now we copy the root file system. -cp ../rootfs.cpio.gz ./rootfs.gz +cp ../rootfs.cpio.xz ./rootfs.xz # Copy all source files to '/src'. Note that the scripts won't work there. mkdir src @@ -104,7 +104,7 @@ else fi # Create ISOLINUX configuration file. -echo 'default kernel.bz initrd=rootfs.gz' > ./isolinux.cfg +echo 'default kernel.xz initrd=rootfs.xz' > ./isolinux.cfg # Delete the '.gitignore' files which we use in order to keep track of otherwise # empty folders.