3

I have done some research on this and found this question many times. However, all the answers I have found only address how to change a partition label. I am talking about what is reported by lsblk -o label not lsblk -o partlabel.

I have created a new partition table and created new partitions with both parted and fdisk and I am quite surprised that the old label is still there. I have tried msdos and gpt as partition tables.

This is all the more confusing because parted has this mklabel command with the description "create a new disklabel" but it is equivalent to mktable and does not change the label.

How is the device label stored so that it's independent of the partition table? How can I change it?

The USB stick did not always have this label, it was named when I put a Debian Live System on it. Now where I would like to use it as a normal USB stick again I would like to give it a different name.


EDIT:

With

# fatlabel /dev/sdb1 TEST

I can change the label of a partition which is a good step in the right direction but I can not change the label of the device:

# fatlabel /dev/sdb TEST
Currently, only 1 or 2 FATs are supported, not 251.

Same goes for mlabel which I have installed with pacman -S mtools:

# mlabel -i /dev/sdb1 TEST

works but

# mlabel -i /dev/sdb TEST
init :: non DOS media
mlabel: Cannot initialize the device

I have created the partition table for gpt with:

# parted /dev/sdb
GNU Parted 3.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable                                                          
New disk label type? gpt                                                  
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do
you want to continue?
Yes/No? yes                                                               
(parted) mkpart                                                           
Partition name?  []? test partition
parted: invalid token: partition
File system type?  [ext2]? fat32 
Start? 0%                                                                 
End? 100%                                                                 
(parted) q

and for msdos with:

# parted /dev/sdb
GNU Parted 3.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable                                                          
New disk label type? msdos                                                
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do
you want to continue?
Yes/No? yes                                                               
(parted) mkpart 
Partition type?  primary/extended? primary                                
File system type?  [ext2]? fat32                                          
Start? 0%                                                                 
End? 100%                                                                 
(parted) q

EDIT2: The output of lsblk -o +label,partlabel before I executed dd if=/dev/zero of=/dev/sdb:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT LABEL                       PARTLABEL
sdb      8:16   1   3.8G  0 disk            Debian Jessie-DI-rc1 i386 1
└─sdb1   8:17   1   3.8G  0 part            Debian Jessie-DI-rc1 i386 1
jakun
  • 375
  • Does this work? sudo mlabel -i /dev/sdc1 ::<new_label> – hanxue Jan 16 '20 at 08:57
  • @StephenKitt thank you for your reply. It is appropriate in terms of that it shows how to change a label not a partlabel but it only shows how to change the label of a partion not of a device, I think my question was not explicit enough in that regard. Please see my updated question. – jakun Jan 16 '20 at 10:20
  • @hanxue well, yeah, after installing mlabel with pacman -S mtools I can change the label of a partition with that but I would like to change the label of the device itself. What does the -i do? It is not mentioned in man mlabel. – jakun Jan 16 '20 at 10:26
  • Normally the label is written in the beginning of a partition and can be written by tools to create or modify a file system or swap area (typically in a partition). Why are you so concerned about the label of the driive itself. How do you intend to use it? Maybe it is enough to wipe the first mibibyte (overwrite with zeros) and that way wipe the label inherited from the iso file. – sudodus Jan 16 '20 at 11:39
  • I don’t think there is a device label. Does lsblk show the label opposite the device node, or the partition node? – Stephen Kitt Jan 16 '20 at 12:29
  • @sudodus yes, thank you. dd if=/dev/zero of=/dev/sdb removes the device label. I don't really need to set it, a partition label works as well, but I would be curious to know how to set it, anyway. – jakun Jan 16 '20 at 12:30
  • @StephenKitt yes, it was displayed next to the device /dev/sdb as well as next to the partition /dev/sdb1 if I did not set a label for the partition. – jakun Jan 16 '20 at 12:32
  • 1
    Could the key point here be "when i put a Debian live system on it"? These live systems tend to reside in ISO9660 images, and are usually written on the entire block device /dev/sdb, where they install their own internal structure. A related question might be https://unix.stackexchange.com/questions/516381/why-is-lsblk-showing-the-old-fstype-and-label-of-a-device-that-was-formatted. – AdminBee Jan 16 '20 at 13:10
  • Yes, @AdminBee, iso files with the read-only 9660 file system, originally made for CD disks, later modified to hybrid iso files, have a label, that will be shown as a label for the drive itself. Actually, you can also create a regular read-write file system directly onto a drive (not into a partition). This is the old way used in floppy disks. And when you do so, it can put a label onto the 'drive itself'. – sudodus Jan 16 '20 at 14:09
  • 1
    See also this link about a bug concerning inheritance of the file system and this label. – sudodus Jan 16 '20 at 14:18
  • 1
    @AdminBee yes, thank you. I think that is it. I have flagged my question as a duplicate. – jakun Jan 20 '20 at 06:30

1 Answers1

0

You could also try using:

sudo tune2fs -L {label} {devicename}

or

sudo e2label {device} {label}

for ext[2,3,4] file formats.

You could also look at using Gparted

  • GUI instead of using command prompt
  • would have to install it separately
  • make sure the device is not mounted
  • right click and select "label"