Manipulate devices display in Thunar

Kennel Linux Void-based


Moderator: Forum moderators

Post Reply
User avatar
fredx181
Posts: 2872
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 336 times
Been thanked: 1197 times
Contact:

Manipulate devices display in Thunar

Post by fredx181 »

As I shared also here for gvfs mount: viewtopic.php?p=126123#p126123 , it works in KLV too, from what I tested (but this is NOT a proposal to include by default in KLV !).
It's a hack, I know ;) For who (like me) don't really like the devices display in Thunar and the mount options by the default gvfs/udisks2 configuration, this code will do it completely different, e.g. mountpoints wiil be in /mnt/, mount options are e.g. dev,suid,exec and the display in Thunar is like <LABEL>_<DEVICE> (or just <DEVICE> if label not present).
It works by adding entries to /etc/fstab, and it does NOT (auto) mount anything.

Usage: give the script some name, make it executable, and add it in /root/Startup (requires admin privileges (cannot run as e.g. user spot as it needs to write to /etc/fstab) and reboot or re-login.

Code: Select all

#!/bin/bash

# set mount options (except for vfat and ntfs, it's specified below)
MOPT="noatime,nodiratime,suid,dev,exec,async,x-gvfs-show,noauto"

# Setup fstab function
fstab () {
rm -f /tmp/devices 2>/dev/null
#rm -f /etc/fstab 2>/dev/null
blkid | egrep -v '/dev/sr|/dev/loop|/dev/mapper' >>/tmp/devices
dev=`egrep -v 'TYPE="sw|TYPE="LVM|TYPE=".*_raid_member"' /tmp/devices 2>/dev/null | cut -d: -f1 | cut -d/ -f3 | sort | uniq`
cat > /etc/fstab << EOF

# Device partitions:
EOF
for x in $dev; do
    if [ ! -d /mnt/$x ]; then
	mkdir /mnt/$x
    fi
    uuid=`grep -w /dev/$x /tmp/devices | egrep -o ' UUID=[^ ]+' | cut -d'"' -f2`
    fs=`grep -w /dev/$x /tmp/devices | egrep -o ' TYPE=[^ ]+' | cut -d'"' -f2`
    lbl=`grep -w /dev/$x /tmp/devices | egrep -o ' LABEL=[^ ]+' | cut -d'"' -f2`
    [ -z "$lbl" ] && LBL=$x || LBL="${lbl}_${x}"
    if [ $fs = vfat ]; then
 echo "/dev/disk/by-uuid/$uuid /mnt/$x vfat noatime,nodiratime,suid,dev,exec,async,umask=0,check=s,utf8,x-gvfs-show,noauto,x-gvfs-name=$LBL 0 0" >>/etc/fstab
    elif [ $fs = ntfs ]; then
echo "/dev/disk/by-uuid/$uuid /mnt/$x ntfs rw,noatime,user_id=0,group_id=0,allow_other,blksize=4096,x-gvfs-show,noauto,x-gvfs-name=$LBL 0 0" >>/etc/fstab
    else
 echo "/dev/disk/by-uuid/$uuid /mnt/$x $fs $MOPT,x-gvfs-name=$LBL 0 0" >>/etc/fstab
    fi
done
sleep 1 # wait a sec before renewing fstab
echo '' >> /etc/fstab  # renew, will be re-read by gvfs-mount, all partitions listed then
}

fstab

MON=$(ls /dev/disk/by-uuid)
while true; do
NEWMON=$(ls /dev/disk/by-uuid)
if [ "$NEWMON" != "$MON" ]; then
MON=$NEWMON
echo "content of /dev/disk/by-uuid changed, running fstab"
fstab
continue
fi
sleep 1
done
User avatar
wiak
Posts: 4013
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1165 times
Contact:

Re: Manipulate devices display in Thunar

Post by wiak »

fredx181 wrote: Wed Jul 17, 2024 3:30 pm

It's a hack, I know ;) For who (like me) don't really like the devices display in Thunar and the mount options by the default gvfs/udisks2 configuration

Hack or not hack, it seems Puppy was at fault in modern day and age to use /mnt as the mount point for removable devices since it was the case even long ago that /mnt was supposed to only be used for temporary mount points only. So decision is a matter also of whether you don't mind contravening Linux Filesystem Standard Hierarchy expectations, where /media is designated the mount point for removable devices and why presumably gvfs uses that:

https://refspecs.linuxfoundation.org/FH ... 03s11.html

But of course hard disks aren't usually removable media, so I guess /media only being used to work okay with the likes of gvfs with Thunar. More research regarding the 'standards' are likely required... ;-)
I get the impression there is no 'standard' about where to mount permanent internal media.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
fredx181
Posts: 2872
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 336 times
Been thanked: 1197 times
Contact:

Re: Manipulate devices display in Thunar

Post by fredx181 »

wiak wrote:

Linux Filesystem Standard Hierarchy expectations, where /media is designated the mount point for removable devices and why presumably gvfs uses that

Well, actually the standard for mountpoints it's /run/media/<USER>/<LABEL> by default for gvfs mount (or /run/media/<USER>/<UUID> if no label present) and the display in Thunar left pane, if no label, is something like "16GB Volume" (can't see which drive it actually is, sda? sdb? what?).
It's a matter of preference of course, but in general I don't like this gvfs/udisks2 "standards" very much personally. Also that, with the standard gvfs mount in KLV it does NOT display in Thunar the "boot-from" partition (but accessible in /mnt/ though) and also (for me) not displaying the "bootloader EFI" FAT32 partition if exists, all together a bit annoying IMO.

