resize2fs:尝试打开时超级块中的魔数错误

223
我正在尝试在CentOS7上调整逻辑卷的大小,但遇到以下错误:
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

我尝试添加新的分区(使用fdisk)并使用vgextend扩展卷组,然后调整大小。 使用lvextend调整逻辑卷大小正常,但在resize2fs上失败。
我还尝试删除现有分区(使用fdisk)并创建一个具有较大结束块的新分区,然后使用lvm pvresize调整物理卷的大小,随后使用lvm lvresize调整逻辑卷的大小。同样,到这一步为止一切都正常。
一旦我尝试使用以上两种方法之一使用resize2fs,我收到了完全相同的错误消息。
希望以下某些内容能够阐明问题。
fdisk -l
[root@server~]# fdisk -l

Disk /dev/xvda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x0009323a

Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     1026047      512000   83  Linux
/dev/xvda2         1026048    41943039    20458496   8e  Linux LVM
/dev/xvda3        41943040    62914559    10485760   8e  Linux LVM

Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-root: 29.5 GB, 29532094464 bytes, 57679872 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

pvdisplay

[root@server ~]# pvdisplay
--- Physical volume ---
PV Name               /dev/xvda2
VG Name               centos
PV Size               19.51 GiB / not usable 2.00 MiB
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              4994
Free PE               0
Allocated PE          4994
PV UUID               7bJOPh-OUK0-dGAs-2yqL-CAsV-TZeL-HfYzCt

--- Physical volume ---
PV Name               /dev/xvda3
VG Name               centos
PV Size               10.00 GiB / not usable 4.00 MiB
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              2559
Free PE               0
Allocated PE          2559
PV UUID               p0IClg-5mrh-5WlL-eJ1v-t6Tm-flVJ-gsJOK6

vgdisplay

[root@server ~]# vgdisplay
--- Volume group ---
VG Name               centos
System ID
Format                lvm2
Metadata Areas        2
Metadata Sequence No  6
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                2
Act PV                2
VG Size               29.50 GiB
PE Size               4.00 MiB
Total PE              7553
Alloc PE / Size       7553 / 29.50 GiB
Free  PE / Size       0 / 0
VG UUID               FD7k1M-koJt-2veW-sizL-Srsq-Y6zt-GcCfz6

lvdisplay

[root@server ~]# lvdisplay
--- Logical volume ---
LV Path                /dev/centos/swap
LV Name                swap
VG Name                centos
LV UUID                KyokrR-NGsp-6jVA-P92S-QE3X-hvdp-WAeACd
LV Write Access        read/write
LV Creation host, time localhost, 2014-10-09 08:28:42 +0100
LV Status              available
# open                 2
LV Size                2.00 GiB
Current LE             512
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     8192
Block device           253:0

--- Logical volume ---
LV Path                /dev/centos/root
LV Name                root
VG Name                centos
LV UUID                ugCOcT-sTDK-M8EV-3InM-hjIg-2nwS-KeAOnq
LV Write Access        read/write
LV Creation host, time localhost, 2014-10-09 08:28:42 +0100
LV Status              available
# open                 1
LV Size                27.50 GiB
Current LE             7041
Segments               2
Allocation             inherit
Read ahead sectors     auto
- currently set to     8192
Block device           253:1

我可能做了一些愚蠢的事情,因此非常感谢您提供帮助!


获取备份超级块的位置: newfs -N /dev/device-name 通过FSCK恢复损坏的超级块: fsck -F ufs -o b=<Superblock_stored_location> /dev/device-name 来源:https://docs.oracle.com/cd/E19455-01/805-7228/6j6q7uf0i/index.html - Skanda Shastry
12个回答

442

经过一些尝试和错误...就像可能的答案中所提到的那样,结果需要使用xfs_growfs而不是resize2fs

CentOS 7,

fdisk /dev/xvda

创建新的主分区,将类型设置为linux lvm

n
p
3
t
8e
w

创建一个新的主卷并将卷组扩展到新卷。
partprobe
pvcreate /dev/xvda3
vgextend /dev/centos /dev/xvda3

检查物理卷的可用空间,使用可用空间扩展逻辑卷。
vgdisplay -v
lvextend -l+288 /dev/centos/root

最后执行在线调整大小以调整逻辑卷的大小,然后检查可用空间。
xfs_growfs /dev/centos/root
df -h

