美文网首页linux运维
parted:磁盘分区工作

parted:磁盘分区工作

作者: August________ | 来源:发表于2019-11-01 00:09 被阅读0次

parted:磁盘分区工作

命令详解

  • 大于2TB的磁盘只能用parted分区,且需要将磁盘转化为GPT格式

语法格式

parted  [option]  [device]
选项参数 解释说明
-l 显示所有磁盘分区的信息
-h 查看帮助

例子

#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  525MB   524MB   primary  xfs          boot
 2      525MB   21.5GB  20.9GB  primary               lvm


Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size    Type      File system  Flags
 1      1049kB  106MB  105MB   primary   ext4
 2      106MB   316MB  210MB   primary
 3      316MB   630MB  315MB   primary
 4      630MB   735MB  105MB   extended
 5      631MB   684MB  52.4MB  logical
 6      685MB   735MB  50.3MB  logical


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system     Flags
 1      0.00B  2147MB  2147MB  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 18.8GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  18.8GB  18.8GB  xfs


Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0
has been opened read-only.
Model: NECVMWar VMware IDE CDR10 (scsi)                                   
Disk /dev/sr0: 4330MB
Sector size (logical/physical): 2048B/2048B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 2      4563kB  30.2MB  25.7MB  primary

#parted /dev/sdb
GNU Parted 3.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: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End  Size  Type  File system  Flags

(parted) mklabel apt
parted: invalid token: apt
New disk label type?                                                      
New disk label type? ^C                                                   
Error: Expecting a disk label type.
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End  Size  Type  File system  Flags

(parted) mkpart                                                           
Partition type?  primary/extended? primary
File system type?  [ext2]? ext4                                           
Start?                                                                    
Start? 0                                                                  
End? 500                                                                  
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel?                                                            
Ignore/Cancel? Igonre                                                     
parted: invalid token: Igonre
Ignore/Cancel?                                                            
Ignore/Cancel? Ignore                                                     
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 1      512B   500MB  500MB  primary

(parted) mkpart primary 500 1000
(parted) mkpart                                                           
Partition type?  primary/extended? primary                                
File system type?  [ext2]? ext3                                           
Start? 500                                                                
End? 1000                                                                 
Warning: You requested a partition from 500MB to 1000MB (sectors 976562..1953125).
The closest location we can manage is 500MB to 500MB (sectors 976563..976895).
Is this still acceptable to you?
Yes/No? yes                                                               
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore                                                     
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End     Size   Type     File system  Flags
 1      512B   500MB   500MB  primary
 3      500MB  500MB   170kB  primary
 2      500MB  1000MB  500MB  primary

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

  • 非交互式
[root@lhf 20:04:19 /root]
#parted /dev/sdb mklabel apt Yes
parted: invalid token: apt
New disk label type? apt                                                  
parted: invalid token: apt
New disk label type? p                                                    
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost.
Do you want to continue?
Yes/No? yes                                                               
Information: You may need to update /etc/fstab.

                                                                          
[root@lhf 20:04:40 /root]
#parted /dev/sdb mkpart primary 0 500
Warning: You requested a partition from 0.00B to 500MB (sectors 0..976562).
The closest location we can manage is 8225kB to 502MB (sectors 16065..979964).
Is this still acceptable to you?
Yes/No? yes                                                               
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore                                                     
Information: You may need to update /etc/fstab.

[root@lhf 20:06:05 /root]
#parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: pc98
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 1      8225kB  502MB  494MB               primary

mkfs:创建Liunx文件系统

:alarm_clock:

命令说明

  • 用于在指定设备上创建格式化并创建文件系统。

语法格式

mkfs [option]  [filesys]

选项说明

选项说明 解释说明
-t 指定创建文件的系统类型
-c 创建文件系统时检测磁盘坏块
-v 显示详细信息
  • 查看不同文件系统命令
[root@lhf 20:06:41 /root]
#ls /sbin/mkfs.*
/sbin/mkfs.btrfs   /sbin/mkfs.ext2  /sbin/mkfs.ext4   /sbin/mkfs.xfs
/sbin/mkfs.cramfs  /sbin/mkfs.ext3  /sbin/mkfs.minix

例子

[root@lhf 20:19:38 /root]
#mkfs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
60800 inodes, 242983 blocks
12149 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=249561088
8 block groups
32768 blocks per group, 32768 fragments per group
7600 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376

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

dumpe2fs:导出ext2/ext3/ext4文件系统信息

命令详情

  • 导出ext2/ext3/ext4文件系统内容的相关信息。例如:文件系统的组成包括超级块、块组、inode、block等信息。

语法格式

dumpe2fs  [option] [device]

选项说明

选择参数 解释说明
-b 打印文件预留的块信息
-h 仅提供超级块信息
-i 从指定的文件系统映射文件读取文件的系统信息
-x 已16进制格式打印信息块成员

例子

  • 查看/dev/sdb1的inode信息
[root@lhf 21:06:31 /root]
#dumpe2fs /dev/sdb1 | egrep -i "inode size|inode count"
dumpe2fs 1.42.9 (28-Dec-2013)
Inode count:              60800
Inode size:           256

[root@lhf 21:06:48 /root]
#df -i
Filesystem                Inodes IUsed    IFree IUse% Mounted on
/dev/mapper/centos-root 18317312 28371 18288941    1% /
devtmpfs                  122555   393   122162    1% /dev
tmpfs                     125166     1   125165    1% /dev/shm
tmpfs                     125166   480   124686    1% /run
tmpfs                     125166    13   125153    1% /sys/fs/cgroup
/dev/sda1                 512000   330   511670    1% /boot
tmpfs                     125166     1   125165    1% /run/user/0
/dev/sdb1                  60800    11    60789    1% /mnt
  • 查看/dev/sdb2的block信息
#dumpe2fs /dev/sdb1 | egrep -i "block size|block count"
dumpe2fs 1.42.9 (28-Dec-2013)
Block count:              242983
Reserved block count:     12149
Block size:               4096

相关文章

网友评论

    本文标题:parted:磁盘分区工作

    本文链接:https://www.haomeiwen.com/subject/hmvxbctx.html