SSD Grow

SSD_Grow

Guide to Formatting a Disk in Linux/Ubuntu Operating System

A Linux operating system serves as a platform for running programs, akin to Windows and macOS. It’s favoured by web developers for its robustness and security features. Operating through commands entered into the terminal, users can accomplish various tasks, such as formatting disks in Linux. Formatting a disk in Linux becomes necessary when encountering filesystem issues, requiring additional space, or addressing disk corruption or malware attacks by wiping data entirely. Formatting disks ranks among the routine administrative tasks in Linux. This article aims to provide a comprehensive guide on executing this process efficiently and effectively.

  • 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. 

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

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 crucial pointers to ensure successful formatting or wiping of a Linux disk:

  1. Admin Privileges: Logging in as an administrator streamlines the process.
  2. Selective Installation: You don’t need to install every command; choose only essential ones.
  3. Reliable Commands: Opt for trusted commands when shredding or wiping a disk, given the abundance of third-party applications available.
  4. Trusted Sources: Utilize readily available tools only from trusted sources to mitigate risks.
  5. Command Verification: Always double-check commands before execution to prevent potential irreversible damage to the system due to small errors.
  6. Backup Precaution: Prioritize data backup before wiping the Linux disk. Having a second copy of your data ensures recovery in case of errors or issues, and facilitates data transfer to a new system if needed.

Adhering to these tips before formatting or wiping the disk ensures a smoother and safer process.

Conclusion

That’s a wrap, everyone! Mastering disk formatting or wiping on Linux can swiftly fulfil your needs. In case of accidental data deletion, wiping, or drive formatting, consider employing a dependable data recovery solution like Server Wala. By connecting your Linux device to a PC, you can recover lost or inaccessible content. Feel encouraged to experiment with these methods and share any shortcuts or tips you discover in the comments.

Related Articles