用 fdisk -c=dos 来从63开始分区,而不是2048开始

现象:一个阿里云的数据盘需要从原40GB扩容到60GB,系统是CentOS7。照阿里云文档中的例子操作,创建新分区后,e2fsck检查文件系统错误,Bad magic number in super-block,磁盘扩容失败。

尝试:对比阿里云文档中的例子,原分区的起始位置是63,不是例子中的2048。但默认fdisk的分区是4k对齐的,并不能从63开始,至少是2048。搜索结果中,有人说用参数 -c=dos 来运行fdisk,就可以从63开始分区,保留原分区的数据进行扩容了。

# fdisk -u /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/vdb: 64.4 GB, 64424509440 bytes, 125829120 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: 0x4ca57d7e

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1              63    83885759    41942848+  83  Linux

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-125829119, default 2048): 63
Value out of range.
First sector (2048-125829119, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-125829119, default 125829119):
Using default value 125829119
Partition 1 of type Linux and of size 60 GiB is set

# e2fsck -n /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/vdb1

The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>

fdisk -c=dos /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (with command 'c').Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/vdb: 64.4 GB, 64424509440 bytes, 125829120 sectors
16 heads, 63 sectors/track, 124830 cylinders
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: 0x4ca57d7e

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1              63    83885759    41942848+  83  Linux

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (63-125829119, default 63):
Using default value 63
Last sector, +sectors or +size{K,M,G} (63-125829119, default 125829119):
Using default value 125829119
Partition 1 of type Linux and of size 60 GiB is set

Command (m for help): wq
The partition table has been altered!

参考:

标签: 扩容

添加新评论