How to Securely Erase Data From Your USB Drive or SD Card in Linux | #linux | #linuxsecurity


USB drives and SD cards have become everyday tech accessories these days. But their widespread use also makes them a security concern. Since these devices often contain personal data, you must wipe them entirely before giving them to someone else. Plus, it’s good to get rid of any data on storage devices before throwing them away.

Linux offers several tools that make wiping personal data effortless. Below, we look at some of the ways you can securely erase data from your USB drive or SD card in Linux.

Formatting vs. Erasing: What’s the Difference?

We know formatting a USB makes all the data on that device inaccessible. But does it completely wipe out existing data? The answer is no. Because when you format your device, all you’re doing is creating a new partition and thus making the old partitions writable. But the original data remains on the device.

Many solid data recovery tools make retrieving data from such devices a child’s play. So if your drive holds any sensitive data, you should focus on erasing it instead of just formatting the device. To wipe data from your USB drive or SD card, you have to overwrite them with unnecessary random data.

Secure Wipe Flash Drive or SD Card Contents in Linux

To wipe all personal data from your device, you’ll need to follow a few steps. The first task is to locate the correct device. Use the lsblk command to find the exact device and partition.

lsblk

It’ll display a list of block devices connected to the system. Locate your device based on its storage size. For illustration, we’ll consider /dev/sdb to be the device and /dev/sdb1 as its primary partition. After locating the device and partition, unmount the partition using the below command:

MAKEUSEOF VIDEO OF THE DAY
sudo umount /dev/sdb1

Once unmounted, you’ll need to overwrite the contents of that device. Linux users can choose from several tools, including dd, shred, and badblocks. After wiping the data, you need to create a new partition and format your USB drive on Linux.

Erase USB Drive or SD Card Using dd

The dd command in Linux is used for copying and converting files. However, you can also use dd for wiping out the contents of a storage device.

For example, the following dd command overwrites the contents of your USB drive or SD card with all zeroes. Make sure to specify the correct device name, or you may destroy other partitions.

sudo dd if=/dev/zero of=/dev/sdb bs=4096 status=progress

A simple zero overwrite is more than enough for general users. But in some cases, a portion of the underlying data may still be recoverable using specialized software. If this concerns you, overwrite your drive using random data rather than all zeroes.

sudo dd if=/dev/urandom of=/dev/sdb bs=4096 status=progress

This command can take considerable time to finish, based on the device size. You will notice a prompt saying “No space left on device” once it ends. All you need to do now is create a new partition using your preferred file system.


Secure Wipe USB Drive or SD Card Using shred

The shred utility is a robust data wiping tool included in all Linux distributions by default. It’s part of the coreutils package, making it a solid choice for erasing sensitive data from USB or SD storage.

It is a powerful application that overwrites storage using pseudo-random data. So the chance of recovering deleted contents is next to nothing. On its default settings, shred uses three passes to overwrite. But you can control this parameter using the -n option.

sudo shred -v /dev/sdb

The -v option tells shred to display a progress report of the operation. Using the -z option adds a final overwrite using all zeroes, helpful in hiding the effects of shredding.

sudo shred -v -z /dev/sdb

Moreover, shred also allows overwriting devices using data from random sources like /dev/urandom.

sudo shred -v -z --random-source=/dev/urandom -n1 /dev/sdb

Erase USB Drive or SD Card Using badblocks

You can securely erase the contents of your flash drive with a destructive read-write test using badblocks. It’s a tool used to find bad sectors on storage devices. One key benefit of badblocks is that it’s available on most popular Linux systems by default.

Use the below badblocks command to wipe out the contents of /dev/sdb. This command can take a long time since it writes data using four different passes.

sudo badblocks -wsv /dev/sdb

We’ve combined the -s and -v options to display a progress bar and get detailed information. If you’re looking for a faster approach, use the below command instead:

sudo badblocks -wsv -t 0x00 /dev/sdb

The -t option specifies a test pattern for overwriting. The above command uses a single pass of all zeroes, making it comparably faster.

Create New Partition on Your USB Drive or SD Card

When you overwrite storage using one of the above methods, they wipe everything, including any partitions and partition table. So you’ll need to create a new partition and format it before you can use the device. You can easily create or manage disk partitions in Linux with fdisk.

sudo fdisk -l

This command will list all partitions on your system, including that on your USB or SD card. Use the below command to select your device (/dev/sdb). Be careful with this step and double-check everything.

sudo fdisk /dev/sdb

You’ll enter the fdisk prompt. Now, type n to create a new partition. You’ll have to choose a partition type, number, and the start and end of the storage sector for this partition. It’s best to keep everything default by pressing the Enter key.

After creating the partition, you need to write the changes to your device. Use the w command in fdisk and press Enter. It will create the new partition /dev/sdb1. Once it’s done, format the partition using the below command:

sudo mkfs.vfat -F 32 /dev/sdb1

Safeguard Personal Data From Falling Into the Wrong Hands

Data has become ever so important with the constant rise of technology and everything it has to offer. So protecting personal information should be a top priority for everyone. Thus, you must erase your USB devices and SD cards properly before handing them out to other people or selling them.

It’s also equally important to permanently delete data from old mobile phones since they’re also very easy to recover.

5 Best Ways to Permanently Delete Android Data

Read Next


About The Author



Original Source link

Leave a Reply

Your email address will not be published.

fifty − = 47