linux fdisk等命令,Linux fdisk命令操作磁盤(添加、刪除、轉換分區等)

創建分區

1->查看原始分區

sudo fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000a424d

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 39845887 19921920 83 Linux

/dev/sda2 39847934 41940991 1046529 5 Extended

/dev/sda5 39847936 41940991 1046528 82 Linux swap / Solaris

Disk /dev/sdb: 31.0 GB, 30953963520 bytes

64 heads, 32 sectors/track, 29520 cylinders, total 60456960 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000ababa

Device Boot Start End Blocks Id System

2->創建Partition

sudo 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)

->n

Partition type:

p primary (0 primary, 0 extended, 4 free) (主分區)

e extended (擴展分區)

->Select (default p): p

->Partition number (1-4, default 1): 1

->First sector (2048-60456959, default 2048): (分區起始位置,一般直接回車)

Using default value 2048

->Last sector, +sectors or +size{K,M,G} (2048-60456959, default 60456959): +5G (分區大小)

->Command (m for help): w (保存設置)

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

3->format partition

sudo mkfs.vfat /dev/sdb1

mkfs.vfat 3.0.12 (29 Oct 2011)

4->分區結果

sudo fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000a424d

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 39845887 19921920 83 Linux

/dev/sda2 39847934 41940991 1046529 5 Extended

/dev/sda5 39847936 41940991 1046528 82 Linux swap / Solaris

Disk /dev/sdb: 31.0 GB, 30953963520 bytes

64 heads, 32 sectors/track, 29520 cylinders, total 60456960 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000ababa

Device Boot Start End Blocks Id System

/dev/sdb1 2048 10487807 5242880 83 Linux

No partition is defined yet! 解決辦法

no partition is defined yet翻譯過來意思是:沒有定義分區!白話文的意思是:我們執行命令刪除操作的時候,它在這個磁盤上沒有找到這個分區,因此刪除不了分區;也就是沒有定義分區;

可以使用fdisk -l查看磁盤信息

以上面分區舉例進行刪除分區操作:

1、sudo fdisk /dev/sdb

2、d

3、w

執行sudo fdisk /dev/sdb1就會提示No partition is defined yet!,而執行sudo fdisk /dev/sdb則不會,原因就是fdisk 是掛載磁盤,不是掛載分區;/dev/sdb這才是磁盤,而/dev/sdb1這是主分區,分區號是1;所以會失敗;

查看分區個數

fdisk -l /dev/mmcblk0 | grep "^/dev" | wc -l

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值