Btw, if it's about mounting on /media, my above script can be easily changed to mounting on /media instead on /mnt/ .

P.S. I like how pup-volume-monitor handles things, but it's limited to only drive partitions, where gvfs can handle much more of course...

User avatar
wiak
Posts: 4013
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1165 times
Contact:

Re: Manipulate devices display in Thunar

Post by wiak »

Yes, I know the /run and so on situation, and there was a reason bootfrom partition stayed at /mnt but I cant remember what it was; did have it appearing in the likes of thunar left panel for a while, but there was some nasty side-effect I think. Im certainly not disagreeing - I cant say I like that /run/media stuff or having to go to /mnt currently to see boot partition either. Anything that works more intuitively is good.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
fredx181
Posts: 2872
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 336 times
Been thanked: 1197 times
Contact:

Re: Manipulate devices display in Thunar

Post by fredx181 »

wiak wrote: Wed Jul 17, 2024 6:00 pm

Yes, I know the /run and so on situation, and there was a reason bootfrom partition stayed at /mnt but I cant remember what it was; did have it appearing in the likes of thunar left panel for a while, but there was some nasty side-effect I think. Im certainly not disagreeing - I cant say I like that /run/media stuff or having to go to /mnt currently to see boot partition either. Anything that works more intuitively is good.

I'm almost sure that it doesn't matter if the "bootfrom" partition would be mounted in /media instead of in /mnt (from the initrd), gvfs-mount wouldn't display it in Thunar anyway.
---------------------------------------------------------------------------------
Instead of the script from first post, here's a script that will just add the bootfrom partition in Thunar Devices list (the rest of the partitions showing will stay according to the standard gvfs-mount configuration):
Depends on existing symlink /mnt/home (which is by default created from the initrd, if all is well).

Code: Select all

#!/bin/bash

if [ -e /mnt/home ]; then      # depends on symlink /mnt/home, it should have been created from the initrd, if not exit
rm -f /tmp/devices 2> /dev/null
blkid | egrep -v '/dev/sr|/dev/loop|/dev/mapper' >>/tmp/devices
echo '' > /etc/fstab
homepart=$(basename "$(readlink -f /mnt/home)")
MNT="$(readlink -f /mnt/home)"
    lbl=`grep -w /dev/$homepart /tmp/devices | egrep -o ' LABEL=[^ ]+' | cut -d'"' -f2`
    [ -z "$lbl" ] && LBL=$homepart || LBL="${lbl}_${homepart}"
 echo "/dev/$homepart $MNT auto x-gvfs-show,noauto,x-gvfs-name=$LBL 0 0" >>/etc/fstab

