Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". #19635

Closed
NoteAfterNote opened this issue Apr 1, 2024 · 8 comments
Labels
information Informational post.

Comments

@NoteAfterNote
Copy link

NoteAfterNote commented Apr 1, 2024

What's the correct way to use termux-usb to solve this?

Update-1: The correct syntax is 'usbredirect --device "/dev/bus/usb/001/031" --to 127.0.0.1:23456'. Now 'termux-usb -e usbredirect --device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' returns "termux-usb: illegal option --".

Update-2: Workaround-version-2 passes device bus-string by hard-coding the device bus-string in a separate shell script: echo 'FULL-PATH/usbredirect --device /dev/bus/usb/001/031 --to 127.0.0.1:23456' > u.sh; chmod a+rx u.sh ; termux-usb -e FULL-PATH/u.sh "/dev/bus/usb/001/031" and printf argv[2] in usbredirect displays the hard-coded bus-string.

Update-3: Replaced usbredirect.c source code with the latest version. Used the suggestion from @Grimler91 at https://github.com/termux/termux-packages/issues/19635#issuecomment-2030116274(#19635 (comment)) and the result is posted in the "Termux session: testing usbredirect" section. Major progress and very good news!

Update-4: Replaced usbredirect.c with the latest version.

Update-5: It works! 'termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/003 --as 127.0.0.1:23456" /dev/bus/usb/001/003'. Thank you Termux Team!

Update-6 (using the QEMU Linux server setup in "Excerpts from the Termux session using QEMU and a USB device"): 'mkfs.ext4 /dev/sda' -- works. Create three partitions (two type 83 partitions and one type 7 parition) with 'fdisk /dev/sda' -- works. 'cryptsetup luksFormat /dev/sda1 ; cryptsetup luksOpen /dev/sda1 v1 ; mkfs.ext4 /dev/mapper/v1 ; mount /dev/mapper/v1 /root/1 ; ls -l /root/1 ; chown 1100:1100 /root/1/. ; dd if=/dev/zero of=1gb bs=1M count=1024 status=progress ; sha256sum 1gb > checksum ; ls -l /root/1 ; umount /root/1 ; cryptsetup luksClose v1' -- works. Make sure the USB flash drive's light is not blinking . . . sure there is no I/O activity? . . . 'eject /dev/sda' -- works. Unplug the USB flash drive from the phone -- QEMU and usbredirect are still running. Plug the USB drive in a Linux server (not a virtual server) and open the LUKS container -- works. The QEMU Linux server has been up for over seven hours and it needs 'apk add hdparm ntfs-3g exfatprogs' (the packages are not on the ISO images). The packages will be brought over on a USB flash drive and the USB drive has to be connected to QEMU -- usbredirect must be restarted, QEMU will not be restarted.

Update-7 Continuing From Update-6: The files have been copied to the USB flash drive. Pressing control-c (ctrl-c) will stop usbredirect.

Plug in the USB flash drive and give termux access to it:

~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -l
[
  "/dev/bus/usb/001/013"
]
~/.../usbredir-main/build $ termux-usb -r /dev/bus/usb/001/013
Access granted.                                           

In the QEMU monitor before starting usbredirect in termux:

(qemu)
(qemu) info usb
  Device 0.0, Port 1, Speed 1.5 Mb/s, Product USB Redirection Device, ID: usbredirdev1
(qemu)
(qemu) info chardev
parallel0: filename=null
serial0: filename=mux
serial0-base: filename=stdio
usbredirchardev1: filename=disconnected:tcp:127.0.0.1:23456
(qemu)
(qemu) chardev-remove usbredirchardev1
Error: Chardev 'usbredirchardev1' is busy
(qemu)
(qemu) device_del usbredirdev1
(qemu) info chardev
parallel0: filename=null
serial0: filename=mux
serial0-base: filename=stdio
(qemu)

Start usbredirect in termux:

~/.../usbredir-main/build $ termux-usb -e  "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/013 --as 127.0.0.1:23456" /dev/bus/usb/001/013

Go to the QEMU monitor after starting usbredirect in termux:

(qemu)
(qemu) info usb
(qemu) info chardev
parallel0: filename=null
serial0: filename=mux
serial0-base: filename=stdio
(qemu)
(qemu) chardev-add socket,host=127.0.0.1,port=23456,id=usbredirchardev1
Duplicate ID 'usbredirchardev1' for chardev
Error: Parsing chardev args failed
(qemu)
(qemu) chardev-add socket,host=127.0.0.1,port=23456,id=c2
(qemu)
(qemu) device_add usb-redir,chardev=c2,id=usbredirdev1,debug=3
qemu-system-x86_64: usbredirparser: Peer version: usbredir 0.14.0, using 64-bits ids
qemu-system-x86_64: usb-redir: attaching high speed device 0718:7722 version 1.0 class 00

The connection remains established even after 'eject /dev/sda' and removing the USB flash drive:

(qemu) info chardev
c2: filename=tcp:127.0.0.1:53754 <-> 127.0.0.1:23456
parallel0: filename=null
serial0: filename=mux
serial0-base: filename=stdio

In the QEMU Linux server:

alpine:~# uname -a
Linux alpine 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 GNU/Linux
alpine:~#
alpine:~# dmesg|tail
[47500.715270] usb-storage 1-3:1.0: USB Mass Storage device detected
[47500.912914] scsi host6: usb-storage 1-3:1.0
[47502.812831] scsi 6:0:0:0: Direct-Access     Memorex  USB Flash Drive  PMAP PQ: 0 ANSI: 6
[47503.513000] sd 6:0:0:0: [sda] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[47503.890469] sd 6:0:0:0: [sda] Write Protect is off
[47503.892839] sd 6:0:0:0: [sda] Mode Sense: 23 00 00 00
[47504.081237] sd 6:0:0:0: [sda] No Caching mode page found
[47504.082074] sd 6:0:0:0: [sda] Assuming drive cache: write through
[47506.540642]  sda: sda1 sda2 sda3
[47506.664826] sd 6:0:0:0: [sda] Attached SCSI removable disk
alpine:~#
alpine:~# blkid|grep sda
/dev/sda2: PARTUUID="e568d9fc-02"
/dev/sda3: PARTUUID="e568d9fc-03"
/dev/sda1: UUID="ff212e9e-44dc-4e53-83a9-241e534c47ae" TYPE="crypto_LUKS" PARTUUID="e568d9fc-01"
alpine:~#
alpine:~# blkid /dev/sda
/dev/sda: PTUUID="e568d9fc" PTTYPE="dos"
alpine:~#
alpine:~# cryptsetup luksOpen /dev/sda1 v1
Enter passphrase for /dev/sda1:
alpine:~#
alpine:~# mount /dev/mapper/v1 /root/1
alpine:~#
alpine:~# pwd
/root
alpine:~#
alpine:~# cp -pr /root/1/repo  /root
alpine:~#
alpine:~# ls /etc/apk
arch  keys  protected_paths.d  repositories  world
alpine:~#
alpine:~# cat /etc/apk/repositories
/media/vda/apks
/media/vdb/apks
alpine:~#
alpine:~# cd /etc/apk
alpine:/etc/apk#
alpine:/etc/apk# cp -p repositories  repositories-backup
alpine:/etc/apk#
alpine:/etc/apk# cd
alpine:~#
alpine:~# echo '/root/1/repo/main' > /etc/apk/repositories
alpine:~# echo '/root/1/repo/community' >> /etc/apk/repositories
alpine:~#
alpine:~# apk update
v3.19.0-300-g540383f69ab [/root/1/repo/main]
v3.19.0-304-gfa4cac08506 [/root/1/repo/community]
OK: 22995 distinct packages available
alpine:~#
alpine:~# apk add hdparm ntfs-3g exfatprogs
(1/4) Installing exfatprogs (1.2.2-r0)
(2/4) Installing hdparm (9.65-r2)
(3/4) Installing ntfs-3g-libs (2022.10.3-r3)
(4/4) Installing ntfs-3g (2022.10.3-r3)
Executing busybox-1.36.1-r15.trigger
OK: 65 MiB in 118 packages
alpine:~#
alpine:~# umount /root/1
alpine:~# cryptsetup luksClose v1
alpine:~# eject /dev/sda
alpine:~#
alpine:~# dmesg|tail
[47504.082074] sd 6:0:0:0: [sda] Assuming drive cache: write through
[47506.540642]  sda: sda1 sda2 sda3
[47506.664826] sd 6:0:0:0: [sda] Attached SCSI removable disk
[47826.342509] device-mapper: uevent: version 1.0.3
[47826.427519] device-mapper: ioctl: 4.48.0-ioctl (2023-03-01) initialised: dm-devel@redhat.com
[47854.833751] Key type encrypted registered
[47858.143591] cryptd: max_cpu_qlen set to 1000
[47916.968035] EXT4-fs (dm-0): mounted filesystem 3eaf5d97-67d0-476f-8a05-e4602936d061 r/w with ordered data mode. Quota mode: none.
[50405.334373] EXT4-fs (dm-0): unmounting filesystem 3eaf5d97-67d0-476f-8a05-e4602936d061.
[50466.373451] sda: detected capacity change from 30285824 to 0
alpine:~#
alpine:~# uptime
 17:48:47 up 14:02,  0 users,  load average: 0.37, 0.33, 0.21
alpine:~#

Update-8: Booting from the USB flash drive works:

Termux session:
~/.../usbredir-main/build $ 
~/.../usbredir-main/build $ qemu-system-x86_64 -device usb-redir,help
usb-redir options:
  attached=<bool>
  bootindex=<int32>
  chardev=<str>          - ID of a chardev to use as a backend
  debug=<uint8>          -  (default: 2)
  filter=<str>
  msos-desc=<bool>       - on/off (default: true)
  pcap=<str>
  port=<str>
  serial=<str>
  streams=<bool>         -  (default: true)
  suppress-remote-wake=<bool> -  (default: true)
  

QEMU session, copy file from USB flash drive:
Welcome to Alpine Linux 3.19
Kernel 6.6.4-1-virt on an x86_64 (/dev/ttyS0)

localhost login: root

localhost:~#
localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     966.7M         0    966.7M   0% /dev/shm
/dev/sda                 60.0M     60.0M         0 100% /media/sda
/dev/vda                 60.0M     60.0M         0 100% /media/vda
/dev/vdb                957.0M    957.0M         0 100% /media/vdb
tmpfs                   966.7M     10.1M    956.5M   1% /
tmpfs                   386.7M     44.0K    386.6M   0% /run
/dev/loop0               19.1M     19.1M         0 100% /.modloop
localhost:~# lsblk
-ash: lsblk: not found
localhost:~# blkid
/dev/loop0: TYPE="squashfs"
/dev/vda: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda1: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda2: TYPE="vfat"
/dev/vdb: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb1: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb2: TYPE="vfat"
/dev/loop/0: TYPE="squashfs"
/dev/sdb: LABEL="2gb-drive" UUID="b187eb7b-34d7-46f9-8b04-ef8f5b5a282e" TYPE="ext4"
localhost:~#
localhost:~# mkdir /media/usb1
localhost:~# mount /dev/sdb /media/usb1
mount: mounting /dev/sdb on /media/usb1 failed: Invalid argument
localhost:~#
localhost:~# mount -t ext4 /dev/sdb /media/usb1
localhost:~#
localhost:~# uname -a
Linux localhost 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 Linux
localhost:~#
localhost:~# ls /media/usb1
alpine-virt-3.19.0-x86_64.iso  lost+found
localhost:~# pwd
/root
localhost:~#
localhost:~# cp /media/usb1/a*iso .
localhost:~#
localhost:~# cmp /media/usb1/a*iso ./a*iso
localhost:~# 

QEMU session, in the QEMU monitor:
(qemu)
(qemu) info usb
  Device 0.3, Port 2, Speed 480 Mb/s, Product USB Redirection Device, ID: u1
(qemu)
(qemu) info chardev
parallel0: filename=null
serial0: filename=mux
c1: filename=tcp:127.0.0.1:53910 <-> 127.0.0.1:23456
serial0-base: filename=stdio
(qemu)
(qemu)

QEMU session:
localhost:~# pwd
/root
localhost:~# ls
alpine-virt-3.19.0-x86_64.iso
localhost:~#
localhost:~# umount /media/usb1
localhost:~# eject /dev/sdb
localhost:~#
localhost:~# blkid
/dev/loop0: TYPE="squashfs"
/dev/vda: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda1: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda2: TYPE="vfat"
/dev/vdb: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb1: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb2: TYPE="vfat"
/dev/loop/0: TYPE="squashfs"
localhost:~#
localhost:~#


In the termux session stop usbredirect with ctrl-c, disconnect and reconnect the USB flash drive:

~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -l
[
"/dev/bus/usb/001/028"
]
~/.../usbredir-main/build $ termux-usb -r /dev/bus/usb/001/028
Access granted.
~/.../usbredir-main/build $ termux-usb -e  "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/028  --as 127.0.0.1:23456" /dev/bus/usb/001/028                                                          


QEMU session, in the QEMU monitor to attach the USB flash drive:
(qemu)
(qemu) info chardev
parallel0: filename=null
serial0: filename=mux
c1: filename=disconnected:tcp:127.0.0.1:23456
serial0-base: filename=stdio
(qemu)
(qemu) info usb
  Device 0.0, Port 2, Speed 1.5 Mb/s, Product USB Redirection Device, ID: u1
(qemu)
(qemu) device_del u1
(qemu)
(qemu) chardev-add socket,host=127.0.0.1,port=23456,id=c1
(qemu) device_add usb-redir,chardev=c1,id=u1,debug=3
(qemu) qemu-system-x86_64: usbredirparser: Peer version: usbredir 0.14.0, using 64-bits ids
qemu-system-x86_64: usb-redir: attaching high speed device 0204:6025 version 1.0 class 00
(qemu) info usb
  Device 0.4, Port 3, Speed 480 Mb/s, Product USB Redirection Device, ID: u1
(qemu) info chardev
parallel0: filename=null
serial0: filename=mux
c1: filename=tcp:127.0.0.1:53912 <-> 127.0.0.1:23456
serial0-base: filename=stdio
(qemu)
(qemu)

QEMU session, put the ISO file on the USB flash drive:
localhost:~#
localhost:~# dmesg|grep '7:0:0:0'
[ 4370.593273] scsi 7:0:0:0: Direct-Access     CBM      Flash Disk       5.00 PQ: 0 ANSI: 2
[ 4371.695272] sd 7:0:0:0: [sdb] 4145664 512-byte logical blocks: (2.12 GB/1.98 GiB)
[ 4371.964459] sd 7:0:0:0: [sdb] Write Protect is off
[ 4371.966720] sd 7:0:0:0: [sdb] Mode Sense: 0b 00 00 08
[ 4372.251121] sd 7:0:0:0: [sdb] No Caching mode page found
[ 4372.251791] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[ 4375.135901] sd 7:0:0:0: [sdb] Attached SCSI removable disk
localhost:~#
localhost:~# blkid
/dev/loop0: TYPE="squashfs"
/dev/vda: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda1: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda2: TYPE="vfat"
/dev/vdb: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb1: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb2: TYPE="vfat"
/dev/loop/0: TYPE="squashfs"
/dev/sdb: LABEL="2gb-drive" UUID="b187eb7b-34d7-46f9-8b04-ef8f5b5a282e" TYPE="ext4"
localhost:~#
localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     966.7M         0    966.7M   0% /dev/shm
/dev/sda                 60.0M     60.0M         0 100% /media/sda
/dev/vda                 60.0M     60.0M         0 100% /media/vda
/dev/vdb                957.0M    957.0M         0 100% /media/vdb
tmpfs                   966.7M     70.1M    896.5M   7% /
tmpfs                   386.7M     44.0K    386.6M   0% /run
/dev/loop0               19.1M     19.1M         0 100% /.modloop
localhost:~#
localhost:~# ls
alpine-virt-3.19.0-x86_64.iso
localhost:~# dd if=alpine-virt-3.19.0-x86_64.iso of=/dev/sdb bs=1M
60+0 records in
60+0 records out
62914560 bytes (60.0MB) copied, 72.942032 seconds, 842.3KB/s
localhost:~#
localhost:~# blkid
/dev/loop0: TYPE="squashfs"
/dev/vda: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda1: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda2: TYPE="vfat"
/dev/vdb: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb1: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb2: TYPE="vfat"
/dev/loop/0: TYPE="squashfs"
/dev/sdb: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
localhost:~#
localhost:~# uname -a
Linux localhost 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 Linux
localhost:~#
localhost:~# eject /dev/sdb
localhost:~# poweroff
localhost:~#


In the termux session stop usbredirect with ctrl-c, disconnect and reconnect the USB flash drive:
~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -l
[
"/dev/bus/usb/001/030"
]
~/.../usbredir-main/build $ termux-usb -r /dev/bus/usb/001/030
Access granted.
~/.../usbredir-main/build $ termux-usb -e  "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/030  --as 127.0.0.1:23456" /dev/bus/usb/001/030


QEMU session, boot from the USB flash drive:
~/.../usbredir-main/build $
~/.../usbredir-main/build $ qemu-system-x86_64 -nic none -m 2000M -machine q35 -smp 4 -nographic  -readconfig $HOME/ich9-ehci-uhci.cfg -chardev socket,host=127.0.0.1,port=23456,id=usbredirchardev1  -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1,debug=3

Welcome to Alpine Linux 3.19
Kernel 6.6.4-1-virt on an x86_64 (/dev/ttyS0)

localhost login: root

localhost:~#                                                    
localhost:~# uname -a
Linux localhost 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 Linux
localhost:~#
localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     966.7M         0    966.7M   0% /dev/shm
/dev/sda                 60.0M     60.0M         0 100% /media/sda
tmpfs                   966.7M     10.1M    956.5M   1% /
tmpfs                   386.7M     44.0K    386.6M   0% /run
/dev/loop0               19.1M     19.1M         0 100% /.modloop
localhost:~#
localhost:~# blkid
/dev/loop0: TYPE="squashfs"
/dev/sda: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/sda1: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/sda2: TYPE="vfat"
/dev/loop/0: TYPE="squashfs"
localhost:~#
localhost:~#
localhost:~# dmesg|grep '6:0:0:0'
[   51.005864] scsi 6:0:0:0: Direct-Access     CBM      Flash Disk       5.00 PQ: 0 ANSI: 2
[   51.342692] sd 6:0:0:0: [sda] 4145664 512-byte logical blocks: (2.12 GB/1.98 GiB)
[   51.387099] sd 6:0:0:0: [sda] Write Protect is off
[   51.402118] sd 6:0:0:0: [sda] Mode Sense: 0b 00 00 08
[   51.445395] sd 6:0:0:0: [sda] No Caching mode page found
[   51.446637] sd 6:0:0:0: [sda] Assuming drive cache: write through
[   51.796509]  sda: sda1 sda2
[   51.858203] sd 6:0:0:0: [sda] Attached SCSI removable disk
[   53.344659] usbcore: registered new interface driver uas
localhost:~#

Update-9: Give the QEMU Linux server read-write access to the "/storage/emulated/0/Download/usb1" and "/data/data/com.termux/files" directories for data transfer to and from the USB flash drive:

Termux session:

~ $ cd $PREFIX
.../files/usr $ pwd
/data/data/com.termux/files/usr
.../files/usr $
.../files/usr $ ls /data/data/com.termux/files
apps  home  usr
.../files/usr $
.../files/usr $ du -scb .
2407134593      .
2407134593      total
.../files/usr $
.../files/usr $ du -sch .
2.7G    .
2.7G    total
.../files/usr $
.../files/usr $ find . -type f -exec sha256sum {} > ../termux-checksum.txt \;
.../files/usr $
.../files/usr $ find . -type f > ../termux-listing.txt

In the termux session to give termux access to the USB flash drive and start usbredirect:

 ~/.../usbredir-main/build $
 ~/.../usbredir-main/build $ termux-usb -l
[
"/dev/bus/usb/001/031"
]
~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -r /dev/bus/usb/001/031
Access granted.
~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -e  "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/031  --as 127.0.0.1:23456" /dev/bus/usb/001/031

QEMU Linux server session:

~/.../usbredir-main/build $
~/.../usbredir-main/build $ qemu-system-x86_64 -nic none -m 2000M -machine q35 -smp 4 -nographic  -readconfig $HOME/ich9-ehci-uhci.cfg -chardev socket,host=127.0.0.1,port=23456,id=usbredirchardev1  -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1,debug=3  -virtfs local,security_model=none,id=termux,mount_tag=termux,path=/data/data/com.termux/files   -virtfs local,security_model=none,id=host,mount_tag=host,path=/storage/emulated/0/Download/usb1 -drive if=none,id=iso1,readonly=on,format=raw,file=/storage/emulated/0/Download/alpine-virt-3.19.0-x86_64.iso -device virtio-blk-pci,id=virt1,drive=iso1,bootindex=1  


Welcome to Alpine Linux 3.19
Kernel 6.6.4-1-virt on an x86_64 (/dev/ttyS0)

localhost login: root

