Porting Ventoy

I would like to have a version of Ventoy which works on FreeBSD.

I'm only interested in a text mode version, and hopefully can manage to deal with the shell scripts involved, but a number of utilities involved are compiled, so would appreciate some guidance.

The application is available from https://sourceforge.net/projects/ventoy/files/v1.0.96

git clone https://github.com/ventoy/Ventoy.git retrieves the source code.

For some reason the application includes Ventoy2Disk.sh a shell script, whereas the source has a Ventoy2Disk.c which needs to be compiled.
What I need is a compiled is vtoycli. There is a vtoycli/ which includes a vtoycli.c.

If I enter this directory and run gmake vtoycli should i expect to create a FreeBSD binary?

Apologies for not being familiar with compiling stuff... I started off programming using IBM BAL a very long time ago...
 
I don't see where a FreeBSD version is included for compilation in the sourceforge code you linked. You might be able to ticker around and get this work, but I don't foresee much demand for this becoming a port as dd and other utilities for making bootable ISOs from FreeBSD already exist.
 
I don't see where a FreeBSD version is included for compilation in the sourceforge code you linked. You might be able to ticker around and get this work, but I don't foresee much demand for this becoming a port as dd and other utilities for making bootable ISOs from FreeBSD already exist.
The source code cannot be compile on FreeBSD asis. It needs to be ported, as it's full of Linuxisms. The shell scripts can be made to work on FreeBSD quite easily, but unfortunately the scripts rely on binary executables. If I could work out what some of them do, it may be simple enough to re-write them as shell scripts.

Whilst there are plenty of utilities for making bootable ISO's, I haven't come across anything as easy to use as Ventoy, which basically allows you to dump ISOs into the first partition of the Ventoy device, and you just select which to boot from a provided list. FreeBSD and mfsbsd ISO's boot without a problem.
 
I would like to have a version of Ventoy which works on FreeBSD.

I'm only interested in a text mode version, and hopefully can manage to deal with the shell scripts involved, but a number of utilities involved are compiled, so would appreciate some guidance.

The application is available from https://sourceforge.net/projects/ventoy/files/v1.0.96

git clone https://github.com/ventoy/Ventoy.git retrieves the source code.

For some reason the application includes Ventoy2Disk.sh a shell script, whereas the source has a Ventoy2Disk.c which needs to be compiled.
What I need is a compiled is vtoycli. There is a vtoycli/ which includes a vtoycli.c.

If I enter this directory and run gmake vtoycli should i expect to create a FreeBSD binary?

Apologies for not being familiar with compiling stuff... I started off programming using IBM BAL a very long time ago...
Patches are always welcome. This is how I got my FreeBSD commit bit. One too many patches and they shoved a commit bit in my direction.

