RESIZE-HELPER: integrate improvements
- allow to not start service at startup - fix reboot command on SysVInit - refine resize-helper service launch - use systemd-growfs instead of resize2fs - improve reliability of service Change-Id: I756ae5c73538f96c298ed1586299f35ba657d174
This commit is contained in:
committed by
Bernard PUEL
parent
56d937a7c1
commit
293f05e23d
@ -15,11 +15,13 @@ SRC_URI = " file://resize-helper.service file://resize-helper file://resize-help
|
||||
|
||||
S = "${WORKDIR}/git"
|
||||
|
||||
START_RESIZE_HELPER_SERVICE ?= "1"
|
||||
|
||||
inherit systemd update-rc.d
|
||||
|
||||
SYSTEMD_PACKAGES += " resize-helper "
|
||||
SYSTEMD_SERVICE_${PN} = "resize-helper.service"
|
||||
SYSTEMD_AUTO_ENABLE_${PN} = "enable"
|
||||
SYSTEMD_AUTO_ENABLE_${PN} = "${@bb.utils.contains('START_RESIZE_HELPER_SERVICE','1','enable','disable',d)}"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}${systemd_unitdir}/system ${D}${base_sbindir}
|
||||
@ -31,6 +33,11 @@ do_install() {
|
||||
|
||||
sed -i -e "s:@sbindir@:${base_sbindir}:; s:@sysconfdir@:${sysconfdir}:" \
|
||||
${D}${sysconfdir}/init.d/resize-helper.sh
|
||||
if [ "${START_RESIZE_HELPER_SERVICE}" -eq 0 ]; then
|
||||
rm ${D}${sysconfdir}/init.d/resize-helper.sh
|
||||
echo "#!/bin/sh" > ${D}${sysconfdir}/init.d/resize-helper.sh
|
||||
chmod +x ${D}${sysconfdir}/init.d/resize-helper.sh
|
||||
fi
|
||||
}
|
||||
|
||||
INITSCRIPT_NAME = "resize-helper.sh"
|
||||
|
||||
@ -27,36 +27,54 @@
|
||||
[ $(whoami) = "root" ] || { echo "E: You must be root" && exit 1; }
|
||||
|
||||
# we must have few tools
|
||||
#SGDISK=$(which sgdisk) || { echo "E: You must have sgdisk" && exit 1; }
|
||||
#PARTED=$(which parted) || { echo "E: You must have parted" && exit 1; }
|
||||
#PARTPROBE=$(which partprobe) || { echo "E: You must have partprobe" && exit 1; }
|
||||
RESIZE2FS=$(which resize2fs) || { echo "E: You must have resize2fs" && exit 1; }
|
||||
|
||||
# find root device
|
||||
# ROOT_DEVICE=$(findmnt --noheadings --output=SOURCE / | cut -d'[' -f1)
|
||||
DEVICES=$(ls /sys/fs/ext4/)
|
||||
# prune root device (for example UUID)
|
||||
#ROOT_DEVICE=$(realpath ${ROOT_DEVICE})
|
||||
# get the partition number and type
|
||||
#PART_ENTRY_NUMBER=$(udevadm info --query=property --name=${ROOT_DEVICE} | grep '^ID_PART_ENTRY_NUMBER=' | cut -d'=' -f2)
|
||||
#PART_TABLE_TYPE=$(udevadm info --query=property --name=${ROOT_DEVICE} | grep '^ID_PART_TABLE_TYPE=' | cut -d'=' -f2)
|
||||
# find the block device
|
||||
#DEVICE=$(udevadm info --query=path --name=${ROOT_DEVICE} | awk -F'/' '{print $(NF-1)}')
|
||||
#DEVICE="/dev/${DEVICE}"
|
||||
|
||||
#if [ "$PART_TABLE_TYPE" = "gpt" ]; then
|
||||
# ${SGDISK} -e ${DEVICE}
|
||||
# ${PARTPROBE}
|
||||
#fi
|
||||
echo "RESIZE-HELPER START" > /dev/kmsg
|
||||
|
||||
#${PARTED} ${DEVICE} resizepart ${PART_ENTRY_NUMBER} Yes 100%
|
||||
#${PARTPROBE}
|
||||
for device in ${DEVICES}; do
|
||||
PART_TABLE_TYPE=$(udevadm info --query=property --name=/dev/${device} | grep '^ID_PART_TABLE_TYPE=' | cut -d'=' -f2)
|
||||
if [ -e /dev/${device} ]; then
|
||||
if [ "$PART_TABLE_TYPE" = "gpt" ]; then
|
||||
${RESIZE2FS} "/dev/${device}"
|
||||
fi
|
||||
# disable service to be sure it will be executed only one time
|
||||
if [ -f /bin/systemctl ]; then
|
||||
/bin/systemctl --no-reload disable resize-helper.service
|
||||
else
|
||||
rm /etc/rc[35].d/S22resize-helper.sh &> /dev/null
|
||||
fi
|
||||
sync
|
||||
|
||||
if `grep -q nfsroot /proc/cmdline` ; then
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ -f /lib/systemd/systemd-growfs ]; then
|
||||
echo "RESIZE-HELPER: Using systemd-growfs" > /dev/kmsg
|
||||
# force to mount partitions
|
||||
if [ -z $(findmnt --noheadings --output=SOURCE /boot|cut -d'[' -f1) ];
|
||||
then
|
||||
[ -f /sbin/mount-partitions.sh ] && /sbin/mount-partitions.sh stop
|
||||
fi
|
||||
done
|
||||
/lib/systemd/systemd-growfs /
|
||||
/lib/systemd/systemd-growfs /boot
|
||||
/lib/systemd/systemd-growfs /vendor
|
||||
/lib/systemd/systemd-growfs /usr/local/
|
||||
else
|
||||
echo "RESIZE-HELPER: Using directly resize2fs" > /dev/kmsg
|
||||
# umount partition before to resize it
|
||||
[ -f /sbin/mount-partitions.sh ] && /sbin/mount-partitions.sh stop
|
||||
for device in ${DEVICES}; do
|
||||
PART_TABLE_TYPE=$(udevadm info --query=property --name=/dev/${device} | grep '^ID_PART_TABLE_TYPE=' | cut -d'=' -f2)
|
||||
if [ -e /dev/${device} ]; then
|
||||
if [ "$PART_TABLE_TYPE" = "gpt" ]; then
|
||||
echo "Resize /dev/${device}"
|
||||
${RESIZE2FS} "/dev/${device}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
df -h > /dev/kmsg
|
||||
|
||||
#echo "RESIZE-HELPER: For integrity of file-system after a resize2fs, the system need to be rebooted" > /dev/kmsg
|
||||
#echo "RESIZE-HELPER REBOOTING of system" > /dev/kmsg
|
||||
echo "RESIZE-HELPER FINISH" > /dev/kmsg
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
[Unit]
|
||||
Description=Resize root filesystem to fit available disk space
|
||||
Wants=systemd-udevd.service systemd-udev-trigger.service
|
||||
After=systemd-remount-fs.service systemd-udevd.service
|
||||
DefaultDependencies=false
|
||||
After=mount-partitions.service
|
||||
Before=local-fs.target serial-getty@ttySTM0.service netdata.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStartPre=-/bin/udevadm settle
|
||||
ExecStart=-/sbin/resize-helper
|
||||
ExecStartPost=/bin/systemctl disable resize-helper.service
|
||||
WatchdogSec=30
|
||||
WatchdogSec=45
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
WantedBy=local-fs.target
|
||||
|
||||
@ -12,11 +12,6 @@ case $1 in
|
||||
start)
|
||||
echo "Starting $DESC"
|
||||
@sbindir@/resize-helper
|
||||
|
||||
echo "remove $DESC from runlevels starting"
|
||||
rm @sysconfdir@/rc3.d/S22resize-helper.sh &> /dev/null
|
||||
rm @sysconfdir@/rc5.d/S22resize-helper.sh &> /dev/null
|
||||
echo "remove $DESC from runlevels completed"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: @sysconfdir@/init.d/resize-helper.sh {start}" >&2
|
||||
|
||||
Reference in New Issue
Block a user