initial commit

This commit is contained in:
longpanda
2020-04-05 00:07:50 +08:00
parent 2090c6fa97
commit 05a1b863a6
487 changed files with 114253 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,71 @@
#!/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 [ "$SUBSYSTEM" != "block" ] || [ "$DEVTYPE" != "partition" ]; then
exit 0
fi
if [ -b /dev/${MDEV:0:-1} ]; then
vtlog "/dev/${MDEV:0:-1} exist"
else
$SLEEP 2
fi
if is_ventoy_hook_finished || not_ventoy_disk "${MDEV:0:-1}"; then
exit 0
fi
PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
#
# longpanda:
# Alpine initramfs doesn't contain dm-mod or fuse module,
# and even the worse, the libpthread.so is not included too.
# So here we directly dump the modloop squashfs file from disk to rootfs.
# Fortunately, this file is not too big (< 100MB in alpine 3.11.3).
# After that:
# 1. mount the squashfs file
# 2. find the dm-mod module from the mountpoint and insmod
# 3. unmount and delete the squashfs file
#
vtoydm -i -f $VTOY_PATH/ventoy_image_map -d /dev/${MDEV:0:-1} > $VTOY_PATH/iso_file_list
vtLine=$(grep '[-][-] modloop-lts ' $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 /dev/${MDEV:0:-1} -s $sector -l $length -o /vt_modloop
mkdir -p $VTOY_PATH/mnt
mount /vt_modloop $VTOY_PATH/mnt
KoModPath=$(find $VTOY_PATH/mnt/ -name 'dm-mod.ko*')
vtlog "insmod $KoModPath"
insmod $KoModPath
umount $VTOY_PATH/mnt
rm -f /vt_modloop
ventoy_udev_disk_common_hook "$MDEV" "noreplace"
# OK finish
set_ventoy_hook_finish

View File

@@ -0,0 +1,24 @@
#!/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
echo "-[-a-z0-9]*2 root:root 0666 @$BUSYBOX_PATH/sh $VTOY_PATH/hook/alpine/udev_disk_hook.sh" >> /mdev.conf
$CAT /etc/mdev.conf >> /mdev.conf
$BUSYBOX_PATH/mv /mdev.conf /etc/mdev.conf

View File

@@ -0,0 +1,34 @@
#!/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 archlinux initramfs doesn't contain device-mapper udev rules file
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)
if [ -s "$ARCH_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 > "$ARCH_UDEV_DIR/13-dm-disk.rules"
fi
# use default proc
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"

View File

@@ -0,0 +1,117 @@
#!/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
vtlog "####### $0 $* ########"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
ventoy_os_install_dmsetup_by_unsquashfs() {
vtlog "ventoy_os_install_dmsetup_by_unsquashfs $*"
vtKoPo=$(ventoy_get_module_postfix)
vtlog "vtKoPo=$vtKoPo"
vtoydm -i -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/iso_file_list
vtline=$(grep '[-][-] linuxfs ' $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="/usr/lib/modules/$vtKerVer/kernel/drivers/md/dm-mod.$vtKoPo"
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
dmModPath="/lib/modules/$vtKerVer/kernel/drivers/md/dm-mod.$vtKoPo"
echo $dmModPath > $VTOY_PATH/fsextract
vtoy_unsquashfs -d $VTOY_PATH/sqfs -n -q -e $VTOY_PATH/fsextract $VTOY_PATH/fsdisk
fi
if [ -e $VTOY_PATH/sqfs${dmModPath} ]; then
vtlog "success $VTOY_PATH/sqfs${dmModPath}"
insmod $VTOY_PATH/sqfs${dmModPath}
else
false
fi
}
ventoy_os_install_dmsetup_by_fuse() {
vtlog "ventoy_os_install_dmsetup_by_fuse $*"
mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
mount -t squashfs $VTOY_PATH/mnt/iso/antiX/linuxfs $VTOY_PATH/mnt/squashfs
KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$2/kernel/drivers/md/dm-mod.ko*)
vtlog "insmod $KoName"
insmod $KoName
umount $VTOY_PATH/mnt/squashfs
umount $VTOY_PATH/mnt/iso
umount $VTOY_PATH/mnt/fuse
}
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup"
if grep -q 'device-mapper' /proc/devices; then
vtlog "device-mapper module already loaded"
return;
fi
vtKerVer=$(uname -r)
if ventoy_os_install_dmsetup_by_unsquashfs $1 $vtKerVer; then
vtlog "unsquashfs success"
else
if modprobe fuse 2>>$VTLOG; then
ventoy_os_install_dmsetup_by_fuse $1 $vtKerVer
fi
fi
}
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_os_install_dmsetup $vtdiskname
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
if ! [ -e $VTOY_DM_PATH ]; then
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 0666 $VTOY_DM_PATH b $blkdev_num
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,29 @@
#!/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 $GREP -q 'FILTERED_LIST=[^a-zA-Z0-9_]*$' /init; then
$SED 's#FILTERED_LIST=[^a-zA-Z0-9_]*$#FILTERED_LIST=/dev/mapper/ventoy#' -i /init
elif $GREP -q '\[ "$FILTERED_LIST" \]' /init; then
$SED '/\[ "$FILTERED_LIST" \]/i\ FILTERED_LIST="/dev/mapper/ventoy $FILTERED_LIST"' -i /init
fi
$SED -i "/_search_for_boot_device_/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/antix-disk.sh" /init
# for debug
#$SED -i "/^linuxfs_error/a\exec $VTOY_PATH/busybox/sh" /init

View File

@@ -0,0 +1,21 @@
#!/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_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"

View File

@@ -0,0 +1,111 @@
#!/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() {
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 ' dmsetup.*\.udeb' $VTOY_PATH/iso_file_list)
if [ $? -eq 0 ]; then
install_udeb_from_line "$LINE" ${vt_usb_disk}
fi
# install libdevmapper
LINE=$($GREP ' libdevmapper.*\.udeb' $VTOY_PATH/iso_file_list)
if [ $? -eq 0 ]; then
install_udeb_from_line "$LINE" ${vt_usb_disk}
fi
# install md-modules
LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
if [ $? -eq 0 ]; then
install_udeb_from_line "$LINE" ${vt_usb_disk}
fi
# insmod md-mod if needed
if $GREP -q 'device-mapper' /proc/devices; then
vtlog "device mapper module is loaded"
else
vtlog"device mapper module is NOT loaded, now load it..."
VER=$($BUSYBOX_PATH/uname -r)
KO=$($FIND /lib/modules/$VER/kernel/drivers/md -name "dm-mod*")
vtlog "KO=$KO"
insmod $KO
fi
vtlog "dmsetup install finish, now check it..."
if dmsetup info >> $VTLOG 2>&1; then
vtlog "dmsetup work ok"
else
vtlog "dmsetup not work, now try to load eglibc ..."
# install eglibc (some ubuntu 32 bit version need it)
LINE=$($GREP 'libc6-.*\.udeb' $VTOY_PATH/iso_file_list)
if [ $? -eq 0 ]; then
install_udeb_from_line "$LINE" ${vt_usb_disk}
fi
if dmsetup info >> $VTLOG 2>&1; then
vtlog "dmsetup work ok after retry"
else
vtlog "dmsetup still not work after retry"
fi
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 $*
#
# Some distro default only accept usb partitions as install medium.
# So if ventoy is installed on a non-USB device, we just mount /cdrom here except
# for these has boot=live or boot=casper parameter in cmdline
#
if echo $ID_BUS | $GREP -q -i usb; then
vtlog "$1 is USB device"
else
vtlog "$1 is NOT USB device (bus $ID_BUS)"
if $EGREP -q 'boot=|casper' /proc/cmdline; then
vtlog "boot=, or casper, don't mount"
else
vtlog "No boot param, need to mount"
$BUSYBOX_PATH/mkdir /cdrom
$BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH /cdrom
fi
fi
# OK finish
set_ventoy_hook_finish

View File

@@ -0,0 +1,31 @@
#!/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
DISTRO='default'
if [ -e /etc/initrd-release ]; then
if $EGREP -q "ID=.*antix|ID=.*mx" /etc/initrd-release; then
DISTRO='antix'
fi
fi
echo "##### distribution = $DISTRO ######" >> $VTLOG
. $VTOY_PATH/hook/debian/${DISTRO}-hook.sh

View File