Like you I started out on IBM mainframe, working on key zero supervisor state (that's kernel mode for non-IBM types) extensions to MVS and JES, including cross memory services (shared memory in multiprocessor machines) many many moons ago (over 500 moons ago), pivoting to UNIX about 20 years after my career began. All my work was in IBM BAL, and, JCL. So yes, we old dogs can learn new tricks.
 
A Ventoy installation basically consists of three essential parts. MBR, a holding partition for ISOs and a system partition. The rest of any device can be used for installing any OS you like,


1698183280869.png
 
This is Part2:-

file -s /dev/da0p2


Code:
/dev/da0p2: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", root entries 512, Media descriptor 0xf8, sectors/FAT 254, sectors/track 63, heads 255, sectors 65536 (volumes > 32 MB), serial number 0xb2c840d2, label: "VTOYEFI    ", FAT (16 bit)

How do I create such a partition using gpart?

gpart add -t ms-basic-data -s 32MB -l 'VTOYEFI' da0 ?
 
Using a virgin USB disk,

First we create a GPT partition table:
gpart create -s gpt da0

Next we need to create the PMBR armour. The armour is an MBR partition written to the first sector of the disk:
gpart bootcode -b /boot/pmbr da0

A note about PMBR armour. It's not needed except to protect against unwitting fools who issue fdisk (on any O/S) against it, assume there's nothing there because fdisk can't see GPT partitions, choosing to blow it away to put an MBR there and use the disk for some other purpose.*

Now create your 32 MB FAT partition:
gpart add -t ms-basic-data -i 2 -s 32mb -b $((32*1048576*2-33*1024*2)) /dev/da0

Addjust the start of your second partition as needed.

Finally create your data partition, using a Linux FS as an example. It will consume the remaining space in the centre of the disk:
gpart add -t linux-data -i 1 /dev/da0

Your partition table looks like this:

Code:
# gpart show /dev/da0
=>      40  67108784  da0 GPT  (32G)
        40        24                  - free -  (12K)
        64  67041216               1  linux-data  (32G)
  67041280     65536               2  ms-basic-data  (32M)
  67106816      2008                  - free -  (1.0M)
#
Personally, I'd create the first partition first:

gpart add -t linux-data -i 1 -s $((32*1048576*2-33*1024*2)) /dev/da0

Then create the Ventoy partition:
gpart add -t ms-basic-data -i 2 /dev/da0

Giving this,
Code:
# gpart show /dev/da0
=>      40  67108784  da0  GPT  (32G)
        40        24                  - free -  (12K)
        64  67041280               1  linux-data  (32G)
  67041344     67456               2  ms-basic-data  (33M)
  67108800        24                  - free -  (12K)
#

If Ventoy expects a 32 MB partition at the end of your disk you could still do,
gpart add -t ms-basic-data -i 2 -s 32mb /dev/da0

But that would give you,

Code:
# gpart show /dev/da0
=>      40  67108784  da0  GPT  (32G)
        40        24                  - free -  (12K)
        64  67041280               1  linux-data  (32G)
  67041344     65536               2  ms-basic-data  (32M)
  67106880      1944                  - free -  (972K)

slippy#

This should get you started.

* At one place they put LVM PVs on raw disks without any partition table. The advantage is that one can resize an LVM PV without having to muck around with partition tables. If one doesn't have the correct tool one needs to reboot Linux after running fdisk because the kernel will not re-read the partition table without the correct tool installed, and many Linux systems don't have the tool so one needs to reboot. The downside of this approach is that sure you save a reboot but some fool can come along and blow away the data on a disk. This happened when a DBA put Oracle ASM on a disk that happened to contain an LVM PV. That didn't go too well as it not only corrupted the EXT4 on the LVM but also completely corrupted his Oracle database. So yeah, an MBR or PMBR is always a good idea. It's a red flag for fools doing foolish things.
 
Now create your 32 MB FAT partition:
gpart add -t ms-basic-data -i 2 -s 32mb -b $((32*1048576*2-33*1024*2)) /dev/da0


This should get you started.

Could you explain what is behind this figure?

I have manage to create partitions 1 and 2 and have manged to populate P2, the VTOYEFI partition, but what I'm missing a boot loader...

I was wondering whether to dd the 1MB at the start of an existing Ventoy to a virgin disk.
 
It looks like I need to install the Ventoy boot loader.....

AFAICT the required code is here:


lines 332->

Bash:
vtinfo "writing data to disk ..."
    dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446

    if [ -n "$VTGPT" ]; then
        echo -en '\x22' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92
        xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2014 seek=34
        echo -en '\x23' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none
    else
        xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
    fi
Can't get this working on FreeBSD.

Any suggestions?
 
BTW, there was discussion this morning on the -current mailing list about native support for ventoy in ports or base.
 
Could you explain what is behind this figure?

I have manage to create partitions 1 and 2 and have manged to populate P2, the VTOYEFI partition, but what I'm missing a boot loader...

I was wondering whether to dd the 1MB at the start of an existing Ventoy to a virgin disk.
This creates your partition #2.

We're letting the shell do the math rather than do it in our head. Try,

echo $((32*1048576*2-33*1024*2))

I don't know enough about ventoy to comment about whether you should dd anything to the start of your disk. If you do you will need to force geom to re-taste the disk.
 
This creates your partition #2.

We're letting the shell do the math rather than do it in our head. Try,

echo $((32*1048576*2-33*1024*2))

I don't know enough about ventoy to comment about whether you should dd anything to the start of your disk. If you do you will need to force geom to re-taste the disk.
AFAICT Partition #2 is simply a 32MB exfat partition populated by

ventoy-1.0.96/ventoy/ventoy.disk.img.xz

in https://sourceforge.net/projects/ventoy/files/v1.0.96
 
Correct. The graphic you posted previously in this thread clearly identified this.

How you populate this should be described by the ventoy documentation.

Looking through various shell scripts it looks like the boot loader is created as per code in

Thread 90697/post-626350

Unfortunately I don't know how to code this in FreeBSD.
 
Returning to an old thread, it appears from my understanding that there is, or was a FreeBSD boot loader for Ventoy, going by:-


Has anyone come across a /boot/kernel/geom_ventoy.ko?
 
Returning to an old thread, it appears from my understanding that there is, or was a FreeBSD boot loader for Ventoy, going by:-

Has anyone come across a /boot/kernel/geom_ventoy.ko?

Bash:
wget https://download.freebsd.org/releases/amd64/14.0-RC4/src.txz # NOTE: Change accordingly
sudo tar xz src.txz  -C /
git clone https://github.com/ventoy/Ventoy/
cd ./Ventoy/Unix/ventoy_unix_src/FreeBSD/geom_ventoy_src/13.x/sys/modules/geom/geom_ventoy
mkdir -p geom/ventoy
cp ../../../geom/ventoy/* geom/ventoy
cp ../../../geom/ventoy/* .
export CC=$(which clang)
make
xz geom_ventoy.ko
 
I'm trying to understand the code in

from around line 332

I've commented a few lines to try and clarify what is going on. My guess is that this is where Ventoy writes a bootloader to the disk but am unsure if I have understood/interpreted the code properly.

Any comments wold be appreciated.

Code:
# ./boot/boot.img  is 512B                                                                                                                                                                                                       
# file -s boot.img -> boot.img: DOS/MBR boot sector                                                                                                                                                                            
# ./boot/core.img  is 1048064B                                                                                                                                                                                                       
                                                                                                                                                                                                                                
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446                                                                                                                                       
                                                                                                                                                                                                                                
# 446B of boot.img written to start of device                                                                                                                                                                                   
                                                                                                                                                                                                                                
    if [ -n "$VTGPT" ]; then                                                                                                                                                                                                     
                                                                                                                                                                                                                                
# if GPT                                                                                                                                                                                                                         
                                                                                                                                                                                                                                
#       echo -en '\x22' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92                                                                                                                                echo -en '"' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92                                                                                                                             
# insert '"' in position 92 of device                                                                                                                                                                                           
xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2014 seek=34                                                                                                    
# insert  512 * 2014 (1031168 Bytes) of extracted core.img at position 34 of device                                                                                                                       

#        echo -en '\x23' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none                                                                                                               
          echo -en '#' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none                                                                                                                    
# insert '#' in position 17908 of device                                                                                                                                                                                         
else                                                                                                                                                                                                                             
# else MBR                                                                                                                                                                                                                       
xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1                                                                                                     
# extract core.img (512 * 2047 = 1048064B)  to device
 
Code:
vtinfo "writing data to disk ..."
    dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446
    xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1

Can someone clarify? ...

Am I right interpreting this as 446 bytes of boot.img gets copied to the start of $DISK and then core.img gets copied to $DISK starting from position 513? (BTW this is from a Linux script)
 
Could someone check this code for any obvious errors in building a Ventoy boot device?

(ISO points at any old ISO you have locally...)

Bash:
#!/bin/sh                                                                                                                                                                                                                       
#* fetch ventoy                                                                                                                                                                                                                 
echo 'hello'                                                                                                                                                                                                                     
DISK=da0                                                                                                                                                                                                                         
MBR=boot/boot.img                                                                                                                                                                                                               
BOOTLDR=boot/core.img.xz                                                                                                                                                                                                         
VTPART=ventoy/ventoy.disk.img.xz                                                                                                                                                                                                 
ISO=/net/repo/software/iso/mfsbsd-mini-11.2-RELEASE-amd64.iso                                                                                                                                                   gpart destroy -F $DISK                                                                                                                                                                                                           
gpart create -s MBR $DISK                                                                                                                                                                                                       
SRC=file:////net/repo/software/iso/                                                                                                                                                                                             
SRC=https://mirrors.sdu.edu.cn/github-release/ventoy_Ventoy/v1.0.96/                                                                                                                                           WRKDIR=/tmp/VT-wrk                                                                                                                                                                                                               
rm -R /tmp/VT-wrk/                                                                                                                                                                                                               
mkdir /tmp/VT-wrk                                                                                                                                                                                                               
cd /tmp/VT-wrk                                                                                                                                                                                                                   
fetch -o - ${SRC}ventoy-1.0.96-linux.tar.gz | tar zxf - -C $WRKDIR                                                                                                                                                       
cd $WRKDIR/ventoy-1.0.96                                                                                                                                                                                                         
gpart show $DISK                                                                                                                                                                                                                 
gpart destroy -F $DISK                                                                                                                                                                                                           
gpart create -s MBR $DISK                                                                                                                                                                                                       
DISK=/dev/$DISK                                                                                                                                                                                                                 
echo $DISK                                                                                                                                                                                                                       
gpart bootcode -b $MBR $DISK                                                                                                                                                                                                     
xzcat $BOOTLDR | dd status=progress of=$DISK bs=512 count=2047 seek=1                                                                                                                                 
export PART=`gpart add -t fat32 -s 5G da0 | cut -d ' ' -f 1`                                                                                                                                                                     
echo $PART                                                                                                                                                                                                                       
newfs_msdos /dev/$PART                                                                                                                                                                                                           
mount -t msdosfs /dev/$PART /media                                                                                                                                                                                               
cp $ISO /media                                                                                                                                                                                                                   
umount /media/                                                                                                                                                                                                                   
export PART=`gpart add -t fat32 -s 32M da0 | cut -d ' ' -f 1`                                                                                                                                                                 
echo $PART                                                                                                                                                                                                                       
newfs_msdos /dev/$PART                                                                                                                                                                                                           
gpart show $DISK                                                                                                                                                                                                                 
xzcat $VTPART | dd status=progress of=$DISK bs=512                                                                                                                                                                         
exit

I came up with this code which I thought would create a Ventoy bootable USB stick in that it creates the three sections which such a device has, ie a boot loader, storage for ISO's (Part1) and the Ventoy ISO launcher (Part 2), but there is something missing which I can't figure out.

When attempting to boot I get

VTloading.......
error: out of memory.
Incompatible license.
Aborted. Press any key to exit.

This is for an MBR partitioned device.

I don't know if the error is because missing labels on the partitions.

This is how my device is partitioned:

Code:
root@X1:~ # gpart show da0
=>      63  61439937  da0  MBR  (29G)
        63  10485760    1  fat32  (5.0G)
  10485823     65536    2  fat32  (32M)
  10551359  50888641       - free -  (24G)

root@X1:~ # file -s /dev/da0s1
/dev/da0s1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "BSD4.4  ", sectors/cluster 64, sectors/track 63, heads 255, sectors 10485760 (volumes > 32 MB), FAT (32 bit), sectors/FAT 1280, serial number 0x89ca140a, unlabeled
root@X1:~ # file -s /dev/da0s2
/dev/da0s2: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", root entries 512, Media descriptor 0xf8, sectors/FAT 254, sectors/track 63, heads 255, sectors 65536 (volumes > 32 MB), serial number 0xb2c840d2, label: "VTOYEFI    ", FAT (16 bit)
root@X1:~ # file -s /dev/da0
/dev/da0: DOS/MBR boot sector
 
Returning to a previous thread....

I'm still struggling to follow some code around line 332.

Code:
if [ -n "$VTGPT" ]; then
        echo -en '\x22' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92
        xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2014 seek=34
        echo -en '\x23' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none
    else


My understanding is that:

1. The value '\x22' is placed in position 92 of the device.
2. core.img.xz is extracted to position 34 of the device, which seems to overlap the mbr.
core.img, when extracted is 1048064 bytes in size, but (bs * count = 1031168). What happens to the remaining 16896 bytes?
3. The value '\x23' is placed in position 17908 of the device.

Is my understanding correct?
 
Here is some work in (very slow) progress:-


Bash:
#!/bin/sh -x
#* fetch ventoy
echo 'hello'
DISK=da0
MBR=boot/boot.img
BOOTLDR=boot/core.img.xz
VTPART=ventoy/ventoy.disk.img.xz
VERS=1.0.97
SRC=https://github.com/ventoy/Ventoy/releases/download/v$VERS/
WRKDIR=/tmp/VT-wrk
rm -R /tmp/VT-wrk/
mkdir /tmp/VT-wrk
cd /tmp/VT-wrk
fetch -o - ${SRC}ventoy-${VERS}-linux.tar.gz | tar zxf - -C $WRKDIR
cd $WRKDIR/ventoy-$VERS
gpart show $DISK
gpart destroy -F $DISK
gpart create -s MBR $DISK
DISK=/dev/$DISK
echo $DISK
gpart bootcode -b $MBR $DISK


At least it comes up with VTLoading....... on boot before going to a grub> prompt

Hopefully, I'll be able to decipher a bit more before long...
 
Back
Top