Linux

Linux Red Hat Resize VM resize2fs - 找不到有效的文件系統超級塊

  • May 6, 2014

我正在嘗試將 Linux Red Hat 虛擬機的大小增加 10Gig。這只是在我試圖弄清楚的我創建的測試伺服器上。

我使用此命令將 VM 增加了 10 gig

$$ 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

感謝瘋狂帽匠的資訊。這是我執行的對我有用的確切步驟,以防有人在尋找這個

   [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.

如果沒有記錯的話,您需要執行許多步驟。

首先,您需要使用pvresize將現有 PV 擴展到新的分區頂部。

然後您需要使用lvresizelvextend將現有的 LV 卷調整為放大的 PV。

然後您可以使用resize2fs將文件系統的大小調整為新的放大卷。

引用自:https://serverfault.com/questions/592696