Notes on Common Commands for Formatting Hard Disk in Linux

---

Today, I ordered a 1TB hard drive from Newegg to install Ubuntu. Of course, I have to do my homework first and check the precautions!


Basic skills, formatting commands, take formatting /dev/ sda1 partition as an example:
$ sudo umount /dev/ sda1 # This partition must be unmounted first

# Format as FAT partition
$ sudo mkfs.vfat -F 32 /dev/sda1 # The -F parameter must be capitalized. The parameters are 12 , 16 and 32 , corresponding to FAT12, FAT16, and FAT32 respectively.

# Format as an NTFS partition, first install ntfsprogs, take Ubuntu / Debian as an example:
$ sudo apt-get install ntfsprogs

#Then execute the format command, take formatting the /dev/ sda1 partition as an example:
$ sudo umount /dev/ sda1 # This partition must be unmounted first
$ sudo mkfs.ntfs /dev/ sda1 # Formatting to ntfs is a bit slow.

# Format to ext4 / 3 / 2 , take the format of the /dev/ sda1 partition as an example:
$ sudo umount /dev/ sda1 # This partition must be unmounted first
$ sudo mkfs.ext4 /dev/ sda1 # format as ext4 partition
$ sudo mkfs.ext3 /dev/ sda1 # format as ext3 partition
$ sudo mkfs.ext2 /dev/ sda1 # format as ext2 partition

Since the partitions of the ext series have a reserved space for the super user, they must occupy a certain percentage. The default is 5 %. In this way, I don't think that formatting a partition with a small capacity, 5 % is not much, but if it is a few hundred G , 1T partition will have problems, in  this  case , 5 % is not a small amount!

"Solution"

1. For the partition to be formatted, take ext3 as an example:
$ sudo umount /dev/sda1 # The partition must be unmounted first, the /dev/ sda1 partition to be formatted here.
$ sudo mkfs.ext3 -m 0.05 /dev/sda1 # Note that the parameter after -m is already set to percentile, here it is set to 0.05 , which is 0.05 % , which is 5 / 10,000 !

Well, take a 1T partition as an example, 1T = 1024GB = 1048576MB (all are multiplied by 1024), 1048576MB* 0.0005 = 524 .288MB.
That is to say , after 
setting the -m parameter, the reserved area is about 524MB. Of course you can set it according to your liking.

2. For a partition that has been formatted and do not want to wipe out the data in the partition, you can use the method of tune2fs -m :
# This command does not need to unmount the partition first.
$ sudo tune2fs -m 0.05 /dev/sda2 # This example is to convert the super user reserved area of ​​the /dev/sda2 partition, which is also set to 0.05 , and once reminded, it is 0.05 %, which is 5 / 10,000 . linux

 

 

---

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325808720&siteId=291194637