else
echo "/mnt/home not existing or broken symlink"
exit
fi

edit: few minutes later, changed code a little (more compact).

geo_c
Posts: 2853
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 2143 times
Been thanked: 862 times

Re: Manipulate devices display in Thunar

Post by geo_c »

fredx181 wrote: Thu Jul 18, 2024 2:20 pm

Instead of the script from first post, here's a script that will just add the bootfrom partition in Thunar Devices list (the rest of the partitions showing will stay according to the standard gvfs-mount configuration):
Depends on existing symlink /mnt/home (which is by default created from the initrd, if all is well).

This is almost irrelevant to your posts, but I thought you being good scripters might find my little interactive mount scripts amusing. I find them very effective for my uses.

They grep devices and filter colorized output in the terminal and prompt for what drive to mount or unmount. There are four scripts to mount either to /mnt or /run/media/root, or unmount from /mnt or /run/media/root.

I use them in KL's and puppies and they seem to work just fine. They only probe for certain devices, and not every possible device. The drives mounted to /mnt won't show up in devices in Thunar however.

In a KLV airedale I might plug in a USB drive which will show up on the Xfce desktop unmounted. If I run the following cmntdev script, I can see a colorized list of the devices and labels, also mountpoints in /mnt, and then be prompted to mount one, which when mounted will then make the drive icon disappear from the desktop. As soon as I run the cmntudev and unmount it, it pops up on the desktop again.

So the bottom line is I can easily see what drives are attached and what drive letter they are and their label and then choose where to mount it from the terminal.

cmntdev

Code: Select all

#!/bin/bash

## Lists contents of /mnt
## Lists devices sd, mm, and sr devices found in /dev
## Prompts for [device name] to mount
## Creates /mnt/[device name] if it doesn't exist in /mnt
## Mounts to /mnt/[device name]
## Lists files in /mnt/[device name] top level and exits
## Exits if user input [device name] is not found in /dev
## Exits if [device name] already exists in /mnt and is not empty

echo ""
if [ -z "$(ls -A /mnt)" ]
then
  echo -e "\e[93m/mnt:\e[0m"
  echo -e " *\e[37mempty\e[0m*"
  ls -CF --color=auto /mnt
elif ! [ -z "$(ls -A /mnt)" ]
then
  echo -e "\e[93m/mnt:\e[0m"
  ls -CF --color=auto /mnt
fi
echo ""
echo -e "\e[93m/dev:\e[0m"
echo -e "    \e[35mpartition        label    mountpoint\e[0m"
echo -e "    \e[32m=========        =====    ==========\e[0m"
lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINT | grep --color=auto -e mnt'/'sd'[a-z]''[0-9]' -e mnt'/'sd'[a-z]''[0-9]' -e mnt'/'mmcblk'[0-9]''[a-z]''[0-9]' -e mnt'/'sr'[0-9]' -e sd'[a-z]''[0-9]' -e mmcblk'[0-9]''[a-z]''[0-9]' -e sr'[0-9]' -e 'root/''[a-z, A-Z, 0-9]'*
echo ""
read -p "enter partition to mount: " drv2mnt
if ! [[ -e /dev/$drv2mnt ]]
then
  echo ""
  echo "  '"${drv2mnt}"' not found as partition name"
  echo "" ; exit
elif [[ -e /mnt/$drv2mnt ]] && ! [ -z "$(ls -A /mnt/$drv2mnt)" ]
then
  echo ""
  echo "  '/mnt/"${drv2mnt}"' already exists --not empty."
  echo ""
  echo -e "\e[93m/mnt/"${drv2mnt}":\e[0m"
  ls -CF --color=auto /mnt/$drv2mnt 
  echo "" ; exit
fi
if ! [[ -e /mnt/$drv2mnt ]]
then
  echo ""
  echo "creating directory '/mnt/"${drv2mnt}"'"
  mkdir /mnt/$drv2mnt
  echo "mounting '"${drv2mnt}"'"
  mount /dev/$drv2mnt /mnt/$drv2mnt
  if ! [ $? -eq 0 ] && [ -z "$(ls -A /mnt/$drv2mnt)" ]
  then
    echo "'/mnt/"$drv2mnt"' is currently empty." 
    rm -dv /mnt/$drv2mnt
    echo ""
    echo -e "\e[93m/mnt:\e[0m"
    ls -CF --color=auto /mnt
    echo "" ; exit
  else
    pid=$!
    wait $pid
    sleep 2
  fi  
