rootfsinstall.sh: kill processes run from chroot before unmounting; -g option to grow filesystem and update PARTUUID (for Raspbian)
This commit is contained in:
parent
73a57d592f
commit
2722423acb
@ -25,6 +25,7 @@ function usage() {
|
|||||||
echo " Use @ROOT@ as reference to rootfs path and @BOOT@ as reference to bootfs path"
|
echo " Use @ROOT@ as reference to rootfs path and @BOOT@ as reference to bootfs path"
|
||||||
echo "-c command : command to run through chroot in rootfs (may be specified multiple times)"
|
echo "-c command : command to run through chroot in rootfs (may be specified multiple times)"
|
||||||
echo "-fs fstype : filesystem type for system partition (default: ext4)"
|
echo "-fs fstype : filesystem type for system partition (default: ext4)"
|
||||||
|
echo "-g : grow system partition to fit storage size (to be used with -I)"
|
||||||
echo "-h hostname : set given hostname"
|
echo "-h hostname : set given hostname"
|
||||||
echo "-k kernel : extract and use specified kernel file from ROOTFS/boot/ for boot"
|
echo "-k kernel : extract and use specified kernel file from ROOTFS/boot/ for boot"
|
||||||
echo "-k2 kernel : extract and use specified second kernel file from ROOTFS/boot/ for boot"
|
echo "-k2 kernel : extract and use specified second kernel file from ROOTFS/boot/ for boot"
|
||||||
@ -100,6 +101,7 @@ while [ "$1" ]; do
|
|||||||
USEKERNEL2=$2
|
USEKERNEL2=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-g) GROWIMAGE=1 ;;
|
||||||
-h) [ "$2" ] || {
|
-h) [ "$2" ] || {
|
||||||
echo "Error: -h option requires a hostname as argument; aborting."
|
echo "Error: -h option requires a hostname as argument; aborting."
|
||||||
exit 1
|
exit 1
|
||||||
@ -302,11 +304,21 @@ if [ ! "$IMAGEMODE" ]; then
|
|||||||
|
|
||||||
else
|
else
|
||||||
# Image mode
|
# Image mode
|
||||||
gunzip -c ${ROOTFSARCHIVE} | dd of=${DRIVE} bs=32M
|
if [ "${ROOTFSARCHIVE: -4}" == ".zip" ]; then
|
||||||
|
7z e -so ${ROOTFSARCHIVE} | dd of=${DRIVE} bs=4M conv=fsync status=progress
|
||||||
|
elif [ "${ROOTFSARCHIVE: -3}" == ".gz" ]; then
|
||||||
|
gunzip -c ${ROOTFSARCHIVE} | dd of=${DRIVE} bs=4M conv=fsync status=progress
|
||||||
|
else
|
||||||
|
dd if=${ROOTFSARCHIVE} of=${DRIVE} bs=4M conv=fsync status=progress
|
||||||
|
fi
|
||||||
|
if [ "${GROWIMAGE}" ]; then
|
||||||
# Grow system partition to 100%
|
# Grow system partition to 100%
|
||||||
|
SAVE_BOOT_PARTUUID=`blkid -s PARTUUID -o value ${PARTITION1}`
|
||||||
|
SAVE_ROOT_PARTUUID=`blkid -s PARTUUID -o value ${PARTITION2}`
|
||||||
parted ${DRIVE} resizepart 2 100%
|
parted ${DRIVE} resizepart 2 100%
|
||||||
e2fsck -f ${PARTITION2}
|
e2fsck -f ${PARTITION2}
|
||||||
resize2fs ${PARTITION2}
|
resize2fs ${PARTITION2}
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "$BOOTFSTYPE" ] && BOOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX`
|
[ "$BOOTFSTYPE" ] && BOOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX`
|
||||||
@ -605,6 +617,31 @@ for c in `seq 1 ${#CHROOTCOMMANDS[*]}`; do
|
|||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "${IMAGEMODE}" -a "${SAVE_ROOT_PARTUUID}" -a "${GROWIMAGE}" ]; then
|
||||||
|
# Update PARTUUID after growing root filesystem (Raspbian)
|
||||||
|
NEW_BOOT_PARTUUID=`blkid -s PARTUUID -o value ${PARTITION1}`
|
||||||
|
NEW_ROOT_PARTUUID=`blkid -s PARTUUID -o value ${PARTITION2}`
|
||||||
|
sed -i "s|PARTUUID=${SAVE_ROOT_PARTUUID}|PARTUUID=${NEW_ROOT_PARTUUID}|" ${ROOTMP}/etc/fstab
|
||||||
|
sed -i "s|PARTUUID=${SAVE_BOOT_PARTUUID}|PARTUUID=${NEW_BOOT_PARTUUID}|" ${ROOTMP}/etc/fstab
|
||||||
|
if [ "$TARGETDEVICE" = "rpi" ]; then
|
||||||
|
sed -i "s|PARTUUID=${SAVE_ROOT_PARTUUID}|PARTUUID=${NEW_ROOT_PARTUUID}|" ${BOOTMP}/cmdline.txt
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Kill any daemon process run in chroot
|
||||||
|
FOUND=0
|
||||||
|
for ROOT in /proc/*/root; do
|
||||||
|
LINK=$(readlink $ROOT)
|
||||||
|
if [ "x$LINK" != "x" ]; then
|
||||||
|
if [ "x${LINK:0:${#ROOTMP}}" = "x$ROOTMP" ]; then
|
||||||
|
# this process is in the chroot...
|
||||||
|
PID=$(basename $(dirname "$ROOT"))
|
||||||
|
kill -9 "$PID"
|
||||||
|
FOUND=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
sync
|
sync
|
||||||
|
|
||||||
echo "Done."
|
echo "Done."
|
||||||
|
Loading…
Reference in New Issue
Block a user