How to format and partition a USB flash drive under Linux

Source: Internet
Author: User

Note that in order to not work hard, you must first uninstall the device you want to partition before the partition can be executed successfully. By command umount/media/?? or umount/mnt/??? Look at your reality, this step is essential.
1, first through the command fdisk-l under the root command to view the disk's partition information.

2, through the Fdisk command to mount the device partition operation, the command is as follows: Fdisk/dev/sdb (may not necessarily be the case, depending on the actual situation).

3, input fdisk/dev/sdb will have prompt command, input m will be listed, as follows:

[Email protected]:~# fdisk/dev/sdb

Command (M for help): M
Command Action
A toggle a bootable flag
b Edit BSD Disklabel
C Toggle the DOS compatibility flag
D Delete a partition
L list known partition types
M Print this menu
n Add a new partition
o Create a new empty DOS partition table
P Print the partition table
Q Quit without saving changes
s create a new empty Sun Disklabel
t change a partition ' s system ID
U Change display/entry units
V Verify the partition table
W Write table to disk and exit
X Extra functionality (experts only)

Command (M for help):
4. Enter p to browse the partition information of the current device as follows: Command (M for help): P

disk/dev/sdb:7948 MB, 7948206080 bytes
245 heads, Sectors/track, 1021 cylinders, total 15523840 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x13561963

Device Boot Start End Blocks Id System
/DEV/SDB1 2048 268287 133120-up Linux
/DEV/SDB2 268288 15523839 7627776-up Linux

Command (M for help):

5, you can see that there are two partitions, and now I delete the two partitions, D command: Command (M for help): D
Partition number (1-4): 1

Command (M for help): D
Selected Partition 2

Command (M for help):

6. Determine if the partition was deleted in the through P command: commands (M for help): P

disk/dev/sdb:7948 MB, 7948206080 bytes
245 heads, Sectors/track, 1021 cylinders, total 15523840 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x13561963

Device Boot Start End Blocks Id System

Command (M for help):
You can see that the partition information was not removed and the partition succeeded.

7. Now new partition, two partitions: Command (M for help): N
Partition Type:
P Primary (0 primary, 0 extended, 4 free)
E Extended
Select (default P):
Using Default Response P
Partition number (1-4, default 1):
Using Default value 1
First sector (2048-15523839, default 2048):
Using Default Value 2048
Last sector, +sectors or +size{k,m,g} (2048-15523839, default 15523839): +200m//Set the size of this partition

Command (M for help):
The first partition has been created. Now the second partition: Command (M for help): N
Partition Type:
P Primary (1 primary, 0 extended, 3 free)
E Extended
Select (default P):
Using Default Response P
Partition number (1-4, default 2):
Using Default value 2
First sector (411648-15523839, default 411648):
Using Default Value 411648
Last sector, +sectors or +size{k,m,g} (411648-15523839, default 15523839)://Does not write, which means that the rest of the space is this partition.
Using Default Value 15523839

Command (M for help):
By default, the partition is complete.

8. Exit partition operation: Command (M for help): W
The partition table has been altered!

Calling IOCTL () to re-read partition table.
Syncing disks.

This step is likely to go wrong (see below) and the reason for the error is that the existing device is mounted. This device must first be uninstalled for the above operation to succeed. Command (M for help): W
The partition table has been altered!

Calling IOCTL () to re-read partition table.

Warning:re-reading the partition table failed with error 16: The device or resource is busy.
The kernel still uses the old table. The new table is being used at
The next reboot or after you run Partprobe (8) or KPARTX (8)
Syncing disks.


The above partition succeeds, but we want our file system, such as partition 1 is FAT format, Partition 2 is ext2 format, so how to deal with it? Very important command MKFS it has many kinds of commands: Mkfs Mkfs.cramfs mkfs.ext3 mkfs.ext4dev mkfs.msdos mkfs.vfat
Mkfs.bfs mkfs.ext2 MKFS.EXT4 Mkfs.minix mkfs.ntfs

1, partition 1 is FAT format:

Mkfs.vfat-f 32-n VFAT/DEV/SDB1//Behind the VFAT is the command of their own devices
[Email protected]:~# mkfs.vfat-f 32-n FAT/DEV/SDB1
Mkfs.vfat 3.0.12 (OCT 2011)


2, partition 2 is ext2 format:

Mkfs.ext2-f-L EXT2/DEV/SDB2//Ibid, this will be formatted, the time depends on the size of the space variable
[Email protected]:~# mkfs.ext2-f-L EXT2/DEV/SDB2
MKE2FS 1.42 (29-nov-2011)
File System label =EXT2
OS Type:linux
Block size =4096 (log=2)
Chunked size =4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
472352 inodes, 1889024 blocks
94451 blocks (5.00%) reserved for the Super user
First block of data =0
Maximum filesystem blocks=1937768448
Groups block
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: complete
Writing Inode table: complete
Writing Superblocks and filesystem accounting Information:
Complete

[Email protected]:~# If the command does not know, through the man Mkfs.vfat view, at a glance. Complete.

How to format and partition a USB flash drive under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.