localhost:~#
localhost:~# uname -a
Linux localhost 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 Linux
localhost:~#
localhost:~# dmesg|grep '6:0:0:0'
[   50.895323] scsi 6:0:0:0: Direct-Access     Memorex  USB Flash Drive  PMAP PQ: 0 ANSI: 6
[   51.248985] sd 6:0:0:0: [sda] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[   51.290103] sd 6:0:0:0: [sda] Write Protect is off
[   51.294202] sd 6:0:0:0: [sda] Mode Sense: 23 00 00 00
[   51.317477] sd 6:0:0:0: [sda] No Caching mode page found
[   51.318149] sd 6:0:0:0: [sda] Assuming drive cache: write through
[   51.662793] sd 6:0:0:0: [sda] Attached SCSI removable disk
localhost:~#
localhost:~# blkid
/dev/loop0: TYPE="squashfs"
/dev/sda1: LABEL="ext4-drive" UUID="c6a6570a-0a09-46b3-aaa9-f908b017b583" TYPE="ext4"
/dev/vda: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda1: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda2: TYPE="vfat"
/dev/loop/0: TYPE="squashfs"
localhost:~#
localhost:~# mkdir /media/host
localhost:~# mkdir /media/termux
localhost:~#
localhost:~# mount -t 9p -o trans=virtio,version=9p2000.L,msize=1048576 host /media/host
localhost:~#
localhost:~# mount -t 9p -o trans=virtio,version=9p2000.L,msize=1048576 termux /media/termux
localhost:~#
localhost:~# ls -1 /media/termux
apps
home
termux-checksum.txt
termux-checksum.txt-backup
termux-listing.txt
usr
localhost:~#
localhost:~# ls -1 /media/host
localhost:~#
localhost:~# mkdir /media/usb1
localhost:~#
localhost:~# mount /dev/sda1 /media/usb1
localhost:~#
localhost:~# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=10240k,nr_inodes=246054,mode=755,inode64)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,inode64)
/dev/vda on /media/vda type iso9660 (ro,relatime,nojoliet,check=s,map=n,blocksize=2048,iocharset=utf8)
tmpfs on / type tmpfs (rw,relatime,mode=755,inode64)
tmpfs on /run type tmpfs (rw,nosuid,nodev,size=395948k,nr_inodes=819200,mode=755,inode64)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
/dev/loop0 on /.modloop type squashfs (ro,relatime,errors=continue)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
tracefs on /sys/kernel/debug/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
termux on /media/termux type 9p (rw,relatime,access=client,msize=512000,trans=virtio)
host on /media/host type 9p (rw,relatime,access=client,msize=512000,trans=virtio)
/dev/sda1 on /media/usb1 type ext4 (rw,relatime)
localhost:~#
localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     966.7M         0    966.7M   0% /dev/shm
/dev/vda                 60.0M     60.0M         0 100% /media/vda
tmpfs                   966.7M     10.1M    956.5M   1% /
tmpfs                   386.7M     44.0K    386.6M   0% /run
/dev/loop0               19.1M     19.1M         0 100% /.modloop
termux                   23.6G     22.0G      1.5G  94% /media/termux
host                    116.7G     97.5G     18.0G  84% /media/host
/dev/sda1                14.1G      1.1G     13.0G   8% /media/usb1
localhost:~#
localhost:~# ls -1 /media/usb1
alpine-extended-3.19.0-x86_64.iso
alpine-extended-3.19.0-x86_64.iso.asc
alpine-extended-3.19.0-x86_64.iso.sha256
alpine-extended-3.19.0-x86_64.iso.sha512
alpine-virt-3.19.0-x86_64.iso
alpine-virt-3.19.0-x86_64.iso.asc
alpine-virt-3.19.0-x86_64.iso.sha256
alpine-virt-3.19.0-x86_64.iso.sha512
lost+found
repository-directory
repository-index.txt
localhost:~#
localhost:~# date +"%T" ; cp -r /media/usb1/alpine* /media/usb1/repository* /media/
host ; date +"%T"
14:33:11
14:49:24
localhost:~#
localhost:~# cd /media/host
localhost:/media/host# ls -1
alpine-extended-3.19.0-x86_64.iso
alpine-extended-3.19.0-x86_64.iso.asc
alpine-extended-3.19.0-x86_64.iso.sha256
alpine-extended-3.19.0-x86_64.iso.sha512
alpine-virt-3.19.0-x86_64.iso
alpine-virt-3.19.0-x86_64.iso.asc
alpine-virt-3.19.0-x86_64.iso.sha256
alpine-virt-3.19.0-x86_64.iso.sha512
repository-directory
repository-index.txt
localhost:/media/host#
localhost:/media/host# date +"%T" ; sha256sum -c *sha256 ; date +"%T"
14:54:07
alpine-extended-3.19.0-x86_64.iso: OK
alpine-virt-3.19.0-x86_64.iso: OK
14:58:39
localhost:/media/host#
localhost:/media/host# cd
localhost:~#
localhost:~# date +"%T" ; cp -r /media/termux/usr /media/usb1/termux ; date +"%T
"
15:15:02
17:17:27
localhost:~#
localhost:~# date +"%T" ; cp -v /media/termux/usr/termux* /media/usb1/termux ; d
ate +"%T"
17:22:07
cp: can't stat '/media/termux/usr/termux*': No such file or directory
17:22:07
localhost:~#
localhost:~# date +"%T" ; cp -v /media/termux/termux* /media/usb1/termux ; date
+"%T"
17:22:33
'/media/termux/termux-checksum.txt' -> '/media/usb1/termux/termux-checksum.txt'
'/media/termux/termux-checksum.txt-backup' -> '/media/usb1/termux/termux-checksum.txt-backup'
'/media/termux/termux-listing.txt' -> '/media/usb1/termux/termux-listing.txt'
17:22:47
localhost:~#
localhost:~# date +"%T" ; date +"%T"
17:27:21
17:27:21
localhost:~#
localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     966.7M         0    966.7M   0% /dev/shm
/dev/vda                 60.0M     60.0M         0 100% /media/vda
tmpfs                   966.7M     10.1M    956.5M   1% /
tmpfs                   386.7M     44.0K    386.6M   0% /run
/dev/loop0               19.1M     19.1M         0 100% /.modloop
termux                   23.6G     22.0G      1.5G  94% /media/termux
host                    116.7G     98.6G     16.9G  85% /media/host
/dev/sda1                14.1G      3.6G     10.5G  25% /media/usb1
localhost:~#
localhost:~# dmesg|tail -3
[ 1921.317543] EXT4-fs (sda1): mounted filesystem c6a6570a-0a09-46b3-aaa9-f908b017b583 r/w with ordered data mode. Quota mode: none.
[ 3149.988847] hrtimer: interrupt took 10372070 ns
[14979.247719] EXT4-fs (sda1): unmounting filesystem c6a6570a-0a09-46b3-aaa9-f908b017b583.
localhost:~#
localhost:~# eject /dev/sda
localhost:~#
localhost:~# dmesg|tail -3
[ 3149.988847] hrtimer: interrupt took 10372070 ns
[14979.247719] EXT4-fs (sda1): unmounting filesystem c6a6570a-0a09-46b3-aaa9-f908b017b583.
[15245.557213] sda: detected capacity change from 30285824 to 0
localhost:~#

Update-10: SSH tunnels (port forwarding), multiple USB flash drives, and The-Remote-Linux-Server:

[The-Remote-Linux-Server ~]$ #
[The-Remote-Linux-Server ~]$ # Excerpt from "dmesg"
[744192.389656] usb 1-1.5: new high-speed USB device number 19 using ehci-pci
[744192.528354] usb 1-1.5: New USB device found, idVendor=0718, idProduct=7722, bcdDevice= 1.00
[744192.528361] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[744192.528365] usb 1-1.5: Product: USB Flash Drive
[744192.528367] usb 1-1.5: Manufacturer: Memorex
[744192.528664] usb-storage 1-1.5:1.0: USB Mass Storage device detected
[744192.528841] scsi host8: usb-storage 1-1.5:1.0
[744196.096763] scsi 8:0:0:0: Direct-Access     Memorex  USB Flash Drive  PMAP PQ: 0 ANSI: 6
[744196.097060] sd 8:0:0:0: Attached scsi generic sg5 type 0
[744196.101464] sd 8:0:0:0: [sdf] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[744196.104084] sd 8:0:0:0: [sdf] Write Protect is off
[744196.104088] sd 8:0:0:0: [sdf] Mode Sense: 23 00 00 00
[744196.106824] sd 8:0:0:0: [sdf] No Caching mode page found
[744196.106828] sd 8:0:0:0: [sdf] Assuming drive cache: write through
[744196.119085]  sdf: sdf1
[744196.119162] sd 8:0:0:0: [sdf] Attached SCSI removable disk
[744206.469838] usb 1-1.2: new high-speed USB device number 20 using ehci-pci
[744206.548757] usb 1-1.2: New USB device found, idVendor=0204, idProduct=6025, bcdDevice= 1.00
[744206.548763] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[744206.548767] usb 1-1.2: Product: Flash Disk
[744206.548769] usb 1-1.2: Manufacturer: CBM
[744206.549051] usb-storage 1-1.2:1.0: USB Mass Storage device detected
[744206.549220] scsi host9: usb-storage 1-1.2:1.0
[744207.553397] scsi 9:0:0:0: Direct-Access     CBM      Flash Disk       5.00 PQ: 0 ANSI: 2
[744207.553654] sd 9:0:0:0: Attached scsi generic sg6 type 0
[744207.555259] sd 9:0:0:0: [sdg] 4145664 512-byte logical blocks: (2.12 GB/1.98 GiB)
[744207.555878] sd 9:0:0:0: [sdg] Write Protect is off
[744207.555881] sd 9:0:0:0: [sdg] Mode Sense: 0b 00 00 08
[744207.556503] sd 9:0:0:0: [sdg] No Caching mode page found
[744207.556505] sd 9:0:0:0: [sdg] Assuming drive cache: write through
[744207.561886]  sdg: sdg1 sdg2
[744207.562278] sd 9:0:0:0: [sdg] Attached SCSI removable disk
[The-Remote-Linux-Server ~]$ 
[The-Remote-Linux-Server ~]$ lsblk /dev/sdg
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sdg      8:96   1    2G  0 disk 
├─sdg1   8:97   1   60M  0 part 
└─sdg2   8:98   1  1.4M  0 part 
[The-Remote-Linux-Server ~]$ 
[The-Remote-Linux-Server ~]$ lsblk /dev/sdf
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sdf      8:80   1 14.4G  0 disk 
└─sdf1   8:81   1 14.4G  0 part 
[The-Remote-Linux-Server ~]$ 
[The-Remote-Linux-Server ~]$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 04ca:004b Lite-On Technology Corp. Keyboard
Bus 001 Device 019: ID 0718:7722 Imation Corp. USB Flash Drive
Bus 001 Device 020: ID 0204:6025 Chipsbank Microelectronics Co., Ltd CBM2080 / CBM2090 Flash drive controller
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
[The-Remote-Linux-Server ~]$ 
[root@The-Remote-Linux-Server]# Excerpt from "ps -f"
root     1347266 1345960  0 pts/0    00:00:00 usbredirect --device 0204:6025 --as 127.0.0.1:10001 --keepalive
root     1347276 1345960  0 pts/0    00:00:00 usbredirect --device 0718:7722 --as 127.0.0.1:20001 --keepalive
[root@The-Remote-Linux-Server]# 

Connect to The-Remote-Linux-Server in the termux session:

~/.../usbredir-main/build $
~/.../usbredir-main/build $ ssh -f -N -L 127.0.0.1:10000:127.0.0.1:10001 -L 127.0.0.1:20000:127.0.0.1:20001 The-Remote-Linux-Server
The-Remote-Linux-Server's password:                    
~/.../usbredir-main/build $
~/.../usbredir-main/build $ ps -eaf|cat               
UID        PID  PPID  C STIME TTY          TIME CMD   
u0_a189   2383   454  0  1970 ?        01:04:07 com.termux                                                  u0_a189   2577  2383  0  1970 pts/19   00:00:02 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   2598  2383  0  1970 pts/16   00:00:03 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   2963  2383  0  1970 pts/20   00:00:00 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   3821  2383  0  1970 pts/17   00:00:00 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   7800  2383  0  1970 pts/18   00:00:03 /data/data/com.termux/files/usr/bin/bash -l
u0_a189  31886  2963  0  1970 pts/20   00:00:00 man ssh
u0_a189  31887 31886  0  1970 pts/20   00:00:00 less /data/data/com.termux/files/usr/tmp/man.ah7JF5Xf29
u0_a189  31962     1  0  1970 ?        00:00:00 ssh -f -N -L 127.0.0.1:10000:127.0.0.1:10001 -L 127.0.0.1:20000:127.0.0.1:20001 The-Remote-Linux-Server
u0_a189  31965  2598  1  1970 pts/16   00:00:00 ps -eaf
u0_a189  31966  2598  1  1970 pts/16   00:00:00 cat
~/.../usbredir-main/build $

QEMU session, start the QEMU Linux server:

~/.../usbredir-main/build $
~/.../usbredir-main/build $ qemu-system-x86_64 -nic none -m 2000M -machine q35 -smp 4 -nographic  -readconfig $HOME/ich9-ehci-uhci.cfg -drive if=none,id=iso1,readonly=on,format=raw,file=/storage/emulated/0/Download/alpine-virt-3.19.0-x86_64.iso -device virtio-blk-pci,id=virt1,drive=iso1,bootindex=1 -chardev socket,host=127.0.0.1,port=10000,id=disk1 -device usb-redir,chardev=disk1,id=usb1,debug=3 -chardev socket,host=127.0.0.1,port=20000,id=disk2 -device usb-redir,chardev=disk2,id=usb2,debug=3

In the QEMU monitor (press ctrl-a c) as the server boots:

(qemu)
(qemu) info block
iso1 (#block129): /storage/emulated/0/Download/alpine-virt-3.19.0-x86_64.iso (raw, read-only)
    Attached to:      /machine/peripheral/virt1/virtio-backend
    Cache mode:       writeback

ide2-cd0: [not inserted]
    Attached to:      /machine/unattached/device[21]
    Removable device: not locked, tray closed

sd0: [not inserted]
    Removable device: not locked, tray closed
(qemu)
(qemu) info virtio
/machine/peripheral/virt1/virtio-backend [virtio-blk]
(qemu)
(qemu) info chardev
serial0: filename=mux
disk1: filename=tcp:127.0.0.1:53246 <-> 127.0.0.1:10000
parallel0: filename=null
serial0-base: filename=stdio
disk2: filename=tcp:127.0.0.1:47796 <-> 127.0.0.1:20000
(qemu)
(qemu) info usb
  Device 0.2, Port 1, Speed 480 Mb/s, Product USB Redirection Device, ID: usb1
  Device 0.3, Port 2, Speed 480 Mb/s, Product USB Redirection Device, ID: usb2
(qemu)

Press 'ctrl-a c' to leave the QEMU monitor (the server is still booting).

Welcome to Alpine Linux 3.19
Kernel 6.6.4-1-virt on an x86_64 (/dev/ttyS0)

localhost login: root

localhost:~#
localhost:~# uname -a
Linux localhost 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 Linux
localhost:~#
localhost:~# # Excerpt from "dmesg"
[   33.089119] usbcore: registered new interface driver usbfs
[   33.096510] usbcore: registered new interface driver hub
[   33.112453] usbcore: registered new device driver usb
[   33.324365] usbcore: registered new interface driver usb-storage
[   34.961031] ACPI: bus type drm_connector registered
[   35.957719] Loading boot drivers: ok.
[   36.257561] Mounting boot media...
[   49.813670] ehci-pci 0000:00:1d.7: EHCI Host Controller
[   49.845708] ehci-pci 0000:00:1d.7: new USB bus registered, assigned bus number 1
[   49.943217] ehci-pci 0000:00:1d.7: irq 19, io mem 0xfebf2000
[   49.972139] ehci-pci 0000:00:1d.7: USB 2.0 started, EHCI 1.00
[   50.064644] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.06
[   50.066270] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   50.066744] usb usb1: Product: EHCI Host Controller
[   50.067226] usb usb1: Manufacturer: Linux 6.6.4-1-virt ehci_hcd
[   50.067633] usb usb1: SerialNumber: 0000:00:1d.7
[   50.203340] hub 1-0:1.0: USB hub found
[   50.215116] hub 1-0:1.0: 6 ports detected
[   50.595828] uhci_hcd 0000:00:1d.0: UHCI Host Controller
[   50.597381] uhci_hcd 0000:00:1d.0: new USB bus registered, assigned bus number 2
[   50.599951] uhci_hcd 0000:00:1d.0: detected 2 ports
[   50.606305] uhci_hcd 0000:00:1d.0: irq 16, io port 0x0000c0c0
[   50.667360] usb usb2: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.06
[   50.667696] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   50.667818] usb usb2: Product: UHCI Host Controller
[   50.667923] usb usb2: Manufacturer: Linux 6.6.4-1-virt uhci_hcd
[   50.668025] usb usb2: SerialNumber: 0000:00:1d.0
[   50.700502] hub 2-0:1.0: USB hub found
[   50.713687] hub 2-0:1.0: 2 ports detected
[   50.725841] usb 1-1: new high-speed USB device number 2 using ehci-pci
[   50.903819] uhci_hcd 0000:00:1d.1: UHCI Host Controller
[   50.904670] uhci_hcd 0000:00:1d.1: new USB bus registered, assigned bus number 3
[   50.905134] uhci_hcd 0000:00:1d.1: detected 2 ports
[   50.911663] uhci_hcd 0000:00:1d.1: irq 17, io port 0x0000c0e0
[   50.992151] usb usb3: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.06
[   50.992476] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   50.992599] usb usb3: Product: UHCI Host Controller
[   50.992710] usb usb3: Manufacturer: Linux 6.6.4-1-virt uhci_hcd
[   50.992815] usb usb3: SerialNumber: 0000:00:1d.1
[   51.027487] hub 3-0:1.0: USB hub found
[   51.034341] hub 3-0:1.0: 2 ports detected
[   51.174699] uhci_hcd 0000:00:1d.2: UHCI Host Controller
[   51.177501] uhci_hcd 0000:00:1d.2: new USB bus registered, assigned bus number 4
[   51.178086] uhci_hcd 0000:00:1d.2: detected 2 ports
[   51.190722] uhci_hcd 0000:00:1d.2: irq 18, io port 0x0000c100
[   51.220356] usb 1-1: New USB device found, idVendor=0204, idProduct=6025, bcdDevice= 1.00
[   51.220750] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   51.220938] usb 1-1: Product: Flash Disk
[   51.221046] usb 1-1: Manufacturer: CBM
[   51.250689] usb usb4: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.06
[   51.251140] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   51.251275] usb usb4: Product: UHCI Host Controller
[   51.251383] usb usb4: Manufacturer: Linux 6.6.4-1-virt uhci_hcd
[   51.251492] usb usb4: SerialNumber: 0000:00:1d.2
[   51.285742] usb-storage 1-1:1.0: USB Mass Storage device detected
[   51.319973] hrtimer: interrupt took 25288160 ns
[   51.331805] hub 4-0:1.0: USB hub found
[   51.337527] hub 4-0:1.0: 2 ports detected
[   51.511085] scsi host6: usb-storage 1-1:1.0
[   51.893222] usb 1-2: new high-speed USB device number 3 using ehci-pci
[   53.479701] usb 1-2: New USB device found, idVendor=0718, idProduct=7722, bcdDevice= 1.00
[   53.481737] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   53.482043] usb 1-2: Product: USB Flash Drive
[   53.482316] usb 1-2: Manufacturer: Memorex
[   53.623292] usb-storage 1-2:1.0: USB Mass Storage device detected
[   53.760054] scsi host7: usb-storage 1-2:1.0
[   54.004349] sr 2:0:0:0: [sr0] scsi3-mmc drive: 4x/4x cd/rw xa/form2 tray
[   54.026173] scsi 6:0:0:0: Direct-Access     CBM      Flash Disk       5.00 PQ: 0 ANSI: 2
[   54.029932] cdrom: Uniform CD-ROM driver Revision: 3.20
[   54.061936] sr 2:0:0:0: [sr0] Hmm, seems the drive doesn't support multisession CD's
[   54.406444] sd 6:0:0:0: [sda] 4145664 512-byte logical blocks: (2.12 GB/1.98 GiB)
[   54.449094] sr 2:0:0:0: Attached scsi CD-ROM sr0
[   54.466466] sd 6:0:0:0: [sda] Write Protect is off
[   54.487262] sd 6:0:0:0: [sda] Mode Sense: 0b 00 00 08
[   54.551419] sd 6:0:0:0: [sda] No Caching mode page found
[   54.552040] sd 6:0:0:0: [sda] Assuming drive cache: write through
[   54.948049] scsi 7:0:0:0: Direct-Access     Memorex  USB Flash Drive  PMAP PQ: 0 ANSI: 6
[   55.023627]  sda: sda1 sda2
[   55.207250] sd 6:0:0:0: [sda] Attached SCSI removable disk
[   55.317083] sd 7:0:0:0: [sdb] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[   55.345641] sd 7:0:0:0: [sdb] Write Protect is off
[   55.346003] sd 7:0:0:0: [sdb] Mode Sense: 23 00 00 00
[   55.369364] sd 7:0:0:0: [sdb] No Caching mode page found
[   55.369671] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[   56.280577]  sdb: sdb1
[   56.322468] sd 7:0:0:0: [sdb] Attached SCSI removable disk
[   57.998124] virtio_blk virtio0: 4/0/0 default/read/poll queues
[   58.170317] virtio_blk virtio0: [vda] 122880 512-byte logical blocks (62.9 MB/60.0 MiB)
[   58.235446]  vda: vda1 vda2
[   59.595809] usbcore: registered new interface driver uas
[   94.102212] block sr0: the capability attribute has been deprecated.
[  112.828082] ISO 9660 Extensions: Microsoft Joliet Level 3
[  112.983218] ISO 9660 Extensions: RRIP_1991A
[  115.373188] random: crng init done
[  160.817421] EXT4-fs (sdb1): orphan cleanup on readonly fs
[  160.868583] EXT4-fs (sdb1): mounted filesystem c6a6570a-0a09-46b3-aaa9-f908b017b583 ro with ordered data mode. Quota mode: none.
[  161.594002] EXT4-fs (sdb1): unmounting filesystem c6a6570a-0a09-46b3-aaa9-f908b017b583.
[  161.968527] ISO 9660 Extensions: Microsoft Joliet Level 3
[  161.977849] ISO 9660 Extensions: RRIP_1991A
[  163.825154] Mounting boot media: ok.
[  174.746681] Installing packages to root filesystem...
[  191.374728] Installing packages to root filesystem: ok.
[  251.201308] loop0: detected capacity change from 0 to 39088
localhost:~#
localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     966.7M         0    966.7M   0% /dev/shm
/dev/sda                 60.0M     60.0M         0 100% /media/sda
/dev/vda                 60.0M     60.0M         0 100% /media/vda
tmpfs                   966.7M     10.1M    956.5M   1% /
tmpfs                   386.7M     44.0K    386.6M   0% /run
/dev/loop0               19.1M     19.1M         0 100% /.modloop
localhost:~#
localhost:~#

In the termux session plug in the USB flash drive, start the termux SSH server ("sshd"), connect to the termux SSH server, start usbredirect:

