Home > Article > Operation and Maintenance > How to format hard drive in linux
To format a hard disk in Linux, you first need to check the disk partition status in the current system. You can use the command lsblk or fdisk -l to check. The steps are: 1. Use the fdisk command to delete all partitions on the hard disk; 2. Use the fdisk command to create a new partition; 3. Use the mkfs command to format the partition; 4. Mount the newly formatted partition.
To format a hard drive in Linux, you first need to check the disk partition status in the current system. You can use the command lsblk or fdisk -l to view it.
The following are the general steps:
Use the fdisk command to delete all partitions on the hard disk. The command is sudo fdisk /dev/sdX, where sdX is the hard disk you want to format, such as /dev/sdb. Then, enter d to delete all partitions, enter w to save and exit.
Use the fdisk command to create a new partition. The command is sudo fdisk /dev/sdX, then enter n to create a new partition. Enter the partition type, start and end sectors according to the prompts, and finally enter w to save and exit.
Use the mkfs command to format the partition. The command is sudo mkfs -t ext4 /dev/sdX1, where sdX1 is the partition just created and ext4 is the formatted file system type.
Mount the newly formatted partition. You can use graphical tools to format the hard disk, or enter commands in the terminal to complete the mount.
Please note that formatting the hard drive will delete all data, so please make sure you have backed up all important data before performing this operation. In addition, due to different versions and configurations of Linux operating systems, the specific steps may be slightly different. Before formatting the hard disk, it is recommended to read the relevant documentation of the operating system or consult a professional.
The above is the detailed content of How to format hard drive in linux. For more information, please follow other related articles on the PHP Chinese website!