Header Shadow Image


Persistent mounting of USB Devices

I've destroyed quite a few disks because the Linux kernel randomizes their mount points at each startup.  So writing persistent mount rules using /etc/fstab is pointless because you never know where each one will be mounted after repeat reboots.  We can achieve this in a different manner by using the following logic to determine their UUID property instead of using /dev/sdX names via the lsblk -f command:

[root@mbpc-pc mnt]# lsblk -f
NAME                              FSTYPE            LABEL       UUID                                   MOUNTPOINT
sdb                               linux_raid_member mbpc:0      2f36ac48-5e3e-4c54-7217-7c53bea3e41e
`-md0                             LVM2_member                   ShnRBO-lz35-Zkh0-6piB-uzrU-Mqch-QoBdwc
  `-MBPCStorage-MBPCBackup (dm-6) xfs               MBPCBackupx 55d40be4-5e7c-4b49-af62-ac1ba09caaae   /mnt/HTPCBackupXFS
sda                               linux_raid_member mbpc:0      2f36ac48-5e3e-4c54-7217-7c53bea3e41e
`-md0                             LVM2_member                   ShnRBO-lz35-Zkh0-6piB-uzrU-Mqch-QoBdwc
  `-MBPCStorage-MBPCBackup (dm-6) xfs               MBPCBackupx 55d40be4-5e7c-4b49-af62-ac1ba09caaae   /mnt/HTPCBackupXFS
sdc                               linux_raid_member mbpc:0      2f36ac48-5e3e-4c54-7217-7c53bea3e41e
`-md0                             LVM2_member                   ShnRBO-lz35-Zkh0-6piB-uzrU-Mqch-QoBdwc
  `-MBPCStorage-MBPCBackup (dm-6) xfs               MBPCBackupx 55d40be4-5e7c-4b49-af62-ac1ba09caaae   /mnt/HTPCBackupXFS
sdd                               linux_raid_member mbpc:0      2f36ac48-5e3e-4c54-7217-7c53bea3e41e
`-md0                             LVM2_member                   ShnRBO-lz35-Zkh0-6piB-uzrU-Mqch-QoBdwc
  `-MBPCStorage-MBPCBackup (dm-6) xfs               MBPCBackupx 55d40be4-5e7c-4b49-af62-ac1ba09caaae   /mnt/HTPCBackupXFS
sde                               linux_raid_member mbpc:0      2f36ac48-5e3e-4c54-7217-7c53bea3e41e
`-md0                             LVM2_member                   ShnRBO-lz35-Zkh0-6piB-uzrU-Mqch-QoBdwc
  `-MBPCStorage-MBPCBackup (dm-6) xfs               MBPCBackupx 55d40be4-5e7c-4b49-af62-ac1ba09caaae   /mnt/HTPCBackupXFS
sdf                               linux_raid_member mbpc:0      2f36ac48-5e3e-4c54-7217-7c53bea3e41e
`-md0                             LVM2_member                   ShnRBO-lz35-Zkh0-6piB-uzrU-Mqch-QoBdwc
  `-MBPCStorage-MBPCBackup (dm-6) xfs               MBPCBackupx 55d40be4-5e7c-4b49-af62-ac1ba09caaae   /mnt/HTPCBackupXFS
sdg
|-sdg1                            ext4                          1e14bdbf-0f27-49e9-8846-315da38d9aed   /boot
|-sdg2                            LVM2_member                   yfPtyW-SXEW-m0wU-hg1t-J5O6-E3Jr-TVyf1l
| |-mbpcvg-rootlv (dm-0)          ext4                          af6c5c11-6f1c-4735-8a7b-9869613de495   /
| |-mbpcvg-swaplv (dm-1)          swap                          141d7cb7-0ed0-4778-a174-3938d501ca0b   [SWAP]
| `-mbpcvg-fmlv (dm-5)            ext4                          e02c14a4-5a03-4d9a-8e62-760119d749f2   /mnt/HTPCFileStorage
`-sdg3                            LVM2_member                   c612Fm-haCB-DEJX-b29K-NZQc-L9Jo-pQECAd
  |-VGEntertain-olv_swap (dm-2)   swap                          7169d9a4-cb74-4b8a-9818-d792f598d4a5
  |-VGEntertain-oLogVol02 (dm-3)  ext4                          7956b19d-89be-40fc-b34b-12f12833c37c   /mnt/HTPCFirstEntertainment/LogVol02
  `-VGEntertain-olv_root (dm-4)   ext4                          00989ae4-3cc0-4467-a99b-0079ae0edd43   /mnt/HTPCFirstEntertainment/lv_root
sdj                               vfat                          93E8-0250
`-sdj1
sdi
`-sdi1                            vfat              Lexar       5449-9578
sdk
`-sdk1                            ntfs              CENTON USB  B80EDD970EDD4ECE
sdh
`-sdh1                            vfat              Lexar       543D-C137
sr0
sdl
`-sdl1                            vfat                          4CFE-820D
[root@mbpc-pc mnt]#

Next, we structure the /etc/fstab entries to use the UUID property to mount instead of the default device names that can fluctuate.  Include also the right filesystem type:

UUID=93E8-0250              /mnt/FLASHDisk01        vfat    context=system_u:object_r:samba_share_t:s0 0 2
UUID=5449-9578              /mnt/FLASHDisk02        vfat    context=system_u:object_r:samba_share_t:s0 0 2
UUID=B80EDD970EDD4ECE       /mnt/FLASHDisk03        ntfs    context=system_u:object_r:samba_share_t:s0 0 2
UUID=543D-C137              /mnt/FLASHDisk04        vfat    context=system_u:object_r:samba_share_t:s0 0 2
UUID=4CFE-820D              /mnt/FLASHDisk05        vfat    context=system_u:object_r:samba_share_t:s0 0 2

 

Then issue mount /mnt/FLASHDisk01 and so on to mount each one.  To find out more details about each disk, we can now run the df -h command on each one like this:

[root@mbpc-pc mnt]# df -h FLASHDisk01
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdj         30G   16K   30G   1% /mnt/FLASHDisk01
[root@mbpc-pc mnt]# df -h FLASHDisk02
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdi1        30G   20M   30G   1% /mnt/FLASHDisk02
[root@mbpc-pc mnt]# df -h FLASHDisk03
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdk1        30G   29G  1.5G  96% /mnt/FLASHDisk03
[root@mbpc-pc mnt]# df -h FLASHDisk04
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdh1        30G   16K   30G   1% /mnt/FLASHDisk04
[root@mbpc-pc mnt]# df -h FLASHDisk05
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdl1       126M  3.5M  122M   3% /mnt/FLASHDisk05
[root@mbpc-pc mnt]#

Earlier we also adjusted the samba configuration file to share out the disks to the rest of the home, so now we need to adjust the entries to something similar to the below:

[FLASHDisk01]
        comment = FLASH Disk 01
        path = /mnt/FLASHDisk01
        valid users = root
        public = no
        writable = yes
        browseable = yes
        guest ok = no
        printable = no

Followed by restarting the smb service using service smb restart or on newer systems, systemctl restart smb .  Admittedly the naming convention is not too pretty but maintenance wise it is very easy esp when referencing missing disks or adding them back into windows mappings.

Cheers,
TK

 

Leave a Reply

 


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License