[SOLVED] Mount USB drive in Hassio to be used on the Media Folder with udev customization

hi.

It’s actually simpler than you have described (and there might be other ways but I’ve never managed to have HASSIO use the alternative method to load config, the one with the CONFIG folder).

  1. pick the USB key
    You need a USB key just for the initial configuration. Once done this is no longer required, so you could use the same medium you will use later to store your media, or even a ancient old USB key with 32MB since you need this just for a text file.

  2. prepare the USB key
    As per the documented Hassio way to pre-load config, format the USB key (I did it in ext4) and give it CONFIG as label (this is important). Then create a folder on that partition called udev and in that create a file called 80-mount-usb-to-media-by-label.rules with the content of the linked gist. You don’t have to modify it UNLESS you have an advanced setup that boots from USB. In that case you have to modify the rule (as per in line comments) to exclude that USB drive you are already using from the rule (see lines #24 and #50)
    Optionally, if you want to get ssh access to the host and manually verify that the udev rule will land in the right place, also add the authorized_keys file in the root of the USB key, containing your ssh public key, but this is not strictly required.

  3. load the config
    Plug the USB key on an already running Hassio, the in the web UI go in Supervisor -> System, and there in the box Host System, click on the kebab menu and there click on “Import from USB”. You are done, the files should have been imported and gone to the right place. If you enabled ssh you can find them copied under /etc/udev/rules.d/
    You can now unplug the USB key

  4. prepare the media
    You can now repurpose the USB key used before or just plug a new one on your device and you will have it mounted in the right place, and you should be able to see it listed under the media browser ui.
    If you want to use the original key that you have used for the config part, you have to reformat it and CHANGE ITS LABEL since the udev rule explicitly ignore to kick in for devices that are labeled as CONFIG

  5. plug in the USB device (and restart HA)
    When you plug in the drive it’s mounted correctly and if you browse in the Media Browser you will see an entry corresponding to the drive (it will show the partition label) but if you click on it you will see no content.
    To see the content it’s just a matter of restarting HA. (there might be a better way to force the re-scan but I’m not aware of it. Restarting HA just works.)

Notes:

  • I have no clue how to undo the operation. I don’t know how you can remove the udev file. I will try eventually since I don’t see risks with the operation. It might be that an empty udev folder could remove the files deployed, or in the worst-case scenario, a blank rule with the same name might possibly overwrite the deployed file.
  • My 32GB USB key formatted in ext4 works well, I can load media files. But if I try to plug a 320GB HDD, although the drive is mounted correctly in the right place (and I can also see it listed under the media browser) I cannot see any content in it. I suspect it might be related to the size of the disk, but I still need to think about it. This was a HA issue. The drive is mounted correctly in the right place, but I think that HA performs some checks at HA start-up time. It’s just a matter of restarting HA and it will display correctly the content of the drive.

Let me know if you decide to do this, I’d be curious to get confirmation that this works correctly and that the steps are clear enough.

12 Likes