7
也适用于 RHEL 7。谢谢! - Richard Corfield
1
如何缩小一个分区并将其空间添加到另一个分区? xfs_growfs 似乎无法实现此功能。 - GoingMyWay
1
在这里您可以找到更多信息:https://www.tecmint.com/extend-and-reduce-lvms-in-linux/ - Lihai
3
xfs_growfs 适用于 XFS 文件系统。如果有人安装了带有另一种文件系统(ext4)的 CentOS,则 xfs_growfs 将失败。请使用 fsadm,它可以处理 xfs、ext4 和其他几种文件系统。 - karatedog
3
这个答案大部分正确,但是xfs_growfs希望输入挂载点而不是设备!所以"xfs_growfs /dev/centos/root"是不正确的,正确的应该是"xfs_growfs /你挂载它的地方"。我花了一些时间才找出来:https://linux.die.net/man/8/xfs_growfs至少在Fedora 31上,指定设备对我没有用。 - foddex
显示剩余5条评论

86

在Centos 7中,默认的文件系统是xfs

xfs文件系统仅支持扩展而不支持缩小。因此,如果您想调整文件系统大小,请使用xfs_growfs而不是resize2fs。

xfs_growfs /dev/root_vg/root 

注意:适用于ext4文件系统

resize2fs /dev/root_vg/root

2
人们可以使用“mount | column -t”(以及许多其他方法)来找到自己的文件系统类型。 - harperville
3
需要指定挂载点,而不是块设备。xfs_growfs 版本为 5.1.0,Fedora 31,用法为 Usage: xfs_growfs [options] mountpoint - Alois Mahdal

50

我的分区是使用parted->mkpart命令创建的。最后这个方法对我起作用了。 - Yan Zhao

49

今天中午我遇到了完全相同的问题,最后在这里找到了解决方案-->尝试调整resize2fs EB卷失败

由于分区已经挂载,所以我跳过了挂载步骤。

显然CentOS 7使用XFS作为默认文件系统,因此resize2fs将会失败。

我查看了/etc/fstab,猜猜看,XFS直接呼之欲出...希望这可以帮助到你。


2
我运行了"lvextend --resize"命令,它会在CentOS 7中为你重新调整大小。这似乎解决了问题。 - technocrat
25
lvextend的man页面表示它使用fsadm来调整文件系统大小。因此我尝试了fsadm resize /dev/centos/root,并且它成功了。 - Fatih
从技术上讲,这并不是一个真正的答案,那个网址上的信息对我也没有用。最好在这里回答问题,这样我们可以讨论它,并在必要时添加支持文档的链接。 - PJ Brunet

32

在CentOS和Fedora上可以使用fsadm。

fsadm resize /dev/vg_name/root

20

CentOS7 + VM

我已经完成以下操作:

  1. 使用Gparted-live扩展了卷
  2. pvresize -v /dev/sda2
  3. lvresize -r -l+100%FREE centos/root

19

在Centos 7上,针对原始问题的回答,在resize2fs失败并显示“bad magic number”时,请尝试使用以下方式中的fsadm:

fsadm resize /dev/the-device-name-returned-by-df

那么:

df 

...以确认尺寸更改已生效。


在我使用的CentOS虚拟机上,也成功地调整了LVM分区大小。 - Alexandre Germain

11

在了解逻辑卷管理(LVM)并熟悉PV->VG->LV后,以下步骤适用于我:

0) #df -h

Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  824K  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/fedora-root   15G  2.1G   13G  14% /
tmpfs                    1.9G     0  1.9G   0% /tmp
/dev/md126p1             976M  119M  790M  14% /boot
tmpfs                    388M     0  388M   0% /run/user/0

1)#vgs

  VG     #PV #LV #SN Attr   VSize   VFree   
  fedora   1   2   0 wz--n- 231.88g 212.96g

2) # vgdisplay

  --- Volume group ---
  VG Name               fedora
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               231.88 GiB
  PE Size               4.00 MiB
  Total PE              59361
  Alloc PE / Size       4844 / 18.92 GiB
  Free  PE / Size       54517 / 212.96 GiB
  VG UUID               9htamV-DveQ-Jiht-Yfth-OZp7-XUDC-tWh5Lv

3)# lvextend -l +100%FREE /dev/mapper/fedora-root

  Size of logical volume fedora/root changed from 15.00 GiB (3840 extents) to 227.96 GiB (58357 extents).
  Logical volume fedora/root successfully resized.

4) #lvdisplay

5) #fd -h

6) # xfs_growfs /dev/mapper/fedora-root

meta-data=/dev/mapper/fedora-root isize=512    agcount=4, agsize=983040 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=3932160, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3932160 to 59757568

7)#df -h

Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  828K  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/fedora-root  228G  2.3G  226G   2% /
tmpfs                    1.9G     0  1.9G   0% /tmp
/dev/md126p1             976M  119M  790M  14% /boot
tmpfs                    388M     0  388M   0% /run/user/0
最好的祝福。

Fedora Server 35 在树莓派上运行得非常好。没有其他解决方案奏效,感谢提供详细步骤! - Leśny Rumcajs
同样适用于Centos8。谢谢。 - enni707

10

操作系统: RHEL7

在实时系统中使用 gparted 后,使用 # xfs_growfs /dev/mapper/rhel-root 即可扩展文件系统。

$ df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   47G   47G   20M 100% /
devtmpfs               1.9G     0  1.9G   0% /dev
tmpfs                  1.9G     0  1.9G   0% /dev/shm
tmpfs                  1.9G  9.3M  1.9G   1% /run
tmpfs                  1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1             1014M  205M  810M  21% /boot
tmpfs                  379M  8.0K  379M   1% /run/user/42
tmpfs                  379M     0  379M   0% /run/user/1000


# lvresize -l +100%FREE /dev/mapper/rhel-root
  Size of logical volume rhel/root changed from <47.00 GiB (12031 extents) to <77.00 GiB (19711 extents).
  Logical volume rhel/root successfully resized.


# xfs_growfs /dev/mapper/rhel-root
meta-data=/dev/mapper/rhel-root  isize=512    agcount=7, agsize=1900032 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=12319744, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3711, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 12319744 to 20184064


# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   77G   47G   31G  62% /
devtmpfs               1.9G     0  1.9G   0% /dev
tmpfs                  1.9G     0  1.9G   0% /dev/shm
tmpfs                  1.9G  9.3M  1.9G   1% /run
tmpfs                  1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1             1014M  205M  810M  21% /boot
tmpfs                  379M  8.0K  379M   1% /run/user/42
tmpfs                  379M     0  379M   0% /run/user/1000

7
How to resize root partition online :  

1)  [root@oel7 ~]# df -h  
Filesystem                         Size  Used Avail Use% Mounted on  
/dev/mapper/root_vg-root           5.0G  4.5G  548M  90% /

2)   

PV /dev/sda2   VG root_vg     lvm2 [6.00 GiB / 0    free]

as here it shows that there is no space left on root_vg volume group, so first i need to extend VG 

3)  
[root@oel7 ~]# vgextend root_vg /dev/sdb5  

  Volume group "root_vg" successfully extended

4)  

[root@oel7 ~]# pvscan  
    PV /dev/sda2   VG root_vg     lvm2 [6.00 GiB / 0    free]  
    PV /dev/sdb5   VG root_vg     lvm2 [2.00 GiB / 2.00 GiB free]

5)  Now extend the logical volume   

[root@oel7 ~]# lvextend -L +1G /dev/root_vg/root  

  Size of logical volume root_vg/root changed from 5.00 GiB (1280 extents) to 6.00 GiB (1536 extents).
  Logical volume root successfully resized  

3)  [root@oel7 ~]# resize2fs /dev/root_vg/root  

resize2fs 1.42.9 (28-Dec-2013)  
resize2fs: Bad magic number in super-block while trying to open /dev/root_vg  /root  
Couldn't find valid filesystem superblock.  

as root partition is not a ext* partiton so , you resize2fs will not work for you.  

4)  to check the filesystem type of a partition 
[root@oel7 ~]# df -Th  
Filesystem                        Type      Size  Used Avail Use% Mounted on  
/dev/mapper/root_vg-root          xfs       6.0G  4.5G  1.6G  75% /  
devtmpfs                          devtmpfs  481M     0  481M   0% /dev  
tmpfs                             tmpfs     491M   80K  491M   1% /dev/shm  
tmpfs                             tmpfs     491M  7.1M  484M   2% /run  
tmpfs                             tmpfs     491M     0  491M   0% /sys/fs  /cgroup
/dev/mapper/data_vg-home          xfs       3.5G  2.9G  620M  83% /home  
/dev/sda1                         xfs       497M  132M  365M  27% /boot  
/dev/mapper/data_vg01-data_lv001  ext3      4.0G  2.4G  1.5G  62% /sybase  
/dev/mapper/data_vg02-backup_lv01 ext3      4.0G  806M  3.0G  22% /backup  

above command shows that root is an xfs filesystem , so we are sure that we need to use xfs_growfs command to resize the partition.

6)  [root@oel7 ~]# xfs_growfs /dev/root_vg/root  
meta-data=/dev/mapper/root_vg-root isize=256    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1310720 to 1572864  

[root@oel7 ~]# df -Th  

Filesystem                        Type      Size  Used Avail Use% Mounted on
/dev/mapper/root_vg-root          xfs       6.0G  4.5G  1.6G  75% /  

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接