国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Linux fdisk命令詳解:給硬盤分區

2024-08-27 23:56:48
字體:
來源:轉載
供稿:網友
我們在安裝操作系統的過程中已經對系統硬盤進行了分區,但如果新添加了一塊硬盤,想要正常使用,難道需要重新安裝操作系統才可以分區嗎?

當然不是,在 linux 中有專門的分區命令 fdisk 和 parted。其中 fdisk 命令較為常用,但不支持大于 2TB 的分區;如果需要支持大于 2TB 的分區,則需要使用 parted 命令,當然 parted 命令也能分配較小的分區。我們先來看看如何使用 fdisk 命令進行分區。

fdisk 命令的格式如下:

[root@localhost ~]# fdisk ~l
#列出系統分區
[root@localhost ~]# fdisk 設備文件名
#給硬盤分區


注意,千萬不要在當前的硬盤上嘗試使用 fdisk,這會完整刪除整個系統,一定要再找一塊硬盤,或者使用虛擬機。這里給大家舉個例子:

[root@localhost ~]# fdisk -l
#查詢本機可以識別的硬盤和分區
Disk /dev/sda:32.2 GB, 32212254720 bytes
#硬盤文件名和硬盤大小
255 heads, 63 sectors/track, 3916 cylinders
#共255個磁頭、63個扇區和3916個柱面
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: 0x0009e098
Device Boot Start End Blocks ld System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
#分區1沒有占滿硬盤
/dev/sda2 26 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary
#分區2沒有占滿硬盤
/dev/sda3 281 3917 29203456 83 Linux
#設備文件名啟動分區 起始柱面 終止柱面容量 ID 系統
Disk /dev/sdb: 21.5 GB, 21474836480 bytes #第二個硬盤識別,這個硬盤的大小
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" 查看分區信息,能夠看到我們添加的兩塊硬盤(/dev/sda 和 /dev/sdb)的信息。我們解釋一下這些信息,其上半部分態是硬盤的整體狀態,/dev/sda 硬盤的總大小是 32.2 GB,共有 3916 個柱面,每個柱面由 255 個磁頭讀/寫數據,每個磁頭管理 63 個扇區。每個柱面的大小是 8225280 Bytes,每個扇區的大小是 512 Bytes。

信息的下半部分是分區的信息,共 7 列,含義如下:
  • Device:分區的設備文件名。
  • Boot:是否為啟動引導分區,在這里 /dev/sda1 為啟動引導分區。
  • Start:起始柱面,代表分區從哪里開始。
  • End:終止柱面,代表分區到哪里結束。
  • Blocks:分區的大小,單位是 KB。
  • id:分區內文件系統的 ID。在 fdisk 命令中,可以 使用 "i" 查看。
  • System:分區內安裝的系統是什么。

如果這個分區并沒有占滿整塊硬盤,就會提示 "Partition 1 does not end on cyl inder boundary",表示第一個分區沒有到硬盤的結束柱面。大家發現了嗎?/dev/sda 已經分配完了分區,沒有空閑空間了。而第二塊硬盤 /dev/sdb 已經可以被識別了,但是沒有可分區。

我們以硬盤 /dev/sdb 為例來做練習,命令如下:

[root@localhost ~]# fdisk /dev/sdb
#給/dev/sdb分區
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)

注意這里的分區命令是 "fdisk /dev/sdb",這是因為硬盤并沒有分區,使用 fdisk 命令的目的就是建立分區。

在 fdisk 交互界面中輸入 m 可以得到幫助,幫助里列出了 fdisk 可以識別的交互命令,我們來解釋一下這些命令,如表 1 所示。

表 1 fdisk 交互
命令說 明
a設置可引導標記
b編輯 bsd 磁盤標簽
c設置 DOS 操作系統兼容標記
d刪除一個分區
1顯示已知的文件系統類型。82 為 Linux swap 分區,83 為 Linux 分區
m顯示幫助菜單
n新建分區
0建立空白 DOS 分區表
P顯示分區列表
q不保存退出
s新建空白 SUN 磁盤標簽
t改變一個分區的系統 ID
u改變顯示記錄單位
V驗證分區表
w保存退出
X附加功能(僅專家)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肥乡县| 新田县| 兴国县| 潜江市| 剑河县| 大足县| 六安市| 五原县| 枣阳市| 西乡县| 阿克陶县| 房山区| 沐川县| 益阳市| 灌阳县| 九江市| 高台县| 南充市| 广灵县| 泸水县| 科技| 沂南县| 疏勒县| 台州市| 日土县| 易门县| 温泉县| 游戏| 新津县| 聂荣县| 兴山县| 松潘县| 城口县| 鄱阳县| 资兴市| 红原县| 泸州市| 沅陵县| 苍南县| 石景山区| 桦甸市|