Wondershare Recoverit

Hard Drive Recovery

  • Recovers deleted or lost files from hard drive effectively, safely and completely.
  • Supports data recovery from 500+ data loss scenarios, including computer crash, partition loss, accidental human error, etc.
  • Supports 1000+ file formats recovery with a high success rate and without any quality loss.
Free Download Free Download Free Download Learn More >
hard drive recovery

How to Format and Wipe Linux Disk Using Commands?

Wondershare Recoverit Authors

Jan 15, 2024 • Filed to: Answer Hard Drive Problems • Proven solutions

How can I erase an entire Linux disk space? My hard drive is running out of space and I would like to wipe the disk of my Linux computer to create more storage.

If you also own a Linux system, which is running on low disk space, then you might be facing a similar situation. Although Linux is one of the most popular open-source operating systems, it can be a bit complicated at times. For instance, there is no direct solution to do a Linux format disk using a dedicated GUI feature. Don't worry – you can still erase the disk on Linux with the help of the right commands. Read on and clear your Linux disk space by following this extensive guide.

Part 1. Why Do We Need to Format and Wipe Linux Disk?

Before we get to know different ways to format a disk on Linux, it is vital to understand the reasons behind it. Ideally, there could be the following major reasons for wiping or formatting a disk on a Linux system:

You can also click the link to know Easiest Methods to Sync Files Between Linux And Windows.

Part 2. How to Format a Linux Hard Drive?

Unlike Windows or macOS, there is not a dedicated disk management tool that can help us partition or format the disk. Therefore, we need to take the assistance of certain commands to format a Linux disk. If you are connecting your drive for the first time to your Linux system, then you need to create a partition beforehand. To implement this, you can enter the fdisk command. Once a partition is created, you can use the "mkfs.ext4" command to format the disk. Here's a simple solution to format a disk on a Linux system.

Step 1Create a partition of the disk

Firstly, connect the disk to your Linux system if you haven't already and launch the Terminal window on it. You can enter the following command to check it:

sudo fdisk –l.

Now, to create a partition, enter the command "fdsk" in the following format:

sudo fdisk /dev/sdb.

format-linux-drive

This will launch the results of the fdisk command. If you want, you can type "m" to get help. It will display a list of the supported parameters. You can type "n" to create a new partition, "d" to delete the partition, "p" to check the partition table, and so on.

format-linux-drive

Firstly, press "p" and enter to view the partition table. This will let you know about the disk identifier and the sector space. Subsequently, enter the "n" command to create a new partition. You will be given an option to create a primary or an extended partition. Press "p" to create a new primary partition and give it a number from 1 to 4. If you want to create a single partition, then enter "1".

Step 2Format the disk

Great! Once you have created the relevant partition on your Linux system, you can format it by entering the command –

sudo mkfs.ext4 /dev/sdb.

format-linux-drive

This will make the system look for the available partitions on the drive. When you are asked to confirm your choice, just press "y". Afterward, wait for a while as the selected partitions would be formatted on the Linux system.

Step 3Mount the file system (optional)

If you want, you can mount the file system as well. To do this, you can use the "mkdir /data" command to make a directory. After that, end the following command to mount it:

mount /dev/sdb1 /data.


Part 3. How to Wipe a Hard Drive on Linux?

If you are planning to resell your system or are concerned about your privacy, then you should consider wiping the drive instead. Unlike formatting a disk, wiping it will erase the data and make the recovery process harder than before. Thankfully, there are multiple commands to do Linux wipe the disk. Here are some simple solutions to wipe a hard drive on Linux.

1wipe

As the name suggests, the command is used to wipe data from a magnetic disk. Though, a lot of Linux systems do not have the command readily installed. In this case, you can use the apt install command first.

# apt install wipe.

wipe-linux-drive

Once it is done, just use the "wipe" command in the format - wipe [options] target. For instance, to wipe a partition, simply enter the command:

# wipe /dev/sda2

Confirm your choice, by entering "yes" and wait as the selected partition would be wiped.

wipe-linux-drive