elif [[ -e /mnt/$drv2mnt ]] && [ -z "$(ls -A /mnt/$drv2mnt)" ]
then
  echo ""
  echo "found empty directory '/mnt/"${drv2mnt}"'"
  echo "mounting '"${drv2mnt}"'"
  mount /dev/$drv2mnt /mnt/$drv2mnt
  if ! [ $? -eq 0 ] && [ -z "$(ls -A /mnt/$drv2mnt)" ]
  then
    echo ""
    echo "  '/mnt/"$drv2mnt"' is currently empty"
    echo "" 
    echo -e "\e[93m/mnt/"${drv2mnt}":\e[0m"
    echo -e " *\e[37mempty\e[0m*"
    ls -CF --color=auto /mnt/$drv2mnt 
    echo "" ; exit
  else
    pid=$!
    wait $pid
    sleep 2  
  fi  
fi
if [ -z "$(ls -A /mnt/$drv2mnt)" ]
then
  echo ""
  echo -e "\e[93m/mnt/${drv2mnt}:\e[0m"
  echo -e " *\e[37mempty\e[0m*"" \e[92m--mounted\e[0m"
  ls -CF --color=auto /mnt/$drv2mnt
  echo ""
elif ! [ -z "$(ls -A /mnt)" ]
then
  echo ""
  echo -e "\e[93m/mnt/${drv2mnt}:\e[0m"
  ls -CF --color=auto /mnt/$drv2mnt
  echo ""
fi

cmntudev

Code: Select all

#!/bin/bash

## Lists contents of /mnt
## Lists devices sd, mm, sr found in /dev
## Prompts for [device] to unmount
## Exits if user input [device] is not found in /mnt
## Unmounts /mnt/[device]
## Removes /mnt/[device] if empty after unmount
## List contents of /mnt/[device] if not empty after unmount

echo ""
if [ -z "$(ls -A /mnt)" ]
then
  echo -e "\e[93m/mnt:\e[0m"
  echo -e " *\e[37mempty\e[0m*"
  ls -CF --color=auto /mnt
elif ! [ -z "$(ls -A /mnt)" ]
then
  echo -e "\e[93m/mnt:\e[0m"
  ls -CF --color=auto /mnt
fi
echo ""
echo -e "\e[93m/dev:\e[0m"
echo -e "    \e[35mpartition        label    mountpoint\e[0m"
echo -e "    \e[32m=========        =====    ==========\e[0m"
lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINT | grep --color=auto -e mnt'/'sd'[a-z]''[0-9]' -e mnt'/'sd'[a-z]''[0-9]' -e mnt'/'mmcblk'[0-9]''[a-z]''[0-9]' -e mnt'/'sr'[0-9]' -e sd'[a-z]''[0-9]' -e mmcblk'[0-9]''[a-z]''[0-9]' -e sr'[0-9]' -e 'root/''[a-z, A-Z, 0-9]'*
echo ""
read -p "enter partition to unmount: " drv2unmnt
if ! [ -e /mnt/$drv2unmnt ]
then
  echo ""
  echo "  '"${drv2unmnt}"'"" not found in /mnt"
  echo ""
  echo -e "\e[93m/mnt:\e[0m"
  ls -CF --color=auto /mnt
  echo "" ; exit
fi  
if [ -e /mnt/$drv2unmnt ]
then
  echo ""
  echo "unmounting '/mnt/"${drv2unmnt}"'"
  umount /mnt/$drv2unmnt
  pid1=$!
if ! [ $? -eq 0 ]
then
  wait $pid1 
  echo -e "\e[93m/mnt:\e[0m"
  ls -CF --color=auto /mnt
  echo "" ; exit
  fi  
