Rework debootstrap-ng for better Docker and UUID support
This commit is contained in:
parent
e3c0988d3e
commit
67a2ed8d80
@ -19,6 +19,7 @@ USEALLCORES=yes # Use all CPU cores for compiling
|
||||
EXIT_PATCHING_ERROR="" # exit patching if failed
|
||||
HOST="$BOARD" # set hostname to the board
|
||||
CACHEDIR=$DEST/cache
|
||||
ROOTFSCACHE_VERSION=2
|
||||
|
||||
[[ -z $ROOTFS_TYPE ]] && ROOTFS_TYPE=ext4 # default rootfs type is ext4
|
||||
[[ "ext4 f2fs btrfs nfs fel" != *$ROOTFS_TYPE* ]] && exit_with_error "Unknown rootfs type" "$ROOTFS_TYPE"
|
||||
@ -28,7 +29,7 @@ CACHEDIR=$DEST/cache
|
||||
# echo $(( $(blockdev --getsize64 /dev/sdX) / 1024 / 1024 ))
|
||||
[[ "btrfs f2fs" == *$ROOTFS_TYPE* && -z $FIXED_IMAGE_SIZE ]] && exit_with_error "Please define FIXED_IMAGE_SIZE"
|
||||
|
||||
# small SD card with kernel, boot scritpt and .dtb/.bin files
|
||||
# small SD card with kernel, boot script and .dtb/.bin files
|
||||
[[ $ROOTFS_TYPE == nfs ]] && FIXED_IMAGE_SIZE=64
|
||||
|
||||
# used by multiple sources - reduce code duplication
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
# create_rootfs_cache
|
||||
# prepare_partitions
|
||||
# create_image
|
||||
# install_dummy_initctl
|
||||
# mount_chroot
|
||||
# umount_chroot
|
||||
# unmount_on_exit
|
||||
@ -73,17 +72,18 @@ debootstrap_ng()
|
||||
fi
|
||||
|
||||
# cleanup for install_kernel and install_board_specific
|
||||
umount $CACHEDIR/sdcard/tmp/debs && rm -rf $CACHEDIR/sdcard/tmp/debs
|
||||
umount $CACHEDIR/sdcard/tmp/debs
|
||||
mountpoint -q $CACHEDIR/sdcard/tmp/debs || rm -rf $CACHEDIR/sdcard/tmp/debs
|
||||
|
||||
# stage: user customization script
|
||||
# NOTE: installing too many packages may fill tmpfs mount
|
||||
customize_image
|
||||
|
||||
# stage: cleanup
|
||||
rm -f $CACHEDIR/sdcard/usr/sbin/policy-rc.d
|
||||
rm -f $CACHEDIR/sdcard/usr/bin/$QEMU_BINARY
|
||||
[[ -x $CACHEDIR/sdcard/sbin/initctl.REAL ]] && mv -f $CACHEDIR/sdcard/sbin/initctl.REAL $CACHEDIR/sdcard/sbin/initctl
|
||||
[[ -x $CACHEDIR/sdcard/sbin/start-stop-daemon.REAL ]] && mv -f $CACHEDIR/sdcard/sbin/start-stop-daemon.REAL $CACHEDIR/sdcard/sbin/start-stop-daemon
|
||||
rm -f $CACHEDIR/sdcard/sbin/initctl $CACHEDIR/sdcard/sbin/start-stop-daemon
|
||||
chroot $CACHEDIR/sdcard /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/initctl"
|
||||
chroot $CACHEDIR/sdcard /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/start-stop-daemon"
|
||||
rm -f $CACHEDIR/sdcard/usr/sbin/policy-rc.d $CACHEDIR/sdcard/usr/bin/$QEMU_BINARY
|
||||
|
||||
umount_chroot "$CACHEDIR/sdcard"
|
||||
|
||||
@ -115,7 +115,7 @@ debootstrap_ng()
|
||||
#
|
||||
create_rootfs_cache()
|
||||
{
|
||||
local packages_hash=$(get_package_list_hash $PACKAGE_LIST)
|
||||
local packages_hash=$(get_package_list_hash)
|
||||
local cache_fname=$CACHEDIR/rootfs/${RELEASE}-ng-$ARCH.$packages_hash.tgz
|
||||
local display_name=${RELEASE}-ng-$ARCH.${packages_hash:0:3}...${packages_hash:29}.tgz
|
||||
if [[ -f $cache_fname ]]; then
|
||||
@ -163,8 +163,13 @@ create_rootfs_cache()
|
||||
|
||||
# policy-rc.d script prevents starting or reloading services during image creation
|
||||
printf '#!/bin/sh\nexit 101' > $CACHEDIR/sdcard/usr/sbin/policy-rc.d
|
||||
chroot $CACHEDIR/sdcard /bin/bash -c "dpkg-divert --quiet --local --rename --add /sbin/initctl"
|
||||
chroot $CACHEDIR/sdcard /bin/bash -c "dpkg-divert --quiet --local --rename --add /sbin/start-stop-daemon"
|
||||
printf '#!/bin/sh\necho "Warning: Fake start-stop-daemon called, doing nothing"' > $CACHEDIR/sdcard/sbin/start-stop-daemon
|
||||
printf '#!/bin/sh\necho "Warning: Fake initctl called, doing nothing"' > $CACHEDIR/sdcard/sbin/initctl
|
||||
chmod 755 $CACHEDIR/sdcard/usr/sbin/policy-rc.d
|
||||
install_dummy_initctl
|
||||
chmod 755 $CACHEDIR/sdcard/sbin/initctl
|
||||
chmod 755 $CACHEDIR/sdcard/sbin/start-stop-daemon
|
||||
|
||||
# stage: configure language and locales
|
||||
display_alert "Configuring locales" "$DEST_LANG" "info"
|
||||
@ -330,28 +335,45 @@ prepare_partitions()
|
||||
dd if=/dev/zero bs=1M status=none count=$sdsize | pv -p -b -r -s $(( $sdsize * 1024 * 1024 )) | dd status=none of=$CACHEDIR/tmprootfs.raw
|
||||
|
||||
# stage: determine partition configuration
|
||||
if [[ $ROOTFS_TYPE != ext4 && $BOOTSIZE == 0 ]]; then
|
||||
local bootfs=ext4
|
||||
BOOTSIZE=32 # MiB
|
||||
elif [[ $BOOTSIZE != 0 ]]; then
|
||||
if [[ $BOOTSIZE != 0 ]]; then
|
||||
# fat32 /boot + ext4 root, deprecated
|
||||
local bootfs=fat
|
||||
local bootpart=1
|
||||
local rootpart=2
|
||||
elif [[ $ROOTFS_TYPE != ext4 && $ROOTFS_TYPE != nfs ]]; then
|
||||
# ext4 /boot + non-ext4 root
|
||||
BOOTSIZE=32 # MiB
|
||||
local bootfs=ext4
|
||||
local bootpart=1
|
||||
local rootpart=2
|
||||
elif [[ $ROOTFS_TYPE == nfs ]]; then
|
||||
# ext4 /boot, no root
|
||||
BOOTSIZE=32 # For cleanup processing only
|
||||
local bootfs=ext4
|
||||
local bootpart=1
|
||||
else
|
||||
# ext4 root
|
||||
local rootpart=1
|
||||
fi
|
||||
|
||||
# stage: calculate boot partition size
|
||||
BOOTSTART=$(($OFFSET * 2048))
|
||||
ROOTSTART=$(($BOOTSTART + ($BOOTSIZE * 2048)))
|
||||
BOOTEND=$(($ROOTSTART - 1))
|
||||
local bootstart=$(($OFFSET * 2048))
|
||||
local rootstart=$(($bootstart + ($BOOTSIZE * 2048)))
|
||||
local bootend=$(($rootstart - 1))
|
||||
|
||||
# stage: create partition table
|
||||
display_alert "Creating partitions" "${bootfs:+/boot: $bootfs }root: $ROOTFS_TYPE" "info"
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mklabel msdos
|
||||
if [[ $ROOTFS_TYPE == nfs ]]; then
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$bootfs]} ${BOOTSTART}s -1s
|
||||
# single /boot partition
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$bootfs]} ${bootstart}s -1s
|
||||
elif [[ $BOOTSIZE == 0 ]]; then
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${ROOTSTART}s -1s
|
||||
# single root partition
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${rootstart}s -1s
|
||||
else
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$bootfs]} ${BOOTSTART}s ${BOOTEND}s
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${ROOTSTART}s -1s
|
||||
# /boot partition + root partition
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$bootfs]} ${bootstart}s ${bootend}s
|
||||
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${rootstart}s -1s
|
||||
fi
|
||||
|
||||
# stage: mount image
|
||||
@ -359,52 +381,48 @@ prepare_partitions()
|
||||
[[ -z $LOOP ]] && exit_with_error "Unable to find free loop device"
|
||||
|
||||
# NOTE: losetup -P option is not available in Trusty
|
||||
[[ $CONTAINER_COMPAT == yes ]] && mknod -m0660 $LOOP b 7 ${LOOP//\/dev\/loop} > /dev/null
|
||||
|
||||
losetup $LOOP $CACHEDIR/tmprootfs.raw
|
||||
partprobe $LOOP
|
||||
|
||||
# stage: create fs
|
||||
if [[ $BOOTSIZE == 0 ]]; then
|
||||
eval mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} ${LOOP}p1 ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||
[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback ${LOOP}p1 > /dev/null
|
||||
else
|
||||
if [[ $ROOTFS_TYPE != nfs ]]; then
|
||||
eval mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} ${LOOP}p2 ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||
[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback ${LOOP}p2 > /dev/null
|
||||
fi
|
||||
eval mkfs.${mkfs[$bootfs]} ${mkopts[$bootfs]} ${LOOP}p1 ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||
fi
|
||||
|
||||
# stage: mount partitions and create proper fstab
|
||||
# stage: create fs, mount partitions, create fstab
|
||||
rm -f $CACHEDIR/sdcard/etc/fstab
|
||||
|
||||
if [[ $HAS_UUID_SUPPORT == yes ]]; then
|
||||
local part1="UUID=$(blkid -s UUID -o value ${LOOP}p1)"
|
||||
local part2="UUID=$(blkid -s UUID -o value ${LOOP}p2)"
|
||||
else
|
||||
local part1="/dev/mmcblk0p1"
|
||||
local part2="/dev/mmcblk0p2"
|
||||
if [[ -n $rootpart ]]; then
|
||||
display_alert "Creating rootfs" "$ROOTFS_TYPE"
|
||||
[[ $CONTAINER_COMPAT == yes ]] && mknod -m0660 $LOOPp${rootpart} b 259 ${rootpart} > /dev/null
|
||||
mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} ${LOOP}p${rootpart}
|
||||
[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback ${LOOP}p${rootpart} > /dev/null
|
||||
mount ${LOOP}p${rootpart} $CACHEDIR/mount/
|
||||
local rootfs="UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart})"
|
||||
echo "$rootfs / ${mkfs[$ROOTFS_TYPE]} defaults,noatime,nodiratime${mountopts[$ROOTFS_TYPE]} 0 1" >> $CACHEDIR/sdcard/etc/fstab
|
||||
fi
|
||||
|
||||
if [[ $BOOTSIZE == 0 ]]; then
|
||||
mount ${LOOP}p1 $CACHEDIR/mount/
|
||||
echo "$part1 / ${mkfs[$ROOTFS_TYPE]} defaults,noatime,nodiratime${mountopts[$ROOTFS_TYPE]} 0 1" >> $CACHEDIR/sdcard/etc/fstab
|
||||
else
|
||||
if [[ $ROOTFS_TYPE != nfs ]]; then
|
||||
mount ${LOOP}p2 $CACHEDIR/mount/
|
||||
echo "$part2 / ${mkfs[$ROOTFS_TYPE]} defaults,noatime,nodiratime${mountopts[$ROOTFS_TYPE]} 0 1" >> $CACHEDIR/sdcard/etc/fstab
|
||||
else
|
||||
echo "/dev/nfs / nfs defaults 0 0" >> $CACHEDIR/sdcard/etc/fstab
|
||||
fi
|
||||
# create /boot on rootfs after it is mounted
|
||||
if [[ -n $bootpart ]]; then
|
||||
display_alert "Creating /boot" "$bootfs"
|
||||
[[ $CONTAINER_COMPAT == yes ]] && mknod -m0660 $LOOPp${bootpart} b 259 ${bootpart} > /dev/null
|
||||
mkfs.${mkfs[$bootfs]} ${mkopts[$bootfs]} ${LOOP}p${bootpart}
|
||||
mkdir -p $CACHEDIR/mount/boot/
|
||||
mount ${LOOP}p1 $CACHEDIR/mount/boot/
|
||||
echo "$part1 /boot ${mkfs[$bootfs]} defaults${mountopts[$bootfs]} 0 2" >> $CACHEDIR/sdcard/etc/fstab
|
||||
mount ${LOOP}p${bootpart} $CACHEDIR/mount/boot/
|
||||
echo "UUID=$(blkid -s UUID -o value ${LOOP}p${bootpart}) /boot ${mkfs[$bootfs]} defaults${mountopts[$bootfs]} 0 2" >> $CACHEDIR/sdcard/etc/fstab
|
||||
fi
|
||||
if [[ $ROOTFS_TYPE == nfs ]]; then
|
||||
echo "/dev/nfs / nfs defaults 0 0" >> $CACHEDIR/sdcard/etc/fstab
|
||||
fi
|
||||
echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> $CACHEDIR/sdcard/etc/fstab
|
||||
|
||||
if [[ $ROOTFS_TYPE != nfs && $BOOTSIZE != 0 && -f $CACHEDIR/sdcard/boot/boot.cmd ]]; then
|
||||
sed -i 's/mmcblk0p1/mmcblk0p2/' $CACHEDIR/sdcard/boot/boot.cmd
|
||||
sed -i "s/rootfstype=ext4/rootfstype=$ROOTFS_TYPE/" $CACHEDIR/sdcard/boot/boot.cmd
|
||||
# stage: adjust boot script or boot environment
|
||||
if [[ -f $CACHEDIR/sdcard/boot/armbianEnv.txt ]]; then
|
||||
if [[ $HAS_UUID_SUPPORT == yes ]]; then
|
||||
echo "rootdev=$rootfs" >> $CACHEDIR/sdcard/boot/armbianEnv.txt
|
||||
elif [[ $rootpart != 1 ]]; then
|
||||
echo "rootdev=/dev/mmcblk0p${rootpart}" >> $CACHEDIR/sdcard/boot/armbianEnv.txt
|
||||
fi
|
||||
echo "rootfstype=$ROOTFS_TYPE" >> $CACHEDIR/sdcard/boot/armbianEnv.txt
|
||||
elif [[ $rootpart != 1 ]]; then
|
||||
local bootscript_dst=${BOOTSCRIPT##*:}
|
||||
sed -i 's/mmcblk0p1/mmcblk0p2/' $CACHEDIR/sdcard/boot/$bootscript_dst
|
||||
sed -i -e "s/rootfstype=ext4/rootfstype=$ROOTFS_TYPE/" \
|
||||
-e "s/rootfstype \"ext4\"/rootfstype \"$ROOTFS_TYPE\"/" $CACHEDIR/sdcard/boot/$bootscript_dst
|
||||
fi
|
||||
|
||||
# recompile .cmd to .scr if boot.cmd exists
|
||||
@ -513,24 +531,6 @@ sign_and_compress()
|
||||
fi
|
||||
} #############################################################################
|
||||
|
||||
# install_dummy_initctl
|
||||
#
|
||||
# helper to reduce code duplication
|
||||
#
|
||||
install_dummy_initctl()
|
||||
{
|
||||
if [[ -x $CACHEDIR/sdcard/sbin/start-stop-daemon ]] && ! cmp -s $CACHEDIR/sdcard/sbin/start-stop-daemon <(printf '#!/bin/sh\necho "Warning: Fake start-stop-daemon called, doing nothing"'); then
|
||||
mv $CACHEDIR/sdcard/sbin/start-stop-daemon $CACHEDIR/sdcard/sbin/start-stop-daemon.REAL
|
||||
printf '#!/bin/sh\necho "Warning: Fake start-stop-daemon called, doing nothing"' > $CACHEDIR/sdcard/sbin/start-stop-daemon
|
||||
chmod 755 $CACHEDIR/sdcard/sbin/start-stop-daemon
|
||||
fi
|
||||
if [[ -x $CACHEDIR/sdcard/sbin/initctl ]] && ! cmp -s $CACHEDIR/sdcard/sbin/initctl <(printf '#!/bin/sh\necho "Warning: Fake initctl called, doing nothing"'); then
|
||||
mv $CACHEDIR/sdcard/sbin/initctl $CACHEDIR/sdcard/sbin/initctl.REAL
|
||||
printf '#!/bin/sh\necho "Warning: Fake initctl called, doing nothing"' $CACHEDIR/sdcard/sbin/initctl
|
||||
chmod 755 $CACHEDIR/sdcard/sbin/initctl
|
||||
fi
|
||||
} #############################################################################
|
||||
|
||||
# mount_chroot <target>
|
||||
#
|
||||
# helper to reduce code duplication
|
||||
@ -570,4 +570,4 @@ unmount_on_exit()
|
||||
losetup -d $LOOP >/dev/null 2>&1
|
||||
rm -rf $CACHEDIR/sdcard
|
||||
exit_with_error "debootstrap-ng was interrupted"
|
||||
} #############################################################################
|
||||
} #############################################################################
|
||||
|
||||
17
general.sh
17
general.sh
@ -94,14 +94,14 @@ exit_with_error()
|
||||
exit -1
|
||||
}
|
||||
|
||||
# get_package_list_hash <package_list>
|
||||
# get_package_list_hash
|
||||
#
|
||||
# outputs md5hash for space-separated <package_list>
|
||||
# for rootfs cache
|
||||
# returns md5 hash for current package list and rootfs cache version
|
||||
|
||||
get_package_list_hash()
|
||||
{
|
||||
echo $(printf '%s\n' $PACKAGE_LIST | sort -u | md5sum | cut -d' ' -f 1)
|
||||
( printf '%s\n' $PACKAGE_LIST | sort -u; printf '%s\n' $PACKAGE_LIST_EXCLUDE | sort -u; echo "$ROOTFSCACHE_VERSION" ) \
|
||||
| md5sum | cut -d' ' -f 1
|
||||
}
|
||||
|
||||
# create_sources_list <release> <basedir>
|
||||
@ -439,8 +439,8 @@ addtorepo()
|
||||
# * creates directory structure
|
||||
# * changes system settings
|
||||
#
|
||||
prepare_host() {
|
||||
|
||||
prepare_host()
|
||||
{
|
||||
display_alert "Preparing" "host" "info"
|
||||
|
||||
if [[ $(dpkg --print-architecture) == arm* ]]; then
|
||||
@ -494,10 +494,7 @@ prepare_host() {
|
||||
display_alert "apt-cacher is disabled, set NO_APT_CACHER=no to override" "" "wrn"
|
||||
NO_APT_CACHER=yes
|
||||
fi
|
||||
# create device nodes for loop devices
|
||||
for i in {0..6}; do
|
||||
mknod -m0660 /dev/loop$i b 7 $i > /dev/null 2>&1
|
||||
done
|
||||
CONTAINER_COMPAT=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user