Linux下分割槽詳解之—Parted
Linux下分割槽詳解之—Parted
作者:吳偉龍
通常我們用的比較多的一般都是fdisk工具來進行分割槽,但是現在由於磁碟越來越廉價,而且磁碟空間越來越大;而fdisk工具他對分割槽是有大小限制的,它只能劃分小於2T的磁碟。但是現在的磁碟空間很多都已經是遠遠大於2T了,甚至達到2.5T和3T,那要怎麼辦能,有兩個方法,其一是透過卷管理來實現,其二就是透過我們今天談到的Parted工具來實現對GPT磁碟進行分割槽操作。
GPT格式的磁碟相當於原來MBR磁碟中原來保留4個partition table的4*16個位元組,只留第一個16個位元組,類似於擴充套件分割槽,真正的partition table在512位元組之後,GPT磁碟沒有四個主分割槽的限制。
1、 Parted工具詳解:
1.1 進入Parted的方法(在命令列輸入Parted命令即可)
[root@jetsen ~]# partet
Warning: Unable to open /dev/hdc read-write (Read-only file system). /dev/hdc has been
opened read-only.
GNU Parted 1.8.1
Using /dev/hdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
1.2 獲取parted工具幫助的方法:(只需輸入help即可)
(parted) help
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] prints general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on partititon
NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system
move NUMBER START END move partition NUMBER
name NUMBER NAME name partition NUMBER as NAME
print [free|NUMBER|all] display the partition table, a partition, or
all devices
quit exit program
rescue START END rescue a lost partition near START and END
resize NUMBER START END resize partition NUMBER and its file system
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version displays the current version of GNU Parted
and copyright information
(parted)
或
[root@jetsen ~]# parted --help
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE. If no COMMAND(s) are given, run in
interactive mode.
OPTIONs:
-h, --help displays this help message
-i, --interactive where necessary, prompts for user intervention
-l, --list lists partition tables of all detected devices
-s, --script never prompts for user intervention
-v, --version displays the version
COMMANDs:
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] prints general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on partititon NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system
move NUMBER START END move partition NUMBER
name NUMBER NAME name partition NUMBER as NAME
print [free|NUMBER|all] display the partition table, a partition, or all devices
quit exit program
rescue START END rescue a lost partition near START and END
resize NUMBER START END resize partition NUMBER and its file system
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version displays the current version of GNU Parted and copyright information
[root@jetsen ~]#
1.3 退出parted工具(只需輸入quit即可)
(parted) quit
Information: Don't forget to update /etc/fstab, if necessary.
並且同時會提示及時更新/etc/fstab檔案
2、 開始透過parted工具來對磁碟進行操作
2.1 檢視單個磁碟狀態
[root@jetsen ~]# parted /dev/sdb
GNU Parted 1.8.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 16.1GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 16.1GB 16.1GB primary ext3
(parted)
2.2 檢視所有磁碟狀態
[root@jetsen ~]# parted -l
Warning: Unable to open /dev/hdc read-write (Read-only file system). /dev/hdc has been
opened read-only.
Error: Unable to open /dev/hdc - unrecognised disk label.
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 107MB 107MB primary ext3 boot
2 107MB 21.5GB 21.4GB primary lvm
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 16.1GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 16.1GB 16.1GB primary ext3
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 16.1GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Number Start End Size File system Flags
1 0.00kB 16.1GB 16.1GB ext3
Error: Unable to open /dev/sdd - unrecognised disk label.
Error: Unable to open /dev/sde - unrecognised disk label.
Error: Unable to open /dev/md0 - unrecognised disk label.
2.2 透過parted工具來建立大於2T的分割槽
[root@jetsen ~]# parted /dev/sde
GNU Parted 1.8.1 ---Parted的軟體版本號
Using /dev/sde ---將執行下面操作盤
Welcome to GNU Parted! Type 'help' to view a list of commands. –歡迎資訊
(parted) mklabel ----建立建立磁碟標籤
New disk label type? gpt
(parted) p ----檢視分割槽狀態
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sde: 2190GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
(parted) mkpart
Partition name? []? gpt2t ---指定分割槽名稱
File system type? [ext2]ext3 ----指定分割槽型別
Start? 1 ---指定開始位置
End? 2190GB ---指定結束位置
(parted) P ----顯示分割槽資訊
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sde: 2190GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 2190GB 2190GB gpt2t
(parted) Q ---退出
Information: Don't forget to update /etc/fstab, if necessary. -----提示不要忘記更新/etc/fstab檔案
2.3 透過parted 工具來實現單磁碟多分割槽
[root@jetsen ~]# parted /dev/sdd
GNU Parted 1.8.1
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p ---列出分割槽資訊
Error: Unable to open /dev/sdd - unrecognised disk label. ----由於沒有打上磁碟標籤,所以表現資訊無法列出
(parted) mklabel ----建立磁碟標籤
New disk label type? gpt ---輸入磁碟表情名
(parted) p ----再次列出磁碟分割槽
Model: VMware, VMware Virtual S (scsi) ---顯示磁碟型別為SCSI磁碟
Disk /dev/sdd: 1100GB ---磁碟大小為1100GB
Sector size (logical/physical): 512B/512B ---扇區大小為512B
Partition Table: gpt ----顯示標籤名為我剛才輸入的標籤名稱
Number Start End Size File system Name Flags ----現在是一新硬碟還沒有建立分割槽
(parted) mkpart ---建立分割槽
Partition name? []? part1 ---指定分割槽名稱
File system type? [ext2]? ext2 ---定義分割槽型別
Start? 1G ---指定起始位置
End? 10G ----指定終止位置
(parted) mkpart ---建立分割槽
Partition name? []? part2 ---指定分割槽名稱
File system type? [ext2]? ext2 ---定義分割槽型別
Start? 11G ---指定起始位置
End? 100G ---指定終止位置
(parted) mkpart
Partition name? []? part3
File system type? [ext2]?
Start? 101G ----指定分割槽其實位置
End? -1 ----指定到分割槽最後
(parted) p ----顯示分割槽資訊
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 1100GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags ---檢視到下面共有三個分割槽
1 17.4kB 10.0GB 10000MB part1
2 10.0GB 100GB 90.0GB part2
3 100GB 1100GB 1000GB part3
(parted) rm 3 ------刪除分割槽3
(parted) p ------再次檢視分割槽狀態
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 1100GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags ----顯示分割槽刪除成功,只剩下兩個分割槽
1 17.4kB 10.0GB 10000MB part1
2 10.0GB 100GB 90.0GB part2
(parted) quit
Information: Don't forget to update /etc/fstab, if necessary.
[root@jetsen ~]# ls -l /dev/sdd*
brw-r----- 1 root disk 8, 48 May 10 16:48 /dev/sdd
brw-r----- 1 root disk 8, 49 May 10 16:48 /dev/sdd1
brw-r----- 1 root disk 8, 50 May 10 16:48 /dev/sdd2
[root@jetsen ~]#
2.3 透過parted 工具來刪除分割槽
[root@jetsen ~]# parted /dev/sde
GNU Parted 1.8.1
Using /dev/sde
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sde: 2190GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 2190GB 2190GB gpt2t
(parted) rm 1 ----刪除分1號分割槽
(parted) p ----顯示分割槽資訊,看如下是沒有分割槽的
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sde: 2190GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
(parted) q
Information: Don't forget to update /etc/fstab, if necessary.
[root@jetsen ~]#
2.4 透過parted 工具來建立檔案系統
[root@jetsen ~]# parted /dev/sdd -----選擇要格式化的磁碟
GNU Parted 1.8.1
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkfs 2 ext3 ----格式化的型別為ext3分割槽號為2-
Warning: The existing file system will be destroyed and all data on the partition will
be lost. Do you want to continue?
parted: invalid token: 2
Yes/No? yes ----再次確認是否格式化
Partition number? 2 -----再次輸入磁碟分割槽號
File system? [ext2]? ----格式化的型別
(parted)
檢視格式化是否成功:
(parted) p -----檢視檔案系統是否被格式化
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 1100GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.0GB 10000MB part1
2 10.0GB 100GB 90.0GB ext2 part2 -------可以看到檔案系統型別為ext2,可確定檔案系統已經被格式化了。
(parted)
掛載剛才格式化後的檔案系統
[root@jetsen ~]# cd / -----退到根目錄
[root@jetsen /]# mkdir part2 -----建立part目錄
[root@jetsen /]# mount /dev/sdd2 /part2 -----將/dev/sdd2 掛載到/part2
[root@jetsen /]# df –h -----檢視分割槽資訊
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
18G 5.8G 11G 35% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 506M 4.0K 506M 1% /dev/shm
/dev/sdd2 83G 52K 79G 1% /part2 ------可以看到已經被掛載上來
[root@jetsen /]# cd /part2
[root@jetsen part2]# mkdir 1111 ------並且可以訪問
[root@jetsen part2]# ls
1111 lost+found
[root@jetsen part2]#
刪除和恢復分割槽
[root@jetsen /]# umount /dev/sdd2 ----解除安裝分割槽
[root@jetsen /]# parted /dev/sdd ---透過parted選擇/dev/sdd磁碟進入操作
GNU Parted 1.8.1
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) rm 2 ------刪除磁碟分割槽
(parted) rescue -------對磁碟分割槽進行恢復
Start? 10G
End? 100G
Information: A ext2 primary partition was found at 10.0GB -> 100GB. Do you want to add
it to the partition table?
Yes/No/Cancel? Yes ----告訴
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 1100GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.0GB 10000MB part1
2 10.0GB 100GB 90.0GB ext2
(parted)
[root@jetsen /]# cd /part2 ----神奇吧,資料也被恢復回來了
[root@jetsen part2]# ls
1111 lost+found
2.6 透過parted工具來驗證和維護檔案系統及分割槽。
驗證檔案系統的完整性:
(parted) check 1
Error: File system was not cleanly unmounted! You should run e2fsck. Modifying an
unclean file system could cause severe corruption.
Ignore/Cancel? ignore
Information: The ext2 file system passed a basic check. For a more comprehensive check,
use the e2fsck program.
(parted)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20674423/viewspace-723212/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux分割槽之parted命令Linux
- Linux下分割槽詳解之--FdiskLinux
- linux下面的一個分割槽工具--partedLinux
- linux 磁碟 2T以上的分割槽partedLinux
- 分割槽管理工具 fdisk parted
- Linux下新增硬碟,分割槽,格式化詳解Linux硬碟
- redhat 6.5 parted磁碟分割槽工具初識Redhat
- linux磁碟分割槽fdisk命令詳解Linux
- 使用parted,e2label操作磁碟分割槽
- oracle 分割槽表詳解Oracle
- MySQL分割槽(Partition)詳解MySql
- oracle表分割槽詳解Oracle
- oracle分割槽表詳解Oracle
- Oracle 表分割槽詳解Oracle
- 新增儲存用Parted分割槽並建LVM卷LVM
- linux下增加swap分割槽Linux
- Hive動態分割槽詳解Hive
- SQL Server表分割槽詳解SQLServer
- oracle索引詳解 分割槽索引Oracle索引
- 硬碟分割槽表詳解(轉)硬碟
- 磁碟分割槽以及Linux目錄掛載詳解Linux
- linux之硬碟分割槽管理Linux硬碟
- parted和fdisk——兩種磁碟分割槽並掛載的方法
- linux磁碟分割槽講解Linux
- Linux下磁碟分割槽,fdisk,mkfsLinux
- (轉) linux下增加swap分割槽Linux
- linux下磁碟分割槽的案例Linux
- SQL Server表分割槽操作詳解SQLServer
- Linux核心之磁碟和分割槽Linux
- 『學了就忘』Linux檔案系統管理 — 61、使用parted命令進行分割槽Linux
- 使用parted建立大分割槽時 mkpart Warning: The resulting partition is not properly
- Linux分割槽方案、分割槽建議Linux
- Linux主分割槽,擴充套件分割槽,邏輯分割槽Linux套件
- linux下分割槽相關知識Linux
- 【INDEX】Oracle分割槽索引技術詳解IndexOracle索引
- Oracle表分割槽詳解(優缺點)Oracle
- MySQL 分割槽表原理及使用詳解MySql
- 詳細解析kafka之kafka分割槽和副本Kafka