parted 分区管理

Posted on Posted in linux

parted 分区

  • GPT格式:parted 可以创建一个全局唯一的标识符分区表GPT,而FDIST和CFDISK仅限于DOS分区表。
  • 较大的磁盘:一个DOS分区表可以格式化为2TB的磁盘空间,尽管在某些情况下可能达到16TB。但是,GPT分区表最多可以容纳8ZB空间。
  • 更多分区:使用主分区和扩展分区,DOS分区表只允许16个分区。使用GPT,默认情况下最多可以达到128个分区,并且可以选择多个分区。
  • 可靠性:在DOS分区中只存储分区表的一个副本。GPT保存分区表的两个副本(在磁盘的开始和结束)。GPT还使用CRC校验和来检查分区表的完整性,这不是用DOS分区完成的。

parted 查看所有硬盘

root@ubuntu:~# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  512MB   511MB   primary   ext2         boot
 2      513MB   21.5GB  21.0GB  extended
 5      513MB   21.5GB  21.0GB  logical                lvm


Error: /dev/sdb: unrecognised disk label
Model: VMware, VMware Virtual S (scsi)                                    
Disk /dev/sdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 

创建分区

root@ubuntu:~# parted /dev/sdb 
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt  # 或 msdos                                                    
(parted) unit GB # 单位                                                         
(parted) mkpart                                                           
Partition name?  []? primary                                              
File system type?  [ext2]? ext4                                                                                                            
Start? 0.00GB                                                             
End? 5.00GB                                                             
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 5.37GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      0.00GB  5.37GB  5.37GB  ext4         primary

(parted) quit                                                             
Information: You may need to update /etc/fstab.

一条命令创建分区

parted /dev/sdb mklabel gpt
parted /dev/sdb mkpart primary unit GB ext4 5.0GB 10.0GB
parted /dev/sdb mkpart primary ext4 10.0GB 100% # 从10G,到100%最后

查看分区

root@ubuntu:~# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  5368MB  5367MB               primary

查看磁盘剩余空间

root@ubuntu:~# parted /dev/sdb print free
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
        17.4kB  1049kB  1031kB  Free Space
 1      1049kB  5368MB  5367MB               primary
        5368MB  5369MB  1032kB  Free Space

格式化分区

root@ubuntu:~# mkfs.ext4 /dev/sdb1 
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 1310208 4k blocks and 327680 inodes
Filesystem UUID: 183bcfdb-2b0a-4868-952c-e9599e32cdcd
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

调整分区大小

root@ubuntu:~# parted /dev/sdb print free
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
        17.4kB  1049kB  1031kB  Free Space
 1      1049kB  5368MB  5367MB  ext4         primary
        5368MB  5369MB  1032kB  Free Space

parted /dev/sdb resizepart 1 10.0GB # 1是分区号,10G是最后的位置
resize2fs /dev/sdb1 # 重新调整文件系统大小

删除分区

parted /dev/sdb rm 1
» 转载请注明来源:若我若鱼 » parted 分区管理

Leave a Reply

Your email address will not be published. Required fields are marked *

three × three =