Major reorganization (might break the build, not tested). Externalized the "copy source" process. Added properties to fin-tune the "copy source" process. Changed how Linux loader visibility is handled on 64-bit machines. Comments and log messages have been improved.

This commit is contained in:
Ivan Davidov 2016-05-04 18:44:39 +03:00
parent ef799cca0e
commit e11ed73329
35 changed files with 170 additions and 128 deletions

View File

@ -28,40 +28,59 @@ SYSLINUX_SOURCE_URL=http://kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.0
### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ###
# Use predefined '.config' file when building the kernel. This overrides the config generation # Use predefined '.config' file when building the kernel. This overrides the
# in '02_build_kernel.sh' and the build process uses the config file provided in this parameter. # config generation in '03_build_kernel.sh' and the build process uses the
# Place the configuration file here: config_predefined/kernel.config # config file provided in this parameter. Place the configuration file here:
#
# config_predefined/kernel.config
# #
USE_PREDEFINED_KERNEL_CONFIG=false USE_PREDEFINED_KERNEL_CONFIG=false
# Use predefined '.config' file when building BusyBox. This overrides the config generation in # Use predefined '.config' file when building BusyBox. This overrides the config
# '07_build_busybox.sh' and the build process uses the config file provided in this parameter. # generation in '08_build_busybox.sh' and the build process uses the config file
# # Place the configuration file here: config_predefined/busybox.config # provided in this parameter. Place the configuration file here:
#
# config_predefined/busybox.config
# #
USE_PREDEFINED_BUSYBOX_CONFIG=false USE_PREDEFINED_BUSYBOX_CONFIG=false
# Define the overlay type to use. Possible values are 'sparse' and 'folder'. You can use any other # Define the overlay type to use. Possible values are 'sparse' and 'folder'. You
# value, no value, or comment the property in order to disable it. Put your overlay content in the # can use any other value, no value, or comment the property in order to disable
# folder '11_generate_iso' and it will be automatically merged with the root file system on boot. # it. Put your overlay content in the folder '11_generate_iso' and it will be
# The build process creates either '/minimal.img/rootfs' or '/minimal/rootfs' (read below) and this # automatically merged with the root file system on boot. The build process
# folder contains all overlay content in it. The build process also creates '/minimal.img/work' # creates either '/minimal.img/rootfs' or '/minimal/rootfs' (read below) and
# or '/minimal/work'. This folder is used by the overlay driver to store modifications related # this folder contains all overlay content in it. The build process also creates
# to the read only storage. If the overlay media is writeable, then all changes on # '/minimal.img/work' or '/minimal/work'. This folder is used by the overlay
# the root filesystem are automatically persisted and preserved on reboot. # driver to store modifications related to the read only storage. If the overlay
# media is writeable, then all changes on the root filesystem are automatically
#persisted and preserved on reboot.
# #
# sparse - use sparse file 'minimal.img' with hardcoded maximal size of 1MB (see 11_generate_iso.sh). # sparse - use sparse file 'minimal.img' with hardcoded maximal size of 1MB (see
# The generated ISO image is larger because the sparse file is treated as regular file. This # 11_generate_iso.sh). The generated ISO image is larger because the
# option requires root permissions or otherwise sparse file generation is silently skipped. # sparse file is treated as regular file. This option requires root
# Sparse file is treated as separate disk image and works fine on 'vfat'. # permissions or otherwise sparse file generation is silently skipped.
# Sparse file is treated as separate disk image and works fine on FAT.
# #
# folder - use normal folder structure (/minimal/). Note that this doesn't work if the file system is # folder - use normal folder structure (/minimal/). Note that this doesn't work
# 'vfat' because FAT requires special handling, e.g. POSIX overlay (http://sf.net/p/posixovl). # if the file system is FAT because FAT requires special handling, e.g.
# This is the default option because it doesn't require root permissions. # POSIX overlay (http://sf.net/p/posixovl). This is the default option
# because it doesn't require root permissions.
# #
OVERLAY_TYPE=folder OVERLAY_TYPE=folder
# Use already downloaded source bundles instead of downloading them from internet. This is useful # Use already downloaded source bundles instead of downloading them from
# when you have already downloaded the sources and have no internet connection. Or if you want to # internet. This is useful when you have already downloaded the sources and have
# share your version of "Minimal Linux Live" with predefined sources. # no internet connection. Or if you want to share your version of "Minimal Linux
# Live" with predefined sources.
USE_LOCAL_SOURCE=false USE_LOCAL_SOURCE=false
# Copy "Minimal Linux Live" source files and folders in '/src' inside initramfs.
# The default value is 'true'. You can use any other value, no value, or comment
# the property in order to disable it.
COPY_SOURCE_ROOTFS=true
# Copy "Minimal Linux Live" source files and folders in '/src' on the ISO image.
# The default value is 'true'. You can use any other value, no value, or comment
# the property in order to disable it.
COPY_SOURCE_ISO=true

