1. 程式人生 > >Linux下U盤格式化、分割槽

Linux下U盤格式化、分割槽

Linux:

U盤刪除分割槽:

#fdisk /dev/sdb    /*進入fdisk命令操作空間*/
#Command (m for help): m     /*命令檢視*/
Command action
a   toggle a bootable flag                   #設定引導扇區
b   edit bsd disklabel                       #編輯卷標(linux下使用的卷標bsd通用)
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   #生成一個新的空DOS分割槽列表 
p   print the partition table                #列印分割槽列表 
q   quit without saving changes              #不儲存退出
s   create a new empty Sun disklabel
t   change a partition's system id           #改變一個分割槽列表的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): p
Disk /dev/sdb: 2055 MB, 2055208960 bytes
64 heads, 62 sectors/track, 1011 cylinders
Units = cylinders of 3968 * 512 = 2031616 bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         133      263871+   6  FAT16
/dev/sdb2   *         134         200      132928   83  Linux   /*boot 分割槽*/


#Command (m for help): d
#Partition number (1-4): 1
#Command (m for help): p

Disk /dev/sdb: 2055 MB, 2055208960 bytes
64 heads, 62 sectors/track, 1011 cylinders
Units = cylinders of 3968 * 512 = 2031616 bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System
/dev/sdb2   *         134         200      132928   83  Linu


#Command (m for help): d
Selected partition 2


#Command (m for help): p                                      /*檢視此時已無分割槽*/

Disk /dev/sdb: 2055 MB, 2055208960 bytes
64 heads, 62 sectors/track, 1011 cylinders
Units = cylinders of 3968 * 512 = 2031616 bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System


#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: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

U盤不分割槽直接格式化:

/* 在整個/dev/sdb裝置上建立檔案系統 */

#sudo mkfs -t vfat -I /dev/sdb1         /*在整個/dev/sdb裝置上建立檔案系統*/

U盤分割槽並格式化:

/*給磁碟增加一分割槽並格式化*/

#Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
:p                                                                 /*增加主分割槽*/
#Partition number (1-4): 1
#First cylinder (1-1011, default 1):                               /*回車預設*/
Using default value 1
#Last cylinder, +cylinders or +size{K,M,G} (1-1011, default 1011): /*回車預設*/
Using default value 1011


#Command (m for help): p                                           /*此時有sdb1分割槽*/
Disk /dev/sdb: 2055 MB, 2055208960 bytes
64 heads, 62 sectors/track, 1011 cylinders
Units = cylinders of 3968 * 512 = 2031616 bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1011     2005793   83  Linux


#Command (m for help): w                                           /*最後寫入分割槽表*/
The partition table has been altered!

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

#sudo mkfs -t vfat /dev/sdb1                                       /*分割槽完成後格式化*/

格式化完成後, 使用U盤之前需要修復一下,修復命令: fsck -t vfat /dev/sdb