Linux使用fdisk進行磁盤的相關操作
簡介
fdisk 命令是 Linux 中用于管理磁盤分區(qū)的強大文本實用程序。它可以創(chuàng)建、刪除、調整大小和修改硬盤上的分區(qū)。
基本語法
fdisk [options] <device>
<device>:要管理的磁盤,例如 /dev/sda、/dev/nvme0n1 或 /dev/vda
示例用法
列出所有分區(qū)
將顯示所有可用的磁盤及其分區(qū),包括它們的大小和文件系統(tǒng)
fdisk -l
示例輸出
Disk /dev/sda: 500 GB
Sector size (logical/physical): 512B/512B
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1050623 1048576 512M 83 Linux
/dev/sda2 1050624 976773167 975722544 465G 83 Linux
查看指定磁盤的區(qū)分
fdisk -l /dev/sda
管理指定的磁盤
這將打開一個交互式會話來管理磁盤 /dev/sda
fdisk /dev/sda
進入交互式模式
fdisk /dev/sda
示例輸出
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
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)
Command (m for help):
示例
Command (m for help):
常用的交互式命令有:
m:顯示幫助(顯示所有可用的命令)p:打印所選磁盤的分區(qū)表n:添加一個新分區(qū)d:刪除一個存在的分區(qū)t:變更分區(qū)類型,如:Linux、swapa:切換分區(qū)的可啟動標志w:將更改寫入磁盤并退出q:退出而不保存更改
創(chuàng)建一個新的分區(qū)
指定目標磁盤
fdisk /dev/sda
輸入 n 來創(chuàng)建一個新分區(qū)
- 選擇主分區(qū)(
p)或 擴展分區(qū)(e) - 指定分區(qū)號、起始扇區(qū)和結束扇區(qū)(或大?。?/li>
輸入 w 來保存變更然后退出
刪除一個存在的分區(qū)
指定目標磁盤
fdisk /dev/sda
輸入 d 接分區(qū)編號來刪除一個分區(qū)
輸入 w 來保存變更然后退出
變更分區(qū)類型
指定目標磁盤
fdisk /dev/sda
輸入 t 來變更分區(qū)類型
- 輸入分區(qū)編號
- 輸入類型代碼,例如:
82表示Linux swap,83表示Linux,7表示NTFS
輸入 w 來保存變更然后退出
將分區(qū)標記為可引導
指定目標磁盤
fdisk /dev/sda
- 輸入
a來切換可引導標志 - 輸入
w來保存變更然后退出
檢查分區(qū)大小
fdisk -s /dev/sda2
設置磁盤的扇區(qū)大小
fdisk -b 2048 /dev/sda
列出分區(qū)表時,給出扇區(qū)大小,而不是柱面大小
fdisk -u /dev/sda
設置磁盤的磁頭數
fdisk -H 16 /dev/sda
設置磁盤的柱面數
fdisk -C 100 /dev/sda
設置磁盤每個磁道的扇區(qū)數
fdisk -S 63 /dev/sda
檢查分區(qū)變化
partprobe
使用場景
管理基于 MBR 的分區(qū)(針對 ≤ 2 TB 的磁盤)
對于更大的磁盤或 GPT 分區(qū),需要使用 gdisk 或 parted
到此這篇關于Linux使用fdisk進行磁盤的相關操作的文章就介紹到這了,更多相關Linux fdisk磁盤操作內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Linux內核設備驅動之proc文件系統(tǒng)筆記整理
今天小編就為大家分享一篇關于Linux內核設備驅動之proc文件系統(tǒng)筆記整理,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12
安裝ubuntu18.04報:failed to load ldlinux.c32的問題及解決步驟
這篇文章主要介紹了安裝ubuntu18.04報:failed to load ldlinux.c32的問題,本文通過圖文并茂的形式給大家分享解決方法,需要的朋友可以參考下2020-08-08
Linux系統(tǒng)java進程CPU占用過高的問題及排查
這篇文章主要介紹了Linux系統(tǒng)java進程CPU占用過高的問題及排查方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06
Apache No space left on device: mod_rewrite: could not creat
這篇文章主要介紹了Apache No space left on device: mod_rewrite: could not create rewrite_log_lock Configuration Failed問題的解決方法,需要的朋友可以參考下2014-09-09