2shred

This is one of the best ways to protect your private data on a Linux system. Ideally, this works as a dedicated shredder – that would overwrite your data with something else, making the recovery process harder. This Linux based command has the following syntax:

shred [option] target

As you know, "target" would specify the location you wish to shred. It can be a partition, folder, or file name. Subsequently, it can have the following options.

Therefore, you can wipe the Linux disk, by entering a command like this:

# shred -vfz -n 10 /dev/sda2.

This will follow ten passes of overwriting on the provided location, making it impossible for a recovery tool to retrieve data from it.

shred-linux-drive

3dd

If you are running short on time, then consider using the "dd" command to erase disk on a Linux system. Instead of generating random data, it will overwrite the entire disk with strings of zeros. Therefore, it will take less time to wipe the disk and protecting your information. Although, it provides certain options that you can use to customize the process.

dd if=source of=target [Options].

Make sure that you run the command prompt and as a super-user. Here's a simple demonstration of the same.

# dd if=/dev/zero of=/dev/sda2 bs=512 count=1.

The command will overwrite the target location with a string of zeros, as specified in the source. Also, this will copy 512 bytes in a single count. One of the major advantages of this is the time taken by the dd command is lesser than shred.

dd-command-linux

4scrub

Lastly, you can also take the assistance of the "scrub" command to overwrite your disk with specific patterns. Sometimes, the patterns can be randomly generated by the system too. Since the command is not present in every Linux system by default, you might need to install it first. To do this, you can use the apt install command.

Once it is done, just enter the command in the following syntax:

scrub [option] target.

Even if you don't provide an option and just specifies the target location to wipe, the command will work. Though, you would be asked to verify your choice to erase disk on Linux entirely. Here's a quick example of the same:

# scrub /dev/sda5.

scrub-command-linux

Read More:
How to Recover Deleted Files on Linux for Free?
How to Format a Hard Drive Disk Partition in Linux?


Part 4. Tips for Formatting and Wiping Linux Disk

After getting to know about these popular commands to create new disk space on Linux, you would certainly be able to format or wipe it. Besides that, you can consider following these tips to format or wipe the Linux disk successfully.

Video Tutorial on How to Recover Data from Hard Disk After Disk Wipe

Recent Videos from Recoverit

View More >

That's a wrap, folks! Now when you know how to format or wipe disk on Linux, you can easily meet your requirements. In case if you have accidentally deleted your data or have formatted a drive, then use a reliable data recovery solution like Wondershare Recoverit. Using it, you can just attach your Linux device to a PC and later extract the lost or inaccessible content from it. Go ahead and try some of these methods and feel free to share your shortcuts or tips in the comments below.

FAQs

What disk format does Linux use?

Linux is a very versatile operating system and has its own disk format which is EXT, which can be presented in its EXT2, EXT3 and EXT4 versions. However, this is not the only file system that can be supported by this operating system; FAT32 and NTFS systems are fully supported as well as HFS.

Does a full format wipe data?

Not necessarily. Although the information will not be accessible through Windows file explorer. This does not mean that the information is not physically stored on disk yet. Formatting a disk is equivalent to giving disk permission to overwrite where information previously was. Eventually, the residual information will be completely overwritten.

How do I wipe Linux and install Windows?

If you want to remove Linux and install Windows, the procedure is quite simple. First, back up your information. Once you have done this, you will need to insert your bootable DVD or flash drive that has the Windows installer on it. Then you have to follow the steps and in the type of installation, you will choose "custom", then you will erase the partition where Linux is installed and you will be able to install Windows.

Does formatting remove Bitlocker?

As part of Windows security and protection mechanisms, BitLocker has been developed. For security reasons, BitLocker can only be removed by typing its password or, in case you forgot it, the recovery key. If you do not have any of them, it is suggested to format the device, since this process will delete all the information –including BitLocker— contained to reset all settings to the factory default.

Recoverit author

Theo Lucia

chief Editor

Home > Resources > Answer Hard Drive Problems > How to Format and Wipe Linux Disk Using Commands?