Jannah Theme License is not validated, Go to the theme options page to validate the license, You need a single license for each domain name.
DevOpsLinux

How to Format a Disk in Linux/Ubuntu OS?

A Linux operating system is a system for running programs. It is similar to Windows and IOS. Web Developers use it. The process itself provides security for the user. It works on the command given in the terminal by the user itself to complete different tasks like Formatting Disk in Linux.

You’ll need to Format Disk in Linux when you run into file system problems or need more space. It can also be done to delete the entire data or when the disk gets corrupted or faces any malware attack.

Formatting Disk is one of the most common Linux administration tasks. This article will guide you on how to do it easily and effectively.

Check Several Components Before Formatting Disk in Linux

  • Bootloader:-  This software is responsible for starting your computer.
  • Kernel:-The kernel is the heart of the system. It manages the CPU’s memory. Operating systems are based on it. 
  • Init system:- This is the system responsible for managing the boot process once the bootloader has been used.
  • Daemons:- These are the services that run in the background when a machine starts up or when a user logs into the computer.
  • Graphical Server:- It is a subsystem that displays the graphics on the monitor.
  • Desktop Environment:– It is the piece that the user interacts with. Cinnamon & Mate are two examples of desktop environments. 

Before Beginning to Format Disk in Linux

Learn the different Linux types before beginning the Disk Partitioning in Linux –

  • DEBIAN:- It is referred to as Debian GNU/Linux. Developed by the community-supported Debian project, it is composed of free and open-source software.  
  • UBUNTU:- It draws on the infrastructure of Debian. These operating systems run on Linux servers, desktops, phones, and tablets.
  • LINUX MINT:- It is a community-driven Linux distribution based on Ubuntu, a package with various free applications. 
  • FEDORA:- It is sponsored by RED HAT, with additional support and sponsorship from other organizations and companies. In addition to distributing free software, it aims to stay on the leading edge of technology.
  • KALI LINUX:- a software distribution based on Debian designed for use in digital forensics and penetration testing. Hackers also use it in different fields, and offensive security maintains it.

How to install Linux/Ubuntu OS?

Learn in the below steps how to use:

  • First, you have to be familiar with the software by installing it in your system.
  • The next step is to test your hardware with a Live CD.
  • Then do the task you usually use your computer for.
  • Try to learn the distributions of Linux.
  • Please consider booting.
  • Install all the software.
  • Learn how to use the command line.

What to do if you need to Format Disk in Linux/Ubuntu?

It is essential to format a drive in Linux because using Linux, it is usually required to format the drive when a new OS is going to be used by the user. It must be formatted before use.

It can also be done for many other reasons, i.e., changing the file system, fixing errors, or deleting all files/data. There can be many different reasons for formatting the drive i.e.

  • The system has low or free space. 
  • The system is getting slow due to the low free space.
  • If the system is corrupted by malware.
  • If the user is selling their system
  • Due to an issue in system storage. 

Also Read: 14 Tar Commands in Linux (with Examples)

Steps to Format Disk in Linux

No dedicated disk management tool can help the user to perform Linux format disks. The user needs to take the assistance of some commands to format the drive in Linux.

The following steps will explain how you can format a disk on Linux:-

  • Create a partition of the Linux format disk
  • Enter the following command after connecting the disk to your Linux system

sudo fdisk 

  • to create a partition, enter the command fdisk i.e.

sudo fdisk /dev/sdb

  • You can type if you want
  • The supported parameters are listed by ‘m’.
  • The ‘n’ key creates a new partition
  • Delete a partition by typing ‘d’
  • The partition table can be checked with ‘p’
  • Format the disk
  • You can format a partition on your system after creating it by running the following command:

sudo mkfs.ext4 /dev/sdb.

  • this makes the design look for available partitions in the format drive Linux
  • by pressing ‘y’, you can confirm your choice 
  • then wait for a moment while the selected section is formatted.
  • NTFS format for Linux
  • To format a disk using the NTFS file system, run the mkfs command

sudo mkfs -t NTFS /dev/sdb1

  • Use this method to verify the file system 
lsblk -f
  • locate the partition and confirm that it uses the NTFS file system.

Steps to Wipe a Hardware Unit Before Formatting Disk in Linux

Why Wipe a Hard Drive?

If you plan to resell your system or if you care about your privacy, format the hard drive in Linux. Like formatting, wiping a drive can also erase all the files or data of the drive.

The steps are as follows:-

wipe

You can use the apt install command first if a command is not readily available on the Linux system. i.e.

#apt install wipe


once done, just use the command ‘wipe’ to wipe a partition 

# wipe /dev/sda2

enter ‘yes’ to confirm your choice and wait while the partition is wiped.

Note: The wipe command is only supported in Ubuntu.

shred

It is the best way to protect your private data.

It works as an ideal shredder. It will overwrite your data with something else.

The command is:-

shred [option] target

In “target”, you can specify a file name, folder, or partition to shred. 

Among its options are:

  • n: Adding “n” times to a data set
  • f: Changes the permissions and allows writing to occur
  • u: Truncates the files after they have been shredded
  • s: To specify the size of the shred
  • u: Removing files after shredding
  • v: Enable verbosity
  • z: Overwrite the final data with zeros

The Linux disk can be wiped by entering the following command 

#shred -vfz -n 10/dev/sda2

dd

You can use the ‘dd’ command to erase the disk if you have less time.

The entire disk will be overwritten with strings of zeros. 

it has certain options to customize the process i.e. 

dd if=source of=target[options]

A professional user must run the command prompt.

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

Overwriting the data with zeros will overwrite it.

scrub

The scrub command overwrites the disk with a specific pattern.

A few times, the patterns can be generated by the system too.

if the command is not present in the Linux system, you must install the apt install command.

The command must be entered 

scrub[option] target

If you choose to erase the disk, you will be prompted to confirm your decision. For instance,

#scrub /dev/sda5

Tips to Format Disk in Ubuntu

Here are some tips for formatting or wiping the Linux disk successfully.

  • If you logged in as an administrator while wiping the disk, it would make the process easier.
  • You do not need to install every command.
  • It is recommended to use reliable commands when shredding or wiping a disk because there are a lot of third-party applications on the market.
  • When using a readily available tool, only use a trusted source.
  • Always check the command before entering it. A small error might end up causing irreversible damage to the system.
  • The most important tip is that you should always take a backup of your data before wiping the Linux disk so that in case of any error, or any other issue, you have a second copy of your data in your hand. So that you can revive your data, and if you buy a new system, you have the data of your old system that will help you.
  • These are some of the tips recommended to you before formatting or wiping the disk.  

Conclusion on Formatting Disk in Linux:-

That is a wrap, folks! You can quickly meet your requirements when you know how to format or wipe a disk on Linux. Use a reliable data recovery solution like Server Wala if you accidentally deleted or wiped your data or formatted your drive. By attaching your Linux device to a PC, you will be able to recover lost or inaccessible content. Feel free to try out some of these methods and please let me know what shortcuts or tips you found in the comments below.

Arpit Saini

He is the Director of Cloud Operations at Serverwala and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *