Skip to content

Commit

Permalink
Optimization for Fedora boot process
Browse files Browse the repository at this point in the history
  • Loading branch information
ventoy committed Mar 24, 2023
1 parent abfc2a6 commit 652475f
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 23 deletions.
63 changes: 42 additions & 21 deletions IMG/cpio/ventoy/hook/rhel7/ventoy-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

if [ -f $VTOY_PATH/autoinstall ]; then
VTKS="inst.ks=file:$VTOY_PATH/autoinstall"
cp -a $VTOY_PATH/hook/rhel7/ventoy-autoexp.sh /lib/dracut/hooks/pre-mount/99-ventoy-autoexp.sh
else
for vtParam in $($CAT /proc/cmdline); do
if echo $vtParam | $GREP -q 'ks=file:/'; then
Expand Down Expand Up @@ -90,23 +91,7 @@ if ls $VTOY_PATH | $GREP -q 'ventoy_dud[0-9]'; then
fi
echo "vtInstDD=$vtInstDD" >> $VTLOG

if $GREP -q 'root=live' /proc/cmdline; then
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=live:/dev/ventoy $VTKS $VTOVERLAY $vtInstDD#" -i /lib/dracut-lib.sh
else
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE inst.stage2=hd:/dev/ventoy $VTKS $VTOVERLAY $vtInstDD#" -i /lib/dracut-lib.sh
fi

ventoy_set_inotify_script rhel7/ventoy-inotifyd-hook.sh

#Fedora
if $BUSYBOX_PATH/which dmsquash-live-root > /dev/null; then
vtPriority=99
else
vtPriority=01
fi

$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/${vtPriority}-ventoy-inotifyd-start.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-timeout.sh /lib/dracut/hooks/initqueue/timeout/${vtPriority}-ventoy-timeout.sh

vtNeedRepo=
if [ -f /etc/system-release ]; then
Expand All @@ -131,13 +116,53 @@ if $GREP -i -q Fedora /etc/os-release; then
fi
fi


echo "vtNeedRepo=$vtNeedRepo" >> $VTLOG

if [ "$vtNeedRepo" = "yes" ]; then
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-repo.sh /lib/dracut/hooks/pre-pivot/99-ventoy-repo.sh
fi


#iso-scan (currently only for Fedora)
if $GREP -q Fedora /etc/os-release; then
if ventoy_iso_scan_check; then
echo "iso_scan process ..." >> $VTLOG

vtIsoPath=$(/ventoy/tool/vtoydump -p /ventoy/ventoy_os_param)
VTISO_SCAN="iso-scan/filename=$vtIsoPath"
echo -n $vtIsoPath > /ventoy/vtoy_iso_scan

$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE $VTISO_SCAN $VTKS $VTOVERLAY $vtInstDD#" -i /lib/dracut-lib.sh
if [ "$VTOY_LINUX_REMOUNT" = "01" -a "$vtNeedRepo" != "yes" ]; then
ventoy_rw_iso_scan
fi

exit 0
fi
fi


echo "common process ..." >> $VTLOG
if $GREP -q 'root=live' /proc/cmdline; then
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=live:/dev/ventoy $VTKS $VTOVERLAY $VTISO_SCAN $vtInstDD#" -i /lib/dracut-lib.sh
else
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE inst.stage2=hd:/dev/ventoy $VTKS $VTOVERLAY $VTISO_SCAN $vtInstDD#" -i /lib/dracut-lib.sh
fi


ventoy_set_inotify_script rhel7/ventoy-inotifyd-hook.sh

#Fedora
if $BUSYBOX_PATH/which dmsquash-live-root > /dev/null; then
vtPriority=99
else
vtPriority=01
fi

$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/${vtPriority}-ventoy-inotifyd-start.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-timeout.sh /lib/dracut/hooks/initqueue/timeout/${vtPriority}-ventoy-timeout.sh


if [ -e /sbin/dmsquash-live-root ]; then
echo "patch /sbin/dmsquash-live-root ..." >> $VTLOG
$SED "1 a $BUSYBOX_PATH/sh $VTOY_PATH/hook/rhel7/ventoy-make-link.sh" -i /sbin/dmsquash-live-root
Expand All @@ -154,10 +179,6 @@ if $GREP -i -q 'fedora.*coreos' /etc/os-release; then
cp -a $VTOY_PATH/hook/rhel7/ventoy-make-link.sh /lib/dracut/hooks/pre-mount/99-ventoy-premount-mklink.sh
fi

if [ -f $VTOY_PATH/autoinstall ]; then
cp -a $VTOY_PATH/hook/rhel7/ventoy-autoexp.sh /lib/dracut/hooks/pre-mount/99-ventoy-autoexp.sh
fi


#special distro magic
$BUSYBOX_PATH/mkdir -p $VTOY_PATH/distmagic
Expand Down
15 changes: 13 additions & 2 deletions IMG/cpio/ventoy/hook/rhel7/ventoy-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ vtlog "##### $0 $* ..."

VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH

repodev=$(ls $VTOY_PATH/dev_backup*)
echo "inst.repo=hd:/dev/${repodev#*dev_backup_}" >> /sysroot/etc/cmdline
if [ -f /ventoy/vtoy_iso_scan ]; then
repopath=$(cat /ventoy/vtoy_iso_scan)
repodev=$(vtoydump -f /ventoy/ventoy_os_param | awk -F'#' '{print $1}')
if echo $repodev | egrep -q "nvme|mmc|nbd"; then
vtpart1=${repodev}p1
else
vtpart1=${repodev}1
fi
echo "inst.repo=hd:${vtpart1}:${repopath}" >> /sysroot/etc/cmdline
else
repodev=$(ls $VTOY_PATH/dev_backup*)
echo "inst.repo=hd:/dev/${repodev#*dev_backup_}" >> /sysroot/etc/cmdline
fi

PATH=$VTPATH_OLD
45 changes: 45 additions & 0 deletions IMG/cpio/ventoy/hook/ventoy-os-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,48 @@ ventoy_check_mount() {
$BUSYBOX_PATH/mount $1 $2
fi
}

ventoy_has_exfat_ko() {
vtExfat=''
vtKerVer=$($BUSYBOX_PATH/uname -r)
if [ -d /lib/modules/$vtKerVer/kernel/fs/exfat ]; then
vtExfat=$(ls /lib/modules/$vtKerVer/kernel/fs/exfat/)
fi
[ -n "$vtExfat" ]
}

ventoy_is_exfat_part() {
$VTOY_PATH/tool/vtoydump -s /ventoy/ventoy_os_param | $GREP -q exfat
}

ventoy_iso_scan_path() {
if [ -f /sbin/iso-scan ]; then
echo -n '/sbin/iso-scan'
elif [ -f /bin/iso-scan ]; then
echo -n '/bin/iso-scan'
else
echo -n ''
fi
}

ventoy_has_iso_scan() {
vtScanPath=$(ventoy_iso_scan_path)
[ -n "$vtScanPath" ]
}

ventoy_rw_iso_scan() {
vtScanPath=$(ventoy_iso_scan_path)
if [ -n "$vtScanPath" ]; then
if $GREP -q 'mount.* ro .*isoscan' $vtScanPath; then
$SED -i 's/\(mount.*-o.*\) ro /\1 rw /' $vtScanPath
fi
fi
}

ventoy_iso_scan_check() {
if ventoy_is_exfat_part; then
if ventoy_has_exfat_ko; then
ventoy_has_iso_scan
fi
fi
}

0 comments on commit 652475f

Please sign in to comment.