From 848f5e56232818b297aa827836c490d0e6733bbe Mon Sep 17 00:00:00 2001
From: Ivan Davidov <davidov.i@gmail.com>
Date: Fri, 6 May 2016 23:44:54 +0300
Subject: [PATCH] Added support for building additional/overlay software on top
 of MLL. The only such software for now is Links (text browser).

---
 src/.config                                   | 35 +++++++++++--
 src/00_clean.sh                               |  6 ++-
 src/{02_get_kernel.sh => 01_get_kernel.sh}    |  4 ++
 ...{03_build_kernel.sh => 02_build_kernel.sh} | 12 +++--
 src/{04_get_glibc.sh => 03_get_glibc.sh}      |  4 ++
 src/{05_build_glibc.sh => 04_build_glibc.sh}  |  4 ++
 ...6_prepare_glibc.sh => 05_prepare_glibc.sh} |  4 ++
 src/{07_get_busybox.sh => 06_get_busybox.sh}  |  4 ++
 ...8_build_busybox.sh => 07_build_busybox.sh} | 12 +++--
 src/{01_prepare_src.sh => 08_prepare_src.sh}  | 11 +++--
 src/09_generate_rootfs.sh                     |  6 ++-
 src/10_pack_rootfs.sh                         |  6 ++-
 src/11_get_syslinux.sh                        |  4 ++
 src/12_generate_iso.sh                        | 49 ++++++++++++-------
 src/Makefile                                  |  6 ++-
 src/build_minimal_linux_live.sh               | 16 +++---
 src/build_minimal_linux_overlay.sh            |  6 +++
 .../README                                    |  0
 .../README.txt => minimal_overlay/README}     |  0
 .../dev/.gitignore                            |  0
 .../etc/01_prepare.sh                         |  0
 .../etc/02_overlay.sh                         |  0
 .../etc/03_init.sh                            |  0
 .../etc/04_bootscript.sh                      |  0
 .../etc/05_rc.dhcp                            |  0
 .../etc/inittab                               |  0
 .../etc/resolv.conf                           |  0
 .../etc/welcome.txt                           |  0
 .../init                                      |  0
 .../lib/.gitignore                            |  0
 .../mnt/.gitignore                            |  0
 .../proc/.gitignore                           |  0
 .../root/.gitignore                           |  0
 .../sys/.gitignore                            |  0
 .../tmp/.gitignore                            |  0
 src/overlay_00_clean.sh                       | 26 ++++++++++
 src/overlay_01_get_links.sh                   | 39 +++++++++++++++
 src/overlay_02_build_links.sh                 | 31 ++++++++++++
 38 files changed, 241 insertions(+), 44 deletions(-)
 rename src/{02_get_kernel.sh => 01_get_kernel.sh} (94%)
 rename src/{03_build_kernel.sh => 02_build_kernel.sh} (83%)
 rename src/{04_get_glibc.sh => 03_get_glibc.sh} (94%)
 rename src/{05_build_glibc.sh => 04_build_glibc.sh} (96%)
 rename src/{06_prepare_glibc.sh => 05_prepare_glibc.sh} (92%)
 rename src/{07_get_busybox.sh => 06_get_busybox.sh} (94%)
 rename src/{08_build_busybox.sh => 07_build_busybox.sh} (86%)
 rename src/{01_prepare_src.sh => 08_prepare_src.sh} (67%)
 create mode 100755 src/build_minimal_linux_overlay.sh
 rename src/{config_predefined => minimal_config}/README (100%)
 rename src/{12_generate_iso/README.txt => minimal_overlay/README} (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/dev/.gitignore (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/etc/01_prepare.sh (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/etc/02_overlay.sh (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/etc/03_init.sh (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/etc/04_bootscript.sh (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/etc/05_rc.dhcp (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/etc/inittab (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/etc/resolv.conf (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/etc/welcome.txt (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/init (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/lib/.gitignore (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/mnt/.gitignore (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/proc/.gitignore (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/root/.gitignore (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/sys/.gitignore (100%)
 rename src/{09_generate_rootfs => minimal_rootfs}/tmp/.gitignore (100%)
 create mode 100755 src/overlay_00_clean.sh
 create mode 100755 src/overlay_01_get_links.sh
 create mode 100755 src/overlay_02_build_links.sh

diff --git a/src/.config b/src/.config
index 053fa7dab..33258b7d7 100644
--- a/src/.config
+++ b/src/.config
@@ -1,3 +1,9 @@
+###################################################
+#                                                 #
+#  This section contains the main source bundles  #
+#                                                 #
+###################################################
+
 # You can find the latest Linux kernel source bundles here:
 #
 # http://kernel.org
@@ -24,9 +30,27 @@ BUSYBOX_SOURCE_URL=http://busybox.net/downloads/busybox-1.24.2.tar.bz2
 #
 SYSLINUX_SOURCE_URL=http://kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.xz
 
-###   ###   ###   ###
-###   ###   ###   ###
-###   ###   ###   ###
+
+
+######################################################
+#                                                    #
+#  This section contains the overlay source bundles  #
+#                                                    #
+######################################################
+
+# You can find the latest Links source bundles here:
+#
+# http://links.twibright.com
+#
+LINKS_SOURCE_URL=http://links.twibright.com/download/links-2.12.tar.bz2
+
+
+
+####################################################
+#                                                  #
+#  This section contains configuration properties  #
+#                                                  #
+####################################################
 
 # Use predefined '.config' file when building the kernel. This overrides the
 # config generation in '03_build_kernel.sh' and the build process uses the
@@ -84,3 +108,8 @@ COPY_SOURCE_ROOTFS=true
 # the property in order to disable it.
 COPY_SOURCE_ISO=true
 
+# This flag defines whether to build additional overlay software which will be
+# placed in the 'minimal_overlay' folder. This software will be visible and
+# fully usable after boot. The default is 'false'.
+BUILD_OVERLAY_SOFTWARE=true
+
diff --git a/src/00_clean.sh b/src/00_clean.sh
index 6664d1e1c..c7b411246 100755
--- a/src/00_clean.sh
+++ b/src/00_clean.sh
@@ -1,9 +1,13 @@
 #!/bin/sh
 
-echo "Cleaning up the work area. This may take a while..."
+echo "*** CLEAN BEGIN ***"
+
+echo "Cleaning up the main work area. This may take a while..."
 rm -rf work
 mkdir work
 
 # -p stops errors if the directory already exists
 mkdir -p source
 
+echo "*** CLEAN END ***"
+
diff --git a/src/02_get_kernel.sh b/src/01_get_kernel.sh
similarity index 94%
rename from src/02_get_kernel.sh
rename to src/01_get_kernel.sh
index c75c8983e..b6cf209c2 100755
--- a/src/02_get_kernel.sh
+++ b/src/01_get_kernel.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** GET KERNEL BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 # Grab everything after the '=' character.
@@ -37,3 +39,5 @@ tar -xvf $ARCHIVE_FILE -C ../work/kernel
 
 cd $SRC_DIR
 
+echo "*** GET KERNEL END ***"
+
diff --git a/src/03_build_kernel.sh b/src/02_build_kernel.sh
similarity index 83%
rename from src/03_build_kernel.sh
rename to src/02_build_kernel.sh
index 38e97a101..6a615f6cd 100755
--- a/src/03_build_kernel.sh
+++ b/src/02_build_kernel.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** BUILD KERNEL BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 cd work/kernel
@@ -14,15 +16,15 @@ make mrproper
 # Read the 'USE_PREDEFINED_KERNEL_CONFIG' property from '.config'
 USE_PREDEFINED_KERNEL_CONFIG="$(grep -i USE_PREDEFINED_KERNEL_CONFIG $SRC_DIR/.config | cut -f2 -d'=')"
 
-if [ "$USE_PREDEFINED_KERNEL_CONFIG" = "true" -a ! -f $SRC_DIR/config_predefined/kernel.config ] ; then
-  echo "Config file $SRC_DIR/config_predefined/kernel.config does not exist."
+if [ "$USE_PREDEFINED_KERNEL_CONFIG" = "true" -a ! -f $SRC_DIR/minimal_config/kernel.config ] ; then
+  echo "Config file $SRC_DIR/minimal_config/kernel.config does not exist."
   USE_PREDEFINED_KERNEL_CONFIG="false"
 fi
 
 if [ "$USE_PREDEFINED_KERNEL_CONFIG" = "true" ] ; then
   # Use predefined configuration file for the kernel.
-  echo "Using config file $SRC_DIR/config_predefined/kernel.config"  
-  cp -f $SRC_DIR/config_predefined/kernel.config .config
+  echo "Using config file $SRC_DIR/minimal_config/kernel.config"  
+  cp -f $SRC_DIR/minimal_config/kernel.config .config
 else
   # Create default configuration file for the kernel.
   make defconfig
@@ -56,3 +58,5 @@ make headers_install
 
 cd $SRC_DIR
 
+echo "*** BUILD KERNEL END ***"
+
diff --git a/src/04_get_glibc.sh b/src/03_get_glibc.sh
similarity index 94%
rename from src/04_get_glibc.sh
rename to src/03_get_glibc.sh
index 55f0f1acc..6bd042d77 100755
--- a/src/04_get_glibc.sh
+++ b/src/03_get_glibc.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** GET GLIBC BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 # Grab everything after the '=' character.
@@ -37,3 +39,5 @@ tar -xvf $ARCHIVE_FILE -C ../work/glibc
 
 cd $SRC_DIR
 
+echo "*** GET GLIBC END ***"
+
diff --git a/src/05_build_glibc.sh b/src/04_build_glibc.sh
similarity index 96%
rename from src/05_build_glibc.sh
rename to src/04_build_glibc.sh
index 9e475b254..74602cf5b 100755
--- a/src/05_build_glibc.sh
+++ b/src/04_build_glibc.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** BUILD GLIBC BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 # Find the kernel build directory.
@@ -56,3 +58,5 @@ make install \
 
 cd $SRC_DIR
 
+echo "*** BUILD GLIBC END ***"
+
diff --git a/src/06_prepare_glibc.sh b/src/05_prepare_glibc.sh
similarity index 92%
rename from src/06_prepare_glibc.sh
rename to src/05_prepare_glibc.sh
index 9148bc1eb..925ebe782 100755
--- a/src/06_prepare_glibc.sh
+++ b/src/05_prepare_glibc.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** PREPARE GLIBC BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 # Find the kernel build directory.
@@ -50,3 +52,5 @@ ln -s $WORK_KERNEL_DIR/usr/include/mtd mtd
 
 cd $SRC_DIR
 
+echo "*** PREPARE GLIBC END ***"
+
diff --git a/src/07_get_busybox.sh b/src/06_get_busybox.sh
similarity index 94%
rename from src/07_get_busybox.sh
rename to src/06_get_busybox.sh
index c0dbdbe68..dfe3b9e74 100755
--- a/src/07_get_busybox.sh
+++ b/src/06_get_busybox.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** GET BUSYBOX BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 # Grab everything after the '=' character.
@@ -37,3 +39,5 @@ tar -xvf $ARCHIVE_FILE -C ../work/busybox
 
 cd $SRC_DIR
 
+echo "*** GET BUSYBOX END ***"
+
diff --git a/src/08_build_busybox.sh b/src/07_build_busybox.sh
similarity index 86%
rename from src/08_build_busybox.sh
rename to src/07_build_busybox.sh
index 0bc360158..38e64075d 100755
--- a/src/08_build_busybox.sh
+++ b/src/07_build_busybox.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** BUILD BUSYBOX BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 # Remember the glibc installation area.
@@ -20,15 +22,15 @@ make distclean
 # Read the 'USE_PREDEFINED_BUSYBOX_CONFIG' property from '.config'
 USE_PREDEFINED_BUSYBOX_CONFIG="$(grep -i USE_PREDEFINED_BUSYBOX_CONFIG $SRC_DIR/.config | cut -f2 -d'=')"
 
-if [ "$USE_PREDEFINED_BUSYBOX_CONFIG" = "true" -a ! -f $SRC_DIR/config_predefined/busybox.config ] ; then
-  echo "Config file $SRC_DIR/config_predefined/busybox.config does not exist."
+if [ "$USE_PREDEFINED_BUSYBOX_CONFIG" = "true" -a ! -f $SRC_DIR/minimal_config/busybox.config ] ; then
+  echo "Config file $SRC_DIR/minimal_config/busybox.config does not exist."
   USE_PREDEFINED_BUSYBOX_CONFIG="false"
 fi
 
 if [ "$USE_PREDEFINED_BUSYBOX_CONFIG" = "true" ] ; then
   # Use predefined configuration file for Busybox.
-  echo "Using config file $SRC_DIR/config_predefined/busybox.config"  
-  cp -f $SRC_DIR/config_predefined/busybox.config .config
+  echo "Using config file $SRC_DIR/minimal_config/busybox.config"  
+  cp -f $SRC_DIR/minimal_config/busybox.config .config
 else
   # Create default configuration file.
   echo "Generating default BusyBox configuration..."  
@@ -61,3 +63,5 @@ make \
 
 cd $SRC_DIR
 
+echo "*** BUILD BUSYBOX END ***"
+
diff --git a/src/01_prepare_src.sh b/src/08_prepare_src.sh
similarity index 67%
rename from src/01_prepare_src.sh
rename to src/08_prepare_src.sh
index ec937b387..8599c5a10 100755
--- a/src/01_prepare_src.sh
+++ b/src/08_prepare_src.sh
@@ -1,9 +1,12 @@
 #!/bin/sh
 
+echo "*** PREPARE SRC BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 cd work
 
+# Remove old sources (if they exist)
 rm -rf src
 mkdir src
 
@@ -12,9 +15,9 @@ cp ../*.sh src
 cp ../.config src
 cp ../README src
 cp ../*.txt src
-cp -r ../09_generate_rootfs src
-cp -r ../12_generate_iso src
-cp -r ../config_predefined src
+cp -r ../minimal_rootfs src
+cp -r ../minimal_overlay src
+cp -r ../minimal_config src
 
 # Delete the '.gitignore' files which we use in order to keep track of otherwise
 # empty folders.
@@ -24,3 +27,5 @@ echo "Source files and folders have been prepared."
 
 cd $SRC_DIR
 
+echo "*** PREPARE SRC END ***"
+
diff --git a/src/09_generate_rootfs.sh b/src/09_generate_rootfs.sh
index 9d49551b4..f9f9bba21 100755
--- a/src/09_generate_rootfs.sh
+++ b/src/09_generate_rootfs.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** GENERATE ROOTFS BEGIN ***"
+
 SRC_ROOT=$(pwd)
 
 # Remember the glibc prepared folder.
@@ -17,7 +19,7 @@ rm -rf rootfs
 cp -r $BUSYBOX_INSTALLED rootfs
 
 # Copy all rootfs resources to the location of our 'initramfs' folder.
-cp -r src/09_generate_rootfs/* rootfs
+cp -r src/minimal_rootfs/* rootfs
 
 cd rootfs
 
@@ -65,3 +67,5 @@ echo "The initramfs area has been generated."
 
 cd $SRC_ROOT
 
+echo "*** GENERATE ROOTFS END ***"
+
diff --git a/src/10_pack_rootfs.sh b/src/10_pack_rootfs.sh
index 2f928ac05..806e494cd 100755
--- a/src/10_pack_rootfs.sh
+++ b/src/10_pack_rootfs.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** PACK ROOTFS BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 cd work
@@ -13,5 +15,7 @@ cd rootfs
 echo "Packing initramfs..."
 find . | cpio -R root:root -H newc -o | xz --check=none > ../rootfs.cpio.xz
 
-cd cd $SRC_DIR
+cd $SRC_DIR
+
+echo "*** PACK ROOTFS END ***"
 
diff --git a/src/11_get_syslinux.sh b/src/11_get_syslinux.sh
index 042480bae..f841f8cb0 100755
--- a/src/11_get_syslinux.sh
+++ b/src/11_get_syslinux.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** GET SYSLINUX BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 # Grab everything after the '=' character.
@@ -37,3 +39,5 @@ tar -xvf $ARCHIVE_FILE -C ../work/syslinux
 
 cd $SRC_DIR
 
+echo "*** GET SYSLINUX END ***"
+
diff --git a/src/12_generate_iso.sh b/src/12_generate_iso.sh
index 90a6d4b4e..56ede7ebb 100755
--- a/src/12_generate_iso.sh
+++ b/src/12_generate_iso.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "*** GENERATE ISO BEGIN ***"
+
 SRC_DIR=$(pwd)
 
 # Find the kernel build directory.
@@ -24,9 +26,32 @@ rm -rf work/isoimage
 
 # This is the root folder of the ISO image.
 mkdir work/isoimage
-cd work/isoimage
 echo "Prepared new ISO image work area."
 
+# Read the 'COPY_SOURCE_ISO' property from '.config'
+COPY_SOURCE_ISO="$(grep -i COPY_SOURCE_ISO .config | cut -f2 -d'=')"
+
+if [ "$COPY_SOURCE_ISO" = "true" ] ; then
+  # Copy all prepared source files and folders to '/src'. Note that the scripts
+  # will not work there because you also need proper toolchain.
+  cp -r work/src work/isoimage
+  echo "Source files and folders have been copied to '/src'."
+else
+  echo "Source files and folders have been skipped."
+fi
+
+# Read the 'BUILD_OVERLAY_SOFTWARE' property from '.config'
+BUILD_OVERLAY_SOFTWARE="$(grep -i BUILD_OVERLAY_SOFTWARE .config | cut -f2 -d'=')"
+
+if [ "$BUILD_OVERLAY_SOFTWARE" = "true" ] ; then
+  echo "Generating additional overlay software. This may take a while..."
+  sh build_minimal_linux_overlay.sh
+else
+  echo "Generation of additional overlay software has been skipped."
+fi
+
+cd work/isoimage
+
 # Copy the precompiled files 'isolinux.bin' and 'ldlinux.c32' in the ISO image root folder.
 cp $WORK_SYSLINUX_DIR/bios/core/isolinux.bin .
 cp $WORK_SYSLINUX_DIR/bios/com32/elflink/ldlinux/ldlinux.c32 .
@@ -37,25 +62,13 @@ cp $WORK_KERNEL_DIR/arch/x86/boot/bzImage ./kernel.xz
 # Now we copy the root file system.
 cp ../rootfs.cpio.xz ./rootfs.xz
 
-# Read the 'COPY_SOURCE_ISO' property from '.config'
-COPY_SOURCE_ISO="$(grep -i COPY_SOURCE_ISO ../../.config | cut -f2 -d'=')"
-
-if [ "$COPY_SOURCE_ISO" = "true" ] ; then
-  # Copy all prepared source files and folders to '/src'. Note that the scripts
-  # will not work there because you also need proper toolchain.
-  cp -r ../src src
-  echo "Source files and folders have been copied to '/src'."
-else
-  echo "Source files and folders have been skipped."
-fi
-
 # Read the 'OVERLAY_TYPE' property from '.config'
 OVERLAY_TYPE="$(grep -i OVERLAY_TYPE $SRC_DIR/.config | cut -f2 -d'=')"
 
 if [ "$OVERLAY_TYPE" = "sparse" -a "$(id -u)" = "0" ] ; then
   # Use sparse file as storage place. The above check guarantees that the whole
   # script is executed with root permissions or otherwise this block is skipped.
-  # All files and folders located in the folder '12_generate_iso' will be merged
+  # All files and folders located in the folder 'minimal_overlay' will be merged
   # with the root folder on boot.
   
   echo "Using sparse file for overlay."
@@ -84,7 +97,7 @@ if [ "$OVERLAY_TYPE" = "sparse" -a "$(id -u)" = "0" ] ; then
   mkdir -p sparse/work  
   
   # Copy the overlay content.
-  cp -r $SRC_DIR/12_generate_iso/* sparse/rootfs/
+  cp -r $SRC_DIR/work/src/minimal_overlay/* sparse/rootfs/
   
   # Unmount the sparse file and delete the temporary folder.
   $BUSYBOX umount sparse
@@ -94,14 +107,14 @@ if [ "$OVERLAY_TYPE" = "sparse" -a "$(id -u)" = "0" ] ; then
   $BUSYBOX losetup -d $LOOP_DEVICE
 elif [ "$OVERLAY_TYPE" = "folder" ] ; then
   # Use normal folder structure for overlay. All files and folders located in
-  # the folder '12_generate_iso' will be merged with the root folder on boot.
+  # the folder 'minimal_overlay' will be merged with the root folder on boot.
   
   echo "Using folder structure for overlay."
   
   mkdir -p minimal/rootfs
   mkdir -p minimal/work  
   
-  cp -rf $SRC_DIR/12_generate_iso/* minimal/rootfs/
+  cp -rf $SRC_DIR/work/src/minimal_overlay/* minimal/rootfs/
 else
   echo "Generating ISO image with no overlay structure..."
 fi
@@ -128,3 +141,5 @@ fi
 
 cd $SRC_DIR
 
+echo "*** GENERATE ISO END ***"
+
diff --git a/src/Makefile b/src/Makefile
index 39ce03ef8..2ea9f7fcd 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -18,7 +18,9 @@ clean:
 	@echo "Removing generated ISO image..."
 	@rm -f minimal_linux_live.iso
 	@echo "Removing predefined configuration files..."
-	@rm -f config_predefined/*.config
+	@rm -rf minimal_overlay/*.config
+	@echo "Removing source level overlay software..."
+	@cd minimal_overlay && rm -rf $(shell ls -d */) && cd ..
 	@echo "Removing build log file..."
 	@rm -f minimal_linux_live.log
 
@@ -31,7 +33,7 @@ src:
 	@echo "Generating source archive..."
 	@rm -f minimal_linux_live_*_src.tar.xz
 	@mkdir -p work
-	@sh 01_prepare_src.sh 1>/dev/null
+	@sh 08_prepare_src.sh 1>/dev/null
 	@$(eval DATE_PARSED := $(shell LANG=en_US ; date +"%d-%b-%Y"))
 	@cd work/src && tar -cpf - `ls -A` | xz - > ../../minimal_linux_live_$(DATE_PARSED)_src.tar.xz && cd ../..
 	@echo "Source archive: minimal_linux_live_$(DATE_PARSED)_src.tar.xz"
diff --git a/src/build_minimal_linux_live.sh b/src/build_minimal_linux_live.sh
index 567c9275e..4ed6012be 100755
--- a/src/build_minimal_linux_live.sh
+++ b/src/build_minimal_linux_live.sh
@@ -1,14 +1,14 @@
 #!/bin/sh
 
 sh 00_clean.sh
-sh 01_prepare_src.sh
-sh 02_get_kernel.sh
-sh 03_build_kernel.sh
-sh 04_get_glibc.sh
-sh 05_build_glibc.sh
-sh 06_prepare_glibc.sh
-sh 07_get_busybox.sh
-sh 08_build_busybox.sh
+sh 01_get_kernel.sh
+sh 02_build_kernel.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_prepare_src.sh
 sh 09_generate_rootfs.sh
 sh 10_pack_rootfs.sh
 sh 11_get_syslinux.sh
diff --git a/src/build_minimal_linux_overlay.sh b/src/build_minimal_linux_overlay.sh
new file mode 100755
index 000000000..57c898fd0
--- /dev/null
+++ b/src/build_minimal_linux_overlay.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+sh overlay_00_clean.sh
+sh overlay_01_get_links.sh
+sh overlay_02_build_links.sh
+
diff --git a/src/config_predefined/README b/src/minimal_config/README
similarity index 100%
rename from src/config_predefined/README
rename to src/minimal_config/README
diff --git a/src/12_generate_iso/README.txt b/src/minimal_overlay/README
similarity index 100%
rename from src/12_generate_iso/README.txt
rename to src/minimal_overlay/README
diff --git a/src/09_generate_rootfs/dev/.gitignore b/src/minimal_rootfs/dev/.gitignore
similarity index 100%
rename from src/09_generate_rootfs/dev/.gitignore
rename to src/minimal_rootfs/dev/.gitignore
diff --git a/src/09_generate_rootfs/etc/01_prepare.sh b/src/minimal_rootfs/etc/01_prepare.sh
similarity index 100%
rename from src/09_generate_rootfs/etc/01_prepare.sh
rename to src/minimal_rootfs/etc/01_prepare.sh
diff --git a/src/09_generate_rootfs/etc/02_overlay.sh b/src/minimal_rootfs/etc/02_overlay.sh
similarity index 100%
rename from src/09_generate_rootfs/etc/02_overlay.sh
rename to src/minimal_rootfs/etc/02_overlay.sh
diff --git a/src/09_generate_rootfs/etc/03_init.sh b/src/minimal_rootfs/etc/03_init.sh
similarity index 100%
rename from src/09_generate_rootfs/etc/03_init.sh
rename to src/minimal_rootfs/etc/03_init.sh
diff --git a/src/09_generate_rootfs/etc/04_bootscript.sh b/src/minimal_rootfs/etc/04_bootscript.sh
similarity index 100%
rename from src/09_generate_rootfs/etc/04_bootscript.sh
rename to src/minimal_rootfs/etc/04_bootscript.sh
diff --git a/src/09_generate_rootfs/etc/05_rc.dhcp b/src/minimal_rootfs/etc/05_rc.dhcp
similarity index 100%
rename from src/09_generate_rootfs/etc/05_rc.dhcp
rename to src/minimal_rootfs/etc/05_rc.dhcp
diff --git a/src/09_generate_rootfs/etc/inittab b/src/minimal_rootfs/etc/inittab
similarity index 100%
rename from src/09_generate_rootfs/etc/inittab
rename to src/minimal_rootfs/etc/inittab
diff --git a/src/09_generate_rootfs/etc/resolv.conf b/src/minimal_rootfs/etc/resolv.conf
similarity index 100%
rename from src/09_generate_rootfs/etc/resolv.conf
rename to src/minimal_rootfs/etc/resolv.conf
diff --git a/src/09_generate_rootfs/etc/welcome.txt b/src/minimal_rootfs/etc/welcome.txt
similarity index 100%
rename from src/09_generate_rootfs/etc/welcome.txt
rename to src/minimal_rootfs/etc/welcome.txt
diff --git a/src/09_generate_rootfs/init b/src/minimal_rootfs/init
similarity index 100%
rename from src/09_generate_rootfs/init
rename to src/minimal_rootfs/init
diff --git a/src/09_generate_rootfs/lib/.gitignore b/src/minimal_rootfs/lib/.gitignore
similarity index 100%
rename from src/09_generate_rootfs/lib/.gitignore
rename to src/minimal_rootfs/lib/.gitignore
diff --git a/src/09_generate_rootfs/mnt/.gitignore b/src/minimal_rootfs/mnt/.gitignore
similarity index 100%
rename from src/09_generate_rootfs/mnt/.gitignore
rename to src/minimal_rootfs/mnt/.gitignore
diff --git a/src/09_generate_rootfs/proc/.gitignore b/src/minimal_rootfs/proc/.gitignore
similarity index 100%
rename from src/09_generate_rootfs/proc/.gitignore
rename to src/minimal_rootfs/proc/.gitignore
diff --git a/src/09_generate_rootfs/root/.gitignore b/src/minimal_rootfs/root/.gitignore
similarity index 100%
rename from src/09_generate_rootfs/root/.gitignore
rename to src/minimal_rootfs/root/.gitignore
diff --git a/src/09_generate_rootfs/sys/.gitignore b/src/minimal_rootfs/sys/.gitignore
similarity index 100%
rename from src/09_generate_rootfs/sys/.gitignore
rename to src/minimal_rootfs/sys/.gitignore
diff --git a/src/09_generate_rootfs/tmp/.gitignore b/src/minimal_rootfs/tmp/.gitignore
similarity index 100%
rename from src/09_generate_rootfs/tmp/.gitignore
rename to src/minimal_rootfs/tmp/.gitignore
diff --git a/src/overlay_00_clean.sh b/src/overlay_00_clean.sh
new file mode 100755
index 000000000..a64ec0286
--- /dev/null
+++ b/src/overlay_00_clean.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+SRC_DIR=$(pwd)
+
+echo "Cleaning up the overlay work area. This may take a while..."
+rm -rf work/overlay
+mkdir -p work/overlay
+
+# Just in case we execute the overlay software generation script before we
+# execute the main build script.
+mkdir -p work/src/minimal_overlay
+
+# -p stops errors if the directory already exists
+mkdir -p source/overlay
+
+cd minimal_overlay
+
+for dir in $(ls -d */ 2>/dev/null) ; do
+  rm -rf $dir
+  echo "Overlay folder '$dir' has been removed."
+done
+
+echo "Ready to continue building the overlay software."
+
+cd $SRC_DIR
+
diff --git a/src/overlay_01_get_links.sh b/src/overlay_01_get_links.sh
new file mode 100755
index 000000000..3c50fbcc6
--- /dev/null
+++ b/src/overlay_01_get_links.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+SRC_DIR=$(pwd)
+
+# Grab everything after the '=' character.
+DOWNLOAD_URL=$(grep -i LINKS_SOURCE_URL .config | cut -f2 -d'=')
+
+# Grab everything after the last '/' character.
+ARCHIVE_FILE=${DOWNLOAD_URL##*/}
+
+# Read the 'USE_LOCAL_SOURCE' property from '.config'
+USE_LOCAL_SOURCE="$(grep -i USE_LOCAL_SOURCE .config | cut -f2 -d'=')"
+
+if [ "$USE_LOCAL_SOURCE" = "true" -a ! -f $SRC_DIR/source/overlay/$ARCHIVE_FILE  ] ; then
+  echo "Source bundle $SRC_DIR/source/overlay/$ARCHIVE_FILE is missing and will be downloaded."
+  USE_LOCAL_SOURCE="false"
+fi
+
+cd source/overlay
+
+if [ ! "$USE_LOCAL_SOURCE" = "true" ] ; then
+  # Downloading Links source bundle file. The '-c' option allows the download to resume.
+  echo "Downloading Links source bundle from $DOWNLOAD_URL"
+  wget -c $DOWNLOAD_URL
+else
+  echo "Using local Links source bundle $SRC_DIR/source/overlay/$ARCHIVE_FILE"
+fi
+
+# Delete folder with previously extracted Links.
+echo "Removing Links work area. This may take a while..."
+rm -rf ../../work/overlay/links
+mkdir ../../work/overlay/links
+
+# Extract Links to folder 'work/overlay/links'.
+# Full path will be something like 'work/overlay/links/links-2.12'.
+tar -xvf $ARCHIVE_FILE -C ../../work/overlay/links
+
+cd $SRC_DIR
+
diff --git a/src/overlay_02_build_links.sh b/src/overlay_02_build_links.sh
new file mode 100755
index 000000000..ee71a5aca
--- /dev/null
+++ b/src/overlay_02_build_links.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+SRC_DIR=$(pwd)
+
+cd work/overlay/links
+
+# Change to the Links source directory which ls finds, e.g. 'links-2.12'.
+cd $(ls -d links-*)
+
+echo "Preparing Links work area. This may take a while..."
+make clean 2>/dev/null
+
+echo "Configuring Links..."
+./configure \
+  --prefix=../links_installed \
+  --disable-graphics \
+  --enable-utf8 \
+  --without-ipv6 \
+  --without-ssl \
+  --without-x
+
+echo "Building Links..."
+make
+
+make install
+cp -r ../links_installed/bin $SRC_DIR/work/src/minimal_overlay
+ 
+echo "Links has been installed."
+
+cd $SRC_DIR
+