How to copy files easy and fast to a NTFS (or EXT*) formatted disk without using the (almost broken in FreeBSD) fusefs(-ext2 or ntfs) driver.

Hello.

Here is another How-To I wrote because I wanted to avoid the risk to corrupt the disk while I copy files from a disk (UFS or ZFS) to my NTFS (or even EXT*) formatted disks. This happens because the driver used in FreeBSD does not work well (fusefs-ntfs) ; the same happens with the ext2 driver (fusefs-ext2). My idea is to use a Linux vm as a bridge to copy files to a ntfs or ext* disk and place it in background and when we did the copy, kill that vm. Since Linux has a good ext*,zfs and ntfs drivers,using this tecnique will reduce to almost 0 the risk to break the disk and to lose important informations.

Code:
nano /usr/local/etc/doas.conf

permit :wheel
permit nopass keepenv marietto

# cp /usr/local/bin/qemu-system-x86_64 /usr/local/bin/qemu-system-x86_64-debian_fs

and this is the little script that I wrote that does the job :

Code:
#!/usr/local/bin/bash

vmdisk1=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (NM13N4CZ)/ && d{print d}'`
echo "Seagate M3 Portable 1.8 TB UFS ; $vmdisk1"

vmdisk2=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (2015020204055E)/ && d{print d}'`
echo "TOSHIBA External USB 3.0 1.8 TB ZFS ; $vmdisk2"

vmdisk3=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (20130506005976F)/ && d{print d}'`
echo "TOSHIBA External USB 3.0 932G ZFS ; $vmdisk3"

vmdisk4=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (BE0191500218)/ && d{print d}'`
echo "G-DRIVE USB UFS ; $vmdisk4"

vmdisk5=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident: (38434B4237354B45)/ && d{print d}'`
echo "Elements NTFS ; $vmdisk5"

PS3='Please enter your choice. Options :

1. From TOSHIBA External USB 3.0 1.8 TB ZFS to Elements NTFS and viceversa
2. From TOSHIBA External USB 3.0 932G ZFS to Elements NTFS and viceversa
3. From G-DRIVE USB UFS to Elements NTFS and viceversa
4. From Seagate M3 Portable 1.8 TB UFS to Elements NTFS and viceversa
5. ssh debian_fs / Copy Files
6. Check qemu vms
7. Kill debian_fs
8. Quit
Your choice is : '

options=("1. From TOSHIBA External USB 3.0 1.8 TB ZFS to Elements NTFS and viceversa" "2. From TOSHIBA External USB 3.0 932G ZFS to Elements NTFS and viceversa" "3. From G-DRIVE USB UFS to Elements NTFS and viceversa" "4. From Seagate M3 Portable 1.8 TB UFS to Elements NTFS and viceversa" "5. ssh debian_fs / Copy Files" "6. Check qemu vms" "7. Kill debian_fs" "8. Quit")

select opt in "${options[@]}"
do
    case $opt in
        "1. From TOSHIBA External USB 3.0 1.8 TB ZFS to Elements NTFS and viceversa")
            doas zpool export -f zroot-133 && umount /dev/$vmdisk5'p1'
            doas /usr/local/bin/qemu-system-x86_64-debian_fs -machine q35 -cpu kvm64,hv_relaxed,hv_time,hv_synic -m 1G -vga std -drive file=Debian-fs.img,format=raw -drive file=/dev/$vmdisk2,format=raw -drive file=/dev/$vmdisk5,format=raw -rtc base=localtime -device usb-ehci,id=usb,bus=pcie.0,addr=0x3 -device usb-tablet -device usb-kbd -smbios type=2 -nodefaults -netdev tap,id=mynet0,ifname=tap19,script=no,downscript=no -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01 -device ich9-ahci,id=sata -drive if=pflash,format=raw,readonly=on,file=/usr/local/share/edk2-qemu/QEMU_UEFI_CODE-x86_64.fd -drive if=pflash,format=raw,file=/usr/local/share/edk2-qemu/QEMU_UEFI_VARS-x86_64.fd -nographic -serial none -monitor none &
            ;;
        "2. From TOSHIBA External USB 3.0 932G ZFS to Elements NTFS and viceversa")
        doas zpool export -f zroot2 && umount /dev/$vmdisk5'p1'
        doas /usr/local/bin/qemu-system-x86_64-debian_fs -machine q35 -cpu kvm64,hv_relaxed,hv_time,hv_synic -m 1G -vga std -drive file=Debian-fs.img,format=raw -drive file=/dev/$vmdisk3,format=raw -drive file=/dev/$vmdisk5,format=raw -rtc base=localtime -device usb-ehci,id=usb,bus=pcie.0,addr=0x3 -device usb-tablet -device usb-kbd -smbios type=2 -nodefaults -netdev tap,id=mynet0,ifname=tap19,script=no,downscript=no -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01 -device ich9-ahci,id=sata -drive if=pflash,format=raw,readonly=on,file=/usr/local/share/edk2-qemu/QEMU_UEFI_CODE-x86_64.fd -drive if=pflash,format=raw,file=/usr/local/share/edk2-qemu/QEMU_UEFI_VARS-x86_64.fd -nographic -serial none -monitor none &
            ;;
        "3. From G-DRIVE USB UFS to Elements NTFS and viceversa")
            doas umount /dev/$vmdisk4'p2' && umount /dev/$vmdisk5'p1'
            doas /usr/local/bin/qemu-system-x86_64-debian_fs -machine q35 -cpu kvm64,hv_relaxed,hv_time,hv_synic -m 1G -vga std -drive file=Debian-fs.img,format=raw -drive file=/dev/$vmdisk4,format=raw -drive file=/dev/$vmdisk5,format=raw -rtc base=localtime -device usb-ehci,id=usb,bus=pcie.0,addr=0x3 -device usb-tablet -device usb-kbd -smbios type=2 -nodefaults -netdev tap,id=mynet0,ifname=tap19,script=no,downscript=no -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01 -device ich9-ahci,id=sata -drive if=pflash,format=raw,readonly=on,file=/usr/local/share/edk2-qemu/QEMU_UEFI_CODE-x86_64.fd -drive if=pflash,format=raw,file=/usr/local/share/edk2-qemu/QEMU_UEFI_VARS-x86_64.fd -nographic -serial none -monitor none &
            ;;
        "4. From Seagate M3 Portable 1.8 TB UFS to Elements NTFS and viceversa")
            doas umount /dev/$vmdisk1'p2' && umount /dev/$vmdisk5'p1'
            doas /usr/local/bin/qemu-system-x86_64-debian_fs -machine q35 -cpu kvm64,hv_relaxed,hv_time,hv_synic -m 1G -vga std -drive file=Debian-fs.img,format=raw -drive file=/dev/$vmdisk1,format=raw -drive file=/dev/$vmdisk5,format=raw -rtc base=localtime -device usb-ehci,id=usb,bus=pcie.0,addr=0x3 -device usb-tablet -device usb-kbd -smbios type=2 -nodefaults -netdev tap,id=mynet0,ifname=tap19,script=no,downscript=no -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01 -device ich9-ahci,id=sata -drive if=pflash,format=raw,readonly=on,file=/usr/local/share/edk2-qemu/QEMU_UEFI_CODE-x86_64.fd -drive if=pflash,format=raw,file=/usr/local/share/edk2-qemu/QEMU_UEFI_VARS-x86_64.fd -nographic -serial none -monitor none &
            ;;
        "5. ssh debian_fs / Copy Files")
            ssh -Y marietto@192.168.1.8
            ;;
        "6. Check qemu vms")
            ps ax | grep qemu
            ;;
        "7. Kill debian_fs")
            pgrep qemu-system-x86_64-debian_fs | xargs kill
            ;;
        "8. Quit")
            break
            ;;
        *)  echo "invalid option $REPLY";;
    esac
done

I find also comfortable to import or not to import my ZFS disks at certain conditions putting this script in /home/marietto/.zshrc ; this step is important to avoid mounting conflicts with the previous script...

Code:
# nano /home/marietto/.zshrc

if [ ! -d /mnt/zroot2/zroot2/zroot2-pool ] && ! pgrep -f qemu-system-x86_64-debian_fs &> /dev/null 2>&1; then
echo "zpool/zroot2 hasn't been imported. Importing..."
doas zpool import -f -R /mnt/zroot2 zroot2
else
echo "zpool/zroot2 has been already imported"
fi

if [ ! -d /mnt/zroot-133/_13.3_CURRENT_ ] && ! pgrep -f qemu-system-x86_64-debian_fs &> /dev/null 2>&1; then
echo "zpool/zroot-133 hasn't been imported. Importing..."
doas zpool import -f -R /mnt/zroot-133 zroot-133
else
echo "zpool/zroot-133 has been already imported"
fi

anyway I'm not satisfied. I would like to have a better integration of the script with the system,without having to run the script everytime I need to copy my files to a NTFS or EXT* disk.
 
Interesting.
Personnally, I use NTFS for USB devices with fuse on FreeBSD, and I have no particular problem.
You can also format a USB device to NTFS on FreeBSD.
I had writtren a howto here :
 
Back
Top