[HOWTO] Label a USB thumbdrive vfat partition without editing /etc/mtools.conf and without using gparted

Post tutorials, HOWTO's and other useful resources here.
User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

[HOWTO] Label a USB thumbdrive vfat partition without editing /etc/mtools.conf and without using gparted

Post#1 by Rava » 26 Dec 2021, 19:31

The below can easily be quicker than using gparted, since when you have some drives (internal harddisk(s), external harddisk(s), external USB thumbdrive(s)…) connected to your machine, gparted would scan all of these devices and partitions and that takes some time.

Make sure the device you want to label is not mounted!

TL;DR version:
Make sure you know which /dev/sdX1 your USB device is. No tips on how to determine that, read the long version if unsure, you could create a data loss at worst case scenario when you try it on a wrong device!

Use this command as root, as example I use /dev/sdd1 - the label I want to give is "FUJICA":

Code: Select all

mlabel ::FUJICA -i /dev/sdd1
Could be mlabel complains and refuses to work:

Code: Select all

Total number of sectors (62325760) not a multiple of sectors per track (63)!
Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
If that happens, first go into root's home directory if you not already are, then create .mtoolsrc like so:

Code: Select all

root@porteus:/some/path# cd
root@porteus:~# echo mtools_skip_check=1 >.mtoolsrc
then execute the same command as above:

Code: Select all

root@porteus:~# mlabel ::FUJICA -i /dev/sdd1
root@porteus:~# 
Finished!
Your DE file browser now should the updated label.

__________________________________________

Long Version:


Example: the partition is /dev/sdd1

● 1. ● Either check as root your /var/log/messages when you plug in the device what drive name gets reported.
In my case:

Code: Select all

Dec 26 18:50:12 porteus mtp-probe: checking bus 2, device 27: "/sys/devices/pci0
000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1.3" 
Dec 26 18:50:12 porteus mtp-probe: bus: 2, device: 27 was not an MTP device 
Dec 25 21:59:32 porteus kernel: usb 2-1.1.2: new high-speed USB device number 28 using ehci-pci
Dec 25 21:59:32 porteus kernel: usb 2-1.1.2: New USB device found, idVendor=05e3, idProduct=0727, bcdDevice= 2.07
Dec 25 21:59:32 porteus kernel: usb 2-1.1.2: New USB device strings: Mfr=3, Product=4, SerialNumber=2
Dec 25 21:59:32 porteus kernel: usb 2-1.1.2: Product: USB Storage
Dec 25 21:59:32 porteus kernel: usb 2-1.1.2: Manufacturer: Generic
Dec 25 21:59:32 porteus kernel: usb 2-1.1.2: SerialNumber: 000000000207
Dec 25 21:59:32 porteus kernel: usb-storage 2-1.1.2:1.0: USB Mass Storage device detected
Dec 25 21:59:32 porteus kernel: scsi host8: usb-storage 2-1.1.2:1.0
Dec 26 18:51:06 porteus mtp-probe: checking bus 2, device 28: "/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1.2" 
Dec 26 18:51:06 porteus mtp-probe: bus: 2, device: 28 was not an MTP device 
Dec 25 21:59:33 porteus kernel: scsi 8:0:0:0: Direct-Access     Generic  STORAGE DEVICE   0207 PQ: 0 ANSI: 0
Dec 25 21:59:33 porteus kernel: sd 8:0:0:0: [sdd] 62333952 512-byte logical blocks: (31.9 GB/29.7 GiB)
Dec 25 21:59:33 porteus kernel: sd 8:0:0:0: [sdd] Write Protect is off
Dec 25 21:59:33 porteus kernel:  sdd: sdd1
Dec 25 21:59:33 porteus kernel: sd 8:0:0:0: [sdd] Attached SCSI removable disk
(Side note: the date and time the kernel reports is wrong, the reported time by mtp-probe is accurate. This is due to the time the system was in suspend since it was booted up.)

● 2. ● And / or check previously as root via fdisk -l /dev/sdd
In my case fdisk reports this:

Code: Select all