fi
if [ -e /mnt/$drv2unmnt ] && ! [ -z "$(ls -A /mnt/$drv2unmnt)" ]
then
  sleep 1
  echo "  '"${drv2unmnt}"'"" is not empty."
  sleep 1
  echo ""
  echo -e "\e[93m/mnt/""${drv2unmnt}"":\e[0m"
  ls -CF --color=auto /mnt/$drv2unmnt
  echo "" ; exit
fi 
if [ -e /mnt/$drv2unmnt ] && [ -z "$(ls -A /mnt/$drv2unmnt)" ]
then
  echo "removing empty directory '/mnt/"${drv2unmnt}"'"
  sleep 1
  rm -dv /mnt/$drv2unmnt
  pid2=$!
  wait $pid2
fi  
if [ -z "$(ls -A /mnt)" ]
then
  echo ""
  echo -e "\e[93m/mnt:\e[0m"
  echo -e " *\e[37mempty\e[0m*"
  ls -CF --color=auto /mnt
  echo ""
elif ! [ -z "$(ls -A /mnt)" ]
then
  echo ""
  echo -e "\e[93m/mnt:\e[0m"
  ls -CF --color=auto /mnt
  echo ""
fi  

I zipped up the five scripts, there's one that just lists devices:

cmnt.tar.gz
(1.81 KiB) Downloaded 38 times

cmntls -- lists the devices in /dev
cmntdev -- mounts devices by drive letter to /mnt
cmntudev -- unmounts devices from /mnt
cmntlab -- mounts devices by label to /run/media/root
cmntulab -- unmounts devices from /run/media/root

Image
you can see in the screenshot that I have a couple links in /mnt for convenience, the /vmnt link points to where I keep my mount scripts.

geo_c
Old School Hipster, and Such

User avatar
fredx181
Posts: 2872
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 336 times
Been thanked: 1197 times
Contact:

Re: Manipulate devices display in Thunar

Post by fredx181 »

@geo_c Nice ! Just one thing, it doesn't show nvme partitions in the /dev: list, can be solved by simply adding e.g. -e nvme'[0-9]''[a-z]''[0-9]' to the lsblk line:
lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINT | grep --color=auto -e mnt'/'sd'[a-z]''[0-9]' -e mnt'/'sd'[a-z]''[0-9]' -e mnt'/'mmcblk'[0-9]''[a-z]''[0-9]' -e mnt'/'sr'[0-9]' -e sd'[a-z]''[0-9]' -e mmcblk'[0-9]''[a-z]''[0-9]' -e sr'[0-9]' -e 'root/''[a-z, A-Z, 0-9]'* -e nvme'[0-9]''[a-z]''[0-9]'

geo_c
Posts: 2853
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 2143 times
Been thanked: 862 times

Re: Manipulate devices display in Thunar

Post by geo_c »

fredx181 wrote: Fri Jul 19, 2024 7:38 am

@geo_c Nice ! Just one thing, it doesn't show nvme partitions in the /dev: list, can be solved by simply adding e.g. -e nvme'[0-9]''[a-z]''[0-9]' to the lsblk line:
lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINT | grep --color=auto -e mnt'/'sd'[a-z]''[0-9]' -e mnt'/'sd'[a-z]''[0-9]' -e mnt'/'mmcblk'[0-9]''[a-z]''[0-9]' -e mnt'/'sr'[0-9]' -e sd'[a-z]''[0-9]' -e mmcblk'[0-9]''[a-z]''[0-9]' -e sr'[0-9]' -e 'root/''[a-z, A-Z, 0-9]'* -e nvme'[0-9]''[a-z]''[0-9]'

Thanks @fredx181!

I was going to update that at some point because I was just given 6 desktops, Dell Octoplexes, and they all have nvme drives! I haven't setup any linuxes on them yet.

I notice my cmntls doesn't test for if /run/media/root exists, so I don't have 'pretty' messages built in if it doesn't, instead you just get the bash message: ls: cannot access '/run/media/root': No such file or directory

That one needs some more work. but it is funcitonal.

I think I'm going to update these this week, and I'll post them in the Programming section of the forum.

geo_c
Old School Hipster, and Such

Post Reply

Return to “KLV-Airedale”