~/.../usbredir-main/build $
~/.../usbredir-main/build $ sshd -o 'ListenAddress 127.0.0.1:8022'
~/.../usbredir-main/build $
~/.../usbredir-main/build $ ssh -f -N -L 127.0.0.1:30000:127.0.0.1:30001 -p 8022 127.0.0.1
The authenticity of host '[127.0.0.1]:8022 ([127.0.0.1]:8022)' can't be established.
ED25519 key fingerprint is SHA256:tsSHZjU7zAQuhTv0nveEHNDfHUPz8fYIXPv/NOkcFgY.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[127.0.0.1]:8022' (ED25519) to the list of known hosts.
u0_a189@127.0.0.1's password:                         
~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -l
[                                                       
"/dev/bus/usb/001/045"
]
~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -r /dev/bus/usb/001/045
Access granted.                                       
~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/045 --as 127.0.0.1:30001" /dev/bus/usb/001/045 &
[1] 1313
~/.../usbredir-main/build $
~/.../usbredir-main/build $ # Excerpt from "ps -eaf"
UID        PID  PPID  C STIME TTY          TIME CMD   
u0_a189    793     1  0  1970 ?        00:00:00 sshd -o ListenAddress 127.0.0.1:8022
u0_a189    903   793  0  1970 ?        00:00:00 /data/data/com.termux/files/usr/bin/sshd -o ListenAddress 127.0.0.1:8022 -R
u0_a189    906     1  0  1970 ?        00:00:00 ssh -f -N -L 127.0.0.1:30000:127.0.0.1:30001 -p 8022 127.0.0.1
u0_a189   1313  2598  0  1970 pts/16   00:00:00 /data/data/com.termux/files/usr/bin/bash /data/data/com.termux/files/usr/bin/termux-usb -e /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/045 --as 127.0.0.1:30001 /dev/bus/usb/001/045
u0_a189   1314  1313  0  1970 pts/16   00:00:00 /data/data/com.termux/files/usr/bin/bash /data/data/com.termux/files/usr/libexec/termux-callback 7
u0_a189   1333  1314  0  1970 pts/16   00:00:00 /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/045 --as 127.0.0.1:30001 7
~/.../usbredir-main/build $                           

QEMU session, attach the USB flash drive using the QEMU monitor:

(qemu)
(qemu) chardev-add socket,host=127.0.0.1,port=30000,id=disk3
(qemu)
(qemu) device_add usb-redir,chardev=disk3,id=usb3,debug=3
qemu-system-x86_64: usbredirparser: Peer version: usbredir 0.14.0, using 64-bits ids
qemu-system-x86_64: usb-redir: attaching high speed device 0781:5575 version 1.0 class 00
(qemu)
(qemu) info chardev
serial0: filename=mux
disk3: filename=tcp:127.0.0.1:45218 <-> 127.0.0.1:30000
disk1: filename=tcp:127.0.0.1:53246 <-> 127.0.0.1:10000
parallel0: filename=null
serial0-base: filename=stdio
disk2: filename=tcp:127.0.0.1:47796 <-> 127.0.0.1:20000
(qemu)
(qemu) info usb
  Device 0.2, Port 1, Speed 480 Mb/s, Product USB Redirection Device, ID: usb1
  Device 0.3, Port 2, Speed 480 Mb/s, Product USB Redirection Device, ID: usb2
  Device 0.4, Port 3, Speed 480 Mb/s, Product USB Redirection Device, ID: usb3
(qemu)

QEMU Linux server session:

localhost:~#
localhost:~# # Excerpt from 'dmesg'
[ 4600.355991] usb 1-3: new high-speed USB device number 4 using ehci-pci
[ 4600.865274] usb 1-3: New USB device found, idVendor=0781, idProduct=5575, bcdDevice= 1.00
[ 4600.866562] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4600.866978] usb 1-3: Product: Cruzer Glide
[ 4600.867235] usb 1-3: Manufacturer: SanDisk
[ 4601.005070] usb-storage 1-3:1.0: USB Mass Storage device detected
[ 4601.222277] scsi host8: usb-storage 1-3:1.0
[ 4603.435121] scsi 8:0:0:0: Direct-Access     SanDisk  Cruzer Glide     1.00 PQ: 0 ANSI: 6
[ 4604.326513] sd 8:0:0:0: [sdc] 60088320 512-byte logical blocks: (30.8 GB/28.7 GiB)
[ 4604.792004] sd 8:0:0:0: [sdc] Write Protect is off
[ 4604.794015] sd 8:0:0:0: [sdc] Mode Sense: 43 00 00 00
[ 4605.195742] sd 8:0:0:0: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 4611.357506]  sdc: sdc1 sdc2
[ 4611.435070] sd 8:0:0:0: [sdc] Attached SCSI removable disk
localhost:~#
localhost:~#

Update-11: "Termux, sockets, QEMU, and the Linux operating system" at https://github.com/termux/termux-packages/issues/19635#issuecomment-205251940

 

 

Connecting a USB device to QEMU using termux, termux-usb, usbredirect

###########################################################################
#
# You can pass this file directly to qemu using the -readconfig
# command line switch.
#
# This config file creates a EHCI adapter with companion UHCI
# controllers as multifunction device in PCI slot "1d".
#
# Specify "bus=ehci.0" when creating usb devices to hook them up
# there.
#

[device "ehci"]
  driver = "ich9-usb-ehci1"
  addr = "1d.7"
  multifunction = "on"

[device "uhci-1"]
  driver = "ich9-usb-uhci1"
  addr = "1d.0"
  multifunction = "on"
  masterbus = "ehci.0"
  firstport = "0"

[device "uhci-2"]
  driver = "ich9-usb-uhci2"
  addr = "1d.1"
  multifunction = "on"
  masterbus = "ehci.0"
  firstport = "2"

[device "uhci-3"]
  driver = "ich9-usb-uhci3"
  addr = "1d.2"
  multifunction = "on"
  masterbus = "ehci.0"
  firstport = "4"

Extra information:

  • No root.

  • The latest version of the usbredirect.c source code is below. Building and compiling usbredirect.c using meson on termux works. The SPICE protocol is not used.

  • usbredirect.c is being modified using usbtest.c from https://wiki.termux.com/wiki/Termux-usb. Modification indicators: "#ifdef THIS_IS_A_COMMENT" and "#ifdef FOR_TERMUX".

Termux session:

~/.../usbredir-main/build $
~/.../usbredir-main/build $ ../../meson-1.4.0/meson.py compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /data/data/c
om.termux/files/usr/bin/ninja
[1/2] Compiling C object ...edirect.p/usbredirect.c.o
../tools/usbredirect.c:598:1: warning: unused function
'open_usb_device' [-Wunused-function]
598 | open_usb_device(redirect *self)
| ^~~~~~~~~~~~~~~
1 warning generated.
[2/2] Linking target tools/usbredirect
~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -e ./build/tools/usbredirect device "/dev/bus/usb/001/031" --to 127.0.0.1:23456
termux-usb: too many arguments
~/.../usbredir-main/build $

termux-info:

TERMUX_API_APP__VERSION_NAME=0.50.1
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP__AM_SOCKET_SERVER_ENABLED=true
TERMUX_APP__APK_PATH=/data/app/~~zMILa9TgJazQczw9C_x_Cg==/com.termux-t3s8rxYdbG9lbQ81IkrQaw==/base.apk
TERMUX_APP__APK_RELEASE=GITHUB
TERMUX_APP__FILES_DIR=/data/user/0/com.termux/files
TERMUX_APP__IS_DEBUGGABLE_BUILD=true
TERMUX_APP__IS_INSTALLED_ON_EXTERNAL_STORAGE=false
TERMUX_APP__PACKAGE_MANAGER=apt
TERMUX_APP__PACKAGE_NAME=com.termux
TERMUX_APP__PACKAGE_VARIANT=apt-android-7
TERMUX_APP__SE_FILE_CONTEXT=u:object_r:app_data_file:s0:c189,c256,c512,c768
TERMUX_APP__SE_INFO=default:targetSdkVersion=28:complete
TERMUX_APP__SE_PROCESS_CONTEXT=u:r:untrusted_app_27:s0:c189,c256,c512,c768
TERMUX_APP__TARGET_SDK=28
TERMUX_APP__VERSION_CODE=118
TERMUX_APP__VERSION_NAME=0.118.0+9b06e61
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0+9b06e61
TERMUX__USER_ID=0
Packages CPU architecture:
arm
Updatable packages:
All packages up to date
termux-tools version:
1.40.5
Android version:
11
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51
com.termux.gui versionCode:6

Termux session: testing usbredirect

~/.../usbredir-main/build $ ../../meson-1.4.0/meson.py compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /data/data/com.termux/files/usr/bin/ninja
[1/2] Compiling C object ...edirect.p/usbredirect.c.o
../tools/usbredirect.c:596:1: warning: unused function
'open_usb_device' [-Wunused-function]
596 | open_usb_device(redirect *self)
| ^~~~~~~~~~~~~~~
1 warning generated.
[2/2] Linking target tools/usbredirect
~/.../usbredir-main/build $ termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/003 --to 127.0.0.1:23456" /dev/bus/usb/001/003

argv[0] = /data/data/com.termux/files/home/usb-test/us
bredir-main/build/tools/usbredirect

argv[1] = --device

argv[2] = /dev/bus/usb/001/003

argv[3] = --to

argv[4] = 127.0.0.1:23456

argv[5] = 7

AFTER parse_opts

BEFORE sscanf argv[0] = /data/data/com.termux/files/ho
me/usb-test/usbredir-main/build/tools/usbredirect

BEFORE sscanf argv[1] = 7

BEFORE sscanf argv[2] = (null)

BEFORE sscanf argv[3] = (null)

BEFORE sscanf argv[4] = (null)

BEFORE sscanf argv[5] = (null)

Vendor ID: 0718
Product ID: 7722
Manufacturer: Memorex
Product: USB Flash Drive
Serial No: [REMOVED-FOR-PRIVACY]

(usbredirect:8504): usbredirect-WARNING **: 13:21:02.8
78: Failed to connect to the server: Could not connect
to 127.0.0.1: Connection refused
~/.../usbredir-main/build $

Modified source code: usbredirect.c

#define FOR_TERMUX 1

#ifdef THIS_IS_A_COMMENT

//
// Install on termux: ninja, libusb
// Download source code zip file from https://gitlab.freedesktop.org/spice/usbredir
// Install on termux: https://github.com/mesonbuild/meson
// https://mesonbuild.com/Getting-meson.html
//

// "USB redirection over the network": https://web.archive.org/web/20160114122824/www.linux-kvm.com/content/usb-redirection-over-network

// "Bug 1085318 - Can't redirect tcp type USB device ": https://bugzilla.redhat.com/show_bug.cgi?id=1085318

// "usbredirect doesn't know how to handle multiple identical USB devices": https://gitlab.freedesktop.org/spice/usbredir/-/issues/29

// "RFE: add a usbredirclient, to use with a qemu socket chardev in server mode": https://gitlab.freedesktop.org/spice/usbredir/-/issues/1
//    https://bugzilla.redhat.com/show_bug.cgi?id=844657
//    https://web.archive.org/web/20160429170306/bugs.freedesktop.org/show_bug.cgi?id=72766

// "Add a tcp client & server standalone binary": https://gitlab.freedesktop.org/spice/usbredir/-/merge_requests/2


//
// "[Spice-devel] spice-gtk usb-redirection": https://lists.freedesktop.org/archives/spice-devel/2012-July/thread.html
//    "[Spice-devel] spice-gtk usb-redirection": https://lists.freedesktop.org/archives/spice-devel/2012-August/thread.html
// https://hansdegoede.livejournal.com/tag/spice
// Source code for remote-viewer (SPICE): https://gitlab.com/virt-viewer
//

#endif

#ifdef THIS_IS_A_COMMENT

// From https://wiki.termux.com/wiki/Termux-usb
// and 
// https://gist.githubusercontent.com/bndeff/8c391bc3fd8d9f1dbd133ac6ead7f45e/raw/6d7174a129301eeb670fe808cd9d25ec261f7f9e/usbtest.c


#include <stdio.h>
#include <assert.h>
#include <libusb-1.0/libusb.h>

int main(int argc, char **argv) {
    libusb_context *context;
    libusb_device_handle *handle;
    libusb_device *device;
    struct libusb_device_descriptor desc;
    unsigned char buffer[256];
    int fd;
    assert((argc > 1) && (sscanf(argv[1], "%d", &fd) == 1));
    libusb_set_option(NULL, LIBUSB_OPTION_WEAK_AUTHORITY);
    assert(!libusb_init(&context));
    assert(!libusb_wrap_sys_device(context, (intptr_t) fd, &handle));
    device = libusb_get_device(handle);
    assert(!libusb_get_device_descriptor(device, &desc));
    printf("Vendor ID: %04x\n", desc.idVendor);
    printf("Product ID: %04x\n", desc.idProduct);
    assert(libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, buffer, 256) >= 0);
    printf("Manufacturer: %s\n", buffer);
    assert(libusb_get_string_descriptor_ascii(handle, desc.iProduct, buffer, 256) >= 0);
    printf("Product: %s\n", buffer);
    if (libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, buffer, 256) >= 0)
        printf("Serial No: %s\n", buffer);
    libusb_exit(context);
}
#endif

#ifdef FOR_TERMUX
#include <assert.h>
#endif

#include "config.h"
#include <stdio.h>
#include <stdbool.h>

#define G_LOG_DOMAIN "usbredirect"
#define G_LOG_USE_STRUCTURED

#include <glib.h>
#include <gio/gio.h>
#include <libusb.h>
#include <usbredirhost.h>

#ifdef G_OS_UNIX
#include <glib-unix.h>
#include <gio/gunixinputstream.h>
#include <gio/gunixoutputstream.h>
#endif

#ifdef G_OS_WIN32
#include <windows.h>
#include <gio/gwin32inputstream.h>
#include <gio/gwin32outputstream.h>
#endif

typedef struct redirect {
    struct {
        /* vendor:product */
        int vendor;
        int product;
        /* bus-device */
        int bus;
        int device_number;
    } device;
    bool by_bus;
    bool is_client;
    bool keepalive;
    bool watch_inout;
    char *addr;
    int port;
    int verbosity;

    struct usbredirhost *usbredirhost;
    GSocketConnection *connection;
    GThread *event_thread;
    int event_thread_run;
    int watch_server_id;
    GIOChannel *io_channel;

    GMainLoop *main_loop;
} redirect;

static void create_watch(redirect *self);

static bool
parse_opt_device(redirect *self, const char *device)
{
    if (!device) {
        g_warning("No device to redirect. For testing only\n");
        return true;
    }


#ifdef FOR_TERMUX
    if (g_strrstr(device, "/") != NULL) {
        return true;
    }
#endif

    if (g_strrstr(device, "-") != NULL) {
        self->by_bus = true;
        char **usbid = g_strsplit(device, "-", 2);
        if (usbid == NULL || usbid[0] == NULL || usbid[1] == NULL || usbid[2] != NULL) {
            g_strfreev(usbid);
            return false;
        }
        self->device.bus = g_ascii_strtoll(usbid[0], NULL, 10);
        self->device.device_number = g_ascii_strtoll(usbid[1], NULL, 10);
        g_strfreev(usbid);
        return true;
    }

    char **usbid = g_strsplit(device, ":", 2);
    if (usbid == NULL || usbid[0] == NULL || usbid[1] == NULL || usbid[2] != NULL) {
        g_strfreev(usbid);
        return false;
    }

    self->device.vendor = g_ascii_strtoll(usbid[0], NULL, 16);
    self->device.product = g_ascii_strtoll(usbid[1], NULL, 16);
    g_strfreev(usbid);

    if (self->device.vendor <= 0 || self->device.vendor > 0xffff ||
        self->device.product < 0 || self->device.product > 0xffff) {
        g_printerr("Bad vendor:product values %04x:%04x",
                   self->device.vendor, self->device.product);
        return false;
    }

    return true;
}

static bool
parse_opt_uri(const char *uri, char **adr, int *port)
{
    if (uri == NULL) {
        return false;
    }

    char **parts = g_strsplit(uri, ":", 2);
    if (parts == NULL || parts[0] == NULL || parts[1] == NULL || parts[2] != NULL) {
        g_printerr("Failed to parse '%s' - expected simplified uri scheme: host:port", uri);
        g_strfreev(parts);
        return false;
    }

    *adr = g_strdup(parts[0]);
    *port = g_ascii_strtoll(parts[1], NULL, 10);
    g_strfreev(parts);

    return true;
}

static redirect *
parse_opts(int *argc, char ***argv)
{




    char *device = NULL;
    char *remoteaddr = NULL;
    char *localaddr = NULL;
    gboolean keepalive = FALSE;
    gint verbosity = 0; /* none */
    redirect *self = NULL;



    GOptionEntry entries[] = {
        { "device", 0, 0, G_OPTION_ARG_STRING, &device, "Local USB device to be redirected identified as either VENDOR:PRODUCT \"0123:4567\" or BUS-DEVICE \"5-2\"", NULL },
        { "to", 0, 0, G_OPTION_ARG_STRING, &remoteaddr, "Client URI to connect to", NULL },
        { "as", 0, 0, G_OPTION_ARG_STRING, &localaddr, "Server URI to be run", NULL },
        { "keepalive", 'k', 0, G_OPTION_ARG_NONE, &keepalive, "If we should set SO_KEEPALIVE flag on underlying socket", NULL },
        { "verbose", 'v', 0, G_OPTION_ARG_INT, &verbosity, "Set log level between 1-5 where 5 being the most verbose", NULL },
        { NULL }
    };

    GError *err = NULL;
    GOptionContext *ctx = g_option_context_new(NULL);
    g_option_context_add_main_entries(ctx, entries, NULL);
    if (!g_option_context_parse(ctx, argc, argv, &err)) {
        g_printerr("Could not parse arguments: %s\n", err->message);
        g_printerr("%s", g_option_context_get_help(ctx, TRUE, NULL));
        g_clear_error(&err);
        goto end;
    }



    /* check options */

    if (!remoteaddr && !localaddr) {
        g_printerr("%s need to act either as client (-to) or as server (-as)\n", *argv[0]);
        g_printerr("%s", g_option_context_get_help(ctx, TRUE, NULL));
        goto end;
    }

    self = g_new0(redirect, 1);
    self->watch_inout = true;
    if (!parse_opt_device(self, device)) {
        g_printerr("Failed to parse device: '%s' - expected: vendor:product or busnum-devnum\n", device);
        g_clear_pointer(&self, g_free);
        goto end;
    }


    if (parse_opt_uri(remoteaddr, &self->addr, &self->port)) {
        self->is_client = true;
    } else if (!parse_opt_uri(localaddr, &self->addr, &self->port)) {
        g_printerr("Failed to parse uri '%s' - expected: addr:port", remoteaddr ? remoteaddr : localaddr);
        g_clear_pointer(&self, g_free);
        goto end;
    }

    self->keepalive = keepalive;
    self->verbosity = verbosity;
    g_debug("options: keepalive=%s, verbosity=%d",
            self->keepalive ? "ON":"OFF",
            self->verbosity);

end:
    if (self) {
        g_debug("Device: '%04x:%04x', %s addr: '%s', port: %d\n",
                self->device.vendor,
                self->device.product,
                self->is_client ? "client connect" : "server at",
                self->addr,
                self->port);
    }
    g_free(localaddr);
    g_free(remoteaddr);
    g_free(device);
    g_option_context_free(ctx);
    return self;
}

static gpointer
thread_handle_libusb_events(gpointer user_data)
{
    redirect *self = (redirect *) user_data;

    int res = 0;
    const char *desc = "";
    while (g_atomic_int_get(&self->event_thread_run)) {
        res = libusb_handle_events(NULL);
        if (res && res != LIBUSB_ERROR_INTERRUPTED) {
            desc = libusb_strerror(res);
            g_warning("Error handling USB events: %s [%i]", desc, res);
            break;
        }
    }
    if (self->event_thread_run) {
        g_debug("%s: the thread aborted, %s(%d)", __FUNCTION__, desc, res);
    }
    return NULL;
}

#if LIBUSBX_API_VERSION >= 0x01000107
static void
debug_libusb_cb(libusb_context *ctx, enum libusb_log_level level, const char *msg)
{
    GLogLevelFlags glog_level;

    switch(level) {
    case LIBUSB_LOG_LEVEL_ERROR:
        glog_level = G_LOG_LEVEL_ERROR;
        break;
    case LIBUSB_LOG_LEVEL_WARNING:
        glog_level = G_LOG_LEVEL_WARNING;
        break;
    case LIBUSB_LOG_LEVEL_INFO:
        glog_level = G_LOG_LEVEL_INFO;
        break;
    case LIBUSB_LOG_LEVEL_DEBUG:
        glog_level = G_LOG_LEVEL_DEBUG;
        break;
    default:
        g_warn_if_reached();
        return;
    }

    /* Do not print the '\n' line feed */
    size_t len = strlen(msg);
    len = (msg[len - 1] == '\n') ? len - 1 : len;
    g_log_structured(G_LOG_DOMAIN, glog_level, "MESSAGE", "%.*s", len - 1, msg);
}
#endif

static void
usbredir_log_cb(void *priv, int level, const char *msg)
{
    GLogLevelFlags glog_level;

    switch(level) {
    case usbredirparser_error:
        glog_level = G_LOG_LEVEL_ERROR;
        break;
    case usbredirparser_warning:
        glog_level = G_LOG_LEVEL_WARNING;
        break;
    case usbredirparser_info:
        glog_level = G_LOG_LEVEL_INFO;
        break;
    case usbredirparser_debug:
    case usbredirparser_debug_data:
        glog_level = G_LOG_LEVEL_DEBUG;
        break;
    default:
        g_warn_if_reached();
        return;
    }
    g_log_structured(G_LOG_DOMAIN, glog_level, "MESSAGE", msg);
}

static void
update_watch(redirect *self)
{
    const bool watch_inout = usbredirhost_has_data_to_write(self->usbredirhost) != 0;
    if (watch_inout == self->watch_inout) {
        return;
    }
    g_clear_pointer(&self->io_channel, g_io_channel_unref);
    g_source_remove(self->watch_server_id);
    self->watch_server_id = 0;
    self->watch_inout = watch_inout;

    create_watch(self);
}

