1. Introduction

USB drives have become important mediums for data storage and transfer, serving as portable repos for our most critical files. However, we can sometimes encounter partition deletion errors, especially when dealing with USB drives partitioned by low-level device tools such as dd or fdisk.

In this tutorial, we’ll look at using different Linux tools to fix USB drive partition deletion errors and some methods to avoid data loss.

2. Understanding Partitions and Block Sizes

Partitioning refers to dividing a storage device, such as a hard drive or a USB drive, into separate logical sections. Moreover, each partition functions as an independent unit, with its own file system and directory structure.

Partitions enable us to organize data, install multiple operating systems on a single drive, and segregate system files from user data. The most common partitioning schemes include Master Boot Record (MBR) and GUID Partition Table (GPT).

On the other hand, block size, also known as cluster size, refers to the smallest data unit that can be read from a written storage device. Storage devices are divided into fixed-sized blocks, and data is stored and retrieved in multiples of these blocks.

Block sizes affect storage efficiency, as smaller blocks result in less wasted space but may lead to increased overhead. Conversely, larger block sizes can improve performance for specific operations. Different file systems support different block sizes, and some allow for dynamic adjustment of block sizes.

3. Using dd

The dd (data duplicator) command is a powerful Linux tool for low-level copying and conversion of data. It operates at the block level, allowing users to manipulate data streams with precision and flexibility.

Let’s look at some of the key features of the dd command:

  • data copying
  • disk imaging and cloning
  • disk wiping
  • data transformations
  • rescue operations

While the dd command offers control and flexibility over the filesystem, it also carries risks, as erroneous commands can lead to data loss or system damage. Therefore, we should exercise caution while handling critical tasks.

The dd command is available by default in the most minimal installation of all Linux distros.

Before we proceed, let’s make sure we identify the correct USB device name. We can use the lsblk command to list all block devices in the system, including the USB drive:

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 232.9G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0    30G  0 part /
└─sda3   8:3    0 202.4G  0 part /home
sdb      8:16   1   7.5G  0 disk 
└─sdb1   8:17   1   7.5G  0 part /media/user/USB_DRIVE

Next, we need to ensure that the USB drive is not mounted by running the umount command:

$ sudo umount /dev/sdX

The USB drive should be unmounted to prevent errors due to the filesystem changing during the process.

Finally, let’s use the dd command to wipe all partitions in the USB drive:

$ sudo dd if=/dev/zero of=/dev/sdX bs=512 count=1

We should replace /dev/sdX with the correct USB device name. This command writes zeros to the first 512 bytes of the USB drive, effectively deleting the partition table.

4. Using fdisk

fdisk (fixed disk) is a Linux command-line utility that enables us to manipulate disk partition tables on various storage devices attached to the system.

At its core, it has several features including creating, deleting, modifying, resizing, and displaying partitions on a disk. The fdisk command also comes preinstalled in all Linux distros, so we don’t need to bother with the installation.

Our first step is to confirm the USB drive name using the lsblk command and then we also need to unmount the drive using the umount command.

Next, we can run the fdisk command and specify the USB drive name:

$ sudo fdisk /dev/sdX

As a result, we’ll get the fdisk dialogue, and we can type in the p command to display current partitions:

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sdb: 7.5 GiB, 8053063680 bytes, 15728640 sectors
Disk model: USB DISK 2.0
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/sdb1        2048 15728639 15726592  7.5G  b W95 FAT32

Then, we can use the d command to delete a partition. By default, it deletes the first partition, but we can specify the partition number:

Command (m for help): d
Partition number (1, default 1): 
Partition 1 has been deleted.

We can repeat this step to delete multiple partitions, and then use the w command to write the changes and exit fdisk.

5. Using wipefs

The wipefs command is a Linux command-line utility for managing disk partitions and file systems.

It can manipulate partition tables, erase filesystem signatures, and clear partition metadata.

Here are some of the key functionalities of the wipefs command:

  • managing partition tables
  • cleaning disk metadata
  • clearing filesystem signatures
  • data security and privacy

Usage of the wipefs command typically involves specifying the target device or partition to operate on, along with optional flags to customize the behavior.

It’s available in the repository of all popular Linux distros and it’s usually available by default as part of the util-linux package, which also contains other essential system maintenance utilities.

The first step is to confirm the USB drive name to avoid data loss. We can achieve this with the lsblk command or fdisk -l command.

Next, we need to unmount the USB drive with the umount command, and then we can use the wipefs command to clear any existing filesystem signatures or metadata:

$ sudo wipefs --all /dev/sdX

We’re using the –all option to effectively remove all partition information from the USB drive. Moreover, we need to change the device name /dev/sdX to match our USB drive name.

6. Conclusion

In this article, we’ve discussed how to fix USB drive partition deletion errors that mostly arise from corrupted partitions. Low-level device tools such dd, fdisk, and wipefs offer us the flexibility to manipulate disk partitions and filesystems and potentially clear corrupted partitions.

However, we need to exercise caution while using any of these tools. It’s good practice to verify the device name before we clear partitions from a USB to prevent unintended data loss.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments