# June 28, 2016: problem to remove partitions on a USB stick

There are two partitions made by the manufacturer: a small one (3 MiB, FAT16, /dev/sdc1 on my machine) with documentation .pdf, .exe tools, etc. and a larger one (1.86 GiB, FAT32, /dev/sdd on my machine) where to put data. In gparted it is not possible to remove the first partition: an error is obtained, saying that the partition is read-only; after this failed attempt, the FAT16 partition is no more detected (read however to the end of this account). Not better like that:
$sudo dd if=/dev/zero of=/dev/sdc count=5MB dd: failed to open ’/dev/sdc’: Read-only file system$ sudo hdparm -r0 /dev/sdc
/dev/sdc:
$sudo dd if=/dev/zero of=/dev/sdc count=5MB dd: failed to open ’/dev/sdc’: Read-only file system  The following works, but after that does not help to make the above lines work better: $ sudo dd if=/dev/zero of=/dev/sdc1 count=5MB
5000000+0 records in
5000000+0 records out
2560000000 bytes (2.6 GB, 2.4 GiB) copied, 3.88935 s, 658 MB/s

Moreover, trying to create a new partition table on /dev/sdc in gparted, same error (“Can’t write to /dev/sdc, because it is opened read-only.”). Trying to follow the tutorial advised here does not help for /dev/sdc, though it seems to work for /dev/sdc1:
$fdisk -l [...] Disk /dev/sdc: 3 MiB, 3145728 bytes, 6144 sectors 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: 0xc3072e18 Device Boot Start End Sectors Size Id Type /dev/sdc1 * 32 6143 6112 3M 1 FAT12 Disk /dev/sdd: 1,9 GiB, 2000683008 bytes, 3907584 sectors 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: 0x00085407$ sudo fdisk /dev/sdc1
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x72e16990.
Command (m for help): q

$sudo fdisk /dev/sdc Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. fdisk: cannot open /dev/sdc: Read-only file system  Note that using fsck is certainly not the right thing as, as indicated in the manual page, fsck goal is to “check and repair a Linux filesystem“; not to check a partition without file system as /dev/sdc. For instance, if we do: $ sudo fsck /dev/sdc
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
fsck.ext2: Read-only file system while trying to open /dev/sdc
Disk write-protected; use the -n option to do a read-only
check of the device.

\$ sudo fsck -n /dev/sdc
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
fsck.ext2: Bad magic number in super-block while trying to open /dev/sdc
The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>

It seems it tries to read it as an ext file system. Definitely it is not the right thing to do.
Other people have encountered similar problems, e.g. here. As indicated here, the reason is probably that:
AFAIK, this type of "protection" is automatically enabled on physical failure occurrences. This is basically a way for you to recover your data before something critical happens (fried disk).
So at one point in time, the firmware of the USB disk detected a failure.
Finally the solution I have found is to use gparted to (i) create a new partition table in /dev/sdd (ii) create a new FAT32 partition in /dev/sdd1. After that only this partition is detected by the KDE device notifier: /dev/sdc1 is no more visible as there is no valid partition on it. But this is misleading, it must be some Linux bug, because after a reboot, both partitions are detected, and e.g. the PDF on the /dev/sdc1 are still readable. So all in all my attempts above have had no effect on the USB key when it comes to /dev/sdc and /dev/sdc1 (it is different for /dev/sdd, which is now a container with its own partition table, containing a FAT32 file system on /dev/sdd1; before that /dev/sdd was a file system on its own, associated to the partition table in /dev/sdc).