BusyBox and glibc now use separate object/install/prepare folders. Kernel and initramfs are reconfigured to use XZ compression. Added more CFLAGS for smaller output size. As result the fina ISO image is significantly smaller than before.

This commit is contained in:
Ivan Davidov 2016-05-04 01:25:26 +03:00
parent e6b5e215f0
commit c61f217835
7 changed files with 66 additions and 74 deletions

View File

@ -4,8 +4,8 @@ SRC_DIR=$(pwd)
cd work/kernel cd work/kernel
# Change to the first directory ls finds, e.g. 'linux-4.4.6'. # Change to the kernel source directory which ls finds, e.g. 'linux-4.4.6'.
cd $(ls -d *) cd $(ls -d linux-*)
# Cleans up the kernel sources, including configuration files. # Cleans up the kernel sources, including configuration files.
echo "Preparing kernel work area..." echo "Preparing kernel work area..."
@ -33,6 +33,12 @@ else
# Enable overlay support, e.g. merge ro and rw directories. # Enable overlay support, e.g. merge ro and rw directories.
sed -i "s/.*CONFIG_OVERLAY_FS.*/CONFIG_OVERLAY_FS=y/" .config 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 fi
# Compile the kernel with optimization for 'parallel jobs' = 'number of processors'. # 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 # http://unix.stackexchange.com/questions/5518/what-is-the-difference-between-the-following-kernel-makefile-terms-vmlinux-vmlinux
echo "Building kernel..." echo "Building kernel..."
make \ 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) 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

View File

@ -2,49 +2,53 @@
# Find the kernel build directory. # Find the kernel build directory.
cd work/kernel cd work/kernel
cd $(ls -d *) cd $(ls -d kernel-*)
WORK_KERNEL_DIR=$(pwd) WORK_KERNEL_DIR=$(pwd)
cd ../../.. cd ../../..
cd work/glibc cd work/glibc
# Change to the first directory ls finds, e.g. 'glibc-2.23'. # Find the glibc source directory, e.g. 'glibc-2.23' and remember it.
cd $(ls -d *) 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..." echo "Preparing glibc object area. This may take a while..."
rm -rf ./glibc_objects rm -rf glibc_objects
mkdir glibc_objects mkdir glibc_objects
# Prepare install area, e.g. 'work/glibc/glibc-2.23/glibc_installed'. # Prepare the install area, e.g. 'work/glibc/glibc_installed'.
rm -rf ./glibc_installed echo "Preparing glibc install area. This may take a while..."
rm -rf glibc_installed
mkdir glibc_installed mkdir glibc_installed
cd glibc_installed GLIBC_INSTALLED=$(pwd)/glibc_installed
GLIBC_INSTALLED=$(pwd)
echo "Prepared glibc install area."
# All glibc work is done from the working area. # 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 # glibc is configured to use the root folder (--prefix=) and as result all
# will be installed in '/lib'. Kernel headers are taken from our already prepared # libraries will be installed in '/lib'. Kernel headers are taken from our
# kernel header area (see 02_build_kernel.sh). Packages 'gd' and 'selinux' are disabled. # already prepared kernel header area (see 02_build_kernel.sh). Packages 'gd'
# and 'selinux' are disabled.
echo "Configuring glibc..." echo "Configuring glibc..."
../configure \ $GLIBC_SRC/configure \
--prefix= \ --prefix= \
--with-headers=$WORK_KERNEL_DIR/usr/include \ --with-headers=$WORK_KERNEL_DIR/usr/include \
--without-gd \ --without-gd \
--without-selinux \ --without-selinux \
--disable-werror \ --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". # Compile glibc with optimization for "parallel jobs" = "number of processors".
echo "Building glibc..." echo "Building glibc..."
make -j $(grep ^processor /proc/cpuinfo | wc -l) 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..." 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 ../../.. cd ../../..

View File

@ -8,10 +8,12 @@ cd ../../..
cd work/glibc cd work/glibc
# Change to the first directory ls finds, e.g. 'glibc-2.22' echo "Preparing glibc..."
cd $(ls -d *)
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. # Create custom 'usr' area and link it with some of the kernel header directories.
# BusyBox compilation process uses these linked directories. The following # BusyBox compilation process uses these linked directories. The following
@ -31,29 +33,17 @@ cd glibc_installed
# | # |
# +--lib (glibc) # +--lib (glibc)
echo "Preparing glibc..."
mkdir -p usr mkdir -p usr
cd usr cd usr
unlink include 2>/dev/null
ln -s ../include include ln -s ../include include
unlink lib 2>/dev/null
ln -s ../lib lib ln -s ../lib lib
cd ../include cd ../include
unlink linux 2>/dev/null
ln -s $WORK_KERNEL_DIR/usr/include/linux linux ln -s $WORK_KERNEL_DIR/usr/include/linux linux
unlink asm 2>/dev/null
ln -s $WORK_KERNEL_DIR/usr/include/asm asm 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 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 ln -s $WORK_KERNEL_DIR/usr/include/mtd mtd
cd ../../../.. cd ../../../..