26
src/01_prepare_src.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
SRC_DIR=$(pwd)
cd work
rm -rf src
mkdir src
# Copy all source files and folders to 'work/src'.
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
# Delete the '.gitignore' files which we use in order to keep track of otherwise
# empty folders.
find * -type f -name '.gitignore' -exec rm {} +
echo "Source files and folders have been prepared."
cd $SRC_DIR

View File

@ -2,7 +2,7 @@
# Find the kernel build directory. # Find the kernel build directory.
cd work/kernel cd work/kernel
cd $(ls -d kernel-*) cd $(ls -d linux-*)
WORK_KERNEL_DIR=$(pwd) WORK_KERNEL_DIR=$(pwd)
cd ../../.. cd ../../..
@ -28,9 +28,11 @@ GLIBC_INSTALLED=$(pwd)/glibc_installed
cd glibc_objects cd glibc_objects
# glibc is configured to use the root folder (--prefix=) and as result all # 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 # libraries will be installed in '/lib'. Note that on 64-bit machines BusyBox
# already prepared kernel header area (see 02_build_kernel.sh). Packages 'gd' # will be linked with the libraries in '/lib' while the Linux loader is expected
# and 'selinux' are disabled. # to be in '/lib64'. Kernel headers are taken from our already prepared kernel
# header area (see 03_build_kernel.sh). Packages 'gd' and 'selinux' are disabled
# for better build compatibility with the host system.
echo "Configuring glibc..." echo "Configuring glibc..."
$GLIBC_SRC/configure \ $GLIBC_SRC/configure \
--prefix= \ --prefix= \

View File

@ -1,61 +0,0 @@
#!/bin/sh
# Remember the prepared glibc folder.
GLIBC_PREPARED=$(pwd)/work/glibc/glibc_prepared
cd work
echo "Preparing initramfs work area..."
rm -rf rootfs
# Copy all BusyBox generated stuff to the location of our 'initramfs' folder.
cp -r busybox/busybox_installed rootfs
# Copy all rootfs resources to the location of our 'initramfs' folder.
cp -r ../08_generate_rootfs/* rootfs
cd rootfs
# Remove 'linuxrc' which is used when we boot in 'RAM disk' mode.
rm -f linuxrc
# Copy all source files to '/src'. Note that the scripts won't work there.
cp ../../*.sh src
cp ../../.config src
cp ../../README src
cp ../../*.txt src
cp -r ../../08_generate_rootfs src
cp -r ../../11_generate_iso src
# Make all files readable and all scripts executable.
chmod -R +rx **/*.sh
chmod -R +r **/.config
chmod -R +r **/README
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_PREPARED/lib/ld-linux* ./lib
# BusyBox has direct dependencies on these libraries.
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_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
# Copy all necessary 'glibc' libraries to '/lib' END.
# Delete the '.gitignore' files which we use in order to keep track of otherwise
# empty folders.
find * -type f -name '.gitignore' -exec rm {} +
echo "The initramfs area has been generated."
cd ../..

62
src/09_generate_rootfs.sh Executable file
View File