Disk /dev/sdd: 29.72 GiB, 31914983424 bytes, 62333952 sectors
Disk model: STORAGE DEVICE  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdd1        8192 62333951 62325760 29.7G  c W95 FAT32 (LBA)
The Disk identifier seems… less legit.
The drive is called generic STORAGE DEVICE since it is a MicroSDHC card accessed via a USB card reader.

The almost 32 GB is what I expected, so my recently present drive is indeed the microSDHC card at /dev/sdd1

● 3. ● You can also just mount the drive via your DE file browser and let the browser tell you where it is mounted. When it is mounted at /mnt/sdd1 then /dev/sdd1 is the device.
When it is mounted elsewhere use the df command to get to know what device is the one of the just mounted folder via your DE file browser.

Cave! df shows lots of less helpful stuff - the command name means "disk free" - so showing squashfs (all mounted modules) is usually not something you would be interested in since all of these always have 0 byte free. That is the reason I usually always use my dx command instead of df itself:

Code: Select all

root@porteus:~# type dx
dx is a function
dx () 
{ 
    echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________;
    /bin/df -Tm $* | grep -vE 'tmpfs|/mnt/live/run|squashfs'
}
dx omits all kind of partitions I am not interested in: tmpfs or squashfs and everything that starts with /mnt/live/run. Your mileage on what you want dx to omit might differ, tweak your dx function so that it fits your need. The above is how I want my dx to be. Image

Cave! Umount the vfat USB device prior executing the command to label the partition!

Then we go on just like in the TL;DR above:

Use this command as root, as example I use /dev/sdd1 - the label I want to give is "FUJICA":

Code: Select all

mlabel ::FUJICA -i /dev/sdd1
Could be mlabel complains and refuses to work:

Code: Select all

Total number of sectors (62325760) not a multiple of sectors per track (63)!
Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
First go into root's home directory if you not already are, then create .mtoolsrc like so:

Code: Select all

root@porteus:/some/path# cd
root@porteus:~# echo mtools_skip_check=1 >.mtoolsrc
then execute the same command as above:

Code: Select all

root@porteus:~# mlabel ::FUJICA -i /dev/sdd1
root@porteus:~# 
Of course you can also create /root/.mtoolsrc anyway with the

Code: Select all

mtools_skip_check=1
, but I would only do so if mtools complains.
:)

Finished!
Your DE file browser now should the updated label.
Cheers!
Yours Rava

nanZor
Shogun
Shogun
Posts: 381
Joined: 09 Apr 2019, 03:27
Distribution: Porteus 5.01 x86-64 LXQT

[HOWTO] Label a USB thumbdrive vfat partition without editing /etc/mtools.conf and without using gparted

Post#2 by nanZor » 26 Dec 2021, 23:41

RAVA - thank you!!

You don't know how many times I reformatted drives just to change the label and now I don't have to. That is sooo handy!

In some specific cases I used UUID's, but they are not very explanatory or friendly, so I mostly use labels which work fine for my needs. Sometimes I live in the cli only environment and this tip is very convenient.

I just checked on another system, and indeed I did NOT have to create a .mtoolsrc in root, so it appears that it depends on how it was initially compiled as an option. But with your explanation, we can sidestep that if the author did not compile mtools in this way.

Fantastic tip. That's going into the notebook immediately. (along with your df / dx tip too). Thank you..
That's a UNIX book - cool. -Garth

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

[HOWTO] Label a USB thumbdrive vfat partition without editing /etc/mtools.conf and without using gparted

Post#3 by Rava » 27 Dec 2021, 08:57

nanZor wrote:
26 Dec 2021, 23:41
I just checked on another system, and indeed I did NOT have to create a .mtoolsrc in root, so it appears that it depends on how it was initially compiled as an option. But with your explanation, we can sidestep that if the author did not compile mtools in this way.
I am not sure if it is because it was compiled like so… I have no idea if the "mtools_skip_check=1" can be a compiled-into-option.

Could it be that on your one system that not complained there exists a .mtoolsrc in root?

Or, maybe more logically, it could just be that in some cases even with large USB thumbdrives the number of sectors still are a multiple of sectors per track, that is just a chance it can be so, or it can't.

