1. 程式人生 > >fdisk使用(分區查看、新建、刪除等)

fdisk使用(分區查看、新建、刪除等)

linux

fdisk命令

1、磁盤分區管理工具,對於一塊硬盤來講,fdisk最多只能管理15個分區。

2、fdisk使用:

fdisk -l [device...]

fdisk子命令:

P:print顯示已有分區

n:new創建分區

d:delete刪除分區

w:write寫入磁盤(保存)

q:quit放棄更新並退出

m:獲取幫助

l:列表所有分區id

t:調整分區id

----------------------------------------------------------

查看分區

[[email protected] ~]# fdisk /dev/sda
歡迎使用 fdisk (util-linux 2.23.2)。

更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。


命令(輸入 m 獲取幫助):m
命令操作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag

d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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)

命令(輸入 m 獲取幫助):p /*查看分區*/

磁盤 /dev/sda:64.4 GB, 64424509440 字節,125829120 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x000aca47

設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 68149247 33561600 8e Linux LVM
/dev/sda3 68149248 125829119 28839936 5 Extended
------------------------------------------------------------------------------------------------------------

創建分區
命令(輸入 m 獲取幫助):n

Partition type:
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
添加邏輯分區 5
起始 扇區 (68151296-125829119,默認為 68151296):
將使用默認值 68151296
Last 扇區, +扇區 or +size{K,M,G} (68151296-125829119,默認為 125829119):
將使用默認值 125829119
分區 5 已設置為 Linux 類型,大小設為 27.5 GiB
------------------------------------------------------------------

刪除分區
命令(輸入 m 獲取幫助):d

分區號 (1-3,5,默認 5):5
分區 5 已刪除
------------------------------------------------------

保存
命令(輸入 m 獲取幫助):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 kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盤。
[[email protected] ~]#

------------------------------------------------------------------------------------

調整分區id

[[email protected] ~]# fdisk /dev/sda
歡迎使用 fdisk (util-linux 2.23.2)。

更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。


命令(輸入 m 獲取幫助):l /*查看分區號*/

0 空 24 NEC DOS 81 Minix / 舊 Linu bf Solaris
1 FAT12 27 隱藏的 NTFS Win 82 Linux 交換 / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 隱藏的 C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux 擴展 c7 Syrinx
5 擴展 41 PPC PReP Boot 86 NTFS 卷集 da 非文件系統數據
6 FAT16 42 SFS 87 NTFS 卷集 db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux 純文本 de Dell 工具
8 AIX 4e QNX4.x 第2部分 8e Linux LVM df BootIt
9 AIX 可啟動 4f QNX4.x 第3部分 93 Amoeba e1 DOS 訪問
a OS/2 啟動管理器 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad 休 eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 擴展 (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC
11 隱藏的 FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq 診斷 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 隱藏的 FAT16 <3 61 SpeedStor ab Darwin 啟動 f2 DOS 次要
16 隱藏的 FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 隱藏的 HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST 智能睡眠 65 Novell Netware b8 BSDI swap fd Linux raid 自動
1b 隱藏的 W95 FAT3 70 DiskSecure 多啟 bb Boot Wizard 隱 fe LANstep
1c 隱藏的 W95 FAT3 75 PC/IX be Solaris 啟動 ff BBT
1e 隱藏的 W95 FAT1 80 舊 Minix


命令(輸入 m 獲取幫助):q /*退出*/
--------------------------------------------------- ---------------------------

創建swap分區

[[email protected] ~]# fdisk /dev/sda
歡迎使用 fdisk (util-linux 2.23.2)。

更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。


命令(輸入 m 獲取幫助):l

0 空 24 NEC DOS 81 Minix / 舊 Linu bf Solaris
1 FAT12 27 隱藏的 NTFS Win 82 Linux 交換 / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 隱藏的 C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux 擴展 c7 Syrinx
5 擴展 41 PPC PReP Boot 86 NTFS 卷集 da 非文件系統數據
6 FAT16 42 SFS 87 NTFS 卷集 db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux 純文本 de Dell 工具
8 AIX 4e QNX4.x 第2部分 8e Linux LVM df BootIt
9 AIX 可啟動 4f QNX4.x 第3部分 93 Amoeba e1 DOS 訪問
a OS/2 啟動管理器 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad 休 eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 擴展 (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC
11 隱藏的 FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq 診斷 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 隱藏的 FAT16 <3 61 SpeedStor ab Darwin 啟動 f2 DOS 次要
16 隱藏的 FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 隱藏的 HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST 智能睡眠 65 Novell Netware b8 BSDI swap fd Linux raid 自動
1b 隱藏的 W95 FAT3 70 DiskSecure 多啟 bb Boot Wizard 隱 fe LANstep
1c 隱藏的 W95 FAT3 75 PC/IX be Solaris 啟動 ff BBT
1e 隱藏的 W95 FAT1 80 舊 Minix

命令(輸入 m 獲取幫助):t /*調整分區ID8*/
分區號 (1-3,5,默認 5):5

Hex 代碼(輸入 L 列出所有代碼):82
已將分區“Linux”的類型更改為“Linux swap / Solaris”

命令(輸入 m 獲取幫助):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 kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盤。
[[email protected] ~]# fdisk /dev/sda
歡迎使用 fdisk (util-linux 2.23.2)。

更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。


命令(輸入 m 獲取幫助):p

磁盤 /dev/sda:64.4 GB, 64424509440 字節,125829120 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x000aca47

設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 68149247 33561600 8e Linux LVM
/dev/sda3 68149248 125829119 28839936 5 Extended
/dev/sda5 68151296 125829119 28838912 82 Linux swap / Solaris

----------------------------------------------------------------------------------------------------------

通知內核重新讀取硬盤分區表

[[email protected] ~]# partx -a /dev/sda

partx: /dev/sda: error adding partitions 1-3

partx: /dev/sda: error adding partitions 5-6

-------------------------------------------

查看內核是否已經識別新的分區

[[email protected] ~]# cat /proc/partitions

major minor #blocks name


2 0 4 fd0

11 0 4228096 sr0

8 0 62914560 sda

8 1 512000 sda1

8 2 33561600 sda2

8 3 1 sda3

8 5 10485760 sda5

8 6 18352128 sda6

253 0 20971520 dm-0

253 1 2097152 dm-1

253 2 10485760 dm-2


本文出自 “gogo” 博客,謝絕轉載!

fdisk使用(分區查看、新建、刪除等)