static int
usbredir_read_cb(void *priv, uint8_t *data, int count)
{
    redirect *self = (redirect *) priv;
    GIOStream *iostream = G_IO_STREAM(self->connection);
    GError *err = NULL;

    GPollableInputStream *instream = G_POLLABLE_INPUT_STREAM(g_io_stream_get_input_stream(iostream));
    gssize nbytes = g_pollable_input_stream_read_nonblocking(instream,
            data,
            count,
            NULL,
            &err);
    if (nbytes <= 0) {
        if (g_error_matches(err, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
            /* Try again later */
            nbytes = 0;
        } else {
            if (err != NULL) {
                g_warning("Failure at %s: %s", __func__, err->message);
            }
            g_main_loop_quit(self->main_loop);
        }
        g_clear_error(&err);
    }
    return nbytes;
}

static int
usbredir_write_cb(void *priv, uint8_t *data, int count)
{
    redirect *self = (redirect *) priv;
    GIOStream *iostream = G_IO_STREAM(self->connection);
    GError *err = NULL;

    GPollableOutputStream *outstream = G_POLLABLE_OUTPUT_STREAM(g_io_stream_get_output_stream(iostream));
    gssize nbytes = g_pollable_output_stream_write_nonblocking(outstream,
            data,
            count,
            NULL,
            &err);
    if (nbytes <= 0) {
        if (g_error_matches(err, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
            /* Try again later */
            nbytes = 0;
            update_watch(self);
        } else {
            if (err != NULL) {
                g_warning("Failure at %s: %s", __func__, err->message);
            }
            g_main_loop_quit(self->main_loop);
        }
        g_clear_error(&err);
    }
    return nbytes;
}

static void
usbredir_write_flush_cb(void *user_data)
{
    redirect *self = (redirect *) user_data;
    if (!self || !self->usbredirhost) {
        return;
    }

    int ret = usbredirhost_write_guest_data(self->usbredirhost);
    if (ret < 0) {
        g_critical("%s: Failed to write to guest", __func__);
        g_main_loop_quit(self->main_loop);
    }
}

static void
*usbredir_alloc_lock(void)
{
    GMutex *mutex;

    mutex = g_new0(GMutex, 1);
    g_mutex_init(mutex);

    return mutex;
}

static void
usbredir_free_lock(void *user_data)
{
    GMutex *mutex = user_data;

    g_mutex_clear(mutex);
    g_free(mutex);
}

static void
usbredir_lock_lock(void *user_data)
{
    GMutex *mutex = user_data;

    g_mutex_lock(mutex);
}

static void
usbredir_unlock_lock(void *user_data)
{
    GMutex *mutex = user_data;

    g_mutex_unlock(mutex);
}

static gboolean
connection_handle_io_cb(GIOChannel *source, GIOCondition condition, gpointer user_data)
{
    redirect *self = (redirect *) user_data;

    if (condition & G_IO_ERR || condition & G_IO_HUP) {
        g_warning("Connection: err=%d, hup=%d - exiting", (condition & G_IO_ERR), (condition & G_IO_HUP));
        goto end;
    }

    if (condition & G_IO_IN) {
        int ret = usbredirhost_read_guest_data(self->usbredirhost);
        if (ret < 0) {
            g_critical("%s: Failed to read guest", __func__);
            goto end;
        }
    }
    // try to write data in any case, to avoid having another iteration and
    // creation of another watch if there is space in output buffer
    if (usbredirhost_has_data_to_write(self->usbredirhost) != 0) {
        int ret = usbredirhost_write_guest_data(self->usbredirhost);
        if (ret < 0) {
            g_critical("%s: Failed to write to guest", __func__);
            goto end;
        }
    }

    // update the watch if needed
    update_watch(self);
    return G_SOURCE_CONTINUE;

end:
    g_main_loop_quit(self->main_loop);
    return G_SOURCE_REMOVE;
}

static void
create_watch(redirect *self)
{
    GSocket *socket = g_socket_connection_get_socket(self->connection);
    int socket_fd = g_socket_get_fd(socket);

    g_assert_null(self->io_channel);
    self->io_channel =
#ifdef G_OS_UNIX
        g_io_channel_unix_new(socket_fd);
#else
        g_io_channel_win32_new_socket(socket_fd);
#endif

    g_assert_cmpint(self->watch_server_id, ==, 0);
    self->watch_server_id = g_io_add_watch(self->io_channel,
            G_IO_IN | G_IO_HUP | G_IO_ERR | (self->watch_inout ? G_IO_OUT : 0),
            connection_handle_io_cb,
            self);
}

#ifdef G_OS_UNIX
static gboolean
signal_handler(gpointer user_data)
{
    redirect *self = (redirect *) user_data;
    g_main_loop_quit(self->main_loop);
    return G_SOURCE_REMOVE;
}
#endif

static bool
can_claim_usb_device(libusb_device *dev, libusb_device_handle **handle)
{
    int ret = libusb_open(dev, handle);
    if (ret != 0) {
        g_debug("Failed to open device");
        return false;
    }

    /* Opening is not enough. We need to check if device can be claimed
     * for I/O operations */
    struct libusb_config_descriptor *config = NULL;
    ret = libusb_get_active_config_descriptor(dev, &config);
    if (ret != 0 || config == NULL) {
        g_debug("Failed to get active descriptor");
        goto fail;
    }

#if LIBUSBX_API_VERSION >= 0x01000102
    libusb_set_auto_detach_kernel_driver(*handle, 1);
#endif

    int i;
    for (i = 0; i < config->bNumInterfaces; i++) {
        int interface_num = config->interface[i].altsetting[0].bInterfaceNumber;
#if LIBUSBX_API_VERSION < 0x01000102
        ret = libusb_detach_kernel_driver(handle, interface_num);
        if (ret != 0 && ret != LIBUSB_ERROR_NOT_FOUND
            && ret != LIBUSB_ERROR_NOT_SUPPORTED) {
            g_error("failed to detach driver from interface %d: %s",
                    interface_num, libusb_error_name(ret));
            goto fail;
        }
#endif
        ret = libusb_claim_interface(*handle, interface_num);
        if (ret != 0) {
            g_debug("Could not claim interface");
            goto fail;
        }
        ret = libusb_release_interface(*handle, interface_num);
        if (ret != 0) {
            g_debug("Could not release interface");
            goto fail;
        }
    }

    libusb_free_config_descriptor(config);
    return true;

fail:
    libusb_free_config_descriptor(config);
    libusb_close(*handle);
    *handle = NULL;
    return false;
}

static libusb_device_handle *
open_usb_device(redirect *self)
{
    struct libusb_device **devs;
    struct libusb_device_handle *dev_handle = NULL;
    size_t i, ndevices;

    ndevices = libusb_get_device_list(NULL, &devs);
    for (i = 0; i < ndevices; i++) {
        struct libusb_device_descriptor desc;
        if (libusb_get_device_descriptor(devs[i], &desc) != 0) {
            g_warning("Failed to get descriptor");
            continue;
        }

        if (self->by_bus &&
            (self->device.bus != libusb_get_bus_number(devs[i]) ||
             self->device.device_number != libusb_get_device_address(devs[i]))) {
             continue;
        }

        if (!self->by_bus &&
            (self->device.vendor != desc.idVendor ||
             self->device.product != desc.idProduct)) {
             continue;
        }

        if (can_claim_usb_device(devs[i], &dev_handle)) {
            break;
        }
    }

    libusb_free_device_list(devs, 1);
    return dev_handle;
}


static gboolean
connection_incoming_cb(GSocketService    *service,
                       GSocketConnection *client_connection,
                       GObject           *source_object,
                       gpointer           user_data)
{
    redirect *self = (redirect *) user_data;
    self->connection = g_object_ref(client_connection);

    /* Add a GSource watch to handle polling for us and handle IO in the callback */
    GSocket *connection_socket = g_socket_connection_get_socket(self->connection);
    g_socket_set_keepalive(connection_socket, self->keepalive);
    create_watch(self);
    return G_SOURCE_REMOVE;
}

int
main(int argc, char *argv[])
{
    GError *err = NULL;
    


#ifdef THIS_IS_A_COMMENT
    if (libusb_init(NULL)) {
        g_warning("Could not init libusb\n");
        goto err_init;
    }
#endif




#ifdef FOR_TERMUX
printf("\n\nIN-MAIN-BEFORE-parse_opts argc = %d\n\n", argc) ;
printf("\n\nIN-MAIN-BEFORE-parse_opts argv[0] = %s\n\n", argv[0]) ;
printf("\n\nIN-MAIN-BEFORE-parse_opts argv[1] = %s\n\n", argv[1]) ;
printf("\n\nIN-MAIN-BEFORE-parse_opts argv[2] = %s\n\n", argv[2]) ;
printf("\n\nIN-MAIN-BEFORE-parse_opts argv[3] = %s\n\n", argv[3]) ;
printf("\n\nIN-MAIN-BEFORE-parse_opts argv[4] = %s\n\n", argv[4]) ;
printf("\n\nIN-MAIN-BEFORE-parse_opts argv[5] = %s\n\n", argv[5]) ;
// printf("\n\nIN-MAIN-BEFORE-parse_opts argv[6] = %s\n\n", argv[6]) ;
// printf("\n\nIN-MAIN-BEFORE-parse_opts argv[7] = %s\n\n", argv[7]) ;
#endif


    redirect *self = parse_opts(&argc, &argv);

    if (!self) {
        /* specific issues logged in parse_opts() */
        return 1;
    }




#if LIBUSBX_API_VERSION >= 0x01000107
    /* This was introduced in 1.0.23 */
    libusb_set_log_cb(NULL, debug_libusb_cb, LIBUSB_LOG_CB_GLOBAL);
#endif

#ifdef G_OS_WIN32
    /* WinUSB is the default by backwards compatibility so this is needed to
     * switch to USBDk backend. */
#   if LIBUSBX_API_VERSION >= 0x01000106
    libusb_set_option(NULL, LIBUSB_OPTION_USE_USBDK); 
#   endif
#endif

#ifdef G_OS_UNIX
    g_unix_signal_add(SIGINT, signal_handler, self);
    g_unix_signal_add(SIGHUP, signal_handler, self);
    g_unix_signal_add(SIGTERM, signal_handler, self);
#endif





#ifdef THIS_IS_A_COMMENT
    libusb_device_handle *device_handle = open_usb_device(self);
    if (!device_handle) {
        g_printerr("Failed to open device!\n");
        goto err_init;
    }
#endif

#ifdef FOR_TERMUX
    libusb_context *context;
    libusb_device_handle *device_handle;
    libusb_device *termux_device;
    struct libusb_device_descriptor desc;
    unsigned char buffer[256];
    int fd;

#ifdef FOR_TERMUX
printf("\n\nIN-MAIN-BEFORE sscanf argc = %d\n\n", argc) ;
printf("\n\nIN-MAIN-BEFORE sscanf argv[0] = %s\n\n", argv[0]) ;
printf("\n\nIN-MAIN-BEFORE sscanf argv[1] = %s\n\n", argv[1]) ;
printf("\n\nIN-MAIN-BEFORE sscanf argv[2] = %s\n\n", argv[2]) ;
printf("\n\nIN-MAIN-BEFORE sscanf argv[3] = %s\n\n", argv[3]) ;
printf("\n\nIN-MAIN-BEFORE sscanf argv[4] = %s\n\n", argv[4]) ;
printf("\n\nIN-MAIN-BEFORE sscanf argv[5] = %s\n\n", argv[5]) ;
// printf("\n\nIN-MAIN-BEFORE sscanf argv[6] = %s\n\n", argv[6]) ;
// printf("\n\nIN-MAIN-BEFORE sscanf argv[7] = %s\n\n", argv[7]) ;
#endif

    assert(sscanf(argv[1], "%d", &fd) == 1);
    libusb_set_option(NULL, LIBUSB_OPTION_WEAK_AUTHORITY);
    assert(!libusb_init(&context));
    assert(!libusb_wrap_sys_device(context, (intptr_t) fd, &device_handle));
    termux_device = libusb_get_device(device_handle);
    assert(!libusb_get_device_descriptor(termux_device, &desc));
    printf("Vendor ID: %04x\n", desc.idVendor);
    printf("Product ID: %04x\n", desc.idProduct);
    assert(libusb_get_string_descriptor_ascii(device_handle, desc.iManufacturer, buffer, 256) >= 0);
    printf("Manufacturer: %s\n", buffer);
    assert(libusb_get_string_descriptor_ascii(device_handle, desc.iProduct, buffer, 256) >= 0);
    printf("Product: %s\n", buffer);
    if (libusb_get_string_descriptor_ascii(device_handle, desc.iSerialNumber, buffer, 256) >= 0)
        printf("Serial No: %s\n", buffer);

#endif




    /* As per doc below, we are not using hotplug so we must first call
     * libusb_open() and then we can start the event thread.
     *
     *      http://libusb.sourceforge.net/api-1.0/group__libusb__asyncio.html#eventthread
     *
     * The event thread is a must for Windows while on Unix we would ge okay
     * getting the fds and polling oursevelves. */
    g_atomic_int_set(&self->event_thread_run, TRUE);
    self->event_thread = g_thread_try_new("usbredirect-libusb-event-thread",
            thread_handle_libusb_events,
            self,
            &err);
    if (!self->event_thread) {
        g_warning("Error starting event thread: %s", err->message);
        libusb_close(device_handle);
        goto err_init;
    }

    self->usbredirhost = usbredirhost_open_full(NULL,
            device_handle,
            usbredir_log_cb,
            usbredir_read_cb,
            usbredir_write_cb,
            usbredir_write_flush_cb,
            usbredir_alloc_lock,
            usbredir_lock_lock,
            usbredir_unlock_lock,
            usbredir_free_lock,
            self,
            PACKAGE_STRING,
            self->verbosity,
            0);
    if (!self->usbredirhost) {
        g_warning("Error starting usbredirhost");
        goto err_init;
    }

    /* Only allow libusb logging if log verbosity is uredirparser_debug_data
     * (or higher), otherwise we disable it here while keeping usbredir's logs enable. */
    if  (self->verbosity < usbredirparser_debug_data)  {
#if LIBUSBX_API_VERSION >= 0x01000106
        int ret = libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_NONE);
        if (ret != LIBUSB_SUCCESS) {
            g_warning("error disabling libusb log level: %s", libusb_error_name(ret));
            goto end;
        }
#else
        libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_NONE);
#endif
    }

    if (self->is_client) {
        /* Connect to a remote sever using usbredir to redirect the usb device */
        GSocketClient *client = g_socket_client_new();
        self->connection = g_socket_client_connect_to_host(client,
                self->addr,
                self->port, /* your port goes here */
                NULL,
                &err);
        g_object_unref(client);
        if (err != NULL) {
            g_warning("Failed to connect to the server: %s", err->message);
            goto end;
        }

        GSocket *connection_socket = g_socket_connection_get_socket(self->connection);
        g_socket_set_keepalive(connection_socket, self->keepalive);
        create_watch(self);
    } else {
        GSocketService *socket_service;

        socket_service = g_socket_service_new ();
        GInetAddress *iaddr = g_inet_address_new_from_string(self->addr);
        if (iaddr == NULL) {
            g_warning("Failed to parse IP: %s", self->addr);
            goto end;
        }

        GSocketAddress *saddr = g_inet_socket_address_new(iaddr, self->port);
        g_object_unref(iaddr);

        g_socket_listener_add_address(G_SOCKET_LISTENER (socket_service),
                saddr,
                G_SOCKET_TYPE_STREAM,
                G_SOCKET_PROTOCOL_TCP,
                NULL,
                NULL,
                &err);
        if (err != NULL) {
            g_warning("Failed to run as TCP server: %s", err->message);
            goto end;
        }

      g_signal_connect(socket_service,
              "incoming", G_CALLBACK (connection_incoming_cb),
              self);
    }

    self->main_loop = g_main_loop_new(NULL, FALSE);
    g_main_loop_run(self->main_loop);
    g_clear_pointer(&self->main_loop, g_main_loop_unref);

    g_atomic_int_set(&self->event_thread_run, FALSE);
    if (self->event_thread) {
        libusb_interrupt_event_handler(NULL);
        g_thread_join(self->event_thread);
        self->event_thread = NULL;
    }

end:
    g_clear_pointer(&self->usbredirhost, usbredirhost_close);
    g_clear_pointer(&self->addr, g_free);
    g_clear_object(&self->connection);
    g_free(self);
err_init:
    libusb_exit(NULL);

    if (err != NULL) {
        g_error_free(err);
        return 1;
    }

    return 0;
}


Excerpts from the Termux session using QEMU and a USB device:

alpine:~#
alpine:~# uname -a
Linux alpine 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 GNU/Linux
alpine:~#
alpine:~# apk add usbutils                            
(1/14) Installing hwdata-usb (0.377.2-r0)
(2/14) Installing udev-init-scripts (35-r1)           
(3/14) Installing udev-init-scripts-openrc (35-r1)
(4/14) Installing eudev-libs (3.2.14-r0)
(5/14) Installing xz-libs (5.4.5-r0)                  
(6/14) Installing zstd-libs (1.5.5-r8)
(7/14) Installing kmod-libs (31-r2)                   
(8/14) Installing eudev (3.2.14-r0)
(9/14) Installing eudev-openrc (3.2.14-r0)
(10/14) Installing pkgconf (2.1.0-r0)                 
(11/14) Installing eudev-dev (3.2.14-r0)
(12/14) Installing libusb (1.0.26-r3)                 
(13/14) Installing libusb-dev (1.0.26-r3)
(14/14) Installing usbutils (017-r0)
Executing busybox-1.36.1-r15.trigger
Executing eudev-3.2.14-r0.trigger                     
OK: 65 MiB in 114 packages
alpine:~#                                             
alpine:~#
alpine:~# lsblk                                       
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS           
loop0    7:0    0 19.1M  1 loop /.modloop             
sda      8:0    1 14.4G  0 disk                       
sr0     11:0    1    2K  0 rom                        
vda    253:0    0   60M  1 disk /media/vda
├─vda1 253:1    0   60M  1 part                       
└─vda2 253:2    0  1.4M  1 part
vdb    253:16   0  957M  1 disk /media/vdb            
├─vdb1 253:17   0  957M  1 part
└─vdb2 253:18   0  1.4M  1 part                       
alpine:~# blkid
/dev/vdb2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vdb1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"  
/dev/loop0: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/sda: LABEL="14GB-EXT4" UUID="acfa68fb-a322-4c4e-95ab-41cb0cef0749" BLOCK_SIZE="4096" TYPE="ext4"
/dev/vda2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vda1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660" 
PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01" 
alpine:~# mkdir /mnt/usb1
alpine:~# mount /dev/sda /mnt/usb1
alpine:~# df -h                                       
Filesystem      Size  Used Avail Use% Mounted on      
devtmpfs         10M     0   10M   0% /dev
shm             967M     0  967M   0% /dev/shm        
/dev/vda         60M   60M     0 100% /media/vda
/dev/vdb        957M  957M     0 100% /media/vdb      
tmpfs           967M   59M  908M   7% /
tmpfs           387M  104K  387M   1% /run            
/dev/loop0       20M   20M     0 100% /.modloop       
/dev/sda         15G  2.1M   15G   1% /mnt/usb1
alpine:~# ls -l /mnt/usb1                             
total 16
drwx------ 2 root root 16384 Mar 25 01:52 lost+found  
alpine:~#     
alpine:~# df -h
Filesystem      Size  Used Avail Use% Mounted on      
devtmpfs         10M     0   10M   0% /dev
shm             967M     0  967M   0% /dev/shm        
/dev/vda         60M   60M     0 100% /media/vda      
/dev/vdb        957M  957M     0 100% /media/vdb
tmpfs           967M   59M  908M   7% /
tmpfs           387M  104K  387M   1% /run
/dev/loop0       20M   20M     0 100% /.modloop
/dev/sda         15G  2.1M   15G   1% /mnt/usb1
alpine:~# ls -l /media/vdb                            
total 6                                               
dr-xr-xr-x 1 root root 2048 Dec  7 09:50 apks
dr-xr-xr-x 1 root root 2048 Dec  7 09:50 boot         
dr-xr-xr-x 1 root root 2048 Dec  7 09:50 efi
alpine:~# date ; cp -pr /media/vdb/a /mnt/usb1 ; date
Mon Apr  1 21:57:42 UTC 2024
Mon Apr  1 22:06:27 UTC 2024
alpine:~# ls -l /mnt/usb1
total 20
dr-xr-xr-x 3 root root  4096 Dec  7 09:50 apks        
drwx------ 2 root root 16384 Mar 25 01:52 lost+found
alpine:~# cd /media/vdb
alpine:/media/vdb# du -sch apks
737M    apks
737M    total
alpine:/media/vdb# 
alpine:/media/vdb# date ; find ./apks -exec sha256sum {} > /root/sum.txt \; ; date
Mon Apr  1 22:11:50 UTC 2024                          
sha256sum: ./apks: Is a directory
sha256sum: ./apks/x86_64: Is a directory              
Mon Apr  1 22:15:13 UTC 2024
alpine:/media/vdb# cd /mnt/usb1
alpine:/mnt/usb1# date ; sha256sum -c /root/sum.txt --quiet  -c /root/sum.txt ; date                      
Mon Apr  1 22:21:05 UTC 2024
Mon Apr  1 22:23:00 UTC 2024                          
alpine:/mnt/usb1# umount /mnt/usb1
umount: /mnt/usb1: target is busy.                    
alpine:/mnt/usb1# cd
alpine:~# umount /mnt/usb1                            
alpine:~# fdisk /dev/sda
                                                      
Welcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.            
                                                      
The device contains 'ext4' signature and it will be re
moved by a write command. See fdisk(8) man page and --
wipe option for more details.                         

Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier
 0x0e8ef502.
                                                      
Command (m for help): p
Disk /dev/sda: 14.44 GiB, 15506341888 bytes, 30285824 
sectors
Disk model: USB Flash Drive                           
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes 
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos                                   
Disk identifier: 0x0e8ef502                           

Command (m for help): q
alpine:~#                  
alpine:~# lsusb -vvvv                                 

