update build_image.sh script added rootfs_archive and unified busybox building
This commit is contained in:
Executable
+300
@@ -0,0 +1,300 @@
|
||||
#!/bin/sh
|
||||
|
||||
#--------------------------------- Logo ---------------------------------------------------------------------
|
||||
# ####### ## ## ## ####### ## ####### | ## ## ## ## ## ## ## ## |
|
||||
# ## ## #### #### ## ## ## ## | ## ## ## ## ## ## ## ## |
|
||||
# ## ## ## ## ## ## ## ## | ## ## ## ## ## ## ## |
|
||||
# ## ## ## ## ## ## ## ## ## | ## ## ### ## ## ## ## |
|
||||
# ####### ## ## ## ####### ## ####### | ## ## #### ## ## ## ## |
|
||||
# ## ## ## ## ## ## ## | ## ## ## #### ## ## ## |
|
||||
# ## ## ## ## ## ## ## | ## ## ## ### ## ## ## ## |
|
||||
# ## ## ## ## ## ## ## | ## ## ## ## ## ## ## ## |
|
||||
# ####### ## ## ## ## ####### ####### | ####### ## ## ## ######## ## ## |
|
||||
#------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# Script to build linux install media image
|
||||
version=0.0.1 # script version
|
||||
# TolaMironcenko is licensed under MIT
|
||||
|
||||
#--- import rolors ---
|
||||
. ./scripts/colors.sh
|
||||
#---------------------
|
||||
#--- import funcs ----
|
||||
. ./scripts/funcs.sh
|
||||
#---------------------
|
||||
|
||||
#------------ config ------------------
|
||||
root=$(pwd) # root build directory
|
||||
disk="sdz" # disk to write install image
|
||||
distro_name="Simple" # distro name
|
||||
distro_desc="Simple linux distro" # distro desctiption
|
||||
distro_codename="zero_zero_one" # distro codename
|
||||
hyperv_support="false" # hyperv support for kernel image
|
||||
out=$root/out # output directory
|
||||
build=$root/build # build directory
|
||||
sourcesfilename=sources.txt # sources file for downloading
|
||||
initramfsfile=$root/initramfs/initramfs.txt # file to created directories for initramfs
|
||||
initramfspath=$build/initramfs # initramfs build directory
|
||||
rootfsfile=$root/rootfs/rootfs.txt # file to created directories for rootfs
|
||||
rootfspath=$build/rootfs # rootfs build directory
|
||||
fulllogfile=$root/.log/fulllog.log # file for full build logs
|
||||
makeflags=-j16 # makeflags
|
||||
#--------------------------------------
|
||||
|
||||
#----- import busybox build funcs ---
|
||||
. ./scripts/busybox.sh
|
||||
#------------------------------------
|
||||
|
||||
#-------- check root ------------------
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
printf "$URED** You are not root\n$RESET"
|
||||
exit 1
|
||||
fi
|
||||
#--------------------------------------
|
||||
|
||||
mkdir $out &>> $fulllogfile
|
||||
mkdir $root/.log &>> $fulllogfile
|
||||
|
||||
#------------ Download needed sources from sources.txt ------------------
|
||||
download_sources() {
|
||||
printf "$UGREEN** Downloading sources\n$RESET"
|
||||
cat $sourcesfilename
|
||||
if [ ! -d downloads ]; then mkdir downloads; fi
|
||||
wget --input-file=$sourcesfilename --continue --directory-prefix=$root/downloads
|
||||
check $? "Download sources"
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
#--------------- Building Linux Kernel ---------------------
|
||||
kernel() {
|
||||
printf "$UGREEN** Building Linux Kernel\n$RESET"
|
||||
rm -r $build/kernel &>> $fulllogfile
|
||||
mkdir -p $build/kernel &>> $fulllogfile
|
||||
cd $build/kernel
|
||||
printf "$UGREEN** Extracting Linux Kernel\n$RESET"
|
||||
tar -xvf $root/downloads/linux-6.7.4.tar.xz &>> $fulllogfile
|
||||
check $? "Extract Linux Kernel"
|
||||
cd linux-6.7.4
|
||||
printf "$UGREEN** Configuring Linux Kernel\n$RESET"
|
||||
make mrproper &>> $fulllogfile
|
||||
cp -v $root/kernel/config-6.7.4 .config &>> $fulllogfile
|
||||
make oldconfig &>> $fulllogfile
|
||||
check $? "Configure Linux Kernel"
|
||||
printf "$UGREEN** Building Linux Kernel\n$RESET"
|
||||
make $makeflags &>> $fulllogfile
|
||||
check $? "Build Linux Kernel"
|
||||
ls -lh arch/x86/boot/bzImage
|
||||
} # kernel
|
||||
#-----------------------------------------------------------
|
||||
|
||||
#----------- Build and Install kernel modules --------------
|
||||
kernel_modules() {
|
||||
printf "$UGREEN** Building Linux Kernel modules\n$RESET"
|
||||
cd $build/kernel/linux-6.7.4
|
||||
make modules &>> fulllogfile
|
||||
check $? "Build Linux Kernel modules"
|
||||
printf "$UGREEN** Installing Linux Kernel modules into rootfs path\n$RESET"
|
||||
mkdir -pv $rootfspath/usr/lib &>> fulllogfile
|
||||
cd $rootfspath
|
||||
ln -sv usr/lib lib &>> $fulllogfile
|
||||
cd $root/build/kernel/linux-6.7.4
|
||||
make INSTALL_MOD_PATH=$rootfspath modules_install &>> $fulllogfile
|
||||
check $? "Install Linux Kernel modules"
|
||||
} # kernel_modules
|
||||
#-----------------------------------------------------------
|
||||
|
||||
#------------ glibc ----------------------------------------
|
||||
glibc() {
|
||||
printf "$UGREEN** Building glibc\n$RESET"
|
||||
mkdir -p $build/glibc &>> $fulllogfile
|
||||
cd $build/glibc
|
||||
tar -xvf $root/downloads/glibc-2.39.tar.xz &>> $fulllogfile
|
||||
check $? "Extract glibc"
|
||||
cd glibc-2.39
|
||||
mkdir build
|
||||
cd build
|
||||
echo "rootsbindir=/usr/bin" > configparms
|
||||
../configure \
|
||||
--prefix=/usr \
|
||||
--disable-werror \
|
||||
--enable-kernel=4.19 \
|
||||
--enable-stack-protector=strong \
|
||||
--disable-nscd \
|
||||
libc_cv_slibdir=/usr/lib &>> $fulllogfile
|
||||
check $? "Configure glibc"
|
||||
make $makeflags &>> $fulllogfile
|
||||
check $? "Build glibc"
|
||||
make DESTDIR=$rootfspath install &>> $fulllogfile
|
||||
check $? "Install glibc to rootfs"
|
||||
cd $rootfspath
|
||||
find -name \*.a -delete &>> $fulllogfile
|
||||
strip --strip-unneeded $rootfspath/usr/lib/* $rootfspath/usr/bin/* &>> $fulllogfile
|
||||
chroot $rootfspath /bin/sh -c "mkdir -p /usr/lib/locale;localedef -i C -f UTF-8 C.UTF-8;localedef -i en_US -f UTF-8 en_US.UTF-8;localedef -i ru_RU -f UTF-8 ru_RU-UTF-8;"
|
||||
cd $root
|
||||
check $? "Build and install glibc"
|
||||
}
|
||||
#-----------------------------------------------------------
|
||||
|
||||
# #------------------ Building busybox for initramfs ----------------
|
||||
# busybox_initramfs() {
|
||||
# printf "$UGREEN** Building busybox for initramfs\n$RESET"
|
||||
# rm -r $build/busybox &>> $fulllogfile
|
||||
# mkdir -p $build/busybox
|
||||
# cd $build/busybox
|
||||
# tar -xjf $root/downloads/busybox-1.36.1.tar.bz2
|
||||
# check $? "Extract busybox"
|
||||
# cd busybox-1.36.1
|
||||
# cp $root/busybox/busybox-initramfs-config .config
|
||||
# export PATH=$PATH:/opt/toolchains/x86_64-buildroot-linux-uclibc-gcc/bin
|
||||
# printf "$UGREEN** Configuring busybox\n$RESET"
|
||||
# make CROSS_COMPILE=x86_64-buildroot-linux-uclibc- oldconfig &> $fulllogfile
|
||||
# check $? "Configure busybox all logs in .log"
|
||||
# printf "$UGREEN** Building busybox\n$RESET"
|
||||
# make CROSS_COMPILE=x86_64-buildroot-linux-uclibc- $makeflags &> $fulllogfile
|
||||
# check $? "Build busybox all logs in .log"
|
||||
# }
|
||||
# # #------------------------------------------------------------------
|
||||
|
||||
# # #----------- Building busybox for rootfs ----------
|
||||
# busybox_rootfs() {
|
||||
# printf "$UGREEN** Building busybox for rootfs\n$RESET"
|
||||
# rm -rv $build/busybox &>> $fulllogfile
|
||||
# mkdir -v $build/busybox &>> $fulllogfile
|
||||
# cd $build/busybox
|
||||
# tar -xvjf $root/downloads/busybox-1.36.1.tar.bz2 &>> $fulllogfile
|
||||
# cd busybox-1.36.1
|
||||
# cp -v $root/busybox/busybox-rootfs-config .config &>> $fulllogfile
|
||||
# printf "$UGREEN** Configuring busybox\n$RESET"
|
||||
# make oldconfig &>> $fulllogfile
|
||||
# check $? "Configure busybox all logs in .log"
|
||||
# printf "$UGREEN** Building busybox\n$RESET"
|
||||
# make $makeflags &>> $fulllogfile
|
||||
# check $? "Build busybox all logs in .log"
|
||||
# }
|
||||
# #--------------------------------------------------
|
||||
|
||||
# #------------------ Building busybox ------------------------------
|
||||
# busybox() {
|
||||
# case "$1" in
|
||||
# initramfs)
|
||||
# busybox_initramfs
|
||||
# ;;
|
||||
# rootfs)
|
||||
# busybox_rootfs
|
||||
# ;;
|
||||
# esac
|
||||
# }
|
||||
#------------------------------------------------------------------
|
||||
|
||||
#------------------ Building initramfs.img ------------------------
|
||||
initramfs() {
|
||||
printf "$UGREEN** Building initramfs\n$RESET"
|
||||
|
||||
#--------- Creating directories and files -------------------
|
||||
rm -r $initramfspath &>> $fulllogfile
|
||||
mkdir -p $initramfspath
|
||||
cd $initramfspath
|
||||
mkdir -p $(cat $initramfsfile)
|
||||
cp $root/initramfs/init.in $initramfspath/init
|
||||
chmod 755 $initramfspath/init
|
||||
#------------------------------------------------------------
|
||||
|
||||
#------------ Building initramfs busybox and copy to initramfs directory --------------------
|
||||
busybox initramfs
|
||||
cp $build/busybox/busybox-1.36.1/busybox $initramfspath/bin
|
||||
cd $initramfspath/bin
|
||||
for i in $(./busybox --list); do ln -s busybox $i; done
|
||||
cd ..
|
||||
#--------------------------------------------------------------------------------------------
|
||||
|
||||
#--------------------- Creating initramfs.img image ------------
|
||||
find . | cpio -H newc -o | gzip > ../initramfs.img
|
||||
check $? "Build initramfs.img image"
|
||||
cd $root
|
||||
#---------------------------------------------------------------
|
||||
|
||||
} # initramfs
|
||||
#------------------------------------------------------------------
|
||||
|
||||
#----------- Building rootfs ----------------------
|
||||
rootfs() {
|
||||
printf "$UGREEN** Building rootfs\n$RESET"
|
||||
rm -rv $rootfspath &>> $fulllogfile
|
||||
mkdir -pv $rootfspath &>> $fulllogfile
|
||||
cd $rootfspath
|
||||
mkdir -pv $(cat $rootfsfile) &>> $fulllogfile
|
||||
ln -sv usr/lib lib &>> $fulllogfile
|
||||
ln -sv usr/lib lib64 &>> $fulllogfile
|
||||
ln -sv usr/bin bin &>> $fulllogfile
|
||||
ln -sv usr/bin sbin &>> $fulllogfile
|
||||
cd usr
|
||||
ln -sv bin sbin &>> $fulllogfile
|
||||
ln -sv lib lib64 &>> $fulllogfile
|
||||
cp -rv $root/rootfs/etc/* $rootfspath/etc/ &>> $fulllogfile
|
||||
cp -rv $root/rootfs/usr/* $rootfspath/usr/ &>> $fulllogfile
|
||||
cp -rv $root/rootfs/boot/* $rootfspath/boot/ &>> $fulllogfile
|
||||
cd ..
|
||||
ln -sv /proc/mounts etc/mtab &>> $fulllogfile
|
||||
|
||||
busybox rootfs
|
||||
cp -v $build/busybox/busybox-1.36.1/busybox $rootfspath/usr/bin &>> $fulllogfile
|
||||
cd $rootfspath/usr/bin
|
||||
for i in $(./busybox --list); do ln -s busybox $i; done
|
||||
|
||||
glibc
|
||||
kernel
|
||||
cp -v $root/build/kernel/linux-6.7.4/arch/x86/boot/bzImage $rootfspath/boot/vmlinuz-linux &>> $fulllogfile
|
||||
kernel_modules &>> $fulllogfile
|
||||
initramfs
|
||||
cp -v $root/build/initramfs.img $rootfspath/boot/
|
||||
|
||||
chmod 640 $rootfspath/etc/shadow $rootfspath/etc/inittab
|
||||
chmod 755 $rootfspath/etc/init.d/* $rootfspath/usr/share/udhcpc/default.script
|
||||
chmod 644 $rootfspath/etc/{passwd,group,hostname,hosts,fstab,shells,issue} $rootfspath/etc/network/interfaces
|
||||
|
||||
check $? "Build rootfs"
|
||||
} # rootfs
|
||||
#--------------------------------------------------
|
||||
|
||||
#---------- Cleaning build and out directory ---------
|
||||
clean() {
|
||||
printf "$UGREEN** Cleaning build and out directories\n$RESET"
|
||||
rm -rv $root/.log/* &>> $fulllogfile
|
||||
mkdir -p $root/.log
|
||||
rm -rv $out &>> $fulllogfile
|
||||
mkdir -p $out
|
||||
rm -rv $build &>> $fulllogfile
|
||||
mkdir -p $build
|
||||
printf "$UGREEN** SUCCESS: Cleaning build and out directories\n$RESET"
|
||||
} # clean
|
||||
#-----------------------------------------------------
|
||||
|
||||
#------------- grub rescue ---------------------------
|
||||
grub_rescue() {
|
||||
grub-mkrescue -o $build/simplelinux.iso $rootfspath &>> $fulllogfile
|
||||
check $? "Build grub-rescue"
|
||||
cp -v $build/simplelinux.iso $out/ &>> $fulllogfile
|
||||
}
|
||||
#-----------------------------------------------------
|
||||
|
||||
#------------------ rootfs archive -------------------
|
||||
rootfs_archive() {
|
||||
cd $rootfspath
|
||||
tar -czvf $out/simplelinux-$version-rootfs.tar.gz . &>> $fulllogfile
|
||||
check $? "Build rootfs archive"
|
||||
}
|
||||
#-----------------------------------------------------
|
||||
|
||||
if [ "$1" = "clean" ]; then
|
||||
clean
|
||||
exit 0
|
||||
fi
|
||||
|
||||
clean
|
||||
download_sources
|
||||
# kernel
|
||||
# kernel_modules
|
||||
# initramfs
|
||||
rootfs
|
||||
grub_rescue
|
||||
rootfs_archive
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
|
||||
#--- import rolors ---
|
||||
. ./scripts/colors.sh
|
||||
#---------------------
|
||||
#--- import funcs ----
|
||||
. ./scripts/funcs.sh
|
||||
#---------------------
|
||||
|
||||
#------------------ Building busybox for initramfs ----------------
|
||||
busybox_initramfs() {
|
||||
printf "$UGREEN** Building busybox for initramfs\n$RESET"
|
||||
rm -r $build/busybox &>> $fulllogfile
|
||||
mkdir -p $build/busybox
|
||||
cd $build/busybox
|
||||
tar -xjf $root/downloads/busybox-1.36.1.tar.bz2
|
||||
check $? "Extract busybox"
|
||||
cd busybox-1.36.1
|
||||
cp $root/busybox/busybox-initramfs-config .config
|
||||
export PATH=$PATH:/opt/toolchains/x86_64-buildroot-linux-uclibc-gcc/bin
|
||||
printf "$UGREEN** Configuring busybox\n$RESET"
|
||||
make CROSS_COMPILE=x86_64-buildroot-linux-uclibc- oldconfig &>> $fulllogfile
|
||||
check $? "Configure busybox all logs in .log"
|
||||
printf "$UGREEN** Building busybox\n$RESET"
|
||||
make CROSS_COMPILE=x86_64-buildroot-linux-uclibc- $makeflags &>> $fulllogfile
|
||||
check $? "Build busybox all logs in .log"
|
||||
}
|
||||
#------------------------------------------------------------------
|
||||
|
||||
#----------- Building busybox for rootfs ----------
|
||||
busybox_rootfs() {
|
||||
printf "$UGREEN** Building busybox for rootfs\n$RESET"
|
||||
rm -rv $build/busybox &>> $fulllogfile
|
||||
mkdir -v $build/busybox &>> $fulllogfile
|
||||
cd $build/busybox
|
||||
tar -xvjf $root/downloads/busybox-1.36.1.tar.bz2 &>> $fulllogfile
|
||||
cd busybox-1.36.1
|
||||
cp -v $root/busybox/busybox-rootfs-config .config &>> $fulllogfile
|
||||
printf "$UGREEN** Configuring busybox\n$RESET"
|
||||
make oldconfig &>> $fulllogfile
|
||||
check $? "Configure busybox all logs in .log"
|
||||
printf "$UGREEN** Building busybox\n$RESET"
|
||||
make $makeflags &>> $fulllogfile
|
||||
check $? "Build busybox all logs in .log"
|
||||
}
|
||||
#--------------------------------------------------
|
||||
|
||||
#------------------ Building busybox ------------------------------
|
||||
busybox() {
|
||||
case "$1" in
|
||||
initramfs)
|
||||
busybox_initramfs
|
||||
;;
|
||||
rootfs)
|
||||
busybox_rootfs
|
||||
;;
|
||||
esac
|
||||
}
|
||||
#------------------------------------------------------------------
|
||||
@@ -0,0 +1,82 @@
|
||||
#!/bin/sh
|
||||
|
||||
#--- reset colors ---
|
||||
RESET="\033[0m"
|
||||
#--------------------
|
||||
|
||||
#--------- regularcolrs ---------
|
||||
GREEN="\033[0;32m" #GREEN
|
||||
BLUE="\033[0;34m" #BLUE
|
||||
YELLOW="\033[1;33m" #YELLOW
|
||||
RED="\033[0;31m" #RED
|
||||
BLACK="\033[0;30m" #BLACK
|
||||
PURPLE="\033[0;35m" #PURPLE
|
||||
CYAN="\033[0;36m" #CYAN
|
||||
WHITE="\033[0;37m" #WHITE
|
||||
#--------------------------------
|
||||
|
||||
#-------- bold ------------------
|
||||
BBLACK="\033[1;30m" #BLACK
|
||||
BRED="\033[1;31m" #RED
|
||||
BGREEN="\033[1;32m" #GREEN
|
||||
BYELLOW="\033[1;33m" #YELLOW
|
||||
BBLUE="\033[1;34m" #BLUE
|
||||
BPURPLE="\033[1;35m" #PURPLE
|
||||
BCYAN="\033[1;36m" #CYAN
|
||||
BWHITE="\033[1;37m" #WHITE
|
||||
#--------------------------------
|
||||
|
||||
#-------- Underline -------------
|
||||
UBLACK="\033[4;30m" #BLACK
|
||||
URED="\033[4;31m" #RED
|
||||
UGREEN="\033[4;32m" #GREEN
|
||||
UYELLOW="\033[4;33m" #YELLOW
|
||||
UBLUE="\033[4;34m" #BLUE
|
||||
UPURPLE="\033[4;35m" #PURPLE
|
||||
UCYAN="\033[4;36m" #CYAN
|
||||
UWHITE="\033[4;37m" #WHITE
|
||||
#--------------------------------
|
||||
|
||||
#--------- Background -----------
|
||||
ON_BLACK="\033[40m" #BLACK
|
||||
ON_RED="\033[41m" #RED
|
||||
ON_GREEN="\033[42m" #GREEN
|
||||
ON_YELLOW="\033[43m" #YELLOW
|
||||
ON_BLUE="\033[44m" #BLUE
|
||||
ON_PURPLE="\033[45m" #PURPLE
|
||||
ON_CYAN="\033[46m" #CYAN
|
||||
ON_WHITE="\033[47m" #WHITE
|
||||
#--------------------------------
|
||||
|
||||
#------ HighIntensity -----------
|
||||
IBLACK="\033[0;90m" #BLACK
|
||||
IRED="\033[0;91m" #RED
|
||||
IGREEN="\033[0;92m" #GREEN
|
||||
IYELLOW="\033[0;93m" #YELLOW
|
||||
IBLUE="\033[0;94m" #BLUE
|
||||
IPURPLE="\033[0;95m" #PURPLE
|
||||
ICYAN="\033[0;96m" #CYAN
|
||||
IWHITE="\033[0;97m" #WHITE
|
||||
#--------------------------------
|
||||
|
||||
#------ BoldHighIntensity -------
|
||||
BIBLACK="\033[1;90m" #BLACK
|
||||
BIRED="\033[1;91m" #RED
|
||||
BIGREEN="\033[1;92m" #GREEN
|
||||
BIYELLOW="\033[1;93m" #YELLOW
|
||||
BIBLUE="\033[1;94m" #BLUE
|
||||
BIPURPLE="\033[1;95m" #PURPLE
|
||||
BICYAN="\033[1;96m" #CYAN
|
||||
BIWHITE="\033[1;97m" #WHITE
|
||||
#--------------------------------
|
||||
|
||||
#--- HighIntensitybackgrounds ---
|
||||
ON_IBLACK="\033[0;100m" #BLACK
|
||||
ON_IRED="\033[0;101m" #RED
|
||||
ON_IGREEN="\033[0;102m" #GREEN
|
||||
ON_IYELLOW="\033[0;103m" #YELLOW
|
||||
ON_IBLUE="\033[0;104m" #BLUE
|
||||
ON_IPURPLE="\033[0;105m" #PURPLE
|
||||
ON_ICYAN="\033[0;106m" #CYAN
|
||||
ON_IWHITE="\033[0;107m" #WHITE
|
||||
#--------------------------------
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
#--- Import colors ---
|
||||
. ./scripts/colors.sh
|
||||
#---------------------
|
||||
|
||||
#------- Check errors func -----------------
|
||||
check() {
|
||||
if [ $1 -ne 0 ]; then
|
||||
printf "$URED** ERROR: $2\n$RESET"
|
||||
exit 1
|
||||
fi
|
||||
printf "$UGREEN** SUCCESS: $2\n$RESET"
|
||||
}
|
||||
#-------------------------------------------
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
#---- System update ----
|
||||
apt update -qq &&
|
||||
apt upgrade -y -qq &&
|
||||
#-----------------------
|
||||
|
||||
#-------------- Nodejs ---------------------------------------------
|
||||
apt install -y curl
|
||||
# curl -sL https://deb.nodesource.com/setup_6.x | bash - &&
|
||||
apt install -y --force-yes -qq build-essential make cmake u-boot-tools bc file wget &&
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
#----------- Toolchains --------------------------------------------
|
||||
mkdir -p /opt/toolchains /var/www/html &&
|
||||
cd /opt/toolchains &&
|
||||
tar -xf ${OLDPWD}/toolchains/x86_64-buildroot-linux-uclibc-gcc.tar.gz &&
|
||||
cd $OLDPWD
|
||||
#-------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user