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

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

我有一个Ubuntu Server 10.04作为KVM主机和一个客户系统,也运行10.04。 主机系统使用LVM,有三个逻辑卷,作为虚拟块设备提供给guest虚拟机 – 一个用于/,一个用于/ home,一个用于交换。 guest虚拟机已在没有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 

分开打印的输出都是

 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 

我想要实现的是简单地增大或调整分区/ 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. 

那我该怎么办? 这是一个无头生产系统。 增长此分区的安全方法是什么? 我可以卸下它 – 所以这不是问题所在。

编辑:Cfdisk显示一个小的可用空间未分区空间,然后是分区(标记为“boot”和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

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

我知道’删除分区’听起来很可怕,但它根本不会改变数据。 它只是改变了引用容器的东西。 只要你不mkfs.ext4你应该没事。

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

我认为评论中的错误与移动起点有关。 你需要在它开始的同一点开始它。 终点可以四处移动。

感谢psusi建议使用fdisk而不是cfdisk并确认起点问题。

一个例子:

/ dev / sdb2是/ boot分区。 它是100 MB,相当小。 要在正在运行的系统上增加此ext4分区(以root或sudo为单位):

umount / boot

parted / dev / sdb

(分开)打印

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

编号开始结束大小类型文件系统标志
1 1049kB 12.9GB 12.9GB主要类型= 83
2 12.9GB 13.0GB 107MB主ext4类型= 83

(分开)rm 2

(分手)mkpart

分区类型? 初级/延长? 主
文件系统类型? [EXT2]?
开始? 12.9GB
结束? 13.4GB

(分开)退出

resize2fs / dev / sdb2

resize2fs 1.42.6(2012年9月21日)
/ dev / sdb2上的文件系统安装在/ boot; 需要在线resize
old_desc_blocks = 1,new_desc_blocks = 2
/ dev / sdb2上的文件系统现在是498688块长。

完成了!

所有数据仍然存在。 / boot已经可以使用,472MB大(分开的大小并不安全,请阅读手册以了解原因)

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

如果失败,请使用以下命令查找停止卸载/ boot的进程:

lsof / boot

祝好运!

如果您尝试删除并重新创建一个分区,当您的分区在2048年以下启动时,您可能会遇到一些问题,就像我使用resize2fs

 Couldn't find valid filesystem superblock. 

从fdisk版本2.17.2开始 ,fdisk IIUC强制您从2048开始,以确保您的硬盘“正确对齐”。 因此,如果您的原始分区在2048年之前启动,那么您将尝试重新创建分区。

克隆磁盘时最好的方法是rsync 。