@@ -0,0 +1,42 @@
# Copyright (C) 2009 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
# Udev rules for device-mapper devices.
#
# These rules create symlinks in /dev/disk directory.
# Symlinks that depend on probing filesystem type,
# label and uuid are created only if the device is not
# suspended.
# "add" event is processed on coldplug only!
ACTION!="add|change", GOTO="dm_end"
ENV{DM_UDEV_RULES_VSN}!="?*", GOTO="dm_end"
ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}=="1", GOTO="dm_end"
SYMLINK+="disk/by-id/dm-name-$env{DM_NAME}"
ENV{DM_UUID}=="?*", SYMLINK+="disk/by-id/dm-uuid-$env{DM_UUID}"
ENV{DM_SUSPENDED}=="1", GOTO="dm_end"
ENV{DM_NOSCAN}=="1", GOTO="dm_watch"
IMPORT{builtin}="blkid"
ENV{DM_UDEV_LOW_PRIORITY_FLAG}=="1", OPTIONS="link_priority=-100"
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}"
ENV{ID_PART_ENTRY_UUID}=="?*", SYMLINK+="disk/by-partuuid/$env{ID_PART_ENTRY_UUID}"
ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK+="disk/by-partlabel/$env{ID_PART_ENTRY_NAME}"
ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_GPT_AUTO_ROOT}=="1", SYMLINK+="gpt-auto-root"
# Add inotify watch to track changes on this device.
# Using the watch rule is not optimal - it generates a lot of spurious
# and useless events whenever the device opened for read-write is closed.
# The best would be to generete the event directly in the tool changing
# relevant information so only relevant events will be processed
# (like creating a filesystem, changing filesystem label etc.).
#
# But let's use this until we have something better...
LABEL="dm_watch"
OPTIONS+="watch"
LABEL="dm_end"

View File

@@ -0,0 +1,30 @@
#!/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

View File

@@ -0,0 +1,24 @@
#!/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"

View File

@@ -0,0 +1,36 @@
#!/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
# Just for KVM test enviroment
$BUSYBOX_PATH/modprobe virtio_blk 2>/dev/null
$BUSYBOX_PATH/modprobe virtio_pci 2>/dev/null
for i in 0 1 2 3 4 5 6 7 8 9; do
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "wait for disk ..."
$SLEEP 2
else
break
fi
done
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"

View File

@@ -0,0 +1,27 @@
#!/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
if [ -d /etc/udev/rules.d ]; then
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
else
$SED "/mdev *-s/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
fi

View File

@@ -0,0 +1,39 @@
#!/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
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
modprobe fuse
mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso
vtoydm -p -f $VTOY_PATH/ventoy_image_map -d "/dev/${1:0:-1}" > $VTOY_PATH/ventoy_dm_table
vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
# OK finish
set_ventoy_hook_finish
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,6 @@
#!/ventoy/busybox/sh
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/kaos/udev_disk_hook.sh %k"

View File

@@ -0,0 +1,40 @@
#!/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 $*
#
# cheatcode for mageia
#
# From mageia/soft/drakx/mdk-stage1 source code, we see that the stage1 binary will search
# /tmp/syslog file to determin whether there is a DAC960 cdrom in the system.
# So we insert some string to /tmp/syslog file to cheat the stage1 program.
#
$BUSYBOX_PATH/mkdir -p /dev/rd
ventoy_copy_device_mapper "/dev/rd/ventoy"
echo 'ventoy cheatcode /dev/rd/ventoy: model' >> /tmp/syslog
# OK finish
set_ventoy_hook_finish

View File

@@ -0,0 +1,7 @@
#!/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"

View File

@@ -0,0 +1,33 @@
#!/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"

View File

@@ -0,0 +1,30 @@
#!/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

View File

@@ -0,0 +1,25 @@
#!/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"

View File

@@ -0,0 +1,72 @@
#!/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

View File

@@ -0,0 +1,57 @@
#!/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

View File

@@ -0,0 +1,23 @@
#!/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/

View File

@@ -0,0 +1,70 @@
#!/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

View File

@@ -0,0 +1,20 @@
#!/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

View File

@@ -0,0 +1,85 @@
#!/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

View File

@@ -0,0 +1,27 @@
#!/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"

View File

@@ -0,0 +1,29 @@
#!/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

View File

@@ -0,0 +1,41 @@
#!/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

View File

@@ -0,0 +1,8 @@
#!/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"

View File

@@ -0,0 +1,60 @@
#!/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

