Mount disk by-id or by-label to prevent /dev/sda1 change

  • OS: LibreElec 11

    My SSD drive with one ext4 partition is recognized as /dev/sda1 on boot and automatically mounted in /media/<label>.

    Sometimes, small physical disconnections happen I think and the SSD is suddenly remapped as /dev/sdb1 or /dev/sdc1 etc...

    This causes my docker volumes mapped in this SSD (through /media/<label>/path ) to raise error when trying to access them later :

    Code
    # ls /data/movies
    ls: reading directory '/data/movies': Input/output error

    Even if disk is correctly remounted to /media/<label> and access to /media/<label> works on the host, I need to reboot to make my containers see the paths again.

    How could I fix this problem ?

    Can I force udevil to mount devices by-id or by-label or by-uuid to fix this ?

    Can I force docker to mount volume through /dev/disk/by-id instead of /media/<label> ?

  • I think I found the solution with docker :

    Code
    # Create "my-volume"
    docker volume create --driver=local --opt type=ext4 --opt device=/dev/disk/by-uuid/d28c6d3a-461e-4d7d-8737-40e56e8f384a my-volume
    # Run a container with it mounted to a path.
    docker run -v my-volume:/my-volume --rm -it alpine sh
    Can Docker volumes be mounted from a device instead of bind mounting a directory?
    I'd like to setup a docker service (docker-compose) on a Linux host with a container mounting an entire [removable] physical hard drive as a docker volume. I…
    serverfault.com