0

I'm running a Docker container based on Alpine (specifically the balenalib/armv7hf-alpine image). Within the container I want to mount a USB drive by its label, but the Alpine mount command doesn't appear to support the --label option.

I'm an Alpine newbie, but under Raspbian/Debian, I'd just use, e.g.:

mount --label USBDRIVE /mnt/usbdrive

Under Alpine I can successfully mount the drive, but I have to use its device name instead of its label, e.g.:

mount /dev/sda1 /mnt/usbdrive

Is there an approach I can use to achieve mount by label under Alpine? E.g.: a different version of mount? Or a way of finding the volume name by iterating through the labels on all available volumes?

Edit: OK, here's a solution that works (with apologies for my Bash scripting):

VOLUME=$(for VOL in $(fdisk -l | grep ^/dev/sd | awk '{print $1}'); \
         do blkid $VOL; done | grep USBDRIVE | awk -F: '{print $1}')

mount $VOLUME /mnt/usbdrive

This lists all disks using fdisk, isolates all the /dev/sd* entries, uses blkid to find the volume labels, identifies the label required and grabs its volume name. (Exceptions ignored for ease of presentation).

3 Answers3

1

I'm sure there are neater ways to do this, but -- as noted in the edit above -- the approach below works for my needs. Note that it would break if multiple volumes with the required label were present.

VOLUME=$(for VOL in $(fdisk -l | grep ^/dev/sd | awk '{print $1}'); \
     do blkid $VOL; done | grep USBDRIVE | awk -F: '{print $1}')

mount $VOLUME /mnt/usbdrive
1

Or just use blkid's -L option:

mount $(blkid -L USBDRIVE) /mnt/usbdrive
0

In my case (Android x86 / BlissOs) following worked

mount $(blkid -t LABEL=mylabel) | awk -F':' '{print $1}') /mnt/myMountPoint
TefoD
  • 41