Linux中磁盤mbr分區——實踐篇


Linux中磁盤mbr分區——實踐篇

fdisk命令

語法

fdisk(選項)(參數)

選項

-b <分區大小> 指定每個分區的大小 -l 列出分區表信息 -v 顯示版本信息

參數

設備文件:例如/dev/sda

實例

選擇要操作的磁盤:

[root@vathe ~]#fdisk /dev/sdb

輸入m可列出可以執行的命令:

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 # 該表分區的系統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): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x48283ee0 Device Boot Start End Blocks Id System

新建分區表:

Command action #選擇新增分區類型 e extended #擴展分區 p primary partition (1-4) #主分區 p // 鍵入p Partition number (1-4): 1 // 鍵入1 First cylinder (1-1305, default 1): # 選擇分區起點柱面 Using default value 1 //選擇默認1 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +1G #設置分區大小1G,+表示往起點后添加,-表示往起點前添加分區

查看確認分區創建成功:

Command (m for help): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes # 磁盤總大小 10.7GB 255 heads, 63 sectors/track, 1305 cylinders # 255個磁頭,每個磁道63個扇區,1305個圓柱面 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: 0x48283ee0 Device Boot Start End Blocks Id System /dev/sdb1 1 132 1060258+ 83 Linux 
再建立一個擴展分區

Command (m for help): n
Command action e extended p primary partition (1-4) e Partition number (1-4): 4 # 分區號 First cylinder (133-1305, default 133): 900
Last cylinder, +cylinders or +size{K,M,G} (900-1305, default 1305): +500M # 擴展分區500M

 

在擴展分區中創建邏輯分區

Command (m for help): n

Command action

l logical (5 or over)

p primary partition (1-4) l

First cylinder (900-964, default 900):

Using default value 900 Last cylinder, +cylinders or +size{K,M,G} (900-964, default 964): +100M  # 邏輯分區100M

 

查看分區列表

Command (m for help): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x48283ee0 Device Boot Start End Blocks Id System /dev/sdb1 1 132 1060258+ 83 Linux /dev/sdb4 900 964 522112+ 5 Extended /dev/sdb5 900 913 112423+ 83 Linux

保存退出

Command (m for help): w # 保存退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.

查看

[root@vathe ~]#lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom sda 8:0 0 200G 0 disk ├─sda1 8:1 0 200M 0 part /boot ├─sda2 8:2 0 20G 0 part /data ├─sda3 8:3 0 10G 0 part /home ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 2G 0 part [SWAP] └─sda6 8:6 0 167.8G 0 part / sdb 8:16 0 10G 0 disk # 顯示分區成功 ├─sdb1 8:17 0 1G 0 part ├─sdb4 8:20 0 1K 0 part └─sdb5 8:21 0 109.8M 0 part

分區成功,當然,要使用磁盤,還需要進行兩部操作,才能使用磁盤——將磁盤掛載在具體目錄(或文件),和對個分區進行格式化。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM