DietPi + AmiBerry | Auto usbmount

Created on 7 Sep 2016  路  10Comments  路  Source: MichaIng/DietPi

check if usbmount is compatible with our existing mounting system (manual in fstab). If it is, we can add the package by default to installation.
If not, i'll need to have a look and see what we can do to help users transfers files from USB drive, whilst being compatible with our "dedicated USB drive / user data" system.

Enhancement

All 10 comments

@midwan

Q: Are the users trying to:

  • Copy their .rom/.adf from a USB drive to the SD card?

or

  • Run .rom/.adf directly from an existing USB drive?

or

  • Both?

The most common scenario will be to:

  • Plug in USB device which contains ROMs, ADFs, HDFs, etc.
  • Copy those on the SD Card for use with the emulator

Many people prefer to get a large sd card (e.g. 8 or 16GB) and store everything in it, so they don't have to plug in anything extra after that.

Of course, the option to have the external USB device used "as-is" is very good, but most users are not familiar with that at the moment. I believe once they pick up on that, they might start using it more and more (maybe I should write a howto specifically for that).

Notes: usbmount

:u6307: | Existing dedicated USB drive setup with DietPi

  • Automatically mounts USB drive as per fstab, when plugged in.
  • Mount location is correct /mnt/usb_1

:u6307: : | No existing USB drive

  • Automatically mounts USB drive to /media/usb0

Works in harmony with /etc/fstab, great stuff.

Notes to self:
Increases filesystem total by 606KB.
Install by default on all DietPi systems?

Please check if you've also got filesystem support available, for FAT16, FAT32, NTFS...

Please check if you've also got filesystem support available, for FAT16, FAT32, NTFS...

Yep. Our image supports vfat/ntfs/ext* as standard.
However, ntfs isnt enabled by default in usbmount.conf:

root@DietPi:~# cat /etc/usbmount/usbmount.conf | grep FILESYSTEM
FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus"

I'll add that in and test ntfs. https://github.com/rbrito/usbmount#the-special-case-of-fuse-filesystems

USBmount + ntfs does not currently work in Jessie, workaround:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=774149#177

NTFS support for USBmount on Jessie, based on: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=774149#177

        sed -i '/^FILESYSTEMS=/c\FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus ntfs-3g fuseblk"' /etc/usbmount/usbmount.conf
        cat << _EOF_ > /etc/udev/rules.d/usbmount.rules
KERNEL=="sd*", DRIVERS=="sbp2",         ACTION=="add",  PROGRAM="/bin/systemd-escape -p [email protected] \$env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="sd*", SUBSYSTEMS=="usb",       ACTION=="add",  PROGRAM="/bin/systemd-escape -p [email protected] \$env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="ub*", SUBSYSTEMS=="usb",       ACTION=="add",  PROGRAM="/bin/systemd-escape -p [email protected] \$env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="sd*",                          ACTION=="remove",       RUN+="/usr/share/usbmount/usbmount remove"
KERNEL=="ub*",                          ACTION=="remove",       RUN+="/usr/share/usbmount/usbmount remove"
_EOF_

        cat << _EOF_ > /etc/systemd/system/[email protected]
[Unit]
BindTo=%i.device
After=%i.device

[Service]
Type=oneshot
TimeoutStartSec=0
Environment=DEVNAME=%I
ExecStart=/usr/share/usbmount/usbmount add
RemainAfterExit=yes
_EOF_

systemctl daemon-reload

Result

root@DietPi:~# blkid
...
/dev/sda1: UUID="A898219D98216AD0" TYPE="ntfs"

root@DietPi:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
...
/dev/sda1       7.3G   23M  7.2G   1% /media/usb0

Write test

root@DietPi:~# echo 1 > /media/usb0/test

root@DietPi:~# ls -lha /media/usb0/test
-rw-r--r-- 1 root root 2 Sep  7 14:50 /media/usb0/test

And now, just stopped working:

Sep  7 15:22:53 DietPi kernel: [   44.695979]  sda: sda1
Sep  7 15:22:53 DietPi kernel: [   44.703815] sd 1:0:0:0: [sda] Attached SCSI removable disk
Sep  7 15:22:53 DietPi systemd[1]: Starting [email protected]...
Sep  7 15:22:53 DietPi systemd[1]: Starting [email protected]...
Sep  7 15:22:53 DietPi usbmount[1719]: loaded usbmount configurations
Sep  7 15:22:53 DietPi usbmount[1719]: trying to acquire lock /var/run/usbmount/.mount.lock
Sep  7 15:22:53 DietPi usbmount[1730]: loaded usbmount configurations
Sep  7 15:22:53 DietPi usbmount[1719]: acquired lock /var/run/usbmount/.mount.lock
Sep  7 15:22:53 DietPi usbmount[1730]: trying to acquire lock /var/run/usbmount/.mount.lock
Sep  7 15:22:53 DietPi usbmount[1719]: dev/sda does not contain a filesystem or disklabel
Sep  7 15:22:53 DietPi systemd[1]: [email protected]: main process exited, code=exited, status=1/FAILURE
Sep  7 15:22:53 DietPi systemd[1]: Failed to start [email protected].
Sep  7 15:22:53 DietPi systemd[1]: Unit [email protected] entered failed state.
Sep  7 15:22:58 DietPi usbmount[1730]: acquired lock /var/run/usbmount/.mount.lock
Sep  7 15:22:58 DietPi usbmount[1730]: dev/sda1 contains filesystem type ntfs
Sep  7 15:22:58 DietPi usbmount[1730]: usbmount execution finished
Sep  7 15:22:58 DietPi systemd[1]: Started [email protected].

Formatted to NTFS and provided a disk label test

Sep  7 15:27:18 DietPi usbmount[1949]: acquired lock /var/run/usbmount/.mount.lock
Sep  7 15:27:18 DietPi usbmount[1949]: dev/sda1 contains filesystem type ntfs
Sep  7 15:27:18 DietPi usbmount[1949]: usbmount execution finished
Sep  7 15:27:18 DietPi systemd[1]: Started [email protected].

But not visible in df

Intermittent results with NTFS.

Ok could probably do this with just systemD using auto FStype and automount:

/dev/sda1       /mnt/usb_1      auto     defaults,noatime,nofail,permissions,x-systemd.automount  0       0

Only downside is:

  • Cant use permissions mount attribute thats used only by NTFS drives. As this prevents other FS types from mounting (eg: ext4).

Done, automount works with:

  • NTFS
  • VFAT
  • EXT*

Also worth noting these changes will help with setting up multiple drives: https://github.com/Fourdee/DietPi/issues/271

EDIT: And this will be patched on users system during v131 dietpi-update
EDIT2: And mount locations will be /mnt/usb_[index]

Was this page helpful?
0 / 5 - 0 ratings