Linux Red Hat 调整 VM resize2fs - 找不到有效的文件系统超级块

Linux Red Hat 调整 VM resize2fs - 找不到有效的文件系统超级块

我正在尝试将 Linux Red Hat 虚拟机的大小增加 10Gig。这只是在我创建的测试服务器上,我正在尝试弄清楚。

我使用此命令将虚拟机增加了 10G [root@rh01 images]# qemu-img resize TestServer.img +10G 图像已调整大小。

然后我点击了这个链接https://gist.github.com/larsks/3933980完成

我最后执行的命令是 resize2fs,但出现了这个错误

    [root@TestServer bmac]# resize2fs /dev/vda2
    resize2fs 1.41.12 (17-May-2010)
    resize2fs: Device or resource busy while trying to open /dev/vda2
    Couldn't find valid filesystem superblock.

以下是我采取的所有步骤:

    [root@rh01 admin]# virt-df -h /home/admin/images/TestServer.img 
    Filesystem                                Size       Used  Available  Use%
    TestServer.img:/dev/sda1                  484M        63M       396M   14%
    TestServer.img:/dev/vg_template/lv_root    40G       4.0G        34G   10%
    [root@rh01 admin]# virt-list-partitions -lh /home/admin/images/TestServer.img 
  /dev/sda1 ext4 500.0M
  /dev/sda2 pv 48.3G
    [root@rh01 admin]# cd images/
    [root@rh01 images]# qemu-img resize TestServer.img +10G
    Image resized.
    [root@rh01 images]# virt-df -h /home/admin/images/TestServer.img
    Filesystem                                Size       Used  Available  Use%
    TestServer.img:/dev/sda1                  484M        63M       396M   14%
TestServer.img:/dev/vg_template/lv_root    40G       4.0G        34G   10%
[root@rh01 images]# virt-list-partitions -lh /home/admin/images/TestServer.img 
/dev/sda1 ext4 500.0M
/dev/sda2 pv 48.3G

[root@rh01 images]# ls -l TestServer.img 
-rw-------. 1 root root 63166218240 May  1 08:55 TestServer.img

[root@rh01 images]# df
Filesystem                          1K-blocks       Used  Available Use% Mounted on
/dev/mapper/vg_rh01-lv_root 51606140    7845612   41139088      17% /
tmpfs                               99166276        296   99165980      1% /dev/shm
/dev/sda1                           495844      92445     377799        20% /boot
/dev/mapper/vg_rh01-lv_home 3305120248  494277716 2642952000  16% /home

[root@rh01 images]# df -B 4k
Filesystem            4K-blocks       Used Available Use% Mounted on
/dev/mapper/vg_rh01-lv_root
                       12901535    1961403  10284772  17% /
tmpfs                  24791569         74  24791495   1% /dev/shm
/dev/sda1                123961      23112     94450  20% /boot
/dev/mapper/vg_rh01-lv_home
                      826280062  123569429 660738000  16% /home

[root@rh01 images]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rh01-lv_root
                       50G  7.5G   40G  17% /
tmpfs                  95G  296K   95G   1% /dev/shm
/dev/sda1             485M   91M  369M  20% /boot
/dev/mapper/vg_rh01-lv_home
                      3.1T  472G  2.5T  16% /home



Boot VM and Login 
[bmac@TestServer ~]$ su
Password: 
[root@TestServer bmac]# cd
[root@TestServer ~]# fdisk /dev/vda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/vda: 63.2 GB, 63166218240 bytes
16 heads, 63 sectors/track, 122392 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cd4ad

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018      101588    50686976   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Command (m for help): d
Partition number (1-4): 2

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1-122392, default 1): 1018
Last cylinder, +cylinders or +size{K,M,G} (1018-122392, default 122392): 122392

Command (m for help): p

Disk /dev/vda: 63.2 GB, 63166218240 bytes
16 heads, 63 sectors/track, 122392 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cd4ad

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018      122392    61172544   83  Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[bmac@TestServer ~]$ su
Password: 
[root@TestServer bmac]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_template-lv_root
                       40G  4.0G   34G  11% /

[root@TestServer bmac]# resize2fs /dev/vda2
resize2fs 1.41.12 (17-May-2010)
resize2fs: Device or resource busy while trying to open /dev/vda2
Couldn't find valid filesystem superblock.
[root@TestServer bmac]# resize4fs /dev/vda2
bash: resize4fs: command not found

    [root@TestServer bmackenzie]# resize2fs /dev/mapper/vg_template-lv_root 
    resize2fs 1.41.12 (17-May-2010)
    The filesystem is already 10622976 blocks long.  Nothing to do!

[root@TestServer bmac]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_template-lv_root
                       40G  4.0G   34G  11% /
tmpfs                 3.9G   80K  3.9G   1% /dev/shm
/dev/vda1             485M   64M  397M  14% /boot

感谢 MadHatter 提供的信息。以下是我执行的具体步骤,如果有人正在寻找这个

    [root@TestServer bmac]# pvresize /dev/vda2
    Physical volume "/dev/vda2" changed
    1 physical volume(s) resized / 0 physical volume(s) not resized

    [root@TestServer bmac]# lvextend /dev/mapper/vg_template-lv_root -L +10G
    Extending logical volume lv_root to 50.52 GiB
    Logical volume lv_root successfully resized

    [root@TestServer bmackenzie]# resize2fs /dev/mapper/vg_template-lv_root
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/mapper/vg_template-lv_root is mounted on /; on-line resizing required
    old desc_blocks = 3, new_desc_blocks = 4
    Performing an on-line resize of /dev/mapper/vg_template-lv_root to 13244416 (4k) blocks.
    The filesystem on /dev/mapper/vg_template-lv_root is now 13244416 blocks long.

答案1

如果记忆不错的话,你需要执行许多步骤。

首先,您需要使用pvresize将现有 PV 扩展到新的分区顶部。

然后您需要使用lvresizelvextend将现有 LV 卷调整为扩大的 PV。

然后,您可以使用resize2fs它将文件系统调整到新的扩大的卷中。

相关内容