General TC > Programming & Scripting - Unofficial

Feature Suggestion: Descriptive Mount Points

(1/2) > >>

SamK:
The machine used to make this post has two internal hard disks and one external (USB) hard disk.  In total, they hold eleven partitions which are correctly listed in /mnt.  Additionally there are two optical drives which are also listed in /mnt.  The result is thirteen mount points which are all either hdxx or sdxx.

The purpose or content of each partition is not immediately obvious and my memory is fallible.  Consequently, I often find it useful to run a command such as blkid /dev/[hs]d* -o list, use the contents of the label column, relate it to the device column and mount on the appropriate mount point.

My suggestion is that creation of the mount points takes account of an existing label and (when present) includes it in the mount point name in /mnt.  When a label is not present, the mount point might default to the current method.
For example:
APPLES on hda1
PEARS on hdc5
BANANAS on hdc6

or

sda1 ORANGES
sdc5 LEMONS
sdc6 LIMES

While not being aware of the coding effort required to implement this suggestion, two primary benefits are apparent:

* For those choosing not to use labels there is no change from current practice
* For those using labels, mounting/unmounting becomes more intuitive.  This may be particularly advantageous for users doing this via a file manager.   

ixbrian:
I think this is a good idea.   Below are some patches that implement this.  With these patches, any file system that has a label will have its mount point created at /mnt/labelname, and any filesystems that don't have a label will behave like they normally do.    If your label has spaces in it, the spaces will be changed to underscores for the mount directory. 

Brian

Patch for /usr/sbin/rebuildfstab:

--- Code: ------ rebuildfstab_orig
+++ rebuildfstab_updated
@@ -63,8 +63,15 @@
     ext2|ext3) OPTIONS="${OPTIONS},relatime" ;;
     swap) OPTIONS="defaults"; MOUNTPOINT="none" ;;
   esac

+  LABEL="$(blkid $DEVROOT/$DEVNAME -o udev 2>/dev/null | grep ID_FS_LABEL= | cut -f2 -d= )"
+
+  if [ -n "$LABEL" ]; then
+    MOUNTPOINT="/mnt/$LABEL"
+  fi

   if [ "$MOUNTPOINT" != "none" ]; then
-    mkdir -p "/mnt/$DEVNAME" 2>/dev/null >/dev/null
+    mkdir -p "$MOUNTPOINT" 2>/dev/null >/dev/null
   fi
   printf "%-15s %-15s %-8s %-20s %-s\n" "$DEVROOT/$DEVNAME" "$MOUNTPOINT" "$FSTYPE" "$OPTIONS" "0 0 $ADDEDBY" >>"$TMP"
 done

--- End code ---

For mnttool to work, there are a couple of more changes needed.

/usr/bin/mountables.sh needs to be changed to:

--- Code: ---#!/bin/sh
cat /etc/fstab | awk -F '/' '/\/mnt\// {print $5}' | awk '{print $1}' | awk '{ sub(/[ \t]+$/, ""); print }' | sort -r | awk 'a != $0; { a = $0 }' | sort > /tmp/mountables

--- End code ---

mnttool.fl needs to be patched and recompiled with this patch:

--- Code: ------ mnttool.fl_orig
+++ mnttool.fl_updated
@@ -40,8 +40,8 @@
 
 ifstream fin("/tmp/mountables");
 string line;
-string commandHead = "grep /mnt/";
-string commandTail = " /etc/mtab >/dev/null";
+string commandHead = "grep '/mnt/";
+string commandTail = " ' /etc/mtab >/dev/null";
 
 while ( getline(fin,line) )
 {
@@ -89,7 +89,7 @@
    int results;
    if (mountState.at(selected) == 0)   // mounted
    {
-      results = system(("sudo umount /dev/" + mountList.at(selected)).c_str());
+      results = system(("sudo umount /mnt/" + mountList.at(selected)).c_str());
       if (results == 0)
       {
          btnState->color((Fl_Color)1);         
@@ -99,7 +99,7 @@
    }   
    else
    {
-      results = system(("sudo mount /dev/" + mountList.at(selected)).c_str());
+      results = system(("sudo mount /mnt/" + mountList.at(selected)).c_str());
       if (results == 0)
       {
          btnState->color((Fl_Color)2);         

--- End code ---

curaga:
IMHO naming it by the label is less descriptive to me. I know /mnt/sda1 is my usb stick, but what the heck is /mnt/asdf_asdf_fasd? Or /mnt/data, FWIW. Maybe the label could be a symlink to the main dir?

Then there's the issue of cd/dvd media. If there's a disc in at boot, the dir shall be /mnt/TheDayAfterTomorrow, even after it has been changed.

SamK:
To help clarify the idea - the suggestion in the opening post is to include the pair of values. 
Example format
APPLES on and hda1
or
sda1 and ORANGES

defaulting to the current format when a label is not present.  I don't know if an underscore is required to replace spaces and will leave that to others.


--- Quote from: curaga on November 27, 2010, 12:09:21 PM ---Then there's the issue of cd/dvd media. If there's a disc in at boot, the dir shall be /mnt/TheDayAfterTomorrow, even after it has been changed.

--- End quote ---
Using the pair values would continue to indicate the CD drive device as at present  (in addition to the label of the media left in the drive at boot-up).
   

ixbrian:

--- Quote from: curaga on November 27, 2010, 12:09:21 PM ---IMHO naming it by the label is less descriptive to me. I know /mnt/sda1 is my usb stick, but what the heck is /mnt/asdf_asdf_fasd? Or /mnt/data, FWIW. Maybe the label could be a symlink to the main dir?

Then there's the issue of cd/dvd media. If there's a disc in at boot, the dir shall be /mnt/TheDayAfterTomorrow, even after it has been changed.

--- End quote ---

Since the label is user customizable, it seems like it would be more descriptive. 

Another advantage is that device names are subject to change at reboot if your hardware has changes or if you are booting on another computer.  Using the labels as mount points would keep your mount points consistent even if your device names change. 

You're right on cd media, that would have to be handled in a different way. 

Having the label be a symlink to the device name is a good idea. 

I'll make some changes and post an update. 

Navigation

[0] Message Index

[#] Next page

Go to full version