Bus 001 Device 001: ID 1d6b:0002 Linux 6.6.4-1-virt ehci_hcd EHCI Host Controller
Device Descriptor:
  bLength                18                           
  bDescriptorType         1                           
  bcdUSB               2.00
  bDeviceClass            9 [unknown]                 
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0                           
  bMaxPacketSize0        64                           
  idVendor           0x1d6b Linux 6.6.4-1-virt ehci_hcd
  idProduct          0x0002 EHCI Host Controller      
  bcdDevice            6.06
  iManufacturer           3 Linux 6.6.4-1-virt ehci_hcd
  iProduct                2 EHCI Host Controller      
  iSerial                 1 0000:00:1d.7
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9                         
    bDescriptorType         2                         
    wTotalLength       0x0019
    bNumInterfaces          1                         
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0                       
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 [unknown]             
      bInterfaceSubClass      0 [unknown]
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:                            
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt          
          Synch Type               None               
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes         
        bInterval              12
Hub Descriptor:
  bLength               9                             
  bDescriptorType      41
  nNbrPorts             6                             
  wHubCharacteristic 0x000a
    No power switching (usb 1.0)                      
    Per-port overcurrent protection                   
  bPwrOn2PwrGood       10 * 2 milli seconds           
  bHubContrCurrent      0 milli Ampere
  DeviceRemovable    0x00
  PortPwrCtrlMask    0xff
 Hub Port Status:
   Port 1: 0000.0503 highspeed power enable connect
   Port 2: 0000.0100 power
   Port 3: 0000.0100 power
   Port 4: 0000.0100 power
   Port 5: 0000.0100 power
   Port 6: 0000.0100 power
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable                                                
Device Status:     0x0001                             
  Self Powered                                        

Bus 001 Device 002: ID 0718:7722 Memorex USB Flash Drive
Device Descriptor:                                    
  bLength                18
  bDescriptorType         1                           
  bcdUSB               2.00
  bDeviceClass            0 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x0718 Memorex                   
  idProduct          0x7722 USB Flash Drive
  bcdDevice            1.00
  iManufacturer           1 Memorex                   
  iProduct                2 USB Flash Drive           
  iSerial                 3 [REMOVED-FOR-PRIVACY]          
  bNumConfigurations      1
  Configuration Descriptor:                           
    bLength                 9
    bDescriptorType         2                         
    wTotalLength       0x0020                         
    bNumInterfaces          1                         
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)                                   
    MaxPower              200mA                       
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0                       
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 [unknown]             
      bInterfaceSubClass      6 [unknown]
      bInterfaceProtocol     80
      iInterface              0
      Endpoint Descriptor:                            
        bLength                 7
        bDescriptorType         5                     
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2                     
          Transfer Type            Bulk
          Synch Type               None               
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes       
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5                     
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2                     
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes       
        bInterval               0                     
Device Qualifier (for other device speed):
  bLength                10                           
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0
  bMaxPacketSize0        64
  bNumConfigurations      1
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)

Bus 002 Device 001: ID 1d6b:0001 Linux 6.6.4-1-virt uh
ci_hcd UHCI Host Controller
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            9 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x1d6b Linux 6.6.4-1-virt uhci_hcd
  idProduct          0x0001 UHCI Host Controller
  bcdDevice            6.06
  iManufacturer           3 Linux 6.6.4-1-virt uhci_hcd
  iProduct                2 UHCI Host Controller
  iSerial                 1 0000:00:1d.0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0019
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 [unknown]
      bInterfaceSubClass      0 [unknown]
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0002  1x 2 bytes
        bInterval             255
Hub Descriptor:
  bLength               9
  bDescriptorType      41
  nNbrPorts             2
  wHubCharacteristic 0x000a
    No power switching (usb 1.0)
    Per-port overcurrent protection
  bPwrOn2PwrGood        1 * 2 milli seconds
  bHubContrCurrent      0 milli Ampere
  DeviceRemovable    0x00                             
  PortPwrCtrlMask    0xff
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0100 power
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0001
  Self Powered

Bus 003 Device 001: ID 1d6b:0001 Linux 6.6.4-1-virt uh
ci_hcd UHCI Host Controller
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            9 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x1d6b Linux 6.6.4-1-virt uhci_hcd
  idProduct          0x0001 UHCI Host Controller
  bcdDevice            6.06
  iManufacturer           3 Linux 6.6.4-1-virt uhci_hcd
  iProduct                2 UHCI Host Controller
  iSerial                 1 0000:00:1d.1
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0019
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup                                   
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 [unknown]
      bInterfaceSubClass      0 [unknown]
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0002  1x 2 bytes
        bInterval             255
Hub Descriptor:
  bLength               9
  bDescriptorType      41
  nNbrPorts             2
  wHubCharacteristic 0x000a
    No power switching (usb 1.0)
    Per-port overcurrent protection
  bPwrOn2PwrGood        1 * 2 milli seconds
  bHubContrCurrent      0 milli Ampere
  DeviceRemovable    0x00
  PortPwrCtrlMask    0xff
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0100 power
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0001
  Self Powered

Bus 004 Device 001: ID 1d6b:0001 Linux 6.6.4-1-virt uh
ci_hcd UHCI Host Controller                           
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            9 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x1d6b Linux 6.6.4-1-virt uhci_hcd
  idProduct          0x0001 UHCI Host Controller
  bcdDevice            6.06
  iManufacturer           3 Linux 6.6.4-1-virt uhci_hcd
  iProduct                2 UHCI Host Controller
  iSerial                 1 0000:00:1d.2
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0019
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 [unknown]
      bInterfaceSubClass      0 [unknown]
      bInterfaceProtocol      0
      iInterface              0                       
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0002  1x 2 bytes
        bInterval             255
Hub Descriptor:
  bLength               9
  bDescriptorType      41
  nNbrPorts             2
  wHubCharacteristic 0x000a
    No power switching (usb 1.0)
    Per-port overcurrent protection
  bPwrOn2PwrGood        1 * 2 milli seconds
  bHubContrCurrent      0 milli Ampere
  DeviceRemovable    0x00
  PortPwrCtrlMask    0xff
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0100 power
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0001
  Self Powered                                        
alpine:~#
alpine:~# dmesg
[    0.000000] Linux version 6.6.4-1-virt (buildozer@build-3-19-x86_64) (gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014, GNU ld (GNU Binutils) 2.41) #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-virt modules=loop,squashfs,sd-mod,usb-storage quiet  initrd=/boot/initramfs-virt
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007cfd4fff] usable
[    0.000000] BIOS-e820: [mem 0x000000007cfd5000-0x000000007cffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000b0000000-0x00000000bfffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fed1c000-0x00000000fed1ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[    0.000000] BIOS-e820: [mem 0x000000fd00000000-0x000000ffffffffff] reserved
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] APIC: Static calls initialized
[    0.000000] SMBIOS 2.8 present.                    
[    0.000000] DMI: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org 04/01/2014
[    0.000000] tsc: Fast TSC calibration failed
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.000000] last_pfn = 0x7cfd5 max_arch_pfn = 0x400000000
[    0.000000] MTRR map: 4 entries (3 fixed + 1 variable; max 19), built from 8 variable MTRRs
[    0.000000] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT
[    0.000000] RAMDISK: [mem 0x7c78e000-0x7cfd4fff]   
[    0.000000] ACPI: Early table checksum verification disabled
[    0.000000] ACPI: RSDP 0x00000000000F59A0 000014 (v00 BOCHS )
[    0.000000] ACPI: RSDT 0x000000007CFE247F 000038 (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.000000] ACPI: FACP 0x000000007CFE225F 0000F4 (v03 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.000000] ACPI: DSDT 0x000000007CFE0040 00221F (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.000000] ACPI: FACS 0x000000007CFE0000 000040
[    0.000000] ACPI: APIC 0x000000007CFE2353 000090 (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.000000] ACPI: HPET 0x000000007CFE23E3 000038 (v01 BOCHS  BXPC     00000001 BXPC 00000001)            
[    0.000000] ACPI: MCFG 0x000000007CFE241B 00003C (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.000000] ACPI: WAET 0x000000007CFE2457 000028 (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.000000] ACPI: Reserving FACP table memory at [mem 0x7cfe225f-0x7cfe2352]
[    0.000000] ACPI: Reserving DSDT table memory at [mem 0x7cfe0040-0x7cfe225e]
[    0.000000] ACPI: Reserving FACS table memory at [mem 0x7cfe0000-0x7cfe003f]
[    0.000000] ACPI: Reserving APIC table memory at [mem 0x7cfe2353-0x7cfe23e2]
[    0.000000] ACPI: Reserving HPET table memory at [mem 0x7cfe23e3-0x7cfe241a]
[    0.000000] ACPI: Reserving MCFG table memory at [mem 0x7cfe241b-0x7cfe2456]
[    0.000000] ACPI: Reserving WAET table memory at [mem 0x7cfe2457-0x7cfe247e]
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.000000]   DMA32    [mem 0x0000000001000000-0x000000007cfd4fff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000001000-0x000000000009efff]
[    0.000000]   node   0: [mem 0x0000000000100000-0x000000007cfd4fff]                                      
[    0.000000] Initmem setup node 0 [mem 0x0000000000001000-0x000000007cfd4fff]
[    0.000000] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.000000] On node 0, zone DMA: 97 pages in unavailable ranges
[    0.000000] On node 0, zone DMA32: 12331 pages in unavailable ranges                                     
[    0.000000] ACPI: PM-Timer IO Port: 0x608
[    0.000000] ACPI: LAPIC_NMI (acpi_id[0xff] dfl dfl lint[0x1])
[    0.000000] IOAPIC[0]: apic_id 0, version 32, address 0xfec00000, GSI 0-23
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 5 global_irq 5 high level)
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 10 global_irq 10 high level)
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 11 global_irq 11 high level)
[    0.000000] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.000000] ACPI: HPET id: 0x8086a201 base: 0xfed00000
[    0.000000] smpboot: Allowing 4 CPUs, 0 hotplug CPUs
[    0.000000] [mem 0xc0000000-0xfed1bfff] available for PCI devices
[    0.000000] Booting paravirtualized kernel on bare hardware
[    0.000000] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.000000] setup_percpu: NR_CPUS:256 nr_cpumask_bits:4 nr_cpu_ids:4 nr_node_ids:1
[    0.000000] percpu: Embedded 57 pages/cpu s195048 r8192 d30232 u524288
[    0.000000] pcpu-alloc: s195048 r8192 d30232 u524288 alloc=1*2097152                                     
[    0.000000] pcpu-alloc: [0] 0 1 2 3
[    0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-virt modules=loop,squashfs,sd-mod,usb-storage quiet  initrd=/boot/initramfs-virt
[    0.000000] Unknown kernel command line parameters "BOOT_IMAGE=/boot/vmlinuz-virt modules=loop,squashfs,sd-mod,usb-storage", will be passed to user space.
[    0.000000] Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.000000] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 503701
[    0.000000] mem auto-init: stack:all(zero), heap alloc:on, heap free:off
[    0.000000] Memory: 1968128K/2047436K available (12288K kernel code, 1744K rwdata, 8008K rodata, 2640K init, 2300K bss, 79048K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] Dynamic Preempt: none
[    0.000000] rcu: Preemptible hierarchical RCU implementation.
[    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=4.
[    0.000000]  Trampoline variant of Tasks RCU enabled.
[    0.000000]  Tracing variant of Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS: 16640, nr_irqs: 456, preallocated irqs: 16
[    0.000000] rcu: srcu_init: Setting srcu_struct sizes based on contention.
[    0.000000] kfence: initialized - using 2097152 bytes for 255 objects at 0x(____ptrval____)-0x(____ptrval____)
[    0.000000] Console: colour VGA+ 80x25
[    0.000000] printk: console [tty0] enabled
[    0.000000] ACPI: Core revision 20230628
[    0.000000] clocksource: hpet: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604467 ns
[    0.050000] APIC: Switch to symmetric I/O mode setup
[    0.100000] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1                                         
[    0.180000] tsc: Unable to calibrate against PIT
[    0.190000] tsc: using HPET reference calibration
[    0.190000] tsc: Detected 999.893 MHz processor
[    0.005570] tsc: Marking TSC unstable due to TSCs unsynchronized
[    0.012057] Calibrating delay loop (skipped), value calculated using timer frequency.. 1999.78 BogoMIPS (lpj=9998930)
[    0.033212] process: using AMD E400 aware idle routine
[    0.035583] Last level iTLB entries: 4KB 512, 2MB 255, 4MB 127
[    0.035879] Last level dTLB entries: 4KB 512, 2MB 255, 4MB 127, 1GB 0
[    0.042182] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.044045] Spectre V2 : Mitigation: Retpolines
[    0.044575] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.045261] Spectre V2 : Spectre v2 / SpectreRSB : Filling RSB on VMEXIT
[    0.080855] x86/fpu: x87 FPU will use FXSAVE
[    1.814417] Freeing SMP alternatives memory: 32K
[    1.829001] pid_max: default: 32768 minimum: 301
[    1.966598] LSM: initializing lsm=capability,landlock,lockdown,integrity
[    2.045512] landlock: Up and running.
[    2.126463] Mount-cache hash table entries: 4096 (order: 3, 32768 bytes, linear)
[    2.128961] Mountpoint-cache hash table entries: 4096 (order: 3, 32768 bytes, linear)
[    2.708276] smpboot: CPU0: AMD QEMU Virtual CPU version 2.5+ (family: 0xf, model: 0x6b, stepping: 0x1)
[    2.869922] RCU Tasks: Setting shift to 2 and lim to 1 rcu_task_cb_adjust=1.
[    2.876143] RCU Tasks Trace: Setting shift to 2 and lim to 1 rcu_task_cb_adjust=1.
[    2.887290] Performance Events: PMU not available due to virtualization, using software events only.
[    2.904949] signal: max sigframe size: 1440
[    2.925528] rcu: Hierarchical SRCU implementation.
[    2.926165] rcu:     Max phase no-delay instances is 1000.
[    3.036199] NMI watchdog: Perf NMI watchdog permanently disabled
[    3.080030] smp: Bringing up secondary CPUs ...
[    3.153592] smpboot: x86: Booting SMP configuration:
[    3.154148] .... node  #0, CPUs:      #1 #2 #3
[    0.000000] calibrate_delay_direct() failed to get a good estimate for loops_per_jiffy.
               Probably due to long platform interrupts. Consider using "lpj=" boot option.                 
[    4.182796] smp: Brought up 1 node, 4 CPUs
[    4.184115] smpboot: Max logical packages: 1
[    4.185455] ----------------
[    4.185717] | NMI testsuite:
[    4.185841] --------------------
[    4.185942]   remote IPI:  ok  |
[    4.200334]    local IPI:  ok  |
[    4.201949] --------------------
[    4.202078] Good, all   2 testcases passed! |
[    4.202739] ---------------------------------
[    4.203589] smpboot: Total of 4 processors activated (8052.22 BogoMIPS)
[    4.538876] devtmpfs: initialized
[    4.653899] x86/mm: Memory block size: 128MB
[    4.824567] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    4.838856] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[    5.250562] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    5.320609] audit: initializing netlink subsys (disabled)
[    5.369305] audit: type=2000 audit(1712007173.540:1): state=initialized audit_enabled=0 res=1
[    5.416226] thermal_sys: Registered thermal governor 'step_wise'
[    5.430288] cpuidle: using governor ladder
[    5.432773] cpuidle: using governor menu
[    5.481745] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5
[    5.565823] PCI: MMCONFIG for domain 0000 [bus 00-ff] at [mem 0xb0000000-0xbfffffff] (base 0xb0000000)
[    5.580566] PCI: MMCONFIG at [mem 0xb0000000-0xbfffffff] reserved as E820 entry
[    5.606562] PCI: Using configuration type 1 for base access
[    5.644744] mtrr: your CPUs had inconsistent fixed MTRR settings
[    5.645173] mtrr: your CPUs had inconsistent variable MTRR settings
[    5.645401] mtrr: your CPUs had inconsistent MTRRdefType settings
[    5.645568] mtrr: probably your BIOS does not setup all CPUs.
[    5.645774] mtrr: corrected configuration.
[    5.683517] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    5.838415] HugeTLB: registered 2.00 MiB page size, pre-allocated 0 pages
[    5.838973] HugeTLB: 28 KiB vmemmap can be freed for a 2.00 MiB page
[    6.241988] ACPI: Added _OSI(Module Device)
[    6.243170] ACPI: Added _OSI(Processor Device)
[    6.243475] ACPI: Added _OSI(3.0 _SCP Extensions)
[    6.243555] ACPI: Added _OSI(Processor Aggregator Device)
[    6.596387] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    6.874212] ACPI: _OSC evaluation for CPUs failed, trying _PDC
[    6.921409] ACPI: Interpreter enabled
[    6.942152] ACPI: PM: (supports S0 S3 S5)
[    6.943170] ACPI: Using IOAPIC for interrupt routing
[    6.965748] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    6.966508] PCI: Using E820 reservations for host bridge windows
[    6.995722] ACPI: Enabled 2 GPEs in block 00 to 3F
[    7.673318] ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-ff])
[    7.684157] acpi PNP0A08:00: _OSC: OS supports [ExtendedConfig ASPM ClockPM Segments MSI HPX-Type3]
[    7.710625] acpi PNP0A08:00: _OSC: platform does not support [PCIeHotplug LTR]
[    7.727940] acpi PNP0A08:00: _OSC: OS now controls [PME PCIeCapability]
[    7.833196] PCI host bridge to bus 0000:00
[    7.835806] pci_bus 0000:00: root bus resource [io  0x0000-0x0cf7 window]
[    7.839180] pci_bus 0000:00: root bus resource [io  0x0d00-0xffff window]                                
[    7.839605] pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff window]
[    7.839741] pci_bus 0000:00: root bus resource [mem 0x7d000000-0xafffffff window]
[    7.839863] pci_bus 0000:00: root bus resource [mem 0xc0000000-0xfebfffff window]
[    7.839984] pci_bus 0000:00: root bus resource [mem 0x100000000-0x8ffffffff window]
[    7.841985] pci_bus 0000:00: root bus resource [bus 00-ff]
[    7.869822] pci 0000:00:00.0: [8086:29c0] type 00 class 0x060000
[    7.954401] pci 0000:00:01.0: [1234:1111] type 00 class 0x030000
[    7.982980] pci 0000:00:01.0: reg 0x10: [mem 0xfd000000-0xfdffffff pref]
[    8.010644] pci 0000:00:01.0: reg 0x18: [mem 0xfebf0000-0xfebf0fff]
[    8.093686] pci 0000:00:01.0: reg 0x30: [mem 0xfebe0000-0xfebeffff pref]                                 
[    8.104398] pci 0000:00:01.0: Video device with shadowed ROM at [mem 0x000c0000-0x000dffff]
[    8.121467] pci 0000:00:02.0: [1af4:1005] type 00 class 0x00ff00
[    8.135172] pci 0000:00:02.0: reg 0x10: [io  0xc140-0xc15f]                                              
[    8.158713] pci 0000:00:02.0: reg 0x14: [mem 0xfebf1000-0xfebf1fff]                                      
[    8.218916] pci 0000:00:02.0: reg 0x20: [mem 0xfe000000-0xfe003fff 64bit pref]                           
[    8.259656] pci 0000:00:03.0: [1af4:1001] type 00 class 0x010000
[    8.268276] pci 0000:00:03.0: reg 0x10: [io  0xc000-0xc07f]                                              
[    8.293318] pci 0000:00:03.0: reg 0x14: [mem 0xfebf2000-0xfebf2fff]                                      
[    8.360305] pci 0000:00:03.0: reg 0x20: [mem 0xfe004000-0xfe007fff 64bit pref]                           
[    8.415745] pci 0000:00:04.0: [1af4:1001] type 00 class 0x010000                                         
[    8.438741] pci 0000:00:04.0: reg 0x10: [io  0xc080-0xc0ff]                                              
[    8.458863] pci 0000:00:04.0: reg 0x14: [mem 0xfebf3000-0xfebf3fff]                                      
[    8.518729] pci 0000:00:04.0: reg 0x20: [mem 0xfe008000-0xfe00bfff 64bit pref]                           
[    8.571916] pci 0000:00:1d.0: [8086:2934] type 00 class 0x0c0300                                         
[    8.613327] pci 0000:00:1d.0: reg 0x20: [io  0xc160-0xc17f]                                              
[    8.651551] pci 0000:00:1d.1: [8086:2935] type 00 class 0x0c0300
[    8.695750] pci 0000:00:1d.1: reg 0x20: [io  0xc180-0xc19f]
[    8.734389] pci 0000:00:1d.2: [8086:2936] type 00 class 0x0c0300                                         
[    8.778900] pci 0000:00:1d.2: reg 0x20: [io  0xc1a0-0xc1bf]
[    8.816343] pci 0000:00:1d.7: [8086:293a] type 00 class 0x0c0320
[    8.822366] pci 0000:00:1d.7: reg 0x10: [mem 0xfebf4000-0xfebf4fff]
[    8.893757] pci 0000:00:1f.0: [8086:2918] type 00 class 0x060100
[    8.902333] pci 0000:00:1f.0: quirk: [io  0x0600-0x067f] claimed by ICH6 ACPI/GPIO/TCO
[    8.920142] pci 0000:00:1f.2: [8086:2922] type 00 class 0x010601
[    9.005055] pci 0000:00:1f.2: reg 0x20: [io  0xc1c0-0xc1df]                                              
[    9.025345] pci 0000:00:1f.2: reg 0x24: [mem 0xfebf5000-0xfebf5fff]                                      
[    9.068624] pci 0000:00:1f.3: [8086:2930] type 00 class 0x0c0500                                         
[    9.109552] pci 0000:00:1f.3: reg 0x20: [io  0x0700-0x073f]                                              
[    9.145874] pci_bus 0000:00: on NUMA node 0
[    9.206097] ACPI: PCI: Interrupt link LNKA configured for IRQ 10
[    9.219745] ACPI: PCI: Interrupt link LNKB configured for IRQ 10                                         
[    9.230480] ACPI: PCI: Interrupt link LNKC configured for IRQ 11                                         
[    9.243157] ACPI: PCI: Interrupt link LNKD configured for IRQ 11                                         
[    9.251789] ACPI: PCI: Interrupt link LNKE configured for IRQ 10                                         
[    9.260973] ACPI: PCI: Interrupt link LNKF configured for IRQ 10                                         
[    9.270558] ACPI: PCI: Interrupt link LNKG configured for IRQ 11                                         
[    9.280116] ACPI: PCI: Interrupt link LNKH configured for IRQ 11                                         
[    9.283274] ACPI: PCI: Interrupt link GSIA configured for IRQ 16                                         
[    9.284740] ACPI: PCI: Interrupt link GSIB configured for IRQ 17                                         
[    9.285960] ACPI: PCI: Interrupt link GSIC configured for IRQ 18                                         
[    9.288731] ACPI: PCI: Interrupt link GSID configured for IRQ 19                                         
[    9.290246] ACPI: PCI: Interrupt link GSIE configured for IRQ 20
[    9.292355] ACPI: PCI: Interrupt link GSIF configured for IRQ 21
[    9.293768] ACPI: PCI: Interrupt link GSIG configured for IRQ 22
[    9.295146] ACPI: PCI: Interrupt link GSIH configured for IRQ 23
[    9.388568] iommu: Default domain type: Translated
[    9.389812] iommu: DMA domain TLB invalidation policy: lazy mode
[    9.444644] SCSI subsystem initialized             
[    9.460369] libata version 3.00 loaded.
[    9.480254] pps_core: LinuxPPS API ver. 1 registered
[    9.480538] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    9.481796] PTP clock support registered           
[    9.695319] PCI: Using ACPI for IRQ routing
[    9.756784] PCI: pci_cache_line_size set to 64 bytes
[    9.767668] e820: reserve RAM buffer [mem 0x0009fc00-0x0009ffff]                                         
[    9.771630] e820: reserve RAM buffer [mem 0x7cfd5000-0x7fffffff]                                         
[    9.827654] hpet: 3 channels of 0 reserved for per-cpu timers                                            
[    9.842671] clocksource: Switched to clocksource hpet                                                    
[   10.024982] VFS: Disk quotas dquot_6.6.0
[   10.042738] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[   10.117639] pnp: PnP ACPI init                     
[   10.264667] system 00:05: [mem 0xb0000000-0xbfffffff window] has been reserved                           
[   10.334474] pnp: PnP ACPI: found 6 devices
[   11.090779] clocksource: acpi_pm: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 2085701024 ns
[   11.112734] NET: Registered PF_INET protocol family
[   11.130886] IP idents hash table entries: 32768 (order: 6, 262144 bytes, linear)                         
[   11.687145] tcp_listen_portaddr_hash hash table entries: 1024 (order: 2, 16384 bytes, linear)            
[   11.734348] Table-perturb hash table entries: 65536
 (order: 6, 262144 bytes, linear)                     
[   11.743379] TCP established hash table entries: 163
84 (order: 5, 131072 bytes, linear)                   
[   11.755257] TCP bind hash table entries: 16384 (order: 7, 524288 bytes, linear)
[   11.762836] TCP: Hash tables configured (established 16384 bind 16384)
[   11.887174] UDP hash table entries: 1024 (order: 3,
 32768 bytes, linear)
[   11.894799] UDP-Lite hash table entries: 1024 (order: 3, 32768 bytes, linear)
[   11.977565] NET: Registered PF_UNIX/PF_LOCAL protocol family                                             
[   11.991567] NET: Registered PF_XDP protocol family 
[   12.007870] pci_bus 0000:00: resource 4 [io  0x0000
-0x0cf7 window]                                       
[   12.016792] pci_bus 0000:00: resource 5 [io  0x0d00
-0xffff window]
[   12.017047] pci_bus 0000:00: resource 6 [mem 0x000a
0000-0x000bffff window]
[   12.017712] pci_bus 0000:00: resource 7 [mem 0x7d00
0000-0xafffffff window]
[   12.017833] pci_bus 0000:00: resource 8 [mem 0xc000
0000-0xfebfffff window]
[   12.017951] pci_bus 0000:00: resource 9 [mem 0x1000
00000-0x8ffffffff window]
[   12.256351] ACPI: \_SB_.GSIA: Enabled at IRQ 16    
[   12.529005] pci 0000:00:1d.0: quirk_usb_early_handoff+0x0/0x7d0 took 454798 usecs
[   12.566595] ACPI: \_SB_.GSIB: Enabled at IRQ 17    
[   12.628369] pci 0000:00:1d.1: quirk_usb_early_handoff+0x0/0x7d0 took 87745 usecs
[   12.661857] ACPI: \_SB_.GSIC: Enabled at IRQ 18    
[   12.701614] pci 0000:00:1d.2: quirk_usb_early_handoff+0x0/0x7d0 took 66438 usecs                         
[   12.734926] ACPI: \_SB_.GSID: Enabled at IRQ 19
[   12.892486] pci 0000:00:1d.7: quirk_usb_early_handoff+0x0/0x7d0 took 185556 usecs
[   12.893941] PCI: CLS 0 bytes, default 64
[   13.394823] Initialise system trusted keyrings     
[   13.463255] workingset: timestamp_bits=46 max_order=19 bucket_order=0                                    
[   13.467560] zbud: loaded
[   13.493907] Unpacking initramfs...                 
[   13.612924] Key type asymmetric registered
[   13.614267] Asymmetric key parser 'x509' registered
[   13.637832] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 247)                         
[   13.695936] io scheduler mq-deadline registered    
[   13.696892] io scheduler kyber registered
[   13.712764] io scheduler bfq registered
[   14.076739] ERST DBG: ERST support is disabled.
[   14.153387] ACPI: \_SB_.GSIG: Enabled at IRQ 22
[   14.313041] ACPI: \_SB_.GSIH: Enabled at IRQ 23    
[   14.374598] ACPI: \_SB_.GSIE: Enabled at IRQ 20
[   14.472766] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[   14.597006] 00:03: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[   15.020698] VMware PVSCSI driver - version 1.0.7.0-k
[   15.027344] ahci 0000:00:1f.2: version 3.0
[   15.292378] ahci 0000:00:1f.2: AHCI 0001.0000 32 slots 6 ports 1.5 Gbps 0x3f impl SATA mode
[   15.294066] ahci 0000:00:1f.2: flags: 64bit ncq only                                                     
[   15.665024] scsi host0: ahci
[   15.791575] scsi host1: ahci                       
[   15.833060] scsi host2: ahci
[   15.941192] scsi host3: ahci                       
[   16.013189] scsi host4: ahci
[   16.087056] scsi host5: ahci                       
[   16.106877] ata1: SATA max UDMA/133 abar m4096@0xfebf5000 port 0xfebf5100 irq 24                         
[   16.119583] ata2: SATA max UDMA/133 abar m4096@0xfebf5000 port 0xfebf5180 irq 24
[   16.119934] ata3: SATA max UDMA/133 abar m4096@0xfebf5000 port 0xfebf5200 irq 24
[   16.120168] ata4: SATA max UDMA/133 abar m4096@0xfebf5000 port 0xfebf5280 irq 24
[   16.120300] ata5: SATA max UDMA/133 abar m4096@0xfebf5000 port 0xfebf5300 irq 24
[   16.120401] ata6: SATA max UDMA/133 abar m4096@0xfebf5000 port 0xfebf5380 irq 24                         
[   16.232543] i8042: PNP: PS/2 Controller [PNP0303:KBD,PNP0f13:MOU] at 0x60,0x64 irq 1,12
[   16.471292] serio: i8042 KBD port at 0x60,0x64 irq 1
[   16.474311] serio: i8042 AUX port at 0x60,0x64 irq 12
[   16.504753] rtc_cmos 00:04: RTC can wake from S4   
[   16.595937] hpet: Lost 1 RTC interrupts
[   16.724557] ata2: SATA link down (SStatus 0 SControl 300)
[   16.740177] rtc_cmos 00:04: registered as rtc0     
[   16.789469] ata3: SATA link up 1.5 Gbps (SStatus 113 SControl 300)                                       
[   16.775969] rtc_cmos 00:04: setting system clock to 2024-04-01T21:33:05 UTC (1712007185)
[   16.866427] rtc_cmos 00:04: alarms up to one day, y3k, 242 bytes nvram, hpet irqs                        
[   16.870397] input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input0           
[   16.891118] amd_pstate: the _CPC object is not present in SBIOS or ACPI disabled
[   16.924064] ata3.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100
[   16.925230] ata3.00: applying bridge limits
[   16.965877] gre: GRE over IPv4 demultiplexor driver
[   16.992084] ata3.00: configured for UDMA/100
[   17.043584] ata1: SATA link down (SStatus 0 SControl 300)
[   17.044815] ata5: SATA link down (SStatus 0 SControl 300)
[   17.045992] ata6: SATA link down (SStatus 0 SControl 300)
[   17.076427] ata4: SATA link down (SStatus 0 SControl 300)
[   17.562645] scsi 2:0:0:0: CD-ROM            QEMU     QEMU DVD-ROM     2.5+ PQ: 0 ANSI: 5
[   18.166330] Key type dns_resolver registered
[   18.263365] IPI shorthand broadcast: enabled
[   19.343165] registered taskstats version 1         
[   19.417162] Loading compiled-in X.509 certificates
[   23.084844] Freeing initrd memory: 8476K
[   27.628304] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: d76a695f66ad9cd28f5c22a8508f36e91f521f7a'                                             
[   27.767312] Key type .fscrypt registered
[   27.767776] Key type fscrypt-provisioning registered
[   27.863714] Unstable clock detected, switching default tracing clock to "global"
               If you want to keep using the local clock, then add:
                 "trace_clock=local"                  
               on the kernel command line
[   28.242968] Freeing unused kernel image (initmem) memory: 2640K
[   28.245890] Write protecting the kernel read-only data: 20480k
[   28.276895] Freeing unused kernel image (rodata/data gap) memory: 184K
[   28.285099] rodata_test: all tests were successful 
[   28.290395] Run /init as init process
[   28.291479]   with arguments:                      
[   28.291875]     /init
[   28.292086]   with environment:                    
[   28.292278]     HOME=/
[   28.292482]     TERM=linux                         
[   28.292554]     BOOT_IMAGE=/boot/vmlinuz-virt
[   28.292671]     modules=loop,squashfs,sd-mod,usb-storage
[   30.565435] Alpine Init 3.9.0-r0                   
[   30.697375] Loading boot drivers...
[   31.909734] loop: module loaded                    
[   32.141796] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[   33.929481] ACPI: bus type USB registered          
[   33.938000] usbcore: registered new interface driver usbfs                                               
[   33.963448] usbcore: registered new interface driver hub                                                 
[   33.966923] usbcore: registered new device driver usb
[   34.213747] usbcore: registered new interface driver usb-storage
[   35.830471] ACPI: bus type drm_connector registered
[   36.912430] Loading boot drivers: ok.
[   37.206693] Mounting boot media...                 
[   50.232058] ehci-pci 0000:00:1d.7: EHCI Host Controller                                                  
[   50.281662] ehci-pci 0000:00:1d.7: new USB bus registered, assigned bus number 1
[   50.365287] ehci-pci 0000:00:1d.7: irq 19, io mem 0xfebf4000                                             
[   50.391930] ehci-pci 0000:00:1d.7: USB 2.0 started, EHCI 1.00                                            
[   50.470802] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.06               
[   50.471593] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   50.471848] usb usb1: Product: EHCI Host Controller
[   50.472076] usb usb1: Manufacturer: Linux 6.6.4-1-virt ehci_hcd                                          
[   50.472305] usb usb1: SerialNumber: 0000:00:1d.7
[   50.591998] hub 1-0:1.0: USB hub found             
[   50.600098] hub 1-0:1.0: 6 ports detected
[   51.033067] uhci_hcd 0000:00:1d.0: UHCI Host Controller
[   51.034542] uhci_hcd 0000:00:1d.0: new USB bus registered, assigned bus number 2                         
[   51.036214] uhci_hcd 0000:00:1d.0: detected 2 ports
[   51.043596] uhci_hcd 0000:00:1d.0: irq 16, io port 0x0000c160
[   51.095418] usb usb2: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.06
[   51.095807] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   51.095934] usb usb2: Product: UHCI Host Controller
[   51.096047] usb usb2: Manufacturer: Linux 6.6.4-1-virt uhci_hcd                                          
[   51.096150] usb usb2: SerialNumber: 0000:00:1d.0
[   51.144307] hub 2-0:1.0: USB hub found             
[   51.147426] hub 2-0:1.0: 2 ports detected
[   51.304600] uhci_hcd 0000:00:1d.1: UHCI Host Controller
[   51.307780] uhci_hcd 0000:00:1d.1: new USB bus registered, assigned bus number 3
[   51.308333] uhci_hcd 0000:00:1d.1: detected 2 ports
[   51.331259] uhci_hcd 0000:00:1d.1: irq 17, io port 0x0000c180                                            
[   51.352775] usb 1-1: new high-speed USB device number 2 using ehci-pci                                   
[   51.433205] usb usb3: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.06               
[   51.433593] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1                           
[   51.433723] usb usb3: Product: UHCI Host Controller
[   51.433835] usb usb3: Manufacturer: Linux 6.6.4-1-virt uhci_hcd
[   51.433939] usb usb3: SerialNumber: 0000:00:1d.1   
[   51.522672] hub 3-0:1.0: USB hub found
[   51.526524] hub 3-0:1.0: 2 ports detected          
[   51.667132] uhci_hcd 0000:00:1d.2: UHCI Host Controller                                                  
[   51.668003] uhci_hcd 0000:00:1d.2: new USB bus registered, assigned bus number 4                         
[   51.681624] uhci_hcd 0000:00:1d.2: detected 2 ports
[   51.687810] uhci_hcd 0000:00:1d.2: irq 18, io port 0x0000c1a0
[   51.703894] usb usb4: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.06
[   51.704302] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   51.704443] usb usb4: Product: UHCI Host Controller
[   51.704548] usb usb4: Manufacturer: Linux 6.6.4-1-virt uhci_hcd                                          
[   51.704695] usb usb4: SerialNumber: 0000:00:1d.2
[   51.745249] hub 4-0:1.0: USB hub found             
[   51.747450] hub 4-0:1.0: 2 ports detected
[   51.995064] usb 1-1: New USB device found, idVendor=0718, idProduct=7722, bcdDevice= 1.00
[   52.001747] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   52.001985] usb 1-1: Product: USB Flash Drive      
[   52.002137] usb 1-1: Manufacturer: Memorex
[   52.002260] usb 1-1: SerialNumber: 070384089800D418
[   52.076283] usb-storage 1-1:1.0: USB Mass Storage device detected                                        
[   52.327784] scsi host6: usb-storage 1-1:1.0
[   53.860031] sr 2:0:0:0: [sr0] scsi3-mmc drive: 4x/4x cd/rw xa/form2 tray
[   53.863863] cdrom: Uniform CD-ROM driver Revision: 3.20
[   53.873434] scsi 6:0:0:0: Direct-Access     Memorex  USB Flash Drive  PMAP PQ: 0 ANSI: 6
[   53.905650] sr 2:0:0:0: [sr0] Hmm, seems the drive doesn't support multisession CD's
[   54.164249] sd 6:0:0:0: [sda] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[   54.208137] sd 6:0:0:0: [sda] Write Protect is off 
[   54.231635] sd 6:0:0:0: [sda] Mode Sense: 23 00 00 00                                                    
[   54.281368] sd 6:0:0:0: [sda] No Caching mode page found                                                 
[   54.281999] sd 6:0:0:0: [sda] Assuming drive cache: write through                                        
[   54.292293] sr 2:0:0:0: Attached scsi CD-ROM sr0
[   54.658378] sd 6:0:0:0: [sda] Attached SCSI removable disk
[   56.311703] virtio_blk virtio1: 4/0/0 default/read/poll queues                                           
[   56.467150] virtio_blk virtio1: [vda] 122880 512-byte logical blocks (62.9 MB/60.0 MiB)                  
[   56.543669]  vda: vda1 vda2
[   56.578045] virtio_blk virtio2: 4/0/0 default/read/poll queues
[   56.647627] virtio_blk virtio2: [vdb] 1959936 512-byte logical blocks (1.00 GB/957 MiB)
[   56.693923]  vdb: vdb1 vdb2                        
[   57.963343] usbcore: registered new interface driver uas                                                 
[   89.393800] block sr0: the capability attribute has been deprecated.                                     
[  103.044024] ISO 9660 Extensions: Microsoft Joliet Level 3                                                
[  103.310735] ISO 9660 Extensions: RRIP_1991A
[  105.769661] hrtimer: interrupt took 70444770 ns    
[  127.367386] EXT4-fs (sda): orphan cleanup on readonly fs                                                 
[  127.394858] EXT4-fs (sda): mounted filesystem acfa68fb-a322-4c4e-95ab-41cb0cef0749 ro with ordered data mode. Quota mode: none.
[  127.557908] EXT4-fs (sda): unmounting filesystem acfa68fb-a322-4c4e-95ab-41cb0cef0749.
[  131.715025] ISO 9660 Extensions: Microsoft Joliet Level 3
[  131.770264] ISO 9660 Extensions: RRIP_1991A        
[  134.773074] Mounting boot media: ok.
[  137.683091] random: crng init done                 
[  143.343684] Installing packages to root filesystem...                                                    
[  160.782514] Installing packages to root filesystem: ok.
[  205.448778] loop0: detected capacity change from 0 to 39088
[  279.818391] input: Power Button as /devices/LNXSYSTM:00/LNXPWRBN:00/input/input3
[  280.373156] ACPI: button: Power Button [PWRF]      
[  300.453217] [drm] Found bochs VGA, ID 0xb0c5.
[  300.453970] [drm] Framebuffer size 16384 kB @ 0xfd000000, mmio @ 0xfebf0000.
[  300.784463] [drm] Found EDID data blob.
[  301.096290] [drm] Initialized bochs-drm 1.0.0 20130925 for 0000:00:01.0 on minor 0                       
[  303.945569] Console: switching to colour frame buffer device 160x50                                      
[  304.323306] bochs-drm 0000:00:01.0: [drm] fb0: bochs-drmdrmfb frame buffer device                        
[  309.744182] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input4        
[  315.962165] mousedev: PS/2 mouse device common for all mice                                              
[  344.606717] NET: Registered PF_PACKET protocol family
[  347.379369] NET: Registered PF_INET6 protocol family
[  347.581294] Segment Routing with IPv6
[  347.584230] In-situ OAM (IOAM) with IPv6           
[ 1241.924528] EXT4-fs (sda): mounted filesystem acfa68fb-a322-4c4e-95ab-41cb0cef0749 r/w with ordered data mode. Quota mode: none.                               
[ 3248.430981] EXT4-fs (sda): unmounting filesystem acfa68fb-a322-4c4e-95ab-41cb0cef0749.
alpine:~#                                             
alpine:~# eject /dev/sda                              
alpine:~#                                             
alpine:~# dmesg|tail
[  304.323306] bochs-drm 0000:00:01.0: [drm] fb0: bochs-drmdrmfb frame buffer device
[  309.744182] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input4
[  315.962165] mousedev: PS/2 mouse device common for all mice
[  344.606717] NET: Registered PF_PACKET protocol family
[  347.379369] NET: Registered PF_INET6 protocol family
[  347.581294] Segment Routing with IPv6              
[  347.584230] In-situ OAM (IOAM) with IPv6
[ 1241.924528] EXT4-fs (sda): mounted filesystem acfa68fb-a322-4c4e-95ab-41cb0cef0749 r/w with ordered data mode. Quota mode: none.
[ 3248.430981] EXT4-fs (sda): unmounting filesystem acfa68fb-a322-4c4e-95ab-41cb0cef0749.
[ 3864.585632] sda: detected capacity change from 30285824 to 0
alpine:~#
alpine:~# lsblk                                       
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
loop0    7:0    0 19.1M  1 loop /.modloop             
sda      8:0    1    0B  0 disk
sr0     11:0    1    2K  0 rom                        
vda    253:0    0   60M  1 disk /media/vda
├─vda1 253:1    0   60M  1 part
└─vda2 253:2    0  1.4M  1 part                       
vdb    253:16   0  957M  1 disk /media/vdb
├─vdb1 253:17   0  957M  1 part
└─vdb2 253:18   0  1.4M  1 part  
alpine:~#
alpine:~# blkid
/dev/vdb2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"                             
/dev/vdb1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"  
/dev/loop0: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/vda2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vda1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"
alpine:~#

@NoteAfterNote NoteAfterNote changed the title Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect "dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". Apr 1, 2024
@NoteAfterNote NoteAfterNote changed the title Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". Apr 1, 2024
@NoteAfterNote NoteAfterNote changed the title Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect --device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". Apr 1, 2024
@NoteAfterNote NoteAfterNote changed the title Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect --device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". Apr 1, 2024
@sylirre
Copy link
Member

sylirre commented Apr 1, 2024

-e option accepts single argument. If command line contains spaces, it should be enclosed in quotes to prevent word splitting.

@Grimler91
Copy link
Member

If I recall correctly you can simply quote the entire command that termux-usb should run, and add path as last argument to termux-usb:

termux-usb -e "usbredirect --device /dev/bus/usb/001/031 --to 127.0.0.1:23456" /dev/bus/usb/001/031

It looks like your usbredirect program tries to get the fd from argv[1] though, and argv[1] will be --device with above command, while fd is passed in argv[5] (last arg).

Might be easier to pass fd as an environmental var with -E arg of termux-usb, and then parse TERMUX_USB_FD in usbredirect.

@NoteAfterNote
Copy link
Author

If I recall correctly you can simply quote the entire command that termux-usb should run, and add path as last argument to termux-usb:

termux-usb -e "usbredirect --device /dev/bus/usb/001/031 --to 127.0.0.1:23456" /dev/bus/usb/001/031

It looks like your usbredirect program tries to get the fd from argv[1] though, and argv[1] will be --device with above command, while fd is passed in argv[5] (last arg).

Might be easier to pass fd as an environmental var with -E arg of termux-usb, and then parse TERMUX_USB_FD in usbredirect.

See "Update-3".

@victortoso
Copy link

usbredirect --device /dev/bus/usb/001/031

This is not correct input for usbredirect. You should use vendor:product or bus-device_number, not a path.

@NoteAfterNote
Copy link
Author

NoteAfterNote commented Apr 12, 2024

Termux, sockets, QEMU, and the Linux operating system

Sessions: Termux, QEMU, QEMU Linux Server

Termux session: USB flash drive

~/.../build/tools $
~/.../build/tools $ termux-usb -l                          
[
"/dev/bus/usb/001/009"
~/.../build/tools $
~/.../build/tools $ termux-usb -r /dev/bus/usb/001/009
Access granted.
~/.../build/tools $
~/.../build/tools $ termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/009 --as 127.0.0.1:40000" /dev/bus/usb/001/009

QEMU Session (Termux):

~/qemu $                            
~/qemu $ export ISO1=$HOME/qemu/alpine-virt-3.19.0-x86_64.iso ; export ISO2=$HOME/qemu/alpine-extended-3.19.0-x86_64.iso ; qemu-system-x86_64 -m 1024M -machine q35 -smp 4 -device virtio-rng-pci -nographic  -readconfig $HOME/ich9-ehci-uhci.cfg  -drive if=none,id=iso1,readonly=on,format=raw,file=$ISO1 -device virtio-blk-pci,id=virt1,drive=iso1,bootindex=1  -drive if=none,id=iso2,readonly=on,format=raw,file=$ISO2 -device virtio-blk-pci,id=virt2,drive=iso2   -virtfs local,security_model=none,id=termux,mount_tag=termux,path=/data/data/com.termux/files   -virtfs local,security_model=none,id=host,mount_tag=host,path=/storage/emulated/0/Download/usb1   -device virtio-serial  -chardev socket,path=$HOME/qemu/termux.socket,id=termux-socket,name=talk-to-termux,server=on,wait=off -device virtserialport,id=port1,chardev=termux-socket  -device virtio-net-pci,netdev=net0,mac=52:54:12:34:56:78 -netdev user,id=net0,ipv6=off,hostfwd=tcp::9999-:80

In The QEMU Monitor (Press CTRL-a c):

QEMU 8.0.2 monitor - type 'help' for more information
(qemu)
(qemu) chardev-add socket,id=c1,host=127.0.0.1,port=40000
(qemu) device_add usb-redir,id=u1,chardev=c1,debug=3
(qemu) qemu-system-x86_64: usbredirparser: Peer version: usbredir 0.14.0, using 64-bitss
qemu-system-x86_64: usb-redir: attaching high speed device 0718:7722 version 1.0 class 0
(qemu)
(qemu) info chardev
parallel0: filename=null
serial0: filename=mux
c1: filename=tcp:127.0.0.1:33302 <-> 127.0.0.1:40000
serial0-base: filename=stdio
termux-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/termux.n
(qemu)
(qemu) info virtio
/machine/peripheral-anon/device[4]/virtio-backend [virtio-net]
/machine/peripheral-anon/device[3]/virtio-backend [virtio-serial]
/machine/peripheral-anon/device[2]/virtio-backend [virtio-9p]
/machine/peripheral-anon/device[1]/virtio-backend [virtio-9p]
/machine/peripheral/virt2/virtio-backend [virtio-blk]
/machine/peripheral/virt1/virtio-backend [virtio-blk]
/machine/peripheral-anon/device[0]/virtio-backend [virtio-rng]
(qemu)
(qemu) info virtio-status /machine/peripheral-anon/device[3]/virtio-backend
/machine/peripheral-anon/device[3]/virtio-backend:
  device_name:             virtio-serial
  device_id:               3
  vhost_started:           false
  bus_name:                (NULL)
  broken:                  false
  disabled:                false
  disable_legacy_check:    false
  started:                 true
  use_started:             true
  start_on_kick:           false
  use_guest_notifier_mask: true
  vm_running:              true
  num_vqs:                 64
  queue_sel:               63
  isr:                     1
  endianness:              little
  status:
        VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found,
        VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device,
        VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete,
        VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready
  Guest features:
        VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled,
        VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
        VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)
        VIRTIO_CONSOLE_F_MULTIPORT: Multiple ports for device supported
  unknown-features(0x0000010000000000)
  Host features:
        VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled,
        VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
        VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy),
        VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts,
        VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ
        VIRTIO_CONSOLE_F_EMERG_WRITE: Emergency write supported,
        VIRTIO_CONSOLE_F_MULTIPORT: Multiple ports for device supported
  unknown-features(0x0000010040000000)
  Backend features:
(qemu)
(qemu)

Leave The QEMU Monitor (Press CTRL-a c).

Welcome to Alpine Linux 3.19
Kernel 6.6.4-1-virt on an x86_64 (/dev/ttyS0)

localhost login: root

localhost:~#
localhost:~# ls -l /dev
total 0
drwxrwxrwx    2 root     root           220 Apr 12 16:38 block
drwxr-xr-x    2 root     root            80 Apr 12 16:35 bsg
drwxr-xr-x    3 root     root            60 Apr 12 16:35 bus
lrwxrwxrwx    1 root     root             3 Apr 12 16:38 cdrom -> sr0
crw-------    1 root     tty         5,   1 Apr 12 16:34 console
crw-rw----    1 root     root       10, 127 Apr 12 16:34 cpu_dma_latency
drwxrwxrwx    5 root     root           100 Apr 12 16:36 disk
drwxr-xr-x    2 root     root            60 Apr 12 16:39 dri
crw-rw----    1 root     video      29,   0 Apr 12 16:39 fb0
lrwxrwxrwx    1 root     root            13 Apr 12 16:37 fd -> /proc/self/fd
crw-rw-rw-    1 root     root        1,   7 Apr 12 16:34 full
crw-rw----    1 root     root       10, 183 Apr 12 16:39 hwrng
drwxr-xr-x    2 root     root           140 Apr 12 16:39 input
crw-rw----    1 root     root        1,  11 Apr 12 16:34 kmsg
srw-rw-rw-    1 root     wheel            0 Apr 12 16:40 log
drwxr-xr-x    2 root     root           200 Apr 12 16:35 loop
crw-rw----    1 root     root       10, 237 Apr 12 16:34 loop-control
brw-------    1 root     root        7,   0 Apr 12 16:34 loop0
brw-------    1 root     root        7,   1 Apr 12 16:34 loop1
brw-------    1 root     root        7,   2 Apr 12 16:34 loop2
brw-------    1 root     root        7,   3 Apr 12 16:34 loop3
brw-------    1 root     root        7,   4 Apr 12 16:34 loop4
brw-------    1 root     root        7,   5 Apr 12 16:34 loop5
brw-------    1 root     root        7,   6 Apr 12 16:34 loop6
brw-------    1 root     root        7,   7 Apr 12 16:34 loop7
crw-r-----    1 root     kmem        1,   1 Apr 12 16:34 mem
drwxr-xr-x    2 root     root            60 Apr 12 16:39 misc
drwxrwxrwt    2 root     root            40 Apr 12 16:34 mqueue
crw-rw-rw-    1 root     root        1,   3 Apr 12 16:34 null
crw-r-----    1 root     kmem        1,   4 Apr 12 16:34 port
crw-------    1 root     root       10,   1 Apr 12 16:39 psaux
crw-rw-rw-    1 root     tty         5,   2 Apr 12 16:34 ptmx
drwxr-xr-x    2 root     root             0 Apr 12 16:34 pts
crw-rw-rw-    1 root     root        1,   8 Apr 12 16:34 random
crw-rw----    1 root     root      251,   0 Apr 12 16:34 rtc0
brw-rw----    1 root     disk        8,   0 Apr 12 16:35 sda
brw-rw----    1 root     disk        8,   1 Apr 12 16:35 sda1
drwxrwxrwt    2 root     root            40 Apr 12 16:34 shm
brw-rw----    1 root     cdrom      11,   0 Apr 12 16:35 sr0
lrwxrwxrwx    1 root     root            15 Apr 12 16:37 stderr -> /proc/self/fd/2
lrwxrwxrwx    1 root     root            15 Apr 12 16:37 stdin -> /proc/self/fd/0
lrwxrwxrwx    1 root     root            15 Apr 12 16:37 stdout -> /proc/self/fd/1
crw-rw-rw-    1 root     tty         5,   0 Apr 12 16:41 tty
crw-------    1 root     root        4,   0 Apr 12 16:34 tty0
crw--w----    1 root     root        4,   1 Apr 12 16:40 tty1
crw-rw----    1 root     tty         4,  10 Apr 12 16:34 tty10
crw-rw----    1 root     tty         4,  11 Apr 12 16:34 tty11
crw-rw----    1 root     tty         4,  12 Apr 12 16:34 tty12
crw-rw----    1 root     tty         4,  13 Apr 12 16:34 tty13
crw-rw----    1 root     tty         4,  14 Apr 12 16:34 tty14
crw-rw----    1 root     tty         4,  15 Apr 12 16:34 tty15
crw-rw----    1 root     tty         4,  16 Apr 12 16:34 tty16
crw-rw----    1 root     tty         4,  17 Apr 12 16:34 tty17
crw-rw----    1 root     tty         4,  18 Apr 12 16:34 tty18
crw-rw----    1 root     tty         4,  19 Apr 12 16:34 tty19
crw--w----    1 root     root        4,   2 Apr 12 16:40 tty2
crw-rw----    1 root     tty         4,  20 Apr 12 16:34 tty20
crw-rw----    1 root     tty         4,  21 Apr 12 16:34 tty21
crw-rw----    1 root     tty         4,  22 Apr 12 16:34 tty22
crw-rw----    1 root     tty         4,  23 Apr 12 16:34 tty23
crw-rw----    1 root     tty         4,  24 Apr 12 16:34 tty24
crw-rw----    1 root     tty         4,  25 Apr 12 16:34 tty25
crw-rw----    1 root     tty         4,  26 Apr 12 16:34 tty26
crw-rw----    1 root     tty         4,  27 Apr 12 16:34 tty27
crw-rw----    1 root     tty         4,  28 Apr 12 16:34 tty28
crw-rw----    1 root     tty         4,  29 Apr 12 16:34 tty29
crw--w----    1 root     root        4,   3 Apr 12 16:40 tty3
crw-rw----    1 root     tty         4,  30 Apr 12 16:34 tty30
crw-rw----    1 root     tty         4,  31 Apr 12 16:34 tty31
crw-rw----    1 root     tty         4,  32 Apr 12 16:34 tty32
crw-rw----    1 root     tty         4,  33 Apr 12 16:34 tty33
crw-rw----    1 root     tty         4,  34 Apr 12 16:34 tty34
crw-rw----    1 root     tty         4,  35 Apr 12 16:34 tty35
crw-rw----    1 root     tty         4,  36 Apr 12 16:34 tty36
crw-rw----    1 root     tty         4,  37 Apr 12 16:34 tty37
crw-rw----    1 root     tty         4,  38 Apr 12 16:34 tty38
crw-rw----    1 root     tty         4,  39 Apr 12 16:34 tty39
crw--w----    1 root     root        4,   4 Apr 12 16:40 tty4
crw-rw----    1 root     tty         4,  40 Apr 12 16:34 tty40
crw-rw----    1 root     tty         4,  41 Apr 12 16:34 tty41
crw-rw----    1 root     tty         4,  42 Apr 12 16:34 tty42
crw-rw----    1 root     tty         4,  43 Apr 12 16:34 tty43
crw-rw----    1 root     tty         4,  44 Apr 12 16:34 tty44
crw-rw----    1 root     tty         4,  45 Apr 12 16:34 tty45
crw-rw----    1 root     tty         4,  46 Apr 12 16:34 tty46
crw-rw----    1 root     tty         4,  47 Apr 12 16:34 tty47
crw-rw----    1 root     tty         4,  48 Apr 12 16:34 tty48
crw-rw----    1 root     tty         4,  49 Apr 12 16:34 tty49
crw--w----    1 root     root        4,   5 Apr 12 16:40 tty5
crw-rw----    1 root     tty         4,  50 Apr 12 16:34 tty50
crw-rw----    1 root     tty         4,  51 Apr 12 16:34 tty51
crw-rw----    1 root     tty         4,  52 Apr 12 16:34 tty52
crw-rw----    1 root     tty         4,  53 Apr 12 16:34 tty53
crw-rw----    1 root     tty         4,  54 Apr 12 16:34 tty54
crw-rw----    1 root     tty         4,  55 Apr 12 16:34 tty55
crw-rw----    1 root     tty         4,  56 Apr 12 16:34 tty56
crw-rw----    1 root     tty         4,  57 Apr 12 16:34 tty57
crw-rw----    1 root     tty         4,  58 Apr 12 16:34 tty58
crw-rw----    1 root     tty         4,  59 Apr 12 16:34 tty59
crw--w----    1 root     root        4,   6 Apr 12 16:40 tty6
crw-rw----    1 root     tty         4,  60 Apr 12 16:34 tty60
crw-rw----    1 root     tty         4,  61 Apr 12 16:34 tty61
crw-rw----    1 root     tty         4,  62 Apr 12 16:34 tty62
crw-rw----    1 root     tty         4,  63 Apr 12 16:34 tty63
crw-------    1 root     root        4,   7 Apr 12 16:34 tty7
crw-------    1 root     root        4,   8 Apr 12 16:34 tty8
crw-------    1 root     root        4,   9 Apr 12 16:34 tty9
crw-------    1 root     root        4,  64 Apr 12 16:41 ttyS0
crw-rw----    1 root     uucp        4,  65 Apr 12 16:34 ttyS1
crw-rw----    1 root     uucp        4,  66 Apr 12 16:34 ttyS2
crw-rw----    1 root     uucp        4,  67 Apr 12 16:34 ttyS3
cr--r--r--    1 root     root        1,   9 Apr 12 16:34 urandom
lrwxrwxrwx    1 root     root             3 Apr 12 16:38 usbdisk -> sda
crw-rw----    1 root     tty         7,   0 Apr 12 16:34 vcs
crw-rw----    1 root     tty         7,   1 Apr 12 16:34 vcs1
crw-rw----    1 root     tty         7,   2 Apr 12 16:40 vcs2
crw-rw----    1 root     tty         7,   3 Apr 12 16:40 vcs3
crw-rw----    1 root     tty         7,   4 Apr 12 16:40 vcs4
crw-rw----    1 root     tty         7,   5 Apr 12 16:40 vcs5
crw-rw----    1 root     tty         7,   6 Apr 12 16:40 vcs6
crw-rw----    1 root     tty         7, 128 Apr 12 16:34 vcsa
crw-rw----    1 root     tty         7, 129 Apr 12 16:34 vcsa1
crw-rw----    1 root     tty         7, 130 Apr 12 16:40 vcsa2
crw-rw----    1 root     tty         7, 131 Apr 12 16:40 vcsa3
crw-rw----    1 root     tty         7, 132 Apr 12 16:40 vcsa4
crw-rw----    1 root     tty         7, 133 Apr 12 16:40 vcsa5
crw-rw----    1 root     tty         7, 134 Apr 12 16:40 vcsa6
crw-rw----    1 root     root        7,  64 Apr 12 16:34 vcsu
crw-rw----    1 root     root        7,  65 Apr 12 16:34 vcsu1
crw-rw----    1 root     root        7,  66 Apr 12 16:40 vcsu2
crw-rw----    1 root     root        7,  67 Apr 12 16:40 vcsu3
crw-rw----    1 root     root        7,  68 Apr 12 16:40 vcsu4
crw-rw----    1 root     root        7,  69 Apr 12 16:40 vcsu5
crw-rw----    1 root     root        7,  70 Apr 12 16:40 vcsu6
brw-rw----    1 root     disk      253,   0 Apr 12 16:35 vda
brw-rw----    1 root     disk      253,   1 Apr 12 16:35 vda1
brw-rw----    1 root     disk      253,   2 Apr 12 16:35 vda2
brw-rw----    1 root     disk      253,  16 Apr 12 16:35 vdb
brw-rw----    1 root     disk      253,  17 Apr 12 16:35 vdb1
brw-rw----    1 root     disk      253,  18 Apr 12 16:35 vdb2
drwxrwxrwx    2 root     root            60 Apr 12 16:38 virtio-ports
crw-------    1 root     root      246,   1 Apr 12 16:34 vport5p1
crw-rw-rw-    1 root     root        1,   5 Apr 12 16:34 zero
localhost:~#
localhost:~# ls -l /dev/virtio-ports
total 0
lrwxrwxrwx    1 root     root            11 Apr 12 16:38 vport5p1 -> ../vport5p1
localhost:~#
localhost:~# blkid
/dev/loop0: TYPE="squashfs"
/dev/sda1: LABEL="ext4-drive" UUID="c6a6570a-0a09-46b3-aaa9-f908b017b583" TYPE="ext4"
/dev/vda: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda1: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda2: TYPE="vfat"
/dev/vdb: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb1: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb2: TYPE="vfat"
/dev/loop/0: TYPE="squashfs"
localhost:~#
localhost:~# # Excerpt from "dmesg"
localhost:~#
[   61.006091] usb-storage 1-1:1.0: USB Mass Storage device detected
[   61.455005] scsi host6: usb-storage 1-1:1.0
[   63.106499] scsi 6:0:0:0: Direct-Access     Memorex  USB Flash Drive  PMAP PQ: 0 ANS6
[   63.484861] sd 6:0:0:0: [sda] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[   63.516423] sd 6:0:0:0: [sda] Write Protect is off
[   63.520492] sd 6:0:0:0: [sda] Mode Sense: 23 00 00 00
[   63.544467] sd 6:0:0:0: [sda] No Caching mode page found
[   63.545145] sd 6:0:0:0: [sda] Assuming drive cache: write through
[   63.883226]  sda: sda1
[   63.937232] sd 6:0:0:0: [sda] Attached SCSI removable disk
localhost:~#
localhost:~# mkdir /media/usb1 /media/test

localhost:~# mount -t ext4 /dev/sda1 /media/usb1
localhost:~#
localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     487.4M         0    487.4M   0% /dev/shm
/dev/vda                 60.0M     60.0M         0 100% /media/vda
/dev/vdb                957.0M    957.0M         0 100% /media/vdb
tmpfs                   487.4M     10.1M    477.3M   2% /
tmpfs                   195.0M     44.0K    194.9M   0% /run
/dev/loop0               19.1M     19.1M         0 100% /.modloop
/dev/sda1                14.1G      6.7G      7.4G  47% /media/usb1
localhost:~#
localhost:~# apk add --repositories-file /media/usb1/repository-index.txt nginx
(1/4) Installing hiredis (1.2.0-r0)
(2/4) Installing pcre (8.45-r3)
(3/4) Installing nginx (1.24.0-r14)
Executing nginx-1.24.0-r14.pre-install
Executing nginx-1.24.0-r14.post-install
(4/4) Installing nginx-openrc (1.24.0-r14)
Executing busybox-1.36.1-r15.trigger
OK: 12 MiB in 31 packages
localhost:~#
localhost:~# apk add socat curl
(1/12) Installing ca-certificates (20230506-r0)
(2/12) Installing brotli-libs (1.1.0-r1)
(3/12) Installing c-ares (1.22.1-r0)
(4/12) Installing libunistring (1.1-r2)
(5/12) Installing libidn2 (2.3.4-r4)
(6/12) Installing nghttp2-libs (1.58.0-r0)
(7/12) Installing libcurl (8.5.0-r0)
(8/12) Installing curl (8.5.0-r0)
(9/12) Installing ncurses-terminfo-base (6.4_p20231125-r0)
(10/12) Installing libncursesw (6.4_p20231125-r0)
(11/12) Installing readline (8.2.1-r2)
(12/12) Installing socat (1.8.0.0-r0)
Executing busybox-1.36.1-r15.trigger
Executing ca-certificates-20230506-r0.trigger
OK: 18 MiB in 43 packages
localhost:~#
localhost:~# cd /media/test
localhost:/media/test#
localhost:/media/test# dd if=/dev/random of=/media/test/100mb bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (100.0MB) copied, 17.739540 seconds, 5.6MB/s
localhost:/media/test#
localhost:/media/test# sha256sum 100mb > checksum
localhost:/media/test#
localhost:/media/test# cat checksum
b738d45880117ab5d9d6686674287936fc079d2c15ee4543f9d576e4d5dea925  100mb
localhost:/media/test#
localhost:/media/test# setup-interfaces
Available interfaces are: eth0.
Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done') [eth0]
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp]
Do you want to do any manual network configuration? (y/n) [n]
localhost:/media/test#
localhost:/media/test# rc-service networking start
 * Caching service dependencies ...
 [ ok ]
 * Starting networking ...
 *   lo ...
 [ ok ]
 *   eth0 ...
udhcpc: started, v1.36.1
udhcpc: broadcasting discover
udhcpc: broadcasting select for 10.0.2.15, server 10.0.2.2
udhcpc: lease of 10.0.2.15 obtained from 10.0.2.2, lease time 86400
 [ ok ]
localhost:/media/test#
localhost:/media/test# cd
localhost:~#
localhost:~# cp -pr /media/usb1/*WORKING2*/etc /media/usb1/*WORKING2*/root
localhost:~#
localhost:~# cp root/*conf .

Termux Session:

.../etc/nginx $ pwd
/data/data/com.termux/files/usr/etc/nginx
.../etc/nginx $
.../etc/nginx $ cat nginx.conf
.../etc/nginx $
#user  nobody;
worker_processes  1;

error_log  etc/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8888;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
#            root   /data/data/com.termux/files/usr/share/nginx/html;
#            index  index.html index.htm;
             proxy_http_version 1.1;
             proxy_set_header Connection "";
             proxy_pass http://unix:/data/data/com.termux/files/home/qemu/termux.socket;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        # error_page   500 502 503 504  /50x.html;
        # location = /50x.html {
        #     root   /data/data/com.termux/files/usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
#    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
.../etc/nginx $ pwd
/data/data/com.termux/files/usr/etc/nginx
.../etc/nginx $

QEMU Linux Server:

localhost:~# ls
etc                    root                   use-socket.conf
fromWORKSdefault.conf  use-network.conf
localhost:~# cat use-network.conf
localhost:/etc/nginx/http.d#
server {
        listen 80 default_server;

        location / {
                root /media;
                autoindex on;
                index index.html index.htm;
        }
}
localhost:/etc/nginx/http.d#
localhost:~# cd /etc/nginx/http.d
localhost:/etc/nginx/http.d# ls
default.conf
localhost:/etc/nginx/http.d# mv default.conf default.conf-original
localhost:/etc/nginx/http.d# cp -p /root/use-network.conf .
localhost:/etc/nginx/http.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# nginx
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# cat /var/log/nginx/access.log /var/log/nginx/

