parted 磁盤分區命令


https://www.cnblogs.com/onlybobby/p/7018788.html

parted命令 和 fdisk命令的區別:

  fdisk命令是針對MBR分區進行操作,MBR分區因為自身設計原因,不能處理大於2TB的硬盤,並且只能有4個分區。

  那么針對大於2TB的硬盤,需要采用GPT分區,使用parted命令進行操作

parted命令使用

print  [free|all | NUMBER]  查看分區狀態信息
mkpart PART-TYPE START END

 創建新分區,

PART-TYPE: primary  extended   logical 

START, END  開始,結束為止

set NUMBER  FLAG  STATE

 對編號為NUMBER的進行標記。

FLAG: boot  引導, hidden 隱藏, raid  軟raid, lvm  邏輯卷, 

STATE:  on| off

mkfs NUMBER FS-TYPE  對NUMBER指定文件系統。FS-Type有:ext2、fat16、fat32、linuxswap、NTFS、reiserfs、ufs 等
 cp  [FROM-DEV] FROM-NUMBER  TO-NUMBER  將分區 FROM-NUMBER 上的文件系統完整地復制到分區TO-NUMBER 中,作為可選項還可以指定一個來源硬盤的設備名稱FROM-DEVICE,若省略則在當前設備上進行復制。
 move NUMBER START END

 將指定編號 NUMBER 的分區移動到從 START 開始 END 結束的位置上。注意:(1)只能將分區移動到空閑空間中。(2)雖然分區被移動了,但它的分區編號是不會改變的

resize NUMBER START END  

對指定編號 NUMBER 的分區調整大小。分區的開始位置和結束位置由 START 和 END 決定

check NUMBER

檢查指定編號 NUMBER 分區中的文件系統是否有什么錯誤

rescue START END  rescue START END 
mklabel,mktable LABELTYPE 創建一個新的 LABEL-TYPE 類型的空磁盤分區表,對於PC而言 msdos 是常用的 LABELTYPE。 若是用 GUID 分區表,LABEL-TYPE 應該為 gpt

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

實例: 

復制代碼
1. 對/dev/sdb分區進行操作
[root@localhost ~]# parted /dev/sdb GNU Parted 3.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands.

2. 制定磁盤格式為gpt (parted) mklabel New disk label type? gpt

3. 查看磁盤分區信息 (parted) print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 1074MB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags
4. 制作分區 (parted) mkpart Partition name? []? d1 File system type? [ext2]? ext4 Start? 0 End? 512M Warning: The resulting partition is not properly aligned for best performance. #注意這個警告。采用這種方式分區只是測試,后邊又把相關分區刪除了。 Ignore/Cancel? i

5. 查看新增分區后的狀態 (parted) prin Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 1074MB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 512MB 512MB d1
6. 刪除分區1(Number號) (parted) rm 1
7. 新增分區 primary 分區,起始2048sector ,結束磁盤大小的50% (parted) mkpart primary 2048s 50% (parted) print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 1074MB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 537MB 536MB primary
8. 新增另一個分區,primary分區,起始磁盤的50%,結束100%大小。 (parted) mkpart primary 50% 100%
(parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 1074MB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 537MB 536MB primary 2 537MB 1073MB 536MB primary
9. 退出parted (parted) q Information: You may need to update /etc/fstab.
10. fdisk查看磁盤狀態。能夠發現新增磁盤分區狀態。 [root@localhost ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos Disk identifier: 0x000c0b7f Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 41943039 20458496 8e Linux LVM Disk /dev/mapper/rhel-root: 18.8 GB, 18798870528 bytes, 36716544 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 /dev/mapper/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 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 WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: gpt # Start End Size Type Name 1 2048 1048575 511M Microsoft basic primary 2 1048576 2095103 511M Microsoft basic primary 11. 新增完成后,建議重新格式化分區。 [root@localhost ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 523264 blocks 26163 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=34078720 64 block groups 8192 blocks per group, 8192 fragments per group 2048 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done [root@localhost ~]# mkfs.ext4 /dev/sdb2 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 523264 blocks 26163 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=34078720 64 block groups 8192 blocks per group, 8192 fragments per group 2048 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done


12. 修改/etc/fstab實現自動掛載

建議使用UUID進行掛在
blkid /dev/sdb1 (或者blkid)
/dev/sdb1: UUID="bc95b330-5eb9-4b68-9f9f-71c52247a1b4" TYPE="ext4"

修改/etc/fstab
UUID=bc95b330-5eb9-4b68-9f9f-71c52247a1b4 /opt                   ext4    defaults        0 0


免責聲明!

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



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