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).

  • Check if you have a LABEL in /dev/disk/by-label/ – mariaczi Jul 10 at 15:33
  • Thanks ... I'm not seeing any labels in the /dev directories. I have a basic solution now, however. – psychlist Jul 10 at 18:49
  • would be nice if you could post your solution as an answer. – Albin Jul 11 at 0:11
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.