如何调整/放大/增长非 LVM ext4 分区

Mis*_*cha 21 partitioning lvm kvm fdisk

我已经搜索了论坛,但找不到合适的答案:

我有一个 Ubuntu Server 10.04 作为 KVM 主机和一个来宾系统,它也运行 10.04。主机系统使用 LVM 并且有三个逻辑卷,它们作为虚拟块设备提供给来宾 - 一个用于 /,一个用于 /home,一个用于交换。来宾已在没有 LVM 的情况下进行分区。

我已经扩大了主机系统中的逻辑卷 - 来宾成功地看到了更大的虚拟磁盘。然而,这个虚拟磁盘包含一个“好旧”分区,它仍然具有旧的小尺寸。

fdisk -l 的输出是

me@produktion:/$ LC_ALL=en_US sudo fdisk -l

Disk /dev/vda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8ce7

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           1        3917    31455232   83  Linux

Disk /dev/vdb: 2147 MB, 2147483648 bytes
244 heads, 47 sectors/track, 365 cylinders
Units = cylinders of 11468 * 512 = 5871616 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f2bf7

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1         366     2095104   82  Linux swap / Solaris
Partition 1 has different physical/logical beginnings (non-Linux?):
     phys=(0, 32, 33) logical=(0, 43, 28)
Partition 1 has different physical/logical endings:
     phys=(260, 243, 47) logical=(365, 136, 44)

Disk /dev/vdc: 225.5 GB, 225485783040 bytes
255 heads, 63 sectors/track, 27413 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00027f25

   Device Boot      Start         End      Blocks   Id  System
/dev/vdc1               1        9138    73398272   83  Linux
Run Code Online (Sandbox Code Playgroud)

parted print all 的输出是

Model: Virtio Block Device (virtblk)
Disk /dev/vda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  32.2GB  32.2GB  primary  ext4         boot


Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  2146MB  2145MB  primary  linux-swap(v1)


Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 225GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  75.2GB  75.2GB  primary  ext4
Run Code Online (Sandbox Code Playgroud)

我想要实现的是简单地增加或调整分区 /dev/vdc1 的大小,以便它使用虚拟块设备 /dev/vdc 提供的整个空间。问题是,当我尝试使用 parted 执行此操作时,它会抱怨:

(parted) select /dev/vdc                                                  
Using /dev/vdc
(parted) print                                                            
Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 225GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  75.2GB  75.2GB  primary  ext4

(parted) resize 1                                                         
WARNING: you are attempting to use parted to operate on (resize) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Start?  [1049kB]?                                                         
End?  [75.2GB]? 224GB                                                     
Error: File system has an incompatible feature enabled.  Compatible features are has_journal, dir_index, filetype, sparse_super and large_file.  Use tune2fs
or debugfs to remove features.
Run Code Online (Sandbox Code Playgroud)

那我能做什么?这是一个无头的生产系统。增加此分区的安全方法是什么?不过,我可以卸载它 - 所以这不是问题。

编辑:Cfdisk 显示一个小的可用空间未分区空间,然后是分区(标记为“引导”和 Linux/ext3),然后是其余的未分区空间。删除分区并使用 cfdisk 再次创建它后 - cfdisk 显示一个大分区区域(这对我来说没问题)并且文件系统类型仅为“Linux”

Resize2fs 返回此错误 resize2fs 1.41.11 (14-Mar-2010) resize2fs: Bad magic number in super-block while trying to open /dev/vdc1 Couldn't find valid filesystem superblock

Rob*_*ans 20

页面指​​示执行此操作的方法是卸载、删除、重新创建具有所需大小的分区,并使用 resize2fs 扩展分区。resize2fs 手册页同意。

我知道“删除分区”听起来很吓人,但它根本不会更改数据。它只是改变了引用容器的东西。只要你不,mkfs.ext4你应该没问题。

您的分区起点需要与原来相同,否则操作系统将不知道如何解释其背后的内容。然后可以进一步沿着端点形成更大的分区。

我认为评论中的错误与移动起点有关。您需要在与启动时完全相同的点启动它。终点可以四处移动。

感谢psusi为暗示的fdisk,而不是CFDISK并确认起点问题。

  • 您需要重新创建分区,以便它从与最初所做的完全相同的扇区开始。你不能用 cfdisk 做到这一点。使用 fdisk 或 parted 并将它们置于扇区模式。 (8认同)

小智 6

一个例子:

/dev/sdb2 是 /boot 分区。它是 100 MB,相当小。要在正在运行的系统上增加此 ext4 分区,请执行以下操作(以 root 或 sudo 身份):

卸载/启动

分开 /dev/sdb

(分开)打印

型号:ATA Patriot Torqx 2 (scsi)
磁盘 /dev/sdb:32.0GB
扇区大小(逻辑/物理):512B/512B
分区表:msdos

Number Start End Size Type File system Flags
1 1049kB 12.9GB 12.9GB primary type=83
2 12.9GB 13.0GB 107MB primary ext4 type=83

(分开) rm 2

(分开) mkpart

分区类型?主要/扩展?主要
文件系统类型?[ext2]?
开始?12.9GB
结束?13.4GB

(分开)退出

resize2fs /dev/sdb2

resize2fs 1.42.6 (21-Sep-2012)
/dev/sdb2 上的文件系统挂载在 /boot 上;需要在线调整大小
old_desc_blocks = 1, new_desc_blocks = 2
/dev/sdb2 上的文件系统现在有 498688 个块长。

完毕!

所有数据保持原样。/boot 已准备好使用并且 472MB 大(parted 的大小不是那么安全,请阅读手册以了解原因)

之前备份了所有数据,但仅作为预防措施。我建议这样做。

使用以下命令查找在 /boot 失败时停止卸载的进程:

lsof /启动

祝你好运!

  • 您需要使用扇区单位,而不是 GB,以确保您在完全相同的位置获得它。 (2认同)