0

I have several SD cards with contents of type cont_A that I would like to mount to /mnt/cont_A if one of them is plugged into the computer.

I have as well several SD cards with contents of type cont_B that I would like to mount to /mnt/cont_B if one of them is plugged into the computer.

I tried to manage this using /etc/fstab or /etc/auto.misc using UUID but what ever I do it works only if the first line in either file has the correct UUID of the actual plugged in card.

example of /etc/fstab:

UUID=c9c87db1-4f03-464d-bfcb-aeec8b3be54d  /mnt/cont_A      ext4   defaults  0  0

UUID=b444832e-e9c1-4a73-8b3f-94771418e247  /mnt/cont_A      ext4   defaults  0  0

UUID=7125a2b3-b157-4e65-b618-3b00309b6d21  /mnt/cont_B      ext4   defaults  0  0

What else can I try?

BTW, in my specific case it is not important to automatically mount the cards. I want just to insert one of the cards and write

bash> mount /mnt/cont_A 

in order to get mounted to cont_A (in case that a cont_A type card is inserted)

brandy25
  • 1
  • 1
  • Partition the cards so that the identifier gives a clue about the content and this folder to be mounted to? (all bit-wise copies of the same partition table will have matching identifiers, so if these cards are or originate from exact copies, there are only two fstab entries you need for all clones) – anx Dec 17 '20 at 20:08
  • Thanks as well for this hint. Unfortunately the cards (i.e. cont_A cards) are not identical in that sense. They can have different sizes and so on. What cont_A cards have in common is basically the partition table. Its like you have 100 cards, formatted with the same partition table but with different data on each set of 50 cards. Now you choose one card of each set and plug them in the same time into the computer. How to "automatically" mount this cards into the cont_A and cont_B folders? – brandy25 Dec 18 '20 at 21:16

1 Answers1

2

What you're trying to achieve: "ensuring that different disks/data-carriers will be mounted on the same mount point" is exactly what UUID's are intended to prevent.

The solution in your case is assigning a "label" to the file-systems and then using the LABEL= option in your /etc/fstab

Assign the correct labels first with the e2label command :

sudo e2label /dev/disk/by-uuid/c9c87db1-4f03-464d-bfcb-aeec8b3be54d cont_A  
sudo e2label /dev/disk/by-uuid/b444832e-e9c1-4a73-8b3f-94771418e247 cont_A  

or respectively

sudo e2label /dev/disk/by-uuid/7125a2b3-b157-4e65-b618-3b00309b6d21 cont_B

and update your /etc/fstab

LABEL=cont_A  /mnt/cont_A      ext4   defaults,user  0  0
LABEL=cont_B  /mnt/cont_B      ext4   defaults,user  0  0
Bob
  • 5,805
  • 7
  • 25
  • Thank you for this solution. Can you imagine any other solution without using the label of the partition? I am asking because for my specific problem I can not change the label of the partion (because of logistic problems). Or let's say, the LABEL is pre-defined and can not be changed. Could partuuid be an option? – brandy25 Dec 16 '20 at 15:30
  • 1
    Not really, no. Maybe udev rules but not really sure how to use those to do the kind of mapping you want to see – Bob Dec 16 '20 at 16:13