Linux下常用的分區(qū)工具:

創(chuàng)新互聯(lián)基于成都重慶香港及美國(guó)等地區(qū)分布式IDC機(jī)房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動(dòng)大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)西部信息中心報(bào)價(jià),主機(jī)托管價(jià)格性價(jià)比高,為金融證券行業(yè)服務(wù)器托管,ai人工智能服務(wù)器托管提供bgp線路100M獨(dú)享,G口帶寬及機(jī)柜租用的專業(yè)成都idc公司。
fdisk/sfdisk:命令行工具,各種版本和環(huán)境都能使用,包含在軟件包util-linux中
diskdruid:圖形化分區(qū)工具,只能在安裝REDHAT系統(tǒng)時(shí)使用。
第一步:fdisk
[root@novice ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
[root@novice ~]# fdisk /dev/sdb
Command (m for help): #在輸入上面的命令后會(huì)出現(xiàn)左邊的提示,輸入m就會(huì)得到一個(gè)幫助菜單,如下:
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)
#help雖然是英文的,可都很簡(jiǎn)單,在這里不再解釋。
#現(xiàn)在,我們正式開(kāi)始分區(qū)的操作:
Command (m for help): n #新建分區(qū)
Command action
e extended
p primary partition (1-4)
#e/p分別對(duì)應(yīng)擴(kuò)展分區(qū) /主分區(qū);我們先分四個(gè)主分區(qū),每個(gè)50M;然后再來(lái)增加主分區(qū)或擴(kuò)展分區(qū),看會(huì)出現(xiàn)怎樣的狀況,嘿嘿。
p #分區(qū)類型為主分區(qū)
Partition number (1-4, default 1): 1 #分區(qū)號(hào),在這里我們依次選擇1、2、3、4
First sector (2048-496127, default 2048): #指定分區(qū)的起始扇區(qū),一般默認(rèn),按enter鍵即可。
Last sector, +sectors or +size{K,M,G} (2048-496127, default 496127): +50M #指定分區(qū)的終止扇區(qū),根據(jù)前面的提示我們可以做出相應(yīng)的選擇+sectors 或 +size{K,M,G}
Command (m for help): p #用p打印出已建好的分區(qū)列表
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
#剩下的三個(gè)分區(qū)的建立操作同上
#分好四個(gè)主分區(qū)后的情況如下
Command (m for help): p
Linux下常用的分區(qū)工具:
fdisk/sfdisk:命令行工具,各種版本和環(huán)境都能使用,包含在軟件包util-linux中
diskdruid:圖形化分區(qū)工具,只能在安裝REDHAT系統(tǒng)時(shí)使用。
第一步:fdisk
[root@novice ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
[root@novice ~]# fdisk /dev/sdb
Command (m for help): #在輸入上面的命令后會(huì)出現(xiàn)左邊的提示,輸入m就會(huì)得到一個(gè)幫助菜單,如下:
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)
#help雖然是英文的,可都很簡(jiǎn)單,在這里不再解釋。
#現(xiàn)在,我們正式開(kāi)始分區(qū)的操作:
Command (m for help): n #新建分區(qū)
Command action
e extended
p primary partition (1-4)
#e/p分別對(duì)應(yīng)擴(kuò)展分區(qū) /主分區(qū);我們先分四個(gè)主分區(qū),每個(gè)50M;然后再來(lái)增加主分區(qū)或擴(kuò)展分區(qū),看會(huì)出現(xiàn)怎樣的狀況,嘿嘿。
p #分區(qū)類型為主分區(qū)
Partition number (1-4, default 1): 1 #分區(qū)號(hào),在這里我們依次選擇1、2、3、4
First sector (2048-496127, default 2048): #指定分區(qū)的起始扇區(qū),一般默認(rèn),按enter鍵即可。
Last sector, +sectors or +size{K,M,G} (2048-496127, default 496127): +50M #指定分區(qū)的終止扇區(qū),根據(jù)前面的提示我們可以做出相應(yīng)的選擇+sectors 或 +size{K,M,G}
Command (m for help): p #用p打印出已建好的分區(qū)列表
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
#剩下的三個(gè)分區(qū)的建立操作同上
#分好四個(gè)主分區(qū)后的情況如下
Command (m for help): p
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 83 Linux
/dev/sdb3 206848 309247 51200 83 Linux
/dev/sdb4 309248 309298 25+ 83 Linux
#已經(jīng)建好四個(gè)主分區(qū)啦,現(xiàn)在我們來(lái)看看如果再建主分區(qū)或是擴(kuò)展分區(qū)的話會(huì)出現(xiàn)怎樣的情況:
Command (m for help): n
You must delete some partition and add an extended partition first
#看到了吧,不能再建分區(qū)啦!要再建分區(qū)的話必須刪除some分區(qū),再新建一個(gè)擴(kuò)展分區(qū)才行。
#現(xiàn)在,我們刪掉一個(gè)主分區(qū),來(lái)新建擴(kuò)展分區(qū)
Command (m for help): d #刪除分區(qū)
Partition number (1-4): 4 #選擇要?jiǎng)h除分區(qū)的分區(qū)號(hào),我們選第四個(gè)
Command (m for help): p #打印,如下,四個(gè)分區(qū)變成了三個(gè)!
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 83 Linux
/dev/sdb3 206848 309247 51200 83 Linux
#新建一個(gè)擴(kuò)展分區(qū)
#如果在沒(méi)有建滿三個(gè)主分的區(qū)的情況下建立擴(kuò)展分區(qū),相關(guān)選項(xiàng)會(huì)有些不同。
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First sector (309248-496127, default 309248): #enter,默認(rèn)
Using default value 309248
Last sector, +sectors or +size{K,M,G} (309248-496127, default 496127): #enter,默認(rèn),使用剩余空間
Using default value 496127
Command (m for help): p
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 83 Linux
/dev/sdb3 206848 309247 51200 83 Linux
/dev/sdb4 309248 496127 93440 5 Extended
#接下來(lái),我們?cè)谛陆ǖ臄U(kuò)展分區(qū)里再新建兩個(gè)邏輯分區(qū),因?yàn)橐呀?jīng)有了三個(gè)主分區(qū),這里不會(huì)再顯示是建立邏輯分區(qū)還是主分區(qū)的提示!
Command (m for help): n
First sector (311296-496127, default 311296): #enter
Using default value 311296
Last sector, +sectors or +size{K,M,G} (311296-496127, default 496127): +50M
Command (m for help): n
First sector (415744-496127, default 415744): #enter
Using default value 415744
Last sector, +sectors or +size{K,M,G} (415744-496127, default 496127): #enter
Using default value 496127
Command (m for help): p
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 83 Linux
/dev/sdb3 206848 309247 51200 83 Linux
/dev/sdb4 309248 496127 93440 5 Extended
/dev/sdb5 311296 413695 51200 83 Linux
/dev/sdb6 415744 496127 40192 83 Linux
#上面的列表,就是我們今天分區(qū)的成果啦!接下來(lái)保存退出,重啟計(jì)算機(jī),就可以進(jìn)行下一步的mkfs操作啦!如果忘記了相關(guān)的操作命令,記得按m!!!
Command (m for help): w #保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
另:在建好分區(qū)后,我們還可以更改相關(guān)分區(qū)的文件系統(tǒng)類型
#如,我們要把第二個(gè)主分區(qū)改成Linux下的交換分區(qū),操作如下
Command (m for help): t #更改文件系統(tǒng)類型
Partition number (1-6): 2 #選擇第二個(gè)分區(qū)
Hex code (type L to list codes): L #選擇要更改的文件系統(tǒng)編碼,可以按L來(lái)查看相關(guān)編碼信息。
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
............
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 82 #查找到linux swap的編碼為82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Command (m for help): p
..............
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 82 Linux swap / Solaris
/dev/sdb3 206848 309247 51200 83 Linux
/dev/sdb4 309248 496127 93440 5 Extended
/dev/sdb5 311296 413695 51200 83 Linux
/dev/sdb6 415744 496127 40192 83 Linux
#最后別忘了保存!如果你須要的話!
#擴(kuò)展分區(qū)不能直接使用,邏輯分區(qū)只能建立在擴(kuò)展分區(qū)上!
第二步:mkfs(mkfs時(shí)分區(qū)的格式最好與fdisk設(shè)定的分區(qū)格式一致,不然.......)
mkfs支持ext2 ext3 vfa msdos jfs reiserfs等文件系統(tǒng)。
用法1:mkfs -t
例: mkfs -t ext3 /dev/sdb2
用法2:mkfs.
例:mkfs,vfat /dev/sdb3
mke2fs支持ext2/ext3文件系統(tǒng)
用法:mke2fs [-j]
例:mke2fs -j /dev/sdb5
# 更多更具體的用法請(qǐng)參照相關(guān)命令的man手冊(cè)
下面,接著實(shí)驗(yàn):
例一
[root@novice ~]# mkfs -t ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
12824 inodes, 51200 blocks
2560 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=52428800
7 block groups
8192 blocks per group, 8192 fragments per group
1832 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
第三部:掛載
掛載:mount
例:mount /dev/sdb1 /mnt /sdb1
卸載:umonut
例:umount /dev/sdb1
命令: print [devices|free|list,all|NUMBER] :使用 print 命令可以查看分區(qū)表信息,包括硬盤參數(shù),硬盤大小,扇區(qū)大小,分區(qū)表類型和分區(qū)信息。
結(jié)果如下:
可以看到 sdb 硬盤大小是21,5GB,文件系統(tǒng)是 msdos ( msdos 文件系統(tǒng)是windows下的文件系統(tǒng),在 parted 命令交互中就是表示MBR分區(qū)表)。
把硬盤由MBR分區(qū)表,改成GPT分區(qū)表,使用的命令如下:
mklabel,mktable LABEL-TYPE :創(chuàng)建新的磁盤卷標(biāo)(分區(qū)表)。
(如果要由GPT分區(qū)表改成MBR分區(qū)表,命令為 mklabel msdos )
我們?cè)诓榭匆幌庐?dāng)前硬盤分區(qū)表情況
可以看到分區(qū)表已經(jīng)變成GPT分區(qū)表,并且之前硬盤的分區(qū)信息已經(jīng)沒(méi)有了。
之后 quit 退出 parted 命令交互,執(zhí)行 reboot 命令重啟計(jì)算機(jī)。
重啟完計(jì)算機(jī)才能執(zhí)行之后的操作。(不重啟后續(xù)操作是無(wú)法完成的)
因?yàn)樾薷倪^(guò)了分區(qū)表,所以 /dev/sdb 硬盤中的所有數(shù)據(jù)都消失了,所以我們可以重新對(duì)這塊硬盤分區(qū)了。
執(zhí)行 parted 命令,進(jìn)入硬盤分區(qū)。
執(zhí)行分區(qū)命令,對(duì)硬盤進(jìn)行分區(qū),命令如下:
mkpart PART-TYPE [FS-TYPE] START END :創(chuàng)建一個(gè)分區(qū)。
查看硬盤的分區(qū)情況
已顯示剛剛創(chuàng)建好的分區(qū)disk1。因?yàn)闆](méi)有格式化,所以 File system:文件系統(tǒng)類型 是空著的。
分區(qū)分完了,我們還需要對(duì)分區(qū)進(jìn)行格式化。不過(guò)我們已經(jīng)知道如果使用 parted 交互命令格式化的話,只能格式化成 ext2 文件系統(tǒng)。我們這里是要演示下 parted 命令的格式化方法。
parted 交互命令的格式化命令為 mkfs ,命令如下:
mkfs NUMBER FS-TYPE :在分區(qū)上建立文件系統(tǒng)。
再查看硬盤的分區(qū)情況
退出
上圖提示你,如果需要讓分區(qū)自動(dòng)掛載,需要手動(dòng)修改 etc/fstab 文件。
如果要把硬盤格式化成 ext4 文件系統(tǒng),需要執(zhí)行 mkfs 命令,重新對(duì)硬盤進(jìn)行格式化。(注意不是 parted 交互命令中的 mkfs 命令,而是系統(tǒng)命令 mkfs )!
執(zhí)行 [root@localhost ~] # mkfs -t ext4 /dev/sdb1
將 sdb1 分區(qū)格式化為 ext4 文件系統(tǒng)之后,就可以進(jìn)行分區(qū)的掛載了。如下圖:
如果你需要開(kāi)機(jī)自動(dòng)掛載,手動(dòng)修改 etc/fstab 文件即可。
parted 命令還有一大優(yōu)勢(shì),就是可以調(diào)整分區(qū)的大小(windows中也可以實(shí)現(xiàn),不過(guò)需要轉(zhuǎn)換成動(dòng)態(tài)磁盤,要不就需要依賴第三方工具,如硬盤分區(qū)魔術(shù)師)。起始Linux中LVM和RAID是可以支持分區(qū)調(diào)整的,不過(guò)這兩種方法也可以看成是動(dòng)態(tài)磁盤方法。使用 parted 命令調(diào)整分區(qū)大小要更加簡(jiǎn)單。
刪除分區(qū)前提,要先把分區(qū)的自動(dòng)掛載在 /etc/fstab 文件刪除,然后用 umount 卸載掉分區(qū)的掛載。在執(zhí)行 parted 命令的刪除分區(qū)命令。
rm NUMBER :刪除分區(qū)。
當(dāng)前標(biāo)題:linux圖形分區(qū)命令,linux圖形界面分區(qū)
鏈接地址:http://chinadenli.net/article46/dsgpheg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、網(wǎng)站維護(hù)、營(yíng)銷型網(wǎng)站建設(shè)、Google、動(dòng)態(tài)網(wǎng)站、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)