Since mtools would only complain and then needs the "mtools_skip_check=1" hack if the number of sectors are not a multiple of sectors per track…
You can check that via the info of either fsck.vfat or via fdisk -l - just do the calculations yourself if the number of sectors is by chance a multiple of sectors per track on that one thumbdrive.
That's at least one tiny thing to keep informed and entertained on a dark and gloomy winter night. :)
nanZor wrote:
26 Dec 2021, 23:41
Fantastic tip. That's going into the notebook immediately. (along with your df / dx tip too). Thank you..
Yay happy my functions are appreciated, seriously, dx is one of my most used functions, along with the mega-bytes tuned equivalent of fx (free) and sx (swap)
fx is the only one I managed to create as alias

Code: Select all

type fx
fx is aliased to `echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________;/bin/free -m'
while sx also has to be a function due to the needed calculations:

Code: Select all

type sx
sx is a function
sx () 
{ 
    echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________;
    { 
        read firstLine;
        echo "$firstLine";
        while read f t s u p; do
            let "s2 = $s / 1024";
            let "u2 = $u / 1024";
            printf '%-40s%-16s%-8s%-8s%-8s\n' $f $t $s2 $u2 $p;
        done
    } < /proc/swaps
}
and I had to change dx from alias to function, since for some very weird reason, the "date +" output would not be accurate when used multiple times, and I appreciate the time stamp divider line, since it tells you e.g. if certain large files have been moved already - or not - when you need to check the free space on several partitions you have to monitor (because at least one is running low on free space), or to know if you started a program that needs lots of RAM already and then monitoring it via the fx;sx info it is - to me, that is - immensely helpful to also have for older non-recent info of dx fx or sx the date/time info so that I know what was going on at that moment - and it makes it possible to compare dx fx and/or sx especially when you note down what you do at what moment in time…

… and you also can use a loop to monitor things, like I do sometimes with my top4x function.

The function:

Code: Select all

type top4x
top4x is a function
top4x () 
{ 
    echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________;
    /usr/bin/top -bn 1 | head -n 11 | tail -n 5
}
The 30 seconds loop:

Code: Select all

while true; do { top4x ; sleep 30s ; } done
a one minute loop

Code: Select all

while true; do { top4x ; sleep 1m ; } done
Just recall to cancel the loop when no longer needed via Ctrl+C in the terminal it is running or it would run indefinitely, since you told it so via the while true; do construct.

There also exists a top9x function:

Code: Select all

type top9x
top9x is a function
top9x () 
{ 
    echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________;
    /usr/bin/top -bn 1 | head -n 16 | tail -n 10
}
As you can imagine the 4 and the 9 are not a reference to the whole number of lines printed but only refers to the number of lines / the number of running programs the top info displays. (And all programs that all have currently 0.0% CPU usage are of no concern, and so often top4x is sufficient, and if not, that's what top9x is for. If one needs more than 9 info lines you can code it yourself accordingly, like top13x or such.)

One example shows more than a novel of technical explanations:

Code: Select all

root@porteus:~# top9x
27.12.2021 09:50:18 ____________________________________________________________
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 6105 guest     20   0 3520392 701140  84732 R  37.5  17.7 250:32.94 palemoon
 1776 guest     20   0 2391308  12576   7020 S  12.5   0.3 277:30.38 pulseaudio
 1669 root      20   0  541748 265268  43272 S   6.2   6.7  91:49.35 Xorg
 5879 guest     20   0 1176328  47344  14056 S   6.2   1.2  76:59.96 ffplay
    1 root      20   0     256      0      0 S   0.0   0.0   0:03.37 init
    2 root      20   0       0      0      0 S   0.0   0.0   0:00.13 kthreadd
    3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp
    4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp
    6 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 kworker/0+
In that case, a top4x would have done the exact same job since only programs 1 to 4 have a CPU usage larger than 0.0% :)
And top4x info is quicker to read, especially when you have several ones displayed compared to several instances of top9x.

Especially when you are working with a system without X or without started X and you only have the virtual text terminals to work with - since all info outside the standard displayed columns is lost when you switch to another terminal and switch back to the original one - info that could be seen via "Shift+Page Up" / "Shift+Page Down" as long as you not move to another virtual text terminal, that is.
Cheers!
Yours Rava

Post Reply