新聞中心

成都創(chuàng)新互聯(lián)主營(yíng)靈壽網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶App定制開發(fā),靈壽h5微信小程序開發(fā)搭建,靈壽網(wǎng)站營(yíng)銷推廣歡迎靈壽等地區(qū)企業(yè)咨詢
當(dāng)然不是,在 linux 中有專門的分區(qū)命令 fdisk 和 parted。其中 fdisk 命令較為常用,但不支持大于 2TB 的分區(qū);如果需要支持大于 2TB 的分區(qū),則需要使用 parted 命令,當(dāng)然 parted 命令也能分配較小的分區(qū)。我們先來看看如何使用 fdisk 命令進(jìn)行分區(qū)。
fdisk 命令的格式如下:
[root@localhost ~]# fdisk ~l
#列出系統(tǒng)分區(qū)
[root@localhost ~]# fdisk 設(shè)備文件名
#給硬盤分區(qū)
注意,千萬不要在當(dāng)前的硬盤上嘗試使用 fdisk,這會(huì)完整刪除整個(gè)系統(tǒng),一定要再找一塊硬盤,或者使用虛擬機(jī)。這里給大家舉個(gè)例子:
[root@localhost ~]# fdisk -l
#查詢本機(jī)可以識(shí)別的硬盤和分區(qū)
Disk /dev/sda:32.2 GB, 32212254720 bytes
#硬盤文件名和硬盤大小
255 heads, 63 sectors/track, 3916 cylinders
#共255個(gè)磁頭、63個(gè)扇區(qū)和3916個(gè)柱面
Units = cylinders of 16065 *512 = 8225280 bytes
#每個(gè)柱面的大小
Sector size (logical/physical): 512 bytes/512 bytes
#每個(gè)扇區(qū)的大小
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x0009e098
Device Boot Start End Blocks ld System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
#分區(qū)1沒有占滿硬盤
/dev/sda2 26 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary
#分區(qū)2沒有占滿硬盤
/dev/sda3 281 3917 29203456 83 Linux
#設(shè)備文件名啟動(dòng)分區(qū) 起始柱面 終止柱面容量 ID 系統(tǒng)
Disk /dev/sdb: 21.5 GB, 21474836480 bytes #第二個(gè)硬盤識(shí)別,這個(gè)硬盤的大小
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes Disk identifier: 0x00000000
使用 "fdisk -l" 查看分區(qū)信息,能夠看到我們添加的兩塊硬盤(/dev/sda 和 /dev/sdb)的信息。我們解釋一下這些信息,其上半部分態(tài)是硬盤的整體狀態(tài),/dev/sda 硬盤的總大小是 32.2 GB,共有 3916 個(gè)柱面,每個(gè)柱面由 255 個(gè)磁頭讀/寫數(shù)據(jù),每個(gè)磁頭管理 63 個(gè)扇區(qū)。每個(gè)柱面的大小是 8225280 Bytes,每個(gè)扇區(qū)的大小是 512 Bytes。
信息的下半部分是分區(qū)的信息,共 7 列,含義如下:
- Device:分區(qū)的設(shè)備文件名。
- Boot:是否為啟動(dòng)引導(dǎo)分區(qū),在這里 /dev/sda1 為啟動(dòng)引導(dǎo)分區(qū)。
- Start:起始柱面,代表分區(qū)從哪里開始。
- End:終止柱面,代表分區(qū)到哪里結(jié)束。
- Blocks:分區(qū)的大小,單位是 KB。
- id:分區(qū)內(nèi)文件系統(tǒng)的 ID。在 fdisk 命令中,可以 使用 "i" 查看。
- System:分區(qū)內(nèi)安裝的系統(tǒng)是什么。
如果這個(gè)分區(qū)并沒有占滿整塊硬盤,就會(huì)提示 "Partition 1 does not end on cyl inder boundary",表示第一個(gè)分區(qū)沒有到硬盤的結(jié)束柱面。大家發(fā)現(xiàn)了嗎?/dev/sda 已經(jīng)分配完了分區(qū),沒有空閑空間了。而第二塊硬盤 /dev/sdb 已經(jīng)可以被識(shí)別了,但是沒有可分區(qū)。
我們以硬盤 /dev/sdb 為例來做練習(xí),命令如下:
[root@localhost ~]# fdisk /dev/sdb
#給/dev/sdb分區(qū)
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xed7e8bc7.
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
#交互界面的等待輸入指令的位置,輸入 m 得到幫助
Command action
#可用指令
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
I 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 verity the partition table
w write table to disk and exit
x extra functionality (experts only)
注意這里的分區(qū)命令是 "fdisk /dev/sdb",這是因?yàn)橛脖P并沒有分區(qū),使用 fdisk 命令的目的就是建立分區(qū)。
在 fdisk 交互界面中輸入 m 可以得到幫助,幫助里列出了 fdisk 可以識(shí)別的交互命令,我們來解釋一下這些命令,如表 1 所示。
| 命令 | 說 明 |
|---|---|
| a | 設(shè)置可引導(dǎo)標(biāo)記 |
| b | 編輯 bsd 磁盤標(biāo)簽 |
| c | 設(shè)置 DOS 操作系統(tǒng)兼容標(biāo)記 |
| d | 刪除一個(gè)分區(qū) |
| 1 | 顯示已知的文件系統(tǒng)類型。82 為 Linux swap 分區(qū),83 為 Linux 分區(qū) |
| m | 顯示幫助菜單 |
| n | 新建分區(qū) |
| 0 | 建立空白 DOS 分區(qū)表 |
| P | 顯示分區(qū)列表 |
| q | 不保存退出 |
| s | 新建空白 SUN 磁盤標(biāo)簽 |
| t | 改變一個(gè)分區(qū)的系統(tǒng) ID |
| u | 改變顯示記錄單位 |
| V | 驗(yàn)證分區(qū)表 |
| w | 保存退出 |
| X | 附加功能(僅專家) |
網(wǎng)頁(yè)標(biāo)題:Linuxfdisk命令詳解:給硬盤分區(qū)
本文URL:http://fisionsoft.com.cn/article/djgsjpd.html


咨詢
建站咨詢