Termux Session:

~/.../usbredir-main/tools $
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:9999/test/100mb
--2024-04-12 13:04:01--  http://127.0.0.1:9999/test/100mb
Connecting to 127.0.0.1:9999... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ‘100mb’

100mb                 100%[=========================>] 100.00M   340KB/s    in 3m 44s

2024-04-12 13:07:45 (456 KB/s) - ‘100mb’ saved [104857600/104857600]
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:9999/test/checksum
--2024-04-12 13:11:34--  http://127.0.0.1:9999/test/checksum
Connecting to 127.0.0.1:9999... connected.
HTTP request sent, awaiting response... 200 OK
Length: 72 [application/octet-stream]
Saving to: ‘checksum’

checksum              100%[=========================>]      72  --.-KB/s    in 0s

2024-04-12 13:11:34 (1.76 MB/s) - ‘checksum’ saved [72/72]
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $

QEMU Linux Server:

localhost:/etc/nginx/http.d# ls /dev|grep vport
vport5p1
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# ls /dev|grep virt
virtio-ports
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# ls -R /dev/virtio-ports
/dev/virtio-ports:
vport5p1
localhost:/etc/nginx/http.d# socat -t 1000 /dev/vport5p1,ignoreeof   TCP4-CONNECT:127.0.0.1:80

Termux Session:

~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:8888/test/100mb
--2024-04-12 13:18:02--  http://127.0.0.1:8888/test/100mb
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ‘100mb.1’

100mb.1               100%[=========================>] 100.00M  3.12MB/s    in 32s

2024-04-12 13:18:34 (3.10 MB/s) - ‘100mb.1’ saved [104857600/104857600]
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:8888/test/checksum
--2024-04-12 13:18:47--  http://127.0.0.1:8888/test/checksum
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 72 [application/octet-stream]
Saving to: ‘checksum.1’

checksum.1            100%[=========================>]      72  --.-KB/s    in 0s

2024-04-12 13:18:47 (1.06 MB/s) - ‘checksum.1’ saved [72/72]
~/.../usbredir-main/tools $

QEMU Linux Server, "^C" (CTRL-C) Stops "socat":

^C
localhost:/etc/nginx/http.d# 
localhost:/etc/nginx/http.d# ls
default.conf-original  use-network.conf
localhost:/etc/nginx/http.d# mv use-network.conf use-network.conf-works
localhost:/etc/nginx/http.d# cp -p /root/use-socket.conf .
localhost:/etc/nginx/http.d# ls
default.conf-original   use-network.conf-works  use-socket.conf
localhost:/etc/nginx/http.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# cat /root/use-socket.conf
server {
        listen unix:/tmp/termux.socket;

        location / {
                root /media;
                autoindex on;
                index index.html index.htm;
        }
}
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# pkill nginx
localhost:/etc/nginx/http.d# pgrep nginx
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# nginx
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# socat -t 1000 /dev/vport5p1,ignoreeof  UNIX-CONNECT:/tmp/termux.socket

Termux Session:

~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:8888/test/100mb
--2024-04-12 13:24:28--  http://127.0.0.1:8888/test/100mb
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ‘100mb.2’

100mb.2               100%[=========================>] 100.00M  4.41MB/s    in 22s

2024-04-12 13:24:51 (4.45 MB/s) - ‘100mb.2’ saved [104857600/104857600]

~/.../usbredir-main/tools $ wget http://127.0.0.1:8888/test/checksum
--2024-04-12 13:24:56--  http://127.0.0.1:8888/test/checksum
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 72 [application/octet-stream]
Saving to: ‘checksum.2’

checksum.2            100%[=========================>]      72  --.-KB/s    in 0s

2024-04-12 13:24:56 (1.00 MB/s) - ‘checksum.2’ saved [72/72]
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ cat checksum
b738d45880117ab5d9d6686674287936fc079d2c15ee4543f9d576e4d5dea925  100mb
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ cat checksum.1
b738d45880117ab5d9d6686674287936fc079d2c15ee4543f9d576e4d5dea925  100mb
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ cat checksum.2
b738d45880117ab5d9d6686674287936fc079d2c15ee4543f9d576e4d5dea925  100mb
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ sha256sum -c checksum
100mb: OK
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ cmp 100mb 100mb.1
~/.../usbredir-main/tools $ cmp 100mb 100mb.2
~/.../usbredir-main/tools $

QEMU Linux Server, "^C" (CTRL-C) Stops "socat":

^C
localhost:/etc/nginx/http.d#

@victortoso
Copy link

There is a lot of information here to parse. The first sentence is just

What's the correct way to use termux-usb to solve this? followed by updates, custom usbredirect implementation and what not.

Could you please add what is the problem and what is your expectation? That would give perspective for what you are testing.

@NoteAfterNote
Copy link
Author

NoteAfterNote commented Apr 14, 2024

@victortoso and @Grimler91 for this comment I will hold back praises and I will hold back kudos and I will hold back Multiple Standing Ovations for Termux, termux-usb, usbredirect, and QEMU (@qemu)!

The modified usbredirect.c source code at https://github.com/termux/termux-packages/issues/19635 (#19635) is used on the Android 11 smartphone (not rooted, 4 cores, 3 gigabytes of RAM) and the QEMU Linux Server is currently running Alpine Linux. Have to share an update: A 5-terabyte platters-are-rotating USB hard drive was plugged in a Fedora Linux server (a physical machine with many USB ports) and connected to the QEMU Linux Server with termux-usb and usbredirect, and querying the drive with "hdparm" and "smartctl" from the QEMU Linux Server worked.

The Goal: The QEMU Linux Server as a USB-Drive I/O Subsystem providing fast as possible file transfers and an easy way to access the files.

On-My-Mind-1: How should the usbredirect.c source code be modified to handle the interface with "termux-usb -e 'usbredirect --device /dev/bus/usb/001/031 --as 127.0.0.1.23456'"? Use "--device termux"? Use "--device ignore"? Disable the "--device" option? Do Termux users using rooted devices need the "--device"? The answers have to come from @Grimler91 and other Termux Team members.

On-My-Mind-2: Better understanding of "-device virtconsole" and "-device virtserialport".

On-My-Mind-3: The experimental "socat" setup at https://github.com/termux/termux-packages/issues/19635#issuecomment-205251940 (#19635 (comment)) with "-device virtserialport" and the Unix domain socket "termux.socket" works and it's faster than using the Internet domain socket interface, but is the experimental configuration safe or correct?

On-My-Mind-4: Is LUKS (Linux Unified Key Setup) without using "cryptsetup" on the QEMU Linux Server console possible? https://github.com/usbarmory/interlock (@usbarmory)?

On-My-Mind-5: There are Android file manager apps that can connect to a Samba server. On the QEMU Linux Server is it possible to setup a Samba server that somehow connects with a Unix domain socket on the QEMU Linux Server? In Termux is there a way to redirect an Internet domain socket to a Unix domain socket, and will it work with Samba?

On-My-Mind-6: WebDAV.

@NoteAfterNote
Copy link
Author

NoteAfterNote commented Apr 15, 2024

On-My-Mind-5: The Samba (SMB) server experiment with (A) the Linux "socat" command, (B) "termux.socket" (Unix domain socket) on Termux, (C) a Samba server on port 445 (Internet domain socket) on the QEMU Linux Server that's running Alpine Linux, (D) a USB flash drive formatted with the ext4 filesystem and plugged in the USB-C 2.0 port on an Android 11 smartphone (4 cores, 3 gigabytes of RAM) that is not rooted, and (E) the "usbredirect" command on Termux connecting the USB Flash drive to QEMU

 

Termux Session, USB flash drive in the smartphone's USB port:

~/.../build/tools $
~/.../build/tools $ termux-usb -l
[
"/dev/bus/usb/001/025"
]
~/.../build/tools $
~/.../build/tools $ termux-usb -r /dev/bus/usb/001/025
Access granted.
~/.../build/tools $
~/.../build/tools $ termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/025 --as 127.0.0.1:10000" /dev/bus/usb/001/025

IN-MAIN-BEFORE-parse_opts argc = 6



IN-MAIN-BEFORE-parse_opts argv[0] = /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect



IN-MAIN-BEFORE-parse_opts argv[1] = --device



IN-MAIN-BEFORE-parse_opts argv[2] = /dev/bus/usb/001/025



IN-MAIN-BEFORE-parse_opts argv[3] = --as



IN-MAIN-BEFORE-parse_opts argv[4] = 127.0.0.1:10000



IN-MAIN-BEFORE-parse_opts argv[5] = 7



IN-MAIN-BEFORE sscanf argc = 2



IN-MAIN-BEFORE sscanf argv[0] = /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect



IN-MAIN-BEFORE sscanf argv[1] = 7



IN-MAIN-BEFORE sscanf argv[2] = (null)



IN-MAIN-BEFORE sscanf argv[3] = (null)



IN-MAIN-BEFORE sscanf argv[4] = (null)



IN-MAIN-BEFORE sscanf argv[5] = (null)

Vendor ID: 0718
Product ID: 7722
Manufacturer: Memorex
Product: USB Flash Drive

 

QEMU Monitor:

(qemu)
(qemu) info chardev
c2: filename=disconnected:tcp:127.0.0.1:50000
serial0: filename=mux
c1: filename=disconnected:tcp:127.0.0.1:50000
serial0-base: filename=stdio
parallel0: filename=null
console-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/console.socket,server=on
termux-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/termux.socket,server=on
(qemu)
(qemu) device_del u1
(qemu) device_del u2
(qemu)                                                          
(qemu) chardev-add socket,host=127.0.0.1,port=10000,id=c1
(qemu)                                                          
(qemu) device_add usb-redir,id=u1,debug=3,chardev=c1            
(qemu) qemu-system-x86_64: usbredirparser: Peer version: usbredir 0.14.0, using 64-bits ids                                     qemu-system-x86_64: usb-redir: attaching high speed device 0718:7722 version 1.0 class 00
                                                              
(qemu)                                                          
(qemu) info chardev
serial0: filename=mux
c1: filename=tcp:127.0.0.1:42376 <-> 127.0.0.1:10000
serial0-base: filename=stdio
parallel0: filename=null
console-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/console.socket,server=on
termux-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/termux.socket,server=on
(qemu)

Termux Session:

~/qemu $ pwd
/data/data/com.termux/files/home/qemu
~/qemu $ ps -eaf|cat
UID        PID  PPID  C STIME TTY          TIME CMD
u0_a189   2668   457  1  1970 ?        01:49:54 com.termux
u0_a189   2872  2668  0  1970 pts/16   00:00:01 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   3606  2668  0  1970 pts/17   00:00:04 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   4268  2668  0  1970 pts/18   00:00:05 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   4477  2668  0  1970 pts/19   00:00:01 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   8110  8114  0  1970 ?        00:00:00 /data/data/com.termux/files/usr/bin/sshd -p 8022 -R
u0_a189   8111  8110  0  1970 pts/21   00:00:00 /data/data/com.termux/files/usr/bin/bash -l
u0_a189   8114     1  0  1970 ?        00:00:00 sshd -p 8022
u0_a189   8219   457  0  1970 ?        00:00:00 com.termux.api
u0_a189   8321  2872  0  1970 pts/16   00:00:00 /data/data/com.termux/files/usr/bin/bash /data/data/com.termux/files/usr/bin/termux-usb -e /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/025 --as 127.0.0.1:10000 /dev/bus/usb/001/025
u0_a189   8322  8321  0  1970 pts/16   00:00:00 /data/data/com.termux/files/usr/bin/bash /data/data/com.termux/files/usr/libexec/termux-callback 7
u0_a189   8340  8322  0  1970 pts/16   00:00:02 /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/025 --as 127.0.0.1:10000 7
u0_a189   8591  8111  1  1970 pts/21   00:00:00 ps -eaf
u0_a189   8592  8111  1  1970 pts/21   00:00:00 cat
u0_a189  10968  2668  0  1970 pts/20   00:00:01 /data/data/com.termux/files/usr/bin/bash -l
u0_a189  14101  4477  0  1970 pts/19   00:00:00 bash
u0_a189  20326  3606 27  1970 pts/17   07:40:14 qemu-system-x86_64 -m 1024M -machine q35 -smp 4 -device virtio-rng-pci -nographic -readconfig /data/data/com.termux/files/home/ich9-ehci-uhci.cfg -drive if=none,id=iso1,readonly=on,format=raw,file=/data/data/com.termux/files/home/qemu/alpine-virt-3.19.0-x86_64.iso -device virtio-blk-pci,id=virt1,drive=iso1,bootindex=1 -drive if=none,id=iso2,readonly=on,format=raw,file=/data/data/com.termux/files/home/qemu/alpine-extended-3.19.0-x86_64.iso -device virtio-blk-pci,id=virt2,drive=iso2 -virtfs local,security_model=none,id=termux,mount_tag=termux,path=/data/data/com.termux/files -virtfs local,security_model=none,id=host,mount_tag=host,path=/storage/emulated/0/Download/usb1 -device virtio-serial -chardev socket,path=/data/data/com.termux/files/home/qemu/termux.socket,id=termux-socket,name=talk-to-termux,server=on,wait=off -device virtserialport,id=port1,chardev=termux-socket -device virtio-net-pci,netdev=net0,mac=52:54:12:34:56:78 -netdev user,id=net0,ipv6=off,hostfwd=tcp::9999-:80 -chardev socket,path=/data/data/com.termux/files/home/qemu/console.socket,id=console-socket,server=on,wait=off,name=talk-to-console -device virtconsole,id=port2,chardev=console-socket
~/qemu $ 

QEMU Linux Server Session:

alpine:/etc/samba# uname -a
Linux alpine 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 GNU/Linux
alpine:/etc/samba# 
alpine:/etc/samba# # Excerpt from "dmesg"
[96543.600169] usb 1-5: new high-speed USB device number 6 using ehci-pci
[96544.144221] usb 1-5: New USB device found, idVendor=0718, idProduct=7722, bcdDevice= 1.00
[96544.145762] usb 1-5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[96544.150614] usb 1-5: Product: USB Flash Drive
[96544.151198] usb 1-5: Manufacturer: Memorex
[96544.351307] usb-storage 1-5:1.0: USB Mass Storage device detected
[96544.530540] scsi host6: usb-storage 1-5:1.0
[96545.923868] scsi 6:0:0:0: Direct-Access     Memorex  USB Flash Drive  PMAP PQ: 0 ANSI: 6
[96546.404591] sd 6:0:0:0: [sda] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[96546.437153] sd 6:0:0:0: [sda] Write Protect is off
[96546.443045] sd 6:0:0:0: [sda] Mode Sense: 23 00 00 00
[96546.467463] sd 6:0:0:0: [sda] No Caching mode page found
[96546.471992] sd 6:0:0:0: [sda] Assuming drive cache: write through
[96546.901541]  sda: sda1
[96546.969643] sd 6:0:0:0: [sda] Attached SCSI removable disk
alpine:/etc/samba# 
alpine:/etc/samba# blkid /dev/sda1
/dev/sda1: LABEL="ext4-drive" UUID="c6a6570a-0a09-46b3-aaa9-f908b017b583" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="e568d9fc-01"
alpine:/etc/samba# 
alpine:/etc/samba# mount /dev/sda1 /media/usb1
alpine:/etc/samba# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         10M     0   10M   0% /dev
shm             488M     0  488M   0% /dev/shm
/dev/vda         60M   60M     0 100% /media/vda
/dev/vdb        957M  957M     0 100% /media/vdb
tmpfs           488M  159M  330M  33% /
tmpfs           195M  176K  195M   1% /run
/dev/loop0       20M   20M     0 100% /.modloop
host            117G  108G  8.1G  94% /media/host
termux           24G   23G  1.4G  95% /media/termux
/dev/sda1        15G  5.1G  9.1G  36% /media/usb1
alpine:/etc/samba# 
alpine:/etc/samba#alpine:/etc/samba# ls -l /media/usb1
total 2090040
-rw-r--r-- 1 1000 1000 1073741824 Apr  6 18:58 1gb
-rw-r--r-- 1 root root         70 Apr 15 16:09 1gb-sha256-checksum.txt
-rw-r--r-- 1 1000 1000 1003487232 Apr  5 11:44 alpine-extended-3.19.0-x86_64.iso
-rw-r--r-- 1 1000 1000        833 Apr  5 11:44 alpine-extended-3.19.0-x86_64.iso.asc
-rw-r--r-- 1 1000 1000        100 Apr  5 11:44 alpine-extended-3.19.0-x86_64.iso.sha256
-rw-r--r-- 1 1000 1000        164 Apr  5 11:44 alpine-extended-3.19.0-x86_64.iso.sha512
-rw-r--r-- 1 1000 1000   62914560 Apr  5 11:43 alpine-virt-3.19.0-x86_64.iso
-rw-r--r-- 1 1000 1000        833 Apr  5 11:43 alpine-virt-3.19.0-x86_64.iso.asc
-rw-r--r-- 1 1000 1000         96 Apr  5 11:43 alpine-virt-3.19.0-x86_64.iso.sha256
-rw-r--r-- 1 1000 1000        160 Apr  5 11:43 alpine-virt-3.19.0-x86_64.iso.sha512
drwx------ 2 1000 1000      16384 Apr  5 11:18 lost+found
alpine:/etc/samba# 
alpine:/etc/samba# cat smb.conf
#======================= Global Settings =====================================
[global]

workgroup = MYGROUP
server string = Samba Server

log file = /usr/local/samba/var/log.%m
max log size = 50

allow insecure wide links = yes
dos charset = cp866
unix charset = utf-8
security = user
map to guest = bad user
dns proxy = no

disable netbios = yes

#============================ Share Definitions ==============================

[public]
path = /media/usb1
browseable = yes 
public = yes
writable = yes
guest ok = yes
follow symlinks = yes
wide links = yes

alpine:/etc/samba# testparm
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed by GnuTLS (e.g. NTLM as a compatibility fallback)

Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
	allow insecure wide links = Yes
	disable netbios = Yes
	dns proxy = No
	dos charset = cp866
	log file = /usr/local/samba/var/log.%m
	map to guest = Bad User
	max log size = 50
	security = USER
	server string = Samba Server
	workgroup = MYGROUP
	idmap config * : backend = tdb


[public]
	guest ok = Yes
	path = /media/usb1
	read only = No
	wide links = Yes
alpine:/etc/samba# 
alpine:/etc/samba# 
alpine:/etc/samba# rc-service samba start
 * Starting smbd ...                                                    [ ok ]
 * Starting nmbd ...                                                    [ ok ]
alpine:/etc/samba# pkill nmbd
alpine:/etc/samba# pgrep nmbd
alpine:/etc/samba# 
alpine:/etc/samba# socat -t 100000 /dev/vport5p1,ignoreeof TCP4-CONNECT:127.0.0.1:445 & 
[1] 8351
alpine:/etc/samba# 

Termux Session:

.../etc/nginx $ 
.../etc/nginx $ cat $HOME/smb.conf
[global]
client min protocol = NT1
.../etc/nginx $ 
.../etc/nginx $ socat TCP4-LISTEN:44444 UNIX-CONNECT:$HOME/qemu/termux.socket &
[1] 9408
.../etc/nginx $
.../etc/nginx $ smbclient --configfile=$HOME/smb.conf --no-pass --ip-address=127.0.0.1 --port=44444 --debuglevel=0 --timeout=60 '//127.0.0.1/public'
Try "help" to get a list of possible commands.
smb: \> 
smb: \> ls alpine*
  alpine-extended-3.19.0-x86_64.iso      N 1003487232  Fri Apr  5 07:44:11 2024
  alpine-virt-3.19.0-x86_64.iso.sha512      N      160  Fri Apr  5 07:43:58 2024
  alpine-extended-3.19.0-x86_64.iso.asc      N      833  Fri Apr  5 07:44:11 2024
  alpine-virt-3.19.0-x86_64.iso.sha256      N       96  Fri Apr  5 07:43:58 2024
  alpine-extended-3.19.0-x86_64.iso.sha512      N      164  Fri Apr  5 07:44:11 2024
  alpine-extended-3.19.0-x86_64.iso.sha256      N      100  Fri Apr  5 07:44:11 2024
  alpine-virt-3.19.0-x86_64.iso       N 62914560  Fri Apr  5 07:43:57 2024
  alpine-virt-3.19.0-x86_64.iso.asc      N      833  Fri Apr  5 07:43:58 2024

        14797704 blocks of size 1024. 9509404 blocks available
smb: \> 
smb: \> get alpine-virt-3.19.0-x86_64.iso.sha256
smb: \> get alpine-virt-3.19.0-x86_64.iso
smb: \> quit
[1]+  Done                    socat TCP4-LISTEN:44444 UNIX-CONNECT:$HOME/qemu/termux.socket
.../etc/nginx $ 
.../etc/nginx $ ls -1
SESSION.txt
alpine-virt-3.19.0-x86_64.iso
alpine-virt-3.19.0-x86_64.iso.sha256
error.log
fastcgi.conf
fastcgi_params
koi-utf
koi-win
mime.types
nginx.conf
nginx.conf-b1
nginx.conf-orig
scgi_params
uwsgi_params
win-utf
.../etc/nginx $ 
.../etc/nginx $ sha256sum -c alpine-virt-3.19.0-x86_64.iso.sha256
alpine-virt-3.19.0-x86_64.iso: OK
.../etc/nginx $ 
.../etc/nginx $ uptime
 15:59:27 up 6 days,  9:55,  load average: 17.17, 17.27, 17.25
.../etc/nginx $ 

QEMU Linux Server:

alpine:/etc/samba# uptime
 19:59:54 up 1 day,  6:26,  0 users,  load average: 0.00, 0.11, 0.18
[1]+  Done                    socat -t 100000 /dev/vport5p1,ignoreeof TCP4-CONNECT:127.0.0.1:445
alpine:/etc/samba#

@sylirre sylirre closed this as completed Apr 16, 2024
@sylirre sylirre added information Informational post. and removed question labels Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
information Informational post.
Projects
None yet
Development

No branches or pull requests

5 participants