3

I have an USB flash drive that I formerly used as installation medium for Linux Fedora.

The stick still has the "Fedora Live USB" installation files on it. When I insert it into my olde laptoppe, it appears as disk named "Fedora-Live-KDE-x86_64-22-3" in KDE dolphin. Fair enough.

So, I destroy all partitions on it using fdisk, create new partition, set up an ext4 filesystem on said partition.

I insert the flash drive. I appears as "Fedora-Live-KDE-x86_64-22-3" in KDE dolphin.

UNDEAD FLASH DRIVE TIME!

Where does that name come from? Feels like it does not come from the USB flash drive, but factoid (3) below indicates that it actually does.

Where is that name coming from and how do I change it?

Here is some research on where the name is coming from, the conclusion being that it apparently comes from the ISO-9660 data left on the disk. But how is this sane behaviour by Linux?

e2label /dev/sdd1 shows nothing: the filesystem has no label

blkid /dev/sdd1 shows

/dev/sdd1: UUID="10aab422-4212-45c8-9f99-35e5eb719154" TYPE="ext4" PARTUUID="5c4a815c-01"

▶ Using the flash drive on another machine also results in the name "Fedora-Live-KDE-x86_64-22-3" being displayed.

▶ One can dump the "labels" (whatever those are) by looking at the filesystem under /dev:

ls -l /dev/disk/by-label/

This shows the symlink

Fedora-Live-KDE-x86_64-22-3 -> ../../sdb

Note that the symlink points to the device, not the partition. So this is not a filesystem label, but something like a "disk label".

▶ The original "filesystem label" obtainable with e2label being empty, we set it and then see what's up:

# e2label /dev/sdb1 "Scooby Doo"
# ls -l /dev/disk/by-label/
lrwxrwxrwx. 1 root root  9 Feb  4 23:43 Fedora-Live-KDE-x86_64-22-3 -> ../../sdb
lrwxrwxrwx. 1 root root 10 Feb  4 23:43 Scooby\x20Doo -> ../../sdb1

So now both the disk and the filesystem/partition have a label. However, after removal/reinsertion, dolphin (or rather, Linux) now settles on the "Scooby Doo" name of the filesystem. And why not! We can then erase the label again using e2label /dev/sdb1 "" ... and then the name is back, but only partially: "Fedora-Live-KDE-" (why partially? because it's read from 0x9000 onwards, whereas the full label is at 0x8000, see below)

▶ Also tried to see what parted does. It seems mightily confused: It thinks the 8GiB stick with 512-byte blocks is actually a 32GiB stick with 2048-byte blocks and detects a Apple partition, while fdisk is absolutely happy with finding an 8GiB Linux partition. Curioser and curioser.

(parted) print
Warning: The driver descriptor says the physical block size is 2048
bytes, but Linux says it is 512 bytes.
Ignore/Cancel? i
Model: Generic USB Flash Disk (scsi)
Disk /dev/sdb: 32.2GB
Sector size (logical/physical): 2048B/512B
Partition Table: mac
Disk Flags:

Number  Start   End     Size    File system  Name   Flags
 1      2048B   10.2kB  8192B                Apple
 2      88.1kB  5278kB  5190kB               EFI
 3      5319kB  26.1MB  20.8MB               EFI

It's probably not TOTALLY confused because on the stick we find this:

Looks like a Mac thing

▶ Additional weirdness: The reformatted USB stick seems to be un-writeable but traversable for a non-root user. Writing as root works though. But that's just a side remark.

▶ Getting a diskdump with okteta shows the disk name string at position just past 0x8000, i.e. in block 64 (blocks being 512-Byte-sized):

okteta dump around 0x8000

This evidently stems from the LiveCD structure.

▶ Looking further shows the name again likely in UTF-16 format just past 0x9000, with the version suffix dropped probably because the field has constant size:

okteta dump around 0x9000

▶ Time to POKE and see what happens. We modify the string at the 0x8000 mark:

modifying string at around 0x8000

We also modify the string at the 0x9000 mark:

modifying string at around 0x9000

Then write the blocks back to the stick (because we have been modifiying a file obtained using dd), sync, sync and eject.

Then reinsert the stick. Linux settles in this case on the string at 0x9000.

[root@elf ~]# ls -l /dev/disk/by-label/
total 0
lrwxrwxrwx. 1 root root 10 Feb  9 22:09 DellUtility -> ../../sda1
lrwxrwxrwx. 1 root root 10 Feb  9 23:20 MOTHRA-Dead-KDE- -> ../../sdb1
lrwxrwxrwx. 1 root root 10 Feb  9 22:09 OS -> ../../sda2
lrwxrwxrwx. 1 root root 10 Feb  9 22:09 RECOVERY -> ../../sda4

Dolphin shows the content of /dev/disk/by-label:

the string has been modified

So, we know where the string comes from. It does not seem useful to be able to change it as it comes from the CD-ROM structure, whereas we have put a standard partitioning scheme onto the USB disk. Why does Linux mash these two two structures?

  • 1
    Oh good, it's not just me! ;) My Debian USB sticks always do this, too. – drewbenn Feb 4 '16 at 20:34
  • Have you tried dd if=zero of=/dev/sdb (wiping it completely)? – redfast00 Feb 4 '16 at 20:49
  • @redfast00 That's next on the menu – David Tonhofer Feb 4 '16 at 21:12
  • Can you run file -s /dev/sdb – redfast00 Feb 4 '16 at 21:16
  • And file -s /dev/sdb – redfast00 Feb 4 '16 at 21:17
1

It's the volume label. That's the -L flag in mkfs.ext4 or, I think, the -n in mkfs.vfat, and so on.

You can change it by passing a new label to it with e2label, or by killing it entirely with dd.

  • Actually, that's not it. There must be another label. I'm sure "dd" will scratch everything. But why does the stick behave like a weird superposition of disk (it has a partition with a label) and CD-ROM (the whole disk has a label)? I think one will have to go and "use the source, Luke" – David Tonhofer Feb 7 '16 at 13:12
  • Ah I see you have updated your question a lot. Very interesting investigation! I think looking at dolphin's source would indeed be enlightening. – Klaatu von Schlacker Feb 7 '16 at 18:43
0

In the end the answer seems to be the following:

  1. The name comes from the remainder of the CD-ROM data (which in retrospect is embarrassingly obvious)
  2. You can't change it because it's not even meant to be used or even to be there - after all, you want to use the USB flash drive as a disk, not a CD-ROM. These two have different formats. Generally there is no usable string at 0x8000 or 0x9000.
  3. Why the name is used when the stick is inserted is unclear. One would have to take a look at the source of whatever part of Linux is responsible for recognizing the format of a block device.

The lesson:

Reset the USB flash drive by zeroing it before you set up a hard disk partition scheme on it. Otherwise, results will be "undefined" and depend on the heuristics used by the system that reads the flash drive. As seen for parted, which detects a mac filesystem.

P.S.

How to "zero the USB flash drive" in 128K increments (128K should be a 1 or more flash memory cells in size, so any flash memory cell will only be written once):

dd if=/dev/zero of=/dev/sdXXX bs=128K 

"zeroing the USB flash drive" is actually and amazingly fraught with unexpected complications. Maybe one should add count=1024 to keep written blocks low:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.