跳转至

使用 parted 调整磁盘分区大小


2015-08-04 by dongnan

环境

CentOS 6.6 amd64

目标

  • 使用 parted 调整磁盘扩展分区大小。
  • 使用 parted 创建4k对齐的分区。

举个栗子

调整分区

查看磁盘信息,注意Free关键字,我们要把这些可用空间划分到扩展分区中。

(parted) print free # 输入命令
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
32.3kB  1049kB  1016kB            Free Space
1      1049kB  420MB   419MB   primary   ext4         boot
2      420MB   43.4GB  42.9GB  primary                lvm
3      43.4GB  75.2GB  31.8GB  extended
5      43.4GB  75.2GB  31.8GB  logical   ext4
75.2GB  107GB   32.2GB           Free Space

选择扩展分区

(parted) resize 3
WARNING: you are attempting to use parted to operate on (resize) a file system.
#...省略
will be removed in an upcoming release.
Start?  [43.4GB]?         #回车
End?  [75.2GB]? 107GB     #输入
Warning: WARNING: the kernel failed to re-read the partition table on /dev/xvda (Device or resource busy).  As a result, it may not reflect all
of your changes until after reboot.

查看调整后的分区信息

print
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
1      1049kB  420MB   419MB   primary   ext4         boot
2      420MB   43.4GB  42.9GB  primary                lvm
3      43.4GB  107GB   64.0GB  extended
5      43.4GB  75.2GB  31.8GB  logical   ext4

调整后的分区3(扩展分区)64.0GB,有可用的空间用于创建新分区。

创建新的逻辑分区

(parted) mkpart # 命令
Partition type?  primary/logical? logical   # 命令
File system type?  [ext2]? ext4 # 命令
Start? 75.2GB   # 命令
End? 107GB  # 命令
Warning: WARNING: the kernel failed to re-read the partition table on /dev/xvda (Device or resource busy).  As a result, it may not reflect all
of your changes until after reboot.

查看创建的分区

(parted) p
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
1      1049kB  420MB   419MB   primary   ext4         boot
2      420MB   43.4GB  42.9GB  primary                lvm
3      43.4GB  107GB   64.0GB  extended
5      43.4GB  75.2GB  31.8GB  logical   ext4
6      75.2GB  107GB   32.2GB  logical

分区6就是新创建的逻辑分区。

创建4k对齐的分区

parted /dev/xvdb
#...省略
(parted) mkpart primary ext4 1 100%

两条命令等效

(parted) mkpart primary ext4 2048s 100%

查看分区信息

fdisk -lu /dev/xvdb
#...省略
Device Boot      Start      End      Blocks   Id  System
/dev/xvdb1       2048       2147483647  1073740800   83  Linux

参考

parted 命令

回到页面顶部