View File

@ -2,20 +2,19 @@
SRC_DIR=$(pwd) SRC_DIR=$(pwd)
# Find the glibc installation area. # Remember the glibc installation area.
cd work/glibc GLIBC_PREPARED=$(pwd)/work/glibc/glibc_prepared
cd $(ls -d *)
cd glibc_installed
GLIBC_INSTALLED=$(pwd)
cd ../../../..
cd work/busybox cd work/busybox
# Change to the first directory ls finds, e.g. 'busybox-1.24.2'. # Remove the old BusyBox install area
cd $(ls -d *) 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. # Remove previously generated artifacts.
echo "Preparing BusyBox work area..." echo "Preparing BusyBox work area. This may take a while..."
make distclean make distclean
# Read the 'USE_PREDEFINED_BUSYBOX_CONFIG' property from '.config' # Read the 'USE_PREDEFINED_BUSYBOX_CONFIG' property from '.config'
@ -35,6 +34,9 @@ else
echo "Generating default BusyBox configuration..." echo "Generating default BusyBox configuration..."
make defconfig 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 # 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 # 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. # 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. # 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. # 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. # 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". # Compile busybox with optimization for "parallel jobs" = "number of processors".
echo "Building BusyBox..." echo "Building BusyBox..."
make \ 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) busybox -j $(grep ^processor /proc/cpuinfo | wc -l)
# Create the symlinks for busybox. The file 'busybox.links' is used for this. # Create the symlinks for busybox. The file 'busybox.links' is used for this.
echo "Generating BusyBox based initramfs area..." echo "Generating BusyBox based initramfs area..."
make install make CONFIG_PREFIX="../busybox_installed" install
cd ../../.. cd ../../..

View File

@ -1,30 +1,20 @@
#!/bin/sh #!/bin/sh
# Find the glibc installation area. # Remember the prepared glibc folder.
cd work/glibc GLIBC_PREPARED=$(pwd)/work/glibc/glibc_prepared
cd $(ls -d *)
cd glibc_installed
GLIBC_INSTALLED=$(pwd)
cd ../../../..
cd work cd work
echo "Preparing initramfs work area..." echo "Preparing initramfs work area..."
rm -rf rootfs 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 cp -r busybox/busybox_installed rootfs
# Copy all rootfs resources to the location of our 'initramfs' folder. # 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. # Remove 'linuxrc' which is used when we boot in 'RAM disk' mode.
rm -f linuxrc rm -f linuxrc
@ -44,15 +34,15 @@ chmod -R +r **/*.txt
# Copy all necessary 'glibc' libraries to '/lib' BEGIN. # 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. # 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. # BusyBox has direct dependencies on these libraries.
cp $GLIBC_INSTALLED/lib/libm.so.6 ./lib cp $GLIBC_PREPARED/lib/libm.so.6 ./lib
cp $GLIBC_INSTALLED/lib/libc.so.6 ./lib cp $GLIBC_PREPARED/lib/libc.so.6 ./lib
# These libraries are necessary for the DNS resolving. # These libraries are necessary for the DNS resolving.
cp $GLIBC_INSTALLED/lib/libresolv.so.2 ./lib cp $GLIBC_PREPARED/lib/libresolv.so.2 ./lib
cp $GLIBC_INSTALLED/lib/libnss_dns.so.2 ./lib cp $GLIBC_PREPARED/lib/libnss_dns.so.2 ./lib
# Make sure the dynamic loader is visible on 64-bit machines. # Make sure the dynamic loader is visible on 64-bit machines.
ln -s lib lib64 ln -s lib lib64

View File

@ -7,9 +7,9 @@ rm -f rootfs.cpio.gz
cd rootfs 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..." 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 ../.. cd ../..

View File

@ -32,10 +32,10 @@ cp $WORK_SYSLINUX_DIR/bios/core/isolinux.bin .
cp $WORK_SYSLINUX_DIR/bios/com32/elflink/ldlinux/ldlinux.c32 . cp $WORK_SYSLINUX_DIR/bios/com32/elflink/ldlinux/ldlinux.c32 .
# Now we copy the kernel. # 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. # 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. # Copy all source files to '/src'. Note that the scripts won't work there.
mkdir src mkdir src
@ -104,7 +104,7 @@ else
fi fi
# Create ISOLINUX configuration file. # 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 # Delete the '.gitignore' files which we use in order to keep track of otherwise
# empty folders. # empty folders.