@ -0,0 +1,62 @@
#!/bin/sh
# Remember the prepared glibc folder.
GLIBC_PREPARED=$(pwd)/work/glibc/glibc_prepared
cd work
echo "Preparing initramfs work area..."
rm -rf rootfs
# Copy all BusyBox generated stuff to the location of our 'initramfs' folder.
cp -r busybox/busybox_installed rootfs
# Copy all rootfs resources to the location of our 'initramfs' folder.
cp -r ../09_generate_rootfs/* rootfs
cd rootfs
# Remove 'linuxrc' which is used when we boot in 'RAM disk' mode.
rm -f linuxrc
# Read the 'COPY_SOURCE_ROOTFS' property from '.config'
COPY_SOURCE_ROOTFS="$(grep -i COPY_SOURCE_ROOTFS ../../.config | cut -f2 -d'=')"
if [ "$COPY_SOURCE_ROOTFS" = "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 "Original source files and folders have been copied."
else
echo "Original source files and folders have been skipped."
fi
# Copy all necessary 'glibc' libraries to '/lib' BEGIN.
# This is the dynamic loader. Note that the file name is different for 32-bit
# and 64-bit machines.
cp $GLIBC_PREPARED/lib/ld-linux* ./lib
# BusyBox has direct dependencies on these libraries.
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_PREPARED/lib/libresolv.so.2 ./lib
cp $GLIBC_PREPARED/lib/libnss_dns.so.2 ./lib
# Make sure the Linux loader is visible on 64-bit machines. We can't rename the
# folder to '/lib64' because the glibc root location is set to '/lib' in the
# '05_build_glibc.sh' source script and therefore all 64-bit executables will
# be looking for shared libraries directly in '/lib'.
BUSYBOX_ARCH=$(file busybox | cut -d\ -f3)
if [ "$BUSYBOX_ARCH" = "64-bit" ] ; then
ln -s lib lib64
fi
# Copy all necessary 'glibc' libraries to '/lib' END.
echo "The initramfs area has been generated."
cd ../..

View File

@ -38,7 +38,7 @@ echo "Created folders for all critical file systems."
# Copy root folders in the new mountpoint. # Copy root folders in the new mountpoint.
echo "Copying the root file system to /mnt..." echo "Copying the root file system to /mnt..."
cp -a bin etc lib lib64 root sbin src usr /mnt cp -a bin etc lib lib64 root sbin src usr /mnt 2>/dev/null
DEFAULT_OVERLAY_DIR="/tmp/minimal/overlay" DEFAULT_OVERLAY_DIR="/tmp/minimal/overlay"
DEFAULT_UPPER_DIR="/tmp/minimal/rootfs" DEFAULT_UPPER_DIR="/tmp/minimal/rootfs"

View File

@ -19,7 +19,7 @@ rm -f minimal_linux_live.iso
echo "Old ISO image files has been removed." echo "Old ISO image files has been removed."
# Remove the old ISO generation area if it exists. # Remove the old ISO generation area if it exists.
echo "Removing old ISO image work area..." echo "Removing old ISO image work area. This may take a while..."
rm -rf work/isoimage rm -rf work/isoimage
# This is the root folder of the ISO image. # This is the root folder of the ISO image.
@ -37,20 +37,17 @@ 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.xz ./rootfs.xz cp ../rootfs.cpio.xz ./rootfs.xz
# Copy all source files to '/src'. Note that the scripts won't work there. # Read the 'COPY_SOURCE_ISO' property from '.config'
mkdir src COPY_SOURCE_ISO="$(grep -i COPY_SOURCE_ISO ../../.config | cut -f2 -d'=')"
cp ../../*.sh src
cp ../../.config src
cp ../../README src
cp ../../*.txt src
cp -r ../../08_generate_rootfs src
cp -r ../../11_generate_iso src
# Make all files readable and all scripts executable. if [ "$COPY_SOURCE_ISO" = "true" ] ; then
chmod -R +rx **/*.sh # Copy all prepared source files and folders to '/src'. Note that the scripts
chmod -R +r **/.config # will not work there because you also need proper toolchain.
chmod -R +r **/README cp -r ../src src
chmod -R +r **/*.txt echo "Original source files and folders have been copied."
else
echo "Original source files and folders have been skipped."
fi
# Read the 'OVERLAY_TYPE' property from '.config' # Read the 'OVERLAY_TYPE' property from '.config'
OVERLAY_TYPE="$(grep -i OVERLAY_TYPE $SRC_DIR/.config | cut -f2 -d'=')" OVERLAY_TYPE="$(grep -i OVERLAY_TYPE $SRC_DIR/.config | cut -f2 -d'=')"
@ -58,7 +55,7 @@ OVERLAY_TYPE="$(grep -i OVERLAY_TYPE $SRC_DIR/.config | cut -f2 -d'=')"
if [ "$OVERLAY_TYPE" = "sparse" -a "$(id -u)" = "0" ] ; then if [ "$OVERLAY_TYPE" = "sparse" -a "$(id -u)" = "0" ] ; then
# Use sparse file as storage place. The above check guarantees that the whole # 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. # script is executed with root permissions or otherwise this block is skipped.
# All files and folders located in the folder '11_generate_iso' will be merged # All files and folders located in the folder '12_generate_iso' will be merged
# with the root folder on boot. # with the root folder on boot.
echo "Using sparse file for overlay." echo "Using sparse file for overlay."
@ -87,7 +84,7 @@ if [ "$OVERLAY_TYPE" = "sparse" -a "$(id -u)" = "0" ] ; then
mkdir -p sparse/work mkdir -p sparse/work
# Copy the overlay content. # Copy the overlay content.
cp -r $SRC_DIR/11_generate_iso/* sparse/rootfs/ cp -r $SRC_DIR/12_generate_iso/* sparse/rootfs/
# Unmount the sparse file and delete the temporary folder. # Unmount the sparse file and delete the temporary folder.
$BUSYBOX umount sparse $BUSYBOX umount sparse
@ -97,14 +94,14 @@ if [ "$OVERLAY_TYPE" = "sparse" -a "$(id -u)" = "0" ] ; then
$BUSYBOX losetup -d $LOOP_DEVICE $BUSYBOX losetup -d $LOOP_DEVICE
elif [ "$OVERLAY_TYPE" = "folder" ] ; then elif [ "$OVERLAY_TYPE" = "folder" ] ; then
# Use normal folder structure for overlay. All files and folders located in # Use normal folder structure for overlay. All files and folders located in
# the folder '11_generate_iso' will be merged with the root folder on boot. # the folder '12_generate_iso' will be merged with the root folder on boot.
echo "Using folder structure for overlay." echo "Using folder structure for overlay."
mkdir -p minimal/rootfs mkdir -p minimal/rootfs
mkdir -p minimal/work mkdir -p minimal/work
cp -rf $SRC_DIR/11_generate_iso/* minimal/rootfs/ cp -rf $SRC_DIR/12_generate_iso/* minimal/rootfs/
else else
echo "Generating ISO image with no overlay structure..." echo "Generating ISO image with no overlay structure..."
fi fi
@ -112,10 +109,6 @@ fi
# Create ISOLINUX configuration file. # Create ISOLINUX configuration file.
echo 'default kernel.xz initrd=rootfs.xz' > ./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.
find * -type f -name '.gitignore' -exec rm {} +
# 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 -input-charset UTF-8 -no-emul-boot -boot-load-size 4 -boot-info-table ./ genisoimage -J -r -o ../minimal_linux_live.iso -b isolinux.bin -c boot.cat -input-charset UTF-8 -no-emul-boot -boot-load-size 4 -boot-info-table ./
@ -133,5 +126,5 @@ if [ "$(id -u)" = "0" ] ; then
echo "Applied original ownership to all affected files and folders." echo "Applied original ownership to all affected files and folders."
fi fi
cd ../.. cd $SRC_DIR

View File

@ -22,9 +22,9 @@ clean:
@echo "Removing build log file..." @echo "Removing build log file..."
@rm -f minimal_linux_live.log @rm -f minimal_linux_live.log
emulator: qemu:
@if [ ! -f ./minimal_linux_live.iso ]; then echo "ISO image \"minimal_linux_live.iso\" not found."; exit 1; fi @if [ ! -f ./minimal_linux_live.iso ]; then echo "ISO image \"minimal_linux_live.iso\" not found."; exit 1; fi
@echo "Launching emulator..." @echo "Launching QEMU..."
@if [ "$(shell uname -m)" = "x86_64" ]; then sh qemu64.sh; else sh qemu32.sh; fi @if [ "$(shell uname -m)" = "x86_64" ]; then sh qemu64.sh; else sh qemu32.sh; fi
help: help:
@ -33,7 +33,7 @@ help:
@echo "" @echo ""
@echo " make clean remove all generated files" @echo " make clean remove all generated files"
@echo "" @echo ""
@echo " make emulator run \"Minimal Linux Live\" in qemu" @echo " make qemu run \"Minimal Linux Live\" in qemu"
@echo "" @echo ""
@echo " make help this is the default target" @echo " make help this is the default target"
@echo "" @echo ""

View File

@ -1,15 +1,16 @@
#!/bin/sh #!/bin/sh
sh 00_prepare.sh sh 00_clean.sh
sh 01_get_kernel.sh sh 01_prepare_src.sh
sh 02_build_kernel.sh sh 02_get_kernel.sh
sh 03_get_glibc.sh sh 03_build_kernel.sh
sh 04_build_glibc.sh sh 04_get_glibc.sh
sh 05_prepare_glibc.sh sh 05_build_glibc.sh
sh 06_get_busybox.sh sh 06_prepare_glibc.sh
sh 07_build_busybox.sh sh 07_get_busybox.sh
sh 08_generate_rootfs.sh sh 08_build_busybox.sh
sh 09_pack_rootfs.sh sh 09_generate_rootfs.sh
sh 10_get_syslinux.sh sh 10_pack_rootfs.sh
sh 11_generate_iso.sh sh 11_get_syslinux.sh
sh 12_generate_iso.sh