View File

@@ -0,0 +1,24 @@
#!/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"

View File

@@ -0,0 +1,45 @@
#!/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

View File

@@ -0,0 +1,24 @@
#!/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"

View File

@@ -0,0 +1,424 @@
#!/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
}

View File

@@ -0,0 +1,98 @@
#!/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"
}

View File

@@ -0,0 +1,32 @@
#!/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 $*
# trick for xen6
ventoy_copy_device_mapper /dev/sr7
# OK finish
set_ventoy_hook_finish

View File

@@ -0,0 +1,24 @@
#!/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/xen/udev_disk_hook.sh %k"

154
IMG/cpio/ventoy/init Normal file
View File

@@ -0,0 +1,154 @@
#!/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/>.
#
#************************************************************************************
###################################################################
# #
# Step 1 : parse kernel debug parameter #
# #
####################################################################
mkdir /proc; mount -t proc proc /proc
vtcmdline=$(cat /proc/cmdline)
vtkerver=$(cat /proc/version)
umount /proc; rm -rf /proc
echo "kenel version=$vtkerver" >>$VTLOG
echo "kenel cmdline=$vtcmdline" >>$VTLOG
#break here for debug
if [ "$VTOY_BREAK_LEVEL" = "01" ] || [ "$VTOY_BREAK_LEVEL" = "11" ]; then
sleep 5
echo -e "\n\n\033[32m ################################################# \033[0m"
echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
echo -e "\033[32m ################################################# \033[0m \n"
if [ "$VTOY_BREAK_LEVEL" = "11" ]; then
cat $VTLOG
fi
exec $BUSYBOX_PATH/sh
fi
####################################################################
# #
# Step 2 : extract real initramfs to / #
# #
####################################################################
cd /
rm -rf /init /linuxrc /sbin /dev/ /root
ventoy_is_initrd_ramdisk() {
#As I known, PCLinuxOS use ramdisk
if echo $vtkerver | grep -i -q 'PCLinuxOS'; then
true
else
false
fi
}
# param: file skip magic tmp
ventoy_unpack_initramfs() {
vtfile=$1; vtskip=$2; vtmagic=$3; vttmp=$4
echo "=====ventoy_unpack_initramfs: #$*#" >> $VTLOG
for vtx in '1F8B zcat' '1F9E zcat' '425A bzcat' '5D00 lzcat' 'FD37 xzcat' '894C lzopcat' '0221 lz4cat' '28B5 zstdcat' '3037 cat'; do
if [ "${vtx:0:4}" = "${vtmagic:0:4}" ]; then
echo "vtx=$vtx" >> $VTLOG
if [ $vtskip -eq 0 ]; then
${vtx:5} $vtfile | (cpio -idm 2>>$VTLOG; cat > $vttmp)
else
dd if=$vtfile skip=$vtskip iflag=skip_bytes status=none | ${vtx:5} | (cpio -idm 2>>$VTLOG; cat > $vttmp)
fi
break
fi
done
}
# param: file magic tmp
ventoy_unpack_initrd() {
vtfile=$1; vtmagic=$2; vttmp=$3
echo "=====ventoy_unpack_initrd: #$*#" >> $VTLOG
for vtx in '1F8B zcat' '1F9E zcat' '425A bzcat' '5D00 lzcat' 'FD37 xzcat' '894C lzopcat' '0221 lz4cat' '28B5 zstdcat' '3037 cat'; do
if [ "${vtx:0:4}" = "${vtmagic:0:4}" ]; then
echo "vtx=$vtx" >> $VTLOG
${vtx:5} $vtfile > $vttmp
break
fi
done
}
# This export is for busybox cpio command
export EXTRACT_UNSAFE_SYMLINKS=1
for vtfile in $(ls /initrd*); do
#decompress first initrd
vtmagic=$(hexdump -n 2 -e '2/1 "%02X"' $vtfile)
if ventoy_is_initrd_ramdisk; then
ventoy_unpack_initrd $vtfile $vtmagic ${vtfile}_tmp
mv ${vtfile}_tmp $vtfile
break
else
ventoy_unpack_initramfs $vtfile 0 $vtmagic ${vtfile}_tmp
fi
#only for cpio,cpio,...,initrd sequence, initrd,cpio or initrd,initrd sequence is not supported
while [ -e ${vtfile}_tmp ] && [ $(stat -c '%s' ${vtfile}_tmp) -gt 512 ]; do
mv ${vtfile}_tmp $vtfile
vtdump=$(hexdump -n 512 -e '512/1 "%02X"' $vtfile)
vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
let vtoffset="(${#vtdump}-${#vtmagic})/2"
if [ -z "$vtmagic" ]; then
echo "terminate with all zero data file" >> $VTLOG
break
fi
ventoy_unpack_initramfs $vtfile $vtoffset ${vtmagic:0:4} ${vtfile}_tmp
done
rm -f $vtfile ${vtfile}_tmp
done
#break here for debug
if [ "$VTOY_BREAK_LEVEL" = "02" ] || [ "$VTOY_BREAK_LEVEL" = "12" ]; then
sleep 5
echo -e "\n\n\033[32m ################################################# \033[0m"
echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
echo -e "\033[32m ################################################# \033[0m \n"
if [ "$VTOY_BREAK_LEVEL" = "12" ]; then
cat $VTOY_PATH/log
fi
exec $BUSYBOX_PATH/sh
fi
####################################################################
# #
# Step 3 : Hand over to ventoy.sh #
# #
####################################################################
echo "Now hand over to ventoy.sh" >>$VTLOG
. $VTOY_PATH/tool/vtoytool_install.sh
export PATH=$VTOY_ORG_PATH
exec $BUSYBOX_PATH/sh $VTOY_PATH/ventoy.sh

