Fdisk功能介紹:
fdisk是linux系統下常用的磁盤分區工具,受mbr分區表的限制,fdisk工具只能給小于2TB的磁盤劃分分區,若磁盤空間大于2TB,就需要使用parted分區工具
語法格式:
fdisk [option] [device]
常用選項:
-l 顯示所有磁盤分區信息
范例:
1)顯示磁盤分區列表(-l 參數)
[root@fenfa ~]# fdisk -l (查看當前系統所有磁盤的分區信息)
Disk /dev/vda: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003bb0f
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 41611 20458496 8e Linux LVM
Partition 2 does not end on cylinder boundary.
范例2: 添加一款硬盤,使用fdisk磁盤分區
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
如果使用fdisk命令不加任何參數,表示,直接進行分區操作,具體如下
[root@fenfa ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x438dbabe.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m -》查看幫助
Command action
a toggle a bootable flag 設置引導扇區
b edit bsd disklabel 編輯bsd卷標
c toggle the dos compatibility flag 設置dos兼容扇區
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 創建新的空sun卷標
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): n ---操作(創建分區)
Command action
e extended----擴展分區
p primary partition (1-4)----主分區(1-4)
p 創建一個主分區,需要人工輸入p后回車
Partition number (1-4): 1---設置分區編號1,需要人工輸入
First cylinder (1-41610, default 1): 設置開始柱面,默認為1
Last cylinder, +cylinders or +size{K,M,G} (1-41610, default 41610): +2G
設置結束柱面,例如這個劃分2G的空間
Command (m for help): p 打印分過的分區表
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x438dbabe
Device Boot Start End Blocks Id System
/dev/vdb1 1 4162 2097616+ 83 Linux
如果要需要創建分區,我們具體輸入n,然后編號設置為2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (4163-41610, default 4163):
Using default value 4163
Last cylinder, +cylinders or +size{K,M,G} (4163-41610, default 41610): +2G
Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x438dbabe
Device Boot Start End Blocks Id System
/dev/vdb1 1 4162 2097616+ 83 Linux
/dev/vdb2 4163 8324 2097648 83 Linux
創建邏輯分區:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 3
First cylinder (8325-41610, default 8325):
Using default value 8325
Last cylinder, +cylinders or +size{K,M,G} (8325-41610, default 41610):
Using default value 41610
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (8325-41610, default 8325):
Using default value 8325
Last cylinder, +cylinders or +size{K,M,G} (8325-41610, default 41610): +2G
Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x438dbabe
Device Boot Start End Blocks Id System
/dev/vdb1 1 4162 2097616+ 83 Linux
/dev/vdb2 4163 8324 2097648 83 Linux
/dev/vdb3 8325 41610 16776144 5 Extended
/dev/vdb5 8325 12486 2097616+ 83 Linux
Command (m for help): w 保存退出
The partition table has been altered!
[root@fenfa ~]# partx /dev/vdb
# 1: 63- 4195295 ( 4195233 sectors, 2147 MB)
# 2: 4195296- 8390591 ( 4195296 sectors, 2147 MB)
# 3: 8390592- 41942879 ( 33552288 sectors, 17178 MB)
# 4: 0- -1 ( 0 sectors, 0 MB)
# 5: 8390655- 12585887 ( 4195233 sectors, 2147 MB)
格式化分區
[root@fenfa ~]# mkfs.ext4 /dev/vdb1
避免磁盤掛載自動檢測磁盤
[root@fenfa ~]# tune2fs -c -1 /dev/vdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
掛載:
臨時:mount /dev/vdb1 /test
持久: 編寫/etc/fstab配置文件
/dev/vdb1 /test ext4 defaults 0 0
范例3: 自動劃分邏輯分區
[root@fenfa test]# fdisk /dev/vdb <<EOF
> n
> l
>
> +1G
> p
> w
> EOF
(如果不需要輸入的,就直接回車)
- 第一章:文件和目錄操作類命令
- 第一節:pwd命令
- 第二節:cd命令
- 第三節:mkdir命令
- 第四節:touch命令
- 第五節:ls命令
- 第六節:cp命令
- 第八節: mv命令
- 第九節:ln命令
- 第十節:find命令
- 第十一節:chattr命令
- 第十二節:chown命令
- 第十三節:chmod命令
- 第二章:文件過濾和內容編輯類命令
- 第一節: cat命令
- 第二節:less命令
- 第三節:head命令
- 第四節:tail命令
- 第五節:cut命令
- 第六節:sort命令
- 第七節:wc命令
- 第八節:tr命令
- 第三章:文本處理三劍客
- 第一節:grep命令
- 第二節:sed命令
- 第四章:linux信息顯示類或搜索命令
- 第一節:uname命令
- 第二節:du命令
- 第三節:data命令
- 第四節:echo命令
- 第五節:watch命令
- 第五章: 文件備份和壓縮類命令
- 第一節:tar命令
- 第二節:gzip壓縮
- 第三節:zip和upzip命令
- 第四節:scp命令
- 第五節: rsync文件同步工具命令
- 第六章:Linux用戶管理及用戶信息查詢類命令
- 第一節:useradd命令
- 第二節:usermod命令
- 第三節:userdel命令
- 第四節:groupadd和groupdel命令
- 第五節:passwd命令
- 第六節:su命令
- 第七節:visudo命令
- 第八節:id命令
- 第九節:w和who命令
- 第十節:last和lastb命令
- 第七章: Linux磁盤及文件系統管理
- 第一節:fdisk命令
- 第二節: partprobe命令
- 第三節:parted磁盤分區工具
- 第四節:mkfs命令
- 第五節:dumpe2fs命令
- 第六節: fsck命令
- 第七節:mount和umount命令
- 第八節:dd命令
- 第九節:df命令