| SD card Type | Partition available | Size of Partition |
|---|---|---|
| A | mmcblk0p1, mmcblk0p2 | mmcblk0p1: 30Mb, mmcblk0p2: 31Gb |
| B | mmcblk0p1 | mmcblk0p1: 31Gb |
I am using a linux system where I need to mount the largest available SD card partition block automatically during boot. I am able to mount a specific partition eg. /dev/mmcblk0p2 by adjusting /etc/fstab. But this does not work if I change the type of SD card, eg. using type B SD card instead of type A.
Is there a way to mount the largest available partition block automatically irrespective of the type used?.
Type is simply used here for explanation purpose. Basically type A is a formatted SD with burned images whereas type B is fresh new SD card.
Any feedback or solution will help a lot. Thank you all.
I made a script and service to achieve it as I was quite interested on this subject.
The script is selecting the largest partition on
/dev/sdb, so if your device has another identification it has to be changed to reflect your env.My environment
The script
Path: /opt/usb_mount_script.sh
Explanation
lsblk -x size -i -n=> list all partitions, sort by size, ASCII mode and no headergrep -Po 'sdb[0-9]+.*'=> filter the partitions by device sdbtail -n 1=> get the last linecut -d ' ' -f 1=> get the partition nameThe service
Path: /etc/systemd/system/test.service
Setup
sudo chmod +x usb_mount_script.shmkdir /mnt/usb_largest_partitionsudo systemctl enable testsystemctl start test