BIN
IMG/cpio/ventoy/tool/ar Normal file

Binary file not shown.

Binary file not shown.

BIN
IMG/cpio/ventoy/tool/lz4cat Normal file

Binary file not shown.

View File

@@ -0,0 +1,20 @@
#!/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/>.
#
#************************************************************************************
exec /ventoy/busybox/sh

View File

@@ -0,0 +1,54 @@
#!/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/>.
#
#************************************************************************************
echo "#### install vtoytool #####" >> $VTLOG
if ! [ -e $BUSYBOX_PATH/ar ]; then
$BUSYBOX_PATH/ln -s $VTOY_PATH/tool/ar $BUSYBOX_PATH/ar
fi
for vtdir in $(ls $VTOY_PATH/tool/vtoytool/); do
echo "try $VTOY_PATH/tool/vtoytool/$vtdir/ ..." >> $VTLOG
if $VTOY_PATH/tool/vtoytool/$vtdir/vtoytool_64 --install 2>>$VTLOG; then
echo "vtoytool_64 OK" >> $VTLOG
break
fi
if $VTOY_PATH/tool/vtoytool/$vtdir/vtoytool_32 --install 2>>$VTLOG; then
echo "vtoytool_32 OK" >> $VTLOG
break
fi
done
if $VTOY_PATH/tool/vtoy_fuse_iso_64 -t 2>>$VTLOG; then
echo "use vtoy_fuse_iso_64" >>$VTLOG
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/vtoy_fuse_iso_64 $VTOY_PATH/tool/vtoy_fuse_iso
else
echo "use vtoy_fuse_iso_32" >>$VTLOG
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/vtoy_fuse_iso_32 $VTOY_PATH/tool/vtoy_fuse_iso
fi
if $VTOY_PATH/tool/unsquashfs_64 -t 2>>$VTLOG; then
echo "use unsquashfs_64" >>$VTLOG
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/unsquashfs_64 $VTOY_PATH/tool/vtoy_unsquashfs
else
echo "use unsquashfs_32" >>$VTLOG
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/unsquashfs_32 $VTOY_PATH/tool/vtoy_unsquashfs
fi

Binary file not shown.

203
IMG/cpio/ventoy/ventoy.sh Normal file
View File

@@ -0,0 +1,203 @@
#!/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/>.
#
#************************************************************************************
####################################################################
# #
# Step 1 : Parse kernel parameter #
# #
####################################################################
if ! [ -e /proc ]; then
$BUSYBOX_PATH/mkdir /proc
rmproc='Y'
fi
$BUSYBOX_PATH/mount -t proc proc /proc
# vtinit=xxx to replace rdinit=xxx
vtcmdline=$($CAT /proc/cmdline)
for i in $vtcmdline; do
if echo $i | $GREP -q vtinit; then
user_rdinit=${i#vtinit=}
echo "user set user_rdinit=${user_rdinit}" >>$VTLOG
fi
done
####################################################################
# #
# Step 2 : Do OS specific hook #
# #
####################################################################
ventoy_get_os_type() {
echo "kernel version" >> $VTLOG
$CAT /proc/version >> $VTLOG
# rhel5/CentOS5 and all other distributions based on them
if $GREP -q 'el5' /proc/version; then
echo 'rhel5'; return
# rhel6/CentOS6 and all other distributions based on them
elif $GREP -q 'el6' /proc/version; then
echo 'rhel6'; return
# rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
elif $GREP -q 'el[78]' /proc/version; then
echo 'rhel7'; return
# Maybe rhel9 rhel1x use the same way? Who knows!
elif $EGREP -q 'el9|el1[0-9]' /proc/version; then
echo 'rhel7'; return
# Fedora : do the same process with rhel7
elif $GREP -q '\.fc[0-9][0-9]\.' /proc/version; then
echo 'rhel7'; return
# Debian :
elif $GREP -q '[Dd]ebian' /proc/version; then
echo 'debian'; return
# Ubuntu : do the same process with debian
elif $GREP -q '[Uu]buntu' /proc/version; then
echo 'debian'; return
# Deepin : do the same process with debian
elif $GREP -q '[Dd]eepin' /proc/version; then
echo 'debian'; return
# SUSE
elif $GREP -q 'SUSE' /proc/version; then
echo 'suse'; return
# ArchLinux
elif $EGREP -q 'archlinux|ARCH' /proc/version; then
echo 'arch'; return
# gentoo
elif $EGREP -q '[Gg]entoo' /proc/version; then
echo 'gentoo'; return
# TinyCore
elif $EGREP -q 'tinycore' /proc/version; then
echo 'tinycore'; return
# manjaro
elif $EGREP -q 'manjaro|MANJARO' /proc/version; then
echo 'manjaro'; return
# mageia
elif $EGREP -q 'mageia' /proc/version; then
echo 'mageia'; return
# pclinux OS
elif $GREP -i -q 'PCLinuxOS' /proc/version; then
echo 'pclos'; return
# KaOS
elif $GREP -i -q 'kaos' /proc/version; then
echo 'kaos'; return
# Alpine
elif $GREP -q 'Alpine' /proc/version; then
echo 'alpine'; return
# NixOS
elif $GREP -i -q 'NixOS' /proc/version; then
echo 'nixos'; return
fi
if [ -e /lib/debian-installer ]; then
echo 'debian'; return
fi
if [ -e /etc/os-release ]; then
if $GREP -q 'XenServer' /etc/os-release; then
echo 'xen'; return
elif $GREP -q 'SUSE ' /etc/os-release; then
echo 'suse'; return
fi
fi
if $BUSYBOX_PATH/dmesg | $GREP -q -m1 "Xen:"; then
echo 'xen'; return
fi
if [ -e /etc/HOSTNAME ] && $GREP -i -q 'slackware' /etc/HOSTNAME; then
echo 'slackware'; return
fi
echo "default"
}
VTOS=$(ventoy_get_os_type)
echo "OS=###${VTOS}###" >>$VTLOG
if [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
$BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
fi
####################################################################
# #
# Step 3 : Check for debug break #
# #
####################################################################
if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
$SLEEP 5
echo -e "\n\n\033[32m ################################################# \033[0m"
echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
echo -e "\033[32m ################################################# \033[0m \n"
if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
$CAT $VTOY_PATH/log
fi
exec $BUSYBOX_PATH/sh
fi
####################################################################
# #
# Step 4 : Hand over to real init #
# #
####################################################################
$BUSYBOX_PATH/umount /proc
if [ "$rmproc" = "Y" ]; then
$BUSYBOX_PATH/rm -rf /proc
fi
cd /
unset VTOY_PATH VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
if [ -d /ventoy_rdroot ]; then
if [ -e "/ventoy_rdroot$vtinit" ]; then
# switch_root will check /init file, this is a cheat code
echo 'switch_root' > /init
exec $BUSYBOX_PATH/switch_root /ventoy_rdroot "$vtinit"
fi
else
if [ -e "$vtinit" ];then
exec "$vtinit"
fi
fi
done
# Should never reach here
echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
exec $BUSYBOX_PATH/sh