mounting multiple STM32 boards Topic is solved

Having issues with your DietPi installation or found a bug? Post it here.
jcwippler
Posts: 7
Joined: Wed May 26, 2021 8:16 pm

mounting multiple STM32 boards

Post by jcwippler »

I'm trying to set up a small build farm on a RasPi 3B+ for STM32 embedded µC boards. These all have an ST-Link USB interface which appears as serial port and as usb drive. The trouble is how to keep them apart, since they all end up being some /dev/ttyACM<x> and the drives all have UUID 2702-1974 (stlink-org/stlink on GitHub helps with this). If I manually connect them using dietpi-drivemanager, I see this:

Code: Select all

$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    1  228K  0 disk
sdb           8:16   1  228K  0 disk
sdc           8:32   1  416K  0 disk
sdd           8:48   1   84K  0 disk
sde           8:64   1  1.5M  0 disk
sdf           8:80   1  420K  0 disk
sdg           8:96   1    6M  0 disk /mnt/l432
sdh           8:112  1  804K  0 disk
mmcblk0     179:0    0 14.8G  0 disk
├─mmcblk0p1 179:1    0  128M  0 part /boot
└─mmcblk0p2 179:2    0 14.7G  0 part /
Trouble is, that "l432" drive is not the right one - after a reboot, drive-manager seems to randomly connect each drive to the /dev/sd<x> devices. Not a surprise, as they are all the same, here's /etc/fstab:

Code: Select all

UUID=2702-1974 /mnt/l053 vfat noatime,lazytime,rw,nofail,noauto,x-systemd.automount
UUID=2702-1974 /mnt/f303 vfat noatime,lazytime,rw,nofail,noauto,x-systemd.automount
UUID=2702-1974 /mnt/f103 vfat noatime,lazytime,rw,nofail,noauto,x-systemd.automount
UUID=2702-1974 /mnt/l011 vfat noatime,lazytime,rw,nofail,noauto,x-systemd.automount
UUID=2702-1974 /mnt/f722 vfat noatime,lazytime,rw,nofail,noauto,x-systemd.automount
UUID=2702-1974 /mnt/g431 vfat noatime,lazytime,rw,nofail,noauto,x-systemd.automount
UUID=2702-1974 /mnt/h743 vfat noatime,lazytime,rw,nofail,noauto,x-systemd.automount
UUID=2702-1974 /mnt/l432 vfat noatime,lazytime,rw,nofail,noauto,x-systemd.automount
There is a way to disambiguate, though:

Code: Select all

$ ls -l /dev/disk/by-label/
total 0
lrwxrwxrwx 1 root root 9 Aug 18 10:45 NODE_F303K8 -> ../../sdb
lrwxrwxrwx 1 root root 9 Aug 18 10:45 NODE_F722ZE -> ../../sde
lrwxrwxrwx 1 root root 9 Aug 18 10:45 NODE_H743ZI -> ../../sdg
lrwxrwxrwx 1 root root 9 Aug 18 10:45 NODE_L011K4 -> ../../sdd
lrwxrwxrwx 1 root root 9 Aug 18 10:45 NODE_L053R8 -> ../../sda
lrwxrwxrwx 1 root root 9 Aug 18 10:45 NODE_L432KC -> ../../sdh
lrwxrwxrwx 1 root root 9 Aug 18 10:45 NOD_G431KB -> ../../sdf
lrwxrwxrwx 1 root root 9 Aug 18 10:45 NUCLEO -> ../../sdc
As you can see, L432 got mis-assigned after a reboot (sdg iso sdh).

Is there a way in dietpi to make use of the label information, somehow?
Or some other workaround, outside of dietpi-drivemanager perhaps?
Otherwise, I don't see how I can avoid these random drive assignments on each reboot.

-jcw
User avatar
Joulinar
Posts: 5619
Joined: Sat Nov 16, 2019 12:49 am

Re: mounting multiple STM32 boards

Post by Joulinar »

Can you check if they all have same PARTUUID as well

Code: Select all

lsblk -o name,fstype,label,size,ro,type,mountpoint,partuuid,uuid
Another try could be to change UUID/PARTUUID for each disk https://askubuntu.com/questions/1250224 ... e-partuuid
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
jcwippler
Posts: 7
Joined: Wed May 26, 2021 8:16 pm

Re: mounting multiple STM32 boards

Post by jcwippler »

These are emulated disks (saving a firmware image to them re-flashes the attached µC).
There's no real storage, i.e. no way to change a disk label or UUID, AFAICT.

Code: Select all

$ lsblk -o name,fstype,label,size,ro,type,mountpoint,partuuid,uuid
NAME        FSTYPE LABEL        SIZE RO TYPE MOUNTPOINT PARTUUID                             UUID
sda         vfat   NODE_L053R8  228K  0 disk                                                 2702-1974
sdb         vfat   NODE_F303K8  228K  0 disk                                                 2702-1974
sdc         vfat   NUCLEO       416K  0 disk                                                 2702-1974
sdd         vfat   NODE_L011K4   84K  0 disk                                                 2702-1974
sde         vfat   NODE_F722ZE  1.5M  0 disk                                                 2702-1974
sdf         vfat   NOD_G431KB   420K  0 disk /mnt/g431                                       2702-1974
sdg         vfat   NODE_H743ZI    6M  0 disk                                                 2702-1974
sdh         vfat   NODE_L432KC  804K  0 disk                                                 2702-1974
The /mnt/g431 instance was mounted manually by me. But I can't get it to allow non-root writes (chmod & chown don't do anything).

From dmesg, one of the disks:

Code: Select all

[24772.808972] scsi 5:0:0:0: Direct-Access     MBED     microcontroller  1.0  PQ: 0 ANSI: 2
[24772.809474] sd 5:0:0:0: Attached scsi generic sg5 type 0
[24772.809821] sd 5:0:0:0: [sdf] 840 512-byte logical blocks: (430 kB/420 KiB)
[24772.810063] sd 5:0:0:0: [sdf] Write Protect is off
[24772.810075] sd 5:0:0:0: [sdf] Mode Sense: 00 00 00 00
[24772.810365] sd 5:0:0:0: [sdf] Asking for cache data failed
[24772.810378] sd 5:0:0:0: [sdf] Assuming drive cache: write through
[24772.863441] sd 5:0:0:0: [sdf] Attached SCSI removable disk
User avatar
Joulinar
Posts: 5619
Joined: Sat Nov 16, 2019 12:49 am

Re: mounting multiple STM32 boards

Post by Joulinar »

it is a vfat file system and not supporting unix file system permissions. Best would be to use ext4

Not sure if it is possible to mount a file system by lable. At least I found a web site describing it https://linuxhint.com/mount_partition_uuid_label_linux/

Just have a look to the last section.

Code: Select all

LABEL=Data   /data  vfat  defaults   0    0
But this is not supported by drive manager and would need to be done manually in /etc/fstab
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
jcwippler
Posts: 7
Joined: Wed May 26, 2021 8:16 pm

Re: mounting multiple STM32 boards

Post by jcwippler »

I have no control over the file system. It's a µC emulating a USB drive, there is no real storage, you copy a file containing a firmware image to this emulated disk and that contents gets flashed into the attached µC (i.e. a fixed µC called an "ST-Link" with fixed USB disk emulation behaviour, and a target µC attached to it, which gets re-flashed).

How do I add entries to /etc/fstab which don't get deleted when drive manager runs?
When I tried this, the changed entries were all removed.

PS. This works fine in fstab: "LABEL=NODE_L432KC /mnt/l432 vfat noatime,rw,nofail,user", but the line is deleted by drive manager.
Last edited by jcwippler on Thu Aug 19, 2021 12:48 pm, edited 1 time in total.
User avatar
Joulinar
Posts: 5619
Joined: Sat Nov 16, 2019 12:49 am

Re: mounting multiple STM32 boards

Post by Joulinar »

How do I add entries to /etc/fstab which don't get deleted when drive manager runs?
When I tried this, the changed entries were all removed.
Driver manager is not capable to keep such entries added by LABLE. If you add them manually, you would need to stay away from drive manager to avoid getting them overwritten
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
jcwippler
Posts: 7
Joined: Wed May 26, 2021 8:16 pm

Re: mounting multiple STM32 boards

Post by jcwippler »

Ok, I'll make drive-manager non-executable on this system.
Perhaps it's an idea to add support for a section which is user-managed.

Anyway, looks like it's a workable solution, many thanks.

Update: disabled by adding this line to the start of /boot/dietpi/dietpi-drive_manager:

Code: Select all

#!/bin/echo disabled
Last edited by jcwippler on Thu Aug 19, 2021 12:59 pm, edited 3 times in total.
User avatar
Joulinar
Posts: 5619
Joined: Sat Nov 16, 2019 12:49 am

Re: mounting multiple STM32 boards

Post by Joulinar »

I guess it's somewhere on the looong to-do list. ;)
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
jcwippler
Posts: 7
Joined: Wed May 26, 2021 8:16 pm

Re: mounting multiple STM32 boards

Post by jcwippler »

I looked into drive-manager a bit. I may be able to create a simple mod for it:

* scan for all lines starting with 'LABEL='
* re-insert them in a new "LABELED drives (manually managed)" section
* i.e. this would carry over such entries with little impact on the rest of the logic

Shall I give that a try?

UPDATE - Never mind. It's really a small change:

Code: Select all

# diff -u2 ~/dietpi-drive_manager /boot/dietpi/dietpi-drive_manager
--- /root/dietpi-drive_manager	2021-07-27 17:24:56.000000000 +0200
+++ /boot/dietpi/dietpi-drive_manager	2021-08-19 13:17:58.000000000 +0200
@@ -108,5 +108,5 @@

 		# Special mounts
-		local swap_mounts tmpfs_mounts misc_mounts net_mounts
+		local swap_mounts tmpfs_mounts misc_mounts net_mounts label_mounts

 		# Mode 4: Force reset/clean fstab (PREP)
@@ -122,4 +122,5 @@
 			swap_mounts=$(grep '^[[:blank:]]*[^#].*[[:blank:]]swap[[:blank:]]' $fp_fstab_tmp)
 			tmpfs_mounts=$(grep '^[[:blank:]]*tmpfs[[:blank:]]' $fp_fstab_tmp)
+			label_mounts=$(grep '^[[:blank:]]*LABEL=' $fp_fstab_tmp)
 			# ecryptfs, vboxsf, glusterfs, bind mounts
 			misc_mounts=$(grep -E '^[[:blank:]]*[^#].*([[:blank:]](ecryptfs|vboxsf|glusterfs)[[:blank:]]|[[:blank:],]bind[[:blank:],])' $fp_fstab_tmp)
@@ -152,4 +153,9 @@

 #----------------------------------------------------------------
+# LABELED drives (manually managed)
+#----------------------------------------------------------------
+$label_mounts
+
+#----------------------------------------------------------------
 # PHYSICAL DRIVES
 #----------------------------------------------------------------" > $fp_fstab_tmp
User avatar
Joulinar
Posts: 5619
Joined: Sat Nov 16, 2019 12:49 am

Re: mounting multiple STM32 boards

Post by Joulinar »

let's check with the developer. Maybe it would be good to have a more broader approach to facilitate other cases as well

@MichaIng
your view?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Post Reply