0

I have a udev rule for USB sticks with fat32 format. The rule contains such attributes:

SUBSYSTEM=="block", KERNEL=="sd?1", ...

Normally, it works very well for USB sticks that I tested so far, since the most USB sticks are represented in the device node as /dev/sda1 or /dev/sdb1.

Now, I have a special USB which has a device node as /dev/sda. The blkid command of this USB stick returns such outputs:

/dev/sda: UUID="AC9E-6C58" TYPE="vfat"

Compared to the normal one (/dev/sda1), I miss the PARTUUID attribute.

Furthermore, The command sfdisk -l /dev/sda returns these outputs:

Disk /dev/sda: 1021 cylinders, 247 heads, 62 sectors/track
Units: cylinders of 7840768 bytes, blocks of 1024 bytes, counting from 0
   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1          0       -       0          0    0  Empty
/dev/sda2          0       -       0          0    0  Empty
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty

This USB has 0 in the /dev/sda1 row. However, the normal USB stick has such entries:

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1          0+   2703-   2704-   7835620    b  W95 FAT32
            start: (c,h,s) expected (0,1,11) found (0,0,57)
            end: (c,h,s) expected (1023,125,46) found (975,125,46)
/dev/sda2          0       -       0          0    0  Empty
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty

Based on this discussion, it means that the USB stick doesn't have a partition table.

If I don't want to change my udev rules, how can I modify this USB stick? A normal re-partition either with Windows tool or Gparted doesn't change this layout.

If changing the partition layout is not possible, how can I change my udev rule so that it can deal with USB stick which either recognize on /dev/sda or /dev/sda1?

Thanks.

Update: I changed the term "mount" with "device node" to avoid confusion. Thanks to Austin.

2

Provided that you have no data you need to keep on the USB stick, and that it shows up as /dev/sda, run the following as root:

wipefs -a /dev/sda

That will erase the FAT32 signature (and any other filesystem signatures too) from the device so it shows up as empty, at which point Both GParted and the Windows disk manager should create a partition table when you go to reformat it.

Also, just to clarify terminology, the kernel does not 'mount' devices to /dev, it creates device nodes there which can be used to interact with the devices (though, if you've got udev, it may be creating the device nodes instead of the kernel), but mounting is an operation that specifically refers to filesystems (more specifically, to 'mount X to Y' implies that X contains a filesystem, and you're making that filesystem accessible directly at location Y, which is not what's happening when device nodes get created).

  • Thanks Austin. In Gparted: Device -> create partition table, which partition table shall I choose? msdos, gpt or other? what is the portable one for all OS? – why2 Dec 1 '17 at 14:38
  • @why2 msdos (possibly listed just as 'dos') is the only one that's truly portable. – Austin Hemmelgarn Dec 1 '17 at 15:08
0

Another solution under Windows is by using diskpart:

  1. Unplug the USB stick
  2. Run the windows terminal or type cmd in the Windows start search field.
  3. Type diskpart and type list disk in the new DiskPart window to see the current devices
  4. Plug the USB stick, and execute again list disk to observe the correct disk number of the USB stick
  5. Type select disk=<number>. Replace the <number> by the disk number of the USB stick that you want to reset.
  6. Run clean, then convert mbrto create a new partition table on the USB stick.
  7. Execute create partition primary command to create a new primary partition.

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.