Excellent software and practical tutorials
Linux format USB disk
It is very simple to format a USB flash drive in Windows. You can either right-click it to format it or enter the hard disk partition to format it. What about Linux? In fact, formatting a USB flash drive in Linux is also very simple. It only takes a few commands to get it done. Let's take a detailed look at it.How to format a USB drive under Linux.
1. Format
Format the /dev/sda1 partition and format the USB disk system as FAT
# You must first unmount the partition umount /dev/sda1 # The -F parameter must be uppercase. The parameters are 12, 16 and 32, corresponding to FAT12, FAT16, and FAT32 respectively. mkfs.vfat -F 32 /dev/sda1
Format as NTFS partition, first install ntfsprogs
dnf install ntfsprogs # You must unmount the partition before formatting umount /dev/sda1 # Formatting to ntfs is a bit slow, please wait patiently mkfs.ntfs /dev/sda1
Format as ext4/3/2:
# Unmount the partition first umount /dev/sda1 # Format as ext4 partition mkfs.ext4 /dev/sda1 # Format as ext3 partition mkfs.ext3 /dev/sda1 # Format as ext2 partition mkfs.ext2 /dev/sda1
Since the ext series partitions have a reserved space for super user, it must occupy a certain percentage, 5% by default. In this way, you won't feel it when formatting a small partition, and 5% is not much. But if it is several hundred GB, 1T partition will have problems. In this case, 5% is not a small number!
Solution to ext partition occupying reserved space
For the partition to be formatted, take ext3 as an example:
#First unmount the partition umount /dev/sda1 #Note the parameter after -m, the setting is already a percentile, set to 0.05, is 0.05%, that is, 5 in 10,000! mkfs.ext3 -m 0.05 /dev/sda1
Take a 1TB partition as an example: 1TB = 1024GB = 1048576MB, which is 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 own preferences.
For a partition that has already been formatted and you do not want to erase the data in the partition, you can use tune2fs -m Method:
#This command does not require unmounting the partition first. tune2fs -m 0.05 /dev/sda2 #This example converts the super user reserved area of the /dev/sda2 partition, and also sets it to 0.05. Remind me again, it is 0.05%, which is 5 ten-thousandths.
mkfs -t ext4 /dev/sdb1 formats the specified partition
-t specifies the file system type
ext4 file type
2. Partition
Linux U disk partition format fdisk command
fdisk /dev/sdb Enter the fdisk command operation space
A. Command (m for help): m /command view/ The main commands are: d delete a partition Delete partition m print this menu Print menu n add a new partition Add a new partition p print the partition table Print partition list q quit without saving changes Exit without saving w write table to disk and exit Write disk list and exit B. Command (m for help): p/Print partition list/ C. Command (m for help): d /Delete partition/ Partition number(1-4):1 D. Command (m for help): p /Check that there is no partition at this time/ E. Command (m for help): w /Finally write the partition table
Next, add a partition to the disk and format it
ls /dev/sd* /Enter fdisk command operation space/
#/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
fdisk /dev/sdb /Enter the fdisk command operation space/
A. Command (m for help): n /Create a new partition/ Command action e extended p primary partition (1-4) p /Add a primary partition/ B. Partition number(1-4):1 C. First cylinder(1-1011,default): /Enter by default/ Using default value 1 Last cylinder, +cylinders or +size{K,M,G}(1-1011,default,1011): /Enter by default/ Using default value 1011 D. Command (m for help):p /At this time there is sdb1 partition/ E. Command (m for help): w /Finally write the partition table/ F. sudo mkfs.vfat -F 32 -n disk /dev/sdb1 /format
3. Change the USB drive letter
#e2label /dev/sdb1 "Tony" (the volume label name is set, the disk is in ext4 format)
4. Check the hard disk partition
1. lsblk -f View the mount status of all devices
2. blkid