live-build/scripts/build/binary_rootfs

415 lines
9.0 KiB
Plaintext
Raw Permalink Normal View History

2007-09-23 08:04:46 +00:00
#!/bin/sh
## live-build(7) - System Build Scripts
## Copyright (C) 2016-2020 The Debian Live team
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.
2007-09-23 08:04:46 +00:00
set -e
2007-09-23 08:05:11 +00:00
# Including common functions
[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
2007-09-23 08:04:46 +00:00
2007-09-23 08:05:11 +00:00
# Setting static variables
DESCRIPTION="Build rootfs image"
2007-09-23 08:04:48 +00:00
USAGE="${PROGRAM} [--force]"
# Processing arguments and configuration files
Init_config_data "${@}"
2007-09-23 08:04:46 +00:00
2007-09-23 08:05:11 +00:00
Echo_message "Begin building root filesystem image..."
2007-09-23 08:04:49 +00:00
2007-09-23 08:04:46 +00:00
# Requiring stage file
Require_stagefiles config bootstrap binary_chroot
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:50 +00:00
# Checking stage file
Check_stagefile
2007-09-23 08:04:50 +00:00
2020-03-13 15:19:59 -01:00
# Acquire lock file
Acquire_lockfile
2007-09-23 08:04:46 +00:00
case "${LB_ARCHITECTURE}" in
amd64|i386)
2007-09-23 08:05:12 +00:00
LINUX="vmlinuz"
;;
powerpc|ppc64el|riscv64)
2007-09-23 08:05:12 +00:00
LINUX="vmlinux"
;;
esac
case "${LB_INITRAMFS}" in
live-boot|dracut-live)
2007-09-23 08:04:52 +00:00
INITFS="live"
;;
*)
INITFS="boot"
;;
2007-09-23 08:04:52 +00:00
esac
2007-09-23 08:04:46 +00:00
# Creating directory
2007-09-23 08:05:11 +00:00
mkdir -p binary/${INITFS}
2007-09-23 08:04:46 +00:00
if In_list "rootfs" ${LB_CACHE_STAGES} && [ -d cache/binary_rootfs ]
then
# Removing old chroot
rm -rf binary/"${INITFS}"/filesystem.*
2007-09-23 08:05:12 +00:00
# Restoring old cache
mkdir -p binary/"${INITFS}"
cp -a cache/binary_rootfs/filesystem.* binary/"${INITFS}"
2007-09-23 08:05:12 +00:00
# Creating stage file
Create_stagefile
exit 0
fi
2007-09-23 08:05:12 +00:00
case "${LB_CHROOT_FILESYSTEM}" in
ext2|ext3|ext4)
2007-09-23 08:04:51 +00:00
# Checking depends
Check_package chroot /sbin/mkfs.${LB_CHROOT_FILESYSTEM} e2fsprogs
2007-09-23 08:04:48 +00:00
2007-09-23 08:05:15 +00:00
# Restoring cache
Restore_package_cache binary
2007-09-23 08:05:15 +00:00
2007-09-23 08:04:51 +00:00
# Installing depends
Install_packages
2007-09-23 08:04:48 +00:00
# Remove old image
if [ -f binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM} ]
2007-09-23 08:04:46 +00:00
then
rm -f binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM}
2007-09-23 08:04:46 +00:00
fi
case "${LB_BUILD_WITH_CHROOT}" in
true)
DU_DIM="$(du -ms chroot/chroot | cut -f1)"
INODES="$(find chroot/chroot | wc -l)"
;;
false)
DU_DIM="$(du -ms chroot | cut -f1)"
INODES="$(find chroot | wc -l)"
;;
esac
REAL_DIM="$(Calculate_partition_size ${DU_DIM} ${LB_CHROOT_FILESYSTEM})"
REAL_INODES="$(Calculate_partition_size ${INODES} ${LB_CHROOT_FILESYSTEM})"
2007-09-23 08:04:46 +00:00
case "${LB_BUILD_WITH_CHROOT}" in
true)
dd if=/dev/zero of=chroot/filesystem.${LB_CHROOT_FILESYSTEM} bs=1024k count=0 seek=${REAL_DIM}
FAKE_MTAB=false
if ! Chroot chroot "test -e /etc/mtab"
then
Chroot chroot "ln -s /proc/mounts/mtab /etc/mtab"
FAKE_MTAB=true
fi
BLOCK_SIZE=1024
if [ "${LB_DM_VERITY}" = "true" ]
then
# dm-verity needs a block size of at least 4k
BLOCK_SIZE=4096
fi
Chroot chroot "mkfs.${LB_CHROOT_FILESYSTEM} -F -b ${BLOCK_SIZE} -N ${REAL_INODES} -m 0 filesystem.${LB_CHROOT_FILESYSTEM}"
mkdir -p filesystem.tmp
mount -o loop chroot/filesystem.${LB_CHROOT_FILESYSTEM} filesystem.tmp
cp -a chroot/chroot/* filesystem.tmp
if $FAKE_MTAB; then
Chroot chroot "rm -f /etc/mtab"
fi
umount filesystem.tmp
rmdir filesystem.tmp
2007-09-23 08:05:15 +00:00
# Move image
mv chroot/filesystem.${LB_CHROOT_FILESYSTEM} binary/${INITFS}
du -B 1 -s chroot/chroot | cut -f1 > binary/${INITFS}/filesystem.size
# Removing depends
Remove_packages
if [ -e chroot/chroot.cache ]
then
Remove_lockfile
mv chroot/chroot chroot.tmp
lb chroot_prep remove all mode-archives-binary "${@}"
rm -rf chroot
mv chroot.tmp chroot
lb chroot_prep install all mode-archives-binary "${@}"
touch .lock
else
rm -rf chroot/chroot
fi
2007-09-23 08:05:15 +00:00
;;
2007-09-23 08:04:48 +00:00
false)
dd if=/dev/zero of=binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM} bs=1024k count=0 seek=${REAL_DIM}
mkfs.${LB_CHROOT_FILESYSTEM} -F -b 1024 -N ${REAL_INODES} -m 0 binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM}
mkdir -p filesystem.tmp
mount -o loop binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM} filesystem.tmp
cp -a chroot/* filesystem.tmp
umount filesystem.tmp
rmdir filesystem.tmp
2007-09-23 08:05:15 +00:00
;;
esac
# Saving cache
Save_package_cache binary
2007-09-23 08:04:46 +00:00
;;
jffs2)
# Checking depends
Check_package chroot /usr/sbin/mkfs.jffs2 mtd-tools
# Restoring cache
Restore_package_cache binary
# Installing depends
Install_packages
# Remove old jffs2 image
if [ -f binary/${INITFS}/filesystem.jffs2 ]
then
rm -f binary/${INITFS}/filesystem.jffs2
fi
if [ -n "${LB_JFFS2_ERASEBLOCK}" ]
then
JFFS2_OPTIONS="--eraseblock=${LB_JFFS2_ERASEBLOCK}"
fi
case "${LB_BUILD_WITH_CHROOT}" in
true)
Chroot chroot "mkfs.jffs2 ${JFFS2_OPTIONS} --root=chroot --output filesystem.jffs2"
# Move image
mv chroot/filesystem.jffs2 binary/${INITFS}
# Removing depends
Remove_packages
if [ -e chroot/chroot.cache ]
then
Remove_lockfile
mv chroot/chroot chroot.tmp
lb chroot_prep remove all mode-archives-binary "${@}"
rm -rf chroot
mv chroot.tmp chroot
lb chroot_prep install all mode-archives-binary "${@}"
touch .lock
else
rm -rf chroot/chroot
fi
;;
false)
mkfs.jffs2 ${JFFS2_OPTIONS} --root=chroot --output binary/${INITFS}/filesystem.jffs2
;;
esac
# Saving cache
Save_package_cache binary
;;
plain)
2007-09-23 08:04:52 +00:00
if [ -d binary/${INITFS}/filesystem.dir ]
2007-09-23 08:04:46 +00:00
then
2007-09-23 08:04:52 +00:00
rm -rf binary/${INITFS}/filesystem.dir
2007-09-23 08:04:46 +00:00
fi
case "${LB_BUILD_WITH_CHROOT}" in
true)
if [ -e chroot/chroot.cache ]
then
# Different from the other LB_CHROOT_FILESYSTEM values:
# continue working in the bootstrap chroot, not the generated chroot.
# This saves the time to create a full copy of the generated chroot.
cp -a chroot/chroot/boot chroot
mv chroot/chroot binary/${INITFS}/filesystem.dir
else
rm -fr chroot/chroot
# Removing depends
Remove_packages
fi
2007-09-23 08:05:15 +00:00
;;
false)
2007-09-23 08:05:15 +00:00
cp -a chroot binary/${INITFS}/filesystem.dir
;;
esac
2007-09-23 08:04:46 +00:00
;;
squashfs)
2007-09-23 08:04:51 +00:00
# Checking depends
Check_package chroot /usr/share/doc/squashfs-tools squashfs-tools
2007-09-23 08:05:15 +00:00
# Restoring cache
Restore_package_cache binary
2007-09-23 08:04:51 +00:00
# Installing depends
Install_packages
2007-09-23 08:04:51 +00:00
Echo_message "Preparing squashfs image..."
Echo_message "This may take a while."
2007-09-23 08:04:51 +00:00
# Remove old squashfs image
2007-09-23 08:04:52 +00:00
if [ -f binary/${INITFS}/filesystem.squashfs ]
2007-09-23 08:04:48 +00:00
then
2007-09-23 08:04:52 +00:00
rm -f binary/${INITFS}/filesystem.squashfs
2007-09-23 08:04:48 +00:00
fi
# Remove stale squashfs image
rm -f chroot/filesystem.squashfs
# Do not display progress bar if:
# - Run with --quiet, or
# - stdin is not a terminal (e.g. in CI, cron, etc)
if [ "${_QUIET}" = "true" ] || [ ! -t 0 ]
then
MKSQUASHFS_OPTIONS="-no-progress ${MKSQUASHFS_OPTIONS}"
fi
2007-09-23 08:04:48 +00:00
if [ "${_VERBOSE}" = "true" ]
2007-09-23 08:04:46 +00:00
then
MKSQUASHFS_OPTIONS="-info ${MKSQUASHFS_OPTIONS}"
2007-09-23 08:04:46 +00:00
fi
if [ -f config/rootfs/squashfs.sort ]
2007-09-23 08:05:11 +00:00
then
MKSQUASHFS_OPTIONS="-sort squashfs.sort ${MKSQUASHFS_OPTIONS}"
case "${LB_BUILD_WITH_CHROOT}" in
true)
2021-01-01 15:51:02 -01:00
cp -a config/rootfs/squashfs.sort chroot
;;
false)
2021-01-01 15:51:02 -01:00
cp -a config/rootfs/squashfs.sort .
;;
esac
2007-09-23 08:05:11 +00:00
fi
# Set squashfs compression type or default to xz
if [ -n "${LB_CHROOT_SQUASHFS_COMPRESSION_TYPE}" ]
then
MKSQUASHFS_OPTIONS="-comp ${LB_CHROOT_SQUASHFS_COMPRESSION_TYPE} ${MKSQUASHFS_OPTIONS}"
else
MKSQUASHFS_OPTIONS="-comp xz ${MKSQUASHFS_OPTIONS}"
fi
if [ -n "${LB_CHROOT_SQUASHFS_COMPRESSION_LEVEL}" ]
then
MKSQUASHFS_OPTIONS="-Xcompression-level ${LB_CHROOT_SQUASHFS_COMPRESSION_LEVEL} ${MKSQUASHFS_OPTIONS}"
fi
case "${LB_BUILD_WITH_CHROOT}" in
true)
if [ -e config/rootfs/excludes ]
then
2021-01-01 15:51:02 -01:00
cp -a config/rootfs/excludes chroot/excludes
MKSQUASHFS_OPTIONS="-wildcards -ef /excludes ${MKSQUASHFS_OPTIONS}"
fi
2007-09-23 08:05:15 +00:00
# Create image
Chroot chroot "nice -n 17 mksquashfs chroot filesystem.squashfs ${MKSQUASHFS_OPTIONS}"
2007-09-23 08:05:15 +00:00
rm -f chroot/excludes
2007-09-23 08:05:15 +00:00
# Move image
mv chroot/filesystem.squashfs binary/${INITFS}
rm -f chroot/squashfs.sort
# Removing depends
Remove_packages
if [ -e chroot/chroot.cache ]
then
Remove_lockfile
mv chroot/chroot chroot.tmp
lb chroot_prep remove all mode-archives-binary "${@}"
rm -rf chroot
mv chroot.tmp chroot
lb chroot_prep install all mode-archives-binary "${@}"
touch .lock
else
rm -rf chroot/chroot
fi
2007-09-23 08:05:15 +00:00
;;
2007-09-23 08:05:09 +00:00
false)
if [ -e config/rootfs/excludes ]
then
MKSQUASHFS_OPTIONS="-wildcards -ef config/rootfs/excludes ${MKSQUASHFS_OPTIONS}"
fi
nice -n 19 mksquashfs chroot binary/${INITFS}/filesystem.squashfs ${MKSQUASHFS_OPTIONS}
2007-09-23 08:05:15 +00:00
;;
esac
2007-09-23 08:04:48 +00:00
chmod 0644 binary/${INITFS}/filesystem.squashfs
2007-09-23 08:05:15 +00:00
# Saving cache
Save_package_cache binary
2007-09-23 08:04:46 +00:00
;;
none)
if [ -d binary ]
then
rm -rf binary
fi
case "${LB_BUILD_WITH_CHROOT}" in
true)
mv chroot/chroot binary
;;
false)
Echo_message "This may take a while."
cp -a chroot binary
;;
esac
;;
2007-09-23 08:04:46 +00:00
esac
if In_list "rootfs" ${LB_CACHE_STAGES}
then
rm -rf cache/binary_rootfs
2007-09-23 08:05:12 +00:00
mkdir -p cache/binary_rootfs
2007-09-23 08:05:12 +00:00
if [ "${LB_CHROOT_FILESYSTEM}" != "none" ]
then
cp -a binary/"${INITFS}"/filesystem.* cache/binary_rootfs
2007-09-23 08:05:12 +00:00
fi
fi
2007-09-23 08:05:12 +00:00
2007-09-23 08:04:46 +00:00
# Creating stage file
Create_stagefile