How do you format a hard disk in Linux?
There are several methods in Linux that can be used to format a hard drive.
- By using the fdisk command, you can create partitions, adjust their sizes, format the hard drive, and create file systems.
sudo fdisk /dev/sdX
/dev/sdX represents the hard disk device to be formatted, such as /dev/sda.
- To create a file system, use the mkfs command. It can be used to format a partition that has been created. The specific command is as follows:
sudo mkfs -t ext4 /dev/sdX1
In this case, ext4 represents the type of file system to create, and /dev/sdX1 represents the partition to format.
- With the parted command: parted is a command-line tool used for creating, deleting, and adjusting partitions. The parted command can be used to format a hard drive and create a file system. The specific commands are as follows:
sudo parted /dev/sdX mklabel msdos
sudo parted /dev/sdX mkpart primary ext4 0% 100%
The mklabel msdos command is used to create a partition table, while the mkpart primary ext4 0% 100% command is used to create a primary partition and specify the file system type as ext4.
Please make sure to back up important data before executing these commands, as formatting the hard drive will delete all data.