Commit 05a1b863 authored by longpanda's avatar longpanda
Browse files

initial commit

parent 2090c6fa
#!/ventoy/busybox/sh
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/mageia/udev_disk_hook.sh %k noreplace"
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
# some distro initramfs doesn't contain device-mapper udev rules file
DISTRO_UDEV_DIR=$(ventoy_get_udev_conf_dir)
if [ -s "$DISTRO_UDEV_DIR/13-dm-disk.rules" ]; then
echo 'dm-disk rule exist' >> $VTLOG
else
echo 'Copy dm-disk rule file' >> $VTLOG
$CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$DISTRO_UDEV_DIR/13-dm-disk.rules"
fi
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
exit 0
fi
ventoy_udev_disk_common_hook $*
# OK finish
set_ventoy_hook_finish
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
vtRuleFile=$($FIND / -name '*.rules' -type f | $GREP udev | $HEAD -n1)
ventoy_add_udev_rule_with_path "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace" "${vtRuleFile%/*}/99-ventoy.rules"
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
ventoy_os_install_device_mapper_by_unsquashfs() {
vtlog "ventoy_os_install_device_mapper_by_unsquashfs $*"
vtKoExt=$(ventoy_get_module_postfix)
vtlog "vtKoExt=$vtKoExt"
vtoydm -i -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/iso_file_list
vtline=$(grep '[-][-] livecd.sqfs ' $VTOY_PATH/iso_file_list)
sector=$(echo $vtline | awk '{print $(NF-1)}')
length=$(echo $vtline | awk '{print $NF}')
vtoydm -E -f $VTOY_PATH/ventoy_image_map -d $1 -s $sector -l $length -o $VTOY_PATH/fsdisk
dmModPath="/lib/modules/$2/kernel/drivers/md/dm-mod.$vtKoExt"
echo $dmModPath > $VTOY_PATH/fsextract
vtoy_unsquashfs -d $VTOY_PATH/sqfs -n -q -e $VTOY_PATH/fsextract $VTOY_PATH/fsdisk
if [ -e $VTOY_PATH/sqfs${dmModPath} ]; then
vtlog "success $VTOY_PATH/sqfs${dmModPath}"
insmod $VTOY_PATH/sqfs${dmModPath}
else
false
fi
}
ventoy_os_install_device_mapper() {
vtlog "ventoy_os_install_device_mapper"
if grep -q 'device-mapper' /proc/devices; then
vtlog "device-mapper module already loaded"
return;
fi
vtKerVer=$(uname -r)
if ventoy_os_install_device_mapper_by_unsquashfs $1 $vtKerVer; then
vtlog "unsquashfs success"
else
vterr "unsquashfs failed"
fi
}
vtdiskname=$(get_ventoy_disk_name)
ventoy_os_install_device_mapper $vtdiskname
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2"
PATH=$VTPATH_OLD
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
# Step 1: dd initrd file to ramdisk
vtRamdiskFile=$($BUSYBOX_PATH/ls /initrd* | $HEAD -n1)
$BUSYBOX_PATH/mknod -m 0666 /ram0 b 1 0
$BUSYBOX_PATH/dd if=$vtRamdiskFile of=/ram0 status=none
$BUSYBOX_PATH/rm -f $vtRamdiskFile
# Step 2: mount ramdisk
$BUSYBOX_PATH/mkdir -p /ventoy_rdroot
ventoy_close_printk
$BUSYBOX_PATH/mount /ram0 /ventoy_rdroot
ventoy_restore_printk
# Step 3: Copy ventoy tool to new root directory.
# Here we make a tmpfs mount to avoid ramdisk out of space (additional space is for log).
vtSize=$($BUSYBOX_PATH/du -m -s $VTOY_PATH | $BUSYBOX_PATH/awk '{print $1}')
let vtSize=vtSize+4
$BUSYBOX_PATH/mkdir -p /ventoy_rdroot/ventoy
$BUSYBOX_PATH/mount -t tmpfs -o size=${vtSize}m tmpfs /ventoy_rdroot/ventoy
$BUSYBOX_PATH/cp -a /ventoy/* /ventoy_rdroot/ventoy/
# Step 4: add hook in linuxrc&rc.sysinit script file
vtLine=$($GREP -n "^find_cdrom" /ventoy_rdroot/linuxrc | $GREP -v '(' | $AWK -F: '{print $1}')
$SED "$vtLine aif test -d /ventoy; then $BUSYBOX_PATH/sh $VTOY_PATH/hook/pclos/disk_hook.sh; fi" -i /ventoy_rdroot/linuxrc
$SED "$vtLine aif test -d /initrd/ventoy; then ln -s /initrd/ventoy /ventoy; fi" -i /ventoy_rdroot/linuxrc
vtRcInit=$($BUSYBOX_PATH/tail /ventoy_rdroot/linuxrc | $GREP 'exec ' | $AWK '{print $2}')
if [ -e /ventoy_rdroot$vtRcInit ]; then
vtRcInit=/ventoy_rdroot$vtRcInit
else
vtRcInit=/ventoy_rdroot/etc/rc.d/rc.sysinit
fi
echo 'exec /sbin/init' >> $vtRcInit
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
#if [ -e $VTOY_PATH/hook/rhel5/loader ]; then
# $BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel5/loader /sbin/loader
#fi
#$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel5/ventoy-loader.sh $VTOY_PATH/tool/
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup $1"
vt_usb_disk=$1
# dump iso file location
$VTOY_PATH/tool/vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vt_usb_disk} > $VTOY_PATH/iso_file_list
# install dmsetup
LINE=$($GREP 'minstg2.img' $VTOY_PATH/iso_file_list)
if [ $? -eq 0 ]; then
extract_file_from_line "$LINE" ${vt_usb_disk} /tmp/minstg2.img
mkdir -p /tmp/ramfs/minstg2.img
mount -t squashfs /tmp/minstg2.img /tmp/ramfs/minstg2.img
$BUSYBOX_PATH/ln -s /tmp/ramfs/minstg2.img/lib64 /lib64
$BUSYBOX_PATH/ln -s /tmp/ramfs/minstg2.img/usr /usr
fi
vtlog "dmsetup install finish, now check it..."
dmsetup_path=$(ventoy_find_bin_path dmsetup)
if [ -z "$dmsetup_path" ]; then
vterr "dmsetup still not found after install"
elif $dmsetup_path info >> $VTLOG 2>&1; then
vtlog "$dmsetup_path work ok"
else
vterr "$dmsetup_path not work"
fi
}
vtlog "##### $0 $* ########"
vtdiskname=$(get_ventoy_disk_name)
dmsetup_path=$(ventoy_find_bin_path dmsetup)
if [ -z "$dmsetup_path" ]; then
ventoy_os_install_dmsetup "$vtdiskname"
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
$BUSYBOX_PATH/unlink /lib64
$BUSYBOX_PATH/unlink /usr
umount /tmp/ramfs/minstg2.img
rm -rf /tmp/ramfs/minstg2.img
rm -f /tmp/minstg2.img
else
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
fi
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
sed -i "s/^enabled.*/enabled=0/g" $2/$3
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup $1"
vt_usb_disk=$1
$BUSYBOX_PATH/modprobe dm-mod
$BUSYBOX_PATH/modprobe linear
# dump iso file location
$VTOY_PATH/tool/vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vt_usb_disk} > $VTOY_PATH/iso_file_list
# install dmsetup
LINE=$($GREP 'device-mapper-[0-9].*\.rpm' $VTOY_PATH/iso_file_list)
if [ $? -eq 0 ]; then
install_rpm_from_line "$LINE" ${vt_usb_disk}
fi
vtlog "dmsetup install finish, now check it..."
dmsetup_path=$(ventoy_find_bin_path dmsetup)
if [ -z "$dmsetup_path" ]; then
vterr "dmsetup still not found after install"
elif $dmsetup_path info >> $VTLOG 2>&1; then
vtlog "$dmsetup_path work ok"
else
vterr "$dmsetup_path not work"
fi
}
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
# /dev/loop7 come first
if [ "$1" = "loop7" ] && [ -b $VTOY_DM_PATH ]; then
ventoy_copy_device_mapper /dev/loop7
fi
exit 0
fi
dmsetup_path=$(ventoy_find_bin_path dmsetup)
if [ -z "$dmsetup_path" ]; then
ventoy_os_install_dmsetup "/dev/${1:0:-1}"
fi
#some distro add there repo file to /etc/anaconda.repos.d/ which will cause error during installation
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $VTOY_PATH/hook/rhel6/anaconda-repo-listen.sh /etc/anaconda.repos.d:n &
ventoy_udev_disk_common_hook $* "noreplace"
$BUSYBOX_PATH/mount $VTOY_DM_PATH /mnt/ventoy
#
# We do a trick for rhel6 series here.
# Use /dev/loop7 and wapper it as a removable cdrom with bind mount.
# Then the anaconda installer will accept /dev/loop7 as the install medium.
#
ventoy_copy_device_mapper /dev/loop7
$BUSYBOX_PATH/cp -a /sys/devices/virtual/block/loop7 /tmp/ >> $VTLOG 2>&1
echo 19 > /tmp/loop7/capability
$BUSYBOX_PATH/mount --bind /tmp/loop7 /sys/block/loop7 >> $VTLOG 2>&1
# OK finish
set_ventoy_hook_finish
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$BUSYBOX_PATH/mkdir -p /etc/anaconda.repos.d /mnt/ventoy
ventoy_print_yum_repo "ventoy" "file:///mnt/ventoy" > /etc/anaconda.repos.d/ventoy.repo
ventoy_add_udev_rule "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
ventoy_add_kernel_udev_rule "loop7" "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
# suppress write protected mount warning
if [ -e /usr/sbin/anaconda-diskroot ]; then
$SED 's/^mount $dev $repodir/mount -oro $dev $repodir/' -i /usr/sbin/anaconda-diskroot
fi
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
exit 0
fi
ventoy_udev_disk_common_hook $*
#
# make a fake cdrom link
#
if [ -e /dev/sr3 ]; then
if ! [ -e /dev/hdp ]; then
ln -s $VTOY_DM_PATH /dev/hdp
fi
else
ln -s $VTOY_DM_PATH /dev/sr3
fi
# OK finish
set_ventoy_hook_finish
#!/ventoy/busybox/sh
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/slackware/udev_disk_hook.sh %k noreplace"
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup $1"
vt_usb_disk=$1
# dump iso file location
$VTOY_PATH/tool/vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vt_usb_disk} > $VTOY_PATH/iso_file_list
# install dmsetup
LINE=$($GREP 'device-mapper-[0-9]\..*\.rpm' $VTOY_PATH/iso_file_list)
if [ $? -eq 0 ]; then
install_rpm_from_line "$LINE" ${vt_usb_disk}
fi
vtlog "dmsetup install finish, now check it..."
dmsetup_path=$(ventoy_find_bin_path dmsetup)
if [ -z "$dmsetup_path" ]; then
vterr "dmsetup still not found after install"
elif $dmsetup_path info >> $VTLOG 2>&1; then
vtlog "$dmsetup_path work ok"
else
vterr "$dmsetup_path not work"
fi
}
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
exit 0
fi
dmsetup_path=$(ventoy_find_bin_path dmsetup)
if [ -z "$dmsetup_path" ]; then
ventoy_os_install_dmsetup "/dev/${1:0:-1}"
fi
ventoy_udev_disk_common_hook $*
# OK finish
set_ventoy_hook_finish
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/suse/udev_disk_hook.sh %k"
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
exit 0
fi
# TinyCore linux distro doesn't contain dmsetup, we use aoe here
sudo $BUSYBOX_PATH/modprobe aoe aoe_iflist=lo
if [ -e /sys/module/aoe ]; then
VBLADE_BIN=$(ventoy_get_vblade_bin)
sudo $VBLADE_BIN -r -f $VTOY_PATH/ventoy_image_map 9 0 lo "/dev/${1:0:-1}" &
while ! [ -b /dev/etherd/e9.0 ]; do
vtlog 'Wait for /dev/etherd/e9.0 ....'
$SLEEP 0.1
done
sudo $BUSYBOX_PATH/cp -a /dev/etherd/e9.0 "/dev/$1"
ventoy_find_bin_run rebuildfstab
else
vterr "aoe driver module load failed..."
fi
# OK finish
set_ventoy_hook_finish
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule_with_name "$VTOY_PATH/hook/tinycore/udev_disk_hook.sh %k" "90-ventoy.rules"
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
VTOY_PATH=/ventoy
BUSYBOX_PATH=$VTOY_PATH/busybox
VTLOG=$VTOY_PATH/log
FIND=$BUSYBOX_PATH/find
GREP=$BUSYBOX_PATH/grep
EGREP=$BUSYBOX_PATH/egrep
CAT=$BUSYBOX_PATH/cat
AWK=$BUSYBOX_PATH/awk
SED=$BUSYBOX_PATH/sed
SLEEP=$BUSYBOX_PATH/sleep
HEAD=$BUSYBOX_PATH/head
VTOY_DM_PATH=/dev/mapper/ventoy
VTOY_DEBUG_LEVEL=$($BUSYBOX_PATH/hexdump -n 1 -s 430 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
if [ "$VTOY_DEBUG_LEVEL" = "01" ]; then
if [ -e /dev/console ]; then
VTLOG=/dev/console
fi
fi
vtlog() {
if [ "$VTLOG" = "$VTOY_PATH/log" ]; then
echo "$*" >>$VTLOG
else
echo -e "\033[32m $* \033[0m" > $VTLOG
$SLEEP 2
fi
}
vterr() {
if [ "$VTLOG" = "$VTOY_PATH/log" ]; then
echo "$*" >>$VTLOG
else
echo -e "\n\033[31m $* \033[0m" > $VTLOG
$SLEEP 30
fi
}
is_ventoy_hook_finished() {
[ -e $VTOY_PATH/hook_finish ]
}
set_ventoy_hook_finish() {
echo 'Y' > $VTOY_PATH/hook_finish
}
get_ventoy_disk_name() {
line=$($VTOY_PATH/tool/vtoydump -f /ventoy/ventoy_os_param)
if [ $? -eq 0 ]; then
echo ${line%%#*}
else
echo "unknown"
fi
}
get_ventoy_iso_name() {
line=$($VTOY_PATH/tool/vtoydump -f /ventoy/ventoy_os_param)
if [ $? -eq 0 ]; then
echo ${line##*#}
else
echo "unknown"
fi
}
wait_for_usb_disk_ready() {
while [ -n "Y" ]; do
usb_disk=$(get_ventoy_disk_name)
vtlog "wait_for_usb_disk_ready $usb_disk ..."
if [ -e "${usb_disk}2" ]; then
vtlog "wait_for_usb_disk_ready $usb_disk finish"
break
else
$SLEEP 0.3
fi
done
}
is_ventoy_disk() {
if $VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c "$1"; then
$BUSYBOX_PATH/true
else
$BUSYBOX_PATH/false
fi
}
not_ventoy_disk() {
if $VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c "$1"; then
$BUSYBOX_PATH/false
else
$BUSYBOX_PATH/true
fi
}
ventoy_get_vblade_bin() {
if $VTOY_PATH/tool/vblade_64 -t >>$VTLOG 2>&1; then
echo $VTOY_PATH/tool/vblade_64
else
echo $VTOY_PATH/tool/vblade_32
fi
}
ventoy_find_bin_path() {
if $BUSYBOX_PATH/which "$1" > /dev/null; then
$BUSYBOX_PATH/which "$1"; return
fi
for vt_path in '/bin' '/sbin' '/usr/bin' '/usr/sbin' '/usr/local/bin' '/usr/local/sbin' '/root/bin'; do
if [ -e "$vt_path/$1" ]; then
echo "$vt_path/$1"; return
fi
done
echo ""
}
ventoy_find_bin_run() {
vtsudo=0
if [ "$1" = "sudo" ]; then
shift
vtsudo=1
fi
vtbinpath=$(ventoy_find_bin_path "$1")
if [ -n "$vtbinpath" ]; then
shift
if [ $vtsudo -eq 0 ]; then
vtlog "$vtbinpath $*"
$vtbinpath $*
else
vtlog "sudo $vtbinpath $*"
sudo $vtbinpath $*
fi
fi
}
ventoy_get_module_postfix() {
vtKerVer=$($BUSYBOX_PATH/uname -r)
vtLine=$($FIND /lib/modules/$vtKerVer/ -name *.ko* | $HEAD -n1)
vtComp=${vtLine##*/*.ko}
echo "ko$vtComp"
}
ventoy_check_dm_module() {
if $GREP -q 'device-mapper' /proc/devices; then
$BUSYBOX_PATH/true; return
fi
vtlog "device-mapper NOT found in /proc/devices, try to load kernel module"
$BUSYBOX_PATH/modprobe dm_mod >>$VTLOG 2>&1
$BUSYBOX_PATH/modprobe dm-mod >>$VTLOG 2>&1
if ! $GREP -q 'device-mapper' /proc/devices; then
vtlog "modprobe failed, now try to insmod ko..."
$FIND /lib/modules/ -name "dm-mod.ko*" | while read vtline; do
vtlog "insmode $vtline "
$BUSYBOX_PATH/insmod $vtline >>$VTLOG 2>&1
done
fi
if $GREP -q 'device-mapper' /proc/devices; then
vtlog "device-mapper found in /proc/devices after retry"
$BUSYBOX_PATH/true; return
else
vtlog "device-mapper still NOT found in /proc/devices after retry"
$BUSYBOX_PATH/false; return
fi
}
create_ventoy_device_mapper() {
vtlog "create_ventoy_device_mapper $*"
VT_DM_BIN=$(ventoy_find_bin_path dmsetup)
if [ -z "$VT_DM_BIN" ]; then
vtlog "no dmsetup avaliable, lastly try inbox dmsetup"
VT_DM_BIN=$VTOY_PATH/tool/dmsetup
fi
vtlog "dmsetup avaliable in system $VT_DM_BIN"
if ventoy_check_dm_module "$1"; then
vtlog "device-mapper module check success"
else
vterr "Error: no dm module avaliable"
fi
$VTOY_PATH/tool/vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
if [ -z "$2" ]; then
$VT_DM_BIN create ventoy $VTOY_PATH/ventoy_dm_table >>$VTLOG 2>&1
else
$VT_DM_BIN "$2" create ventoy $VTOY_PATH/ventoy_dm_table >>$VTLOG 2>&1
fi
}
wait_for_ventoy_dm_disk_label() {
DM=$($BUSYBOX_PATH/readlink $VTOY_DM_PATH)
vtlog "wait_for_ventoy_dm_disk_label $DM ..."
for i in 0 1 2 3 4 5 6 7 8 9; do
vtlog "i=$i ####### ls /dev/disk/by-label/"
ls -l /dev/disk/by-label/ >> $VTLOG
if ls -l /dev/disk/by-label/ | $GREP -q "$DM"; then
break
else
$SLEEP 0.3
fi
done
}
install_udeb_pkg() {
if ! [ -e "$1" ]; then
$BUSYBOX_PATH/false
return
fi
if [ -d /tmp/vtoy_udeb ]; then
$BUSYBOX_PATH/rm -rf /tmp/vtoy_udeb
fi
$BUSYBOX_PATH/mkdir -p /tmp/vtoy_udeb
$BUSYBOX_PATH/cp -a "$1" /tmp/vtoy_udeb/
CURDIR=$($BUSYBOX_PATH/pwd)
cd /tmp/vtoy_udeb
$BUSYBOX_PATH/ar x "$1"
if [ -e 'data.tar.gz' ]; then
$BUSYBOX_PATH/tar -xzf data.tar.gz -C /
elif [ -e 'data.tar.xz' ]; then
$BUSYBOX_PATH/tar -xJf data.tar.xz -C /
elif [ -e 'data.tar.bz2' ]; then
$BUSYBOX_PATH/tar -xjf data.tar.bz2 -C /
elif [ -e 'data.tar.lzma' ]; then
$BUSYBOX_PATH/tar -xaf data.tar.lzma -C /
fi
if [ -e 'control.tar.gz' ]; then
$BUSYBOX_PATH/tar -xzf control.tar.gz -C /
elif [ -e 'control.tar.xz' ]; then
$BUSYBOX_PATH/tar -xJf control.tar.xz -C /
elif [ -e 'control.tar.bz2' ]; then
$BUSYBOX_PATH/tar -xjf control.tar.bz2 -C /
elif [ -e 'control.tar.lzma' ]; then
$BUSYBOX_PATH/tar -xaf control.tar.lzma -C /
fi
cd $CURDIR
$BUSYBOX_PATH/rm -rf /tmp/vtoy_udeb
$BUSYBOX_PATH/true
}
install_udeb_from_line() {
vtlog "install_udeb_from_line $1"
if ! [ -b "$2" ]; then
vterr "disk #$2# not exist"
return
fi
sector=$(echo $1 | $AWK '{print $(NF-1)}')
length=$(echo $1 | $AWK '{print $NF}')
vtlog "sector=$sector length=$length"
$VTOY_PATH/tool/vtoydm -e -f $VTOY_PATH/ventoy_image_map -d ${2} -s $sector -l $length -o /tmp/xxx.udeb
if [ -e /tmp/xxx.udeb ]; then
vtlog "extract udeb file from iso success"
else
vterr "extract udeb file from iso fail"
return
fi
install_udeb_pkg /tmp/xxx.udeb
$BUSYBOX_PATH/rm -f /tmp/xxx.udeb
}
extract_file_from_line() {
vtlog "extract_file_from_line $1 disk=#$2#"
if ! [ -b "$2" ]; then
vterr "disk #$2# not exist"
return
fi
sector=$(echo $1 | $AWK '{print $(NF-1)}')
length=$(echo $1 | $AWK '{print $NF}')
vtlog "sector=$sector length=$length"
$VTOY_PATH/tool/vtoydm -e -f $VTOY_PATH/ventoy_image_map -d ${2} -s $sector -l $length -o $3
if [ -e $3 ]; then
vtlog "extract file from iso success"
$BUSYBOX_PATH/true
else
vterr "extract file from iso fail"
$BUSYBOX_PATH/false
fi
}
install_rpm_from_line() {
vtlog "install_rpm_from_line $1 disk=#$2#"
if ! [ -b "$2" ]; then
vterr "disk #$2# not exist"
return
fi
sector=$(echo $1 | $AWK '{print $(NF-1)}')
length=$(echo $1 | $AWK '{print $NF}')
vtlog "sector=$sector length=$length"
$VTOY_PATH/tool/vtoydm -e -f $VTOY_PATH/ventoy_image_map -d ${2} -s $sector -l $length -o /tmp/xxx.rpm
if [ -e /tmp/xxx.rpm ]; then
vtlog "extract rpm file from iso success"
else
vterr "extract rpm file from iso fail"
return
fi
CURPWD=$($BUSYBOX_PATH/pwd)
cd /
vtlog "install rpm..."
$BUSYBOX_PATH/rpm2cpio /tmp/xxx.rpm | $BUSYBOX_PATH/cpio -idm 2>>$VTLOG
cd $CURPWD
$BUSYBOX_PATH/rm -f /tmp/xxx.rpm
}
dump_whole_iso_file() {
$VTOY_PATH/tool/vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $usb_disk | while read vtline; do
vtlog "dmtable line: $vtline"
vtcount=$(echo $vtline | $AWK '{print $2}')
vtoffset=$(echo $vtline | $AWK '{print $NF}')
$BUSYBOX_PATH/dd if=$usb_disk of="$1" bs=512 count=$vtcount skip=$vtoffset oflag=append conv=notrunc
done
}
ventoy_copy_device_mapper() {
if [ -L $VTOY_DM_PATH ]; then
vtlog "replace block device link $1..."
$BUSYBOX_PATH/mv "$1" $VTOY_PATH/dev_backup_${1#/dev/}
VT_MAPPER_LINK=$($BUSYBOX_PATH/readlink $VTOY_DM_PATH)
$BUSYBOX_PATH/cp -a "/dev/mapper/$VT_MAPPER_LINK" "$1"
elif [ -b $VTOY_DM_PATH ]; then
vtlog "replace block device $1..."
$BUSYBOX_PATH/mv "$1" $VTOY_PATH/dev_backup_${1#/dev/}
$BUSYBOX_PATH/cp -a "$VTOY_DM_PATH" "$1"
else
vtlog "$VTOY_DM_PATH not exist, now check /dev/dm-X ..."
VT_DM_BIN=$(ventoy_find_bin_path dmsetup)
if [ -z "$VT_DM_BIN" ]; then
vtlog "no dmsetup avaliable, lastly try inbox dmsetup"
VT_DM_BIN=$VTOY_PATH/tool/dmsetup
fi
DM_VT_ID=$($VT_DM_BIN ls | $GREP ventoy | $SED 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
vtlog "DM_VT_ID=$DM_VT_ID ..."
$BUSYBOX_PATH/mv "$1" $VTOY_PATH/dev_backup_${1#/dev/}
$BUSYBOX_PATH/mknod -m 0666 "$1" b $DM_VT_ID
fi
}
ventoy_udev_disk_common_hook() {
VTDISK="${1:0:-1}"
# create device mapper for iso image file
if create_ventoy_device_mapper "/dev/$VTDISK" --readonly; then
vtlog "==== create ventoy device mapper success ===="
else
vtlog "==== create ventoy device mapper failed ===="
$SLEEP 5
if $GREP -q "/dev/$VTDISK" /proc/mounts; then
$GREP "/dev/$VTDISK" /proc/mounts | while read vtLine; do
vtPart=$(echo $vtLine | $AWK '{print $1}')
vtMnt=$(echo $vtLine | $AWK '{print $2}')
vtlog "$vtPart is mounted on $vtMnt now umount it ..."
$BUSYBOX_PATH/umount $vtMnt
done
fi
if create_ventoy_device_mapper "/dev/$VTDISK" --readonly; then
vtlog "==== create ventoy device mapper success after retry ===="
else
vtlog "==== create ventoy device mapper failed after retry ===="
return
fi
fi
if [ "$2" = "noreplace" ]; then
vtlog "no need to replace block device"
else
ventoy_copy_device_mapper "/dev/$1"
fi
}
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
VT_RULE_DIR_PREFIX=""
VT_PRINTK_LEVEL=0
VT_UDEV_RULE_FILE_NAME="99-ventoy.rules"
VT_UDEV_RULE_PREFIX="ACTION==\"add\", SUBSYSTEM==\"block\","
ventoy_close_printk() {
VT_PRINTK_LEVEL=$($CAT /proc/sys/kernel/printk | $AWK '{print $1}')
if [ -e /proc/sys/kernel/printk ]; then
echo 0 > /proc/sys/kernel/printk
fi
}
ventoy_restore_printk() {
if [ -e /proc/sys/kernel/printk ]; then
echo $VT_PRINTK_LEVEL > /proc/sys/kernel/printk
fi
}
ventoy_set_rule_dir_prefix() {
VT_RULE_DIR_PREFIX=$1
}
ventoy_get_udev_conf_dir() {
if [ -d $VT_RULE_DIR_PREFIX/etc/udev/rules.d ]; then
VT_RULE_PATH=$VT_RULE_DIR_PREFIX/etc/udev/rules.d
elif [ -d $VT_RULE_DIR_PREFIX/lib/udev/rules.d ]; then
VT_RULE_PATH=$VT_RULE_DIR_PREFIX/lib/udev/rules.d
else
$BUSYBOX_PATH/mkdir -p $VT_RULE_DIR_PREFIX/etc/udev/rules.d
VT_RULE_PATH=$VT_RULE_DIR_PREFIX/etc/udev/rules.d
fi
echo -n "$VT_RULE_PATH"
}
ventoy_get_udev_conf_path() {
VT_RULE_DIR=$(ventoy_get_udev_conf_dir)
echo "$VT_RULE_DIR/$VT_UDEV_RULE_FILE_NAME"
}
ventoy_add_kernel_udev_rule() {
VT_UDEV_RULE_PATH=$(ventoy_get_udev_conf_path)
echo "KERNEL==\"$1\", $VT_UDEV_RULE_PREFIX RUN+=\"$2\"" >> $VT_UDEV_RULE_PATH
}
ventoy_add_udev_rule_with_name() {
VT_UDEV_RULE_DIR=$(ventoy_get_udev_conf_dir)
echo "KERNEL==\"*2\", $VT_UDEV_RULE_PREFIX RUN+=\"$1\"" >> $VT_UDEV_RULE_DIR/$2
}
ventoy_add_udev_rule_with_path() {
echo "KERNEL==\"*2\", $VT_UDEV_RULE_PREFIX RUN+=\"$1\"" >> $2
}
ventoy_add_udev_rule() {
VT_UDEV_RULE_PATH=$(ventoy_get_udev_conf_path)
echo "KERNEL==\"*2\", $VT_UDEV_RULE_PREFIX RUN+=\"$1\"" >> $VT_UDEV_RULE_PATH
}
#
# It seems there is a bug in somw version of systemd-udevd
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=869719
#
ventoy_systemd_udevd_work_around() {
VTSYSTEMUDEV="$VT_RULE_DIR_PREFIX/lib/systemd/system/systemd-udevd.service"
if [ -e $VTSYSTEMUDEV ]; then
if $GREP -q 'SystemCallArchitectures.*native' $VTSYSTEMUDEV; then
$SED "s/.*\(SystemCallArchitectures.*native\)/#\1/g" -i $VTSYSTEMUDEV
fi
fi
}
ventoy_print_yum_repo() {
echo "[$1]"
echo "name=$1"
echo "baseurl=$2"
echo "enabled=1"
echo "gpgcheck=0"
echo "priority=0"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment