resize2fs: Bad magic number in super-block while trying to open

458,976

Solution 1

After a bit of trial and error... as mentioned in the possible answers, it turned out to require xfs_growfs rather than resize2fs.

CentOS 7,

fdisk /dev/xvda

Create new primary partition, set type as linux lvm.

n
p
3
t
8e
w

Create a new primary volume and extend the volume group to the new volume.

partprobe
pvcreate /dev/xvda3
vgextend /dev/centos /dev/xvda3

Check the physical volume for free space, extend the logical volume with the free space.

vgdisplay -v
lvextend -l+288 /dev/centos/root

Finally perform an online resize to resize the logical volume, then check the available space.

xfs_growfs /dev/centos/root
df -h

Solution 2

In Centos 7 default filesystem is xfs.

xfs file system support only extend not reduce. So if you want to resize the filesystem use xfs_growfs rather than resize2fs.

xfs_growfs /dev/root_vg/root 

Note: For ext4 filesystem use

resize2fs /dev/root_vg/root

Solution 3

I ran into the same exact problem around noon today and finally found a solution here --> Trying to resize2fs EB volume fails

I skipped mounting, since the partition was already mounted.

Apparently CentOS 7 uses XFS as the default file system and as a result resize2fs will fail.

I took a look in /etc/fstab, and guess what, XFS was staring me in the face... Hope this helps.

Solution 4

resize2fs Command will not work for all file systems.

Please confirm the file system of your instance using below command. enter image description here

Please follow the procedure to expand volume by following the steps mentioned in Amazon official document for different file systems.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html

Default file system in Centos is xfs, use the following command for xfs file system to increase partition size.

sudo xfs_growfs -d /

then "df -h" to check.

Solution 5

On centos and fedora work with fsadm

fsadm resize /dev/vg_name/root
Share:
458,976

Related videos on Youtube

ChrisKnowles
Author by

ChrisKnowles

Updated on October 21, 2021

Comments

  • ChrisKnowles
    ChrisKnowles 11 months

    I am trying to resize a logical volume on CentOS7 but am running into the following error:

    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.
    

    I have tried adding a new partition (using fdisk) and using vgextend to extend the volume group, then resizing. Resize worked fine for the logical volume using lvextend, but it failed at resize2fs.

    I have also tried deleting an existing partition (using fdisk) and recreating it with a larger end block, then resizing the physical volume using lvm pvresize, followed by a resize of the logical volume using lvm lvresize. Again everything worked fine up to this point.

    Once I tried to use resize2fs, using both methods as above, I received the exact same error.

    Hopefully some of the following will shed some light.

    fdisk -l

    [roo[email protected]~]# 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

    [[email protected] ~]# 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

    [[email protected] ~]# 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

    [[email protected] ~]# 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
    

    I've probably done something stupid, so any help would be greatly appreciated!

  • technocrat
    technocrat almost 7 years
    I ran lvextend --resize which resizes for you in centos 7. This seemed to fix the issue.
  • Richard Corfield
    Richard Corfield over 6 years
    Works for RHEL 7 too. Thanks!
  • GoingMyWay
    GoingMyWay over 6 years
    How to shrink one partition and add the shrinked space to another partition? xfs_growfs seem doesn't work for this.
  • Fatih
    Fatih almost 6 years
    man page of lvextend says it uses fsadm to resize filesystem. So i tried fsadm resize /dev/centos/root and it worked.
  • PJ Brunet
    PJ Brunet almost 6 years
    Technically, this is not really an answer, and the information on that URL did not work for me. Best to answer the question here, where we can discuss it, and add links to supporting documentation if you think that's helpful.
  • Shuliyey
    Shuliyey over 5 years
    you are a legend, ty so much for this guide, didn't realise ubuntu/centos uses different resize method
  • Lihai
    Lihai about 5 years
    Here you can find more information: tecmint.com/extend-and-reduce-lvms-in-linux
  • edib
    edib about 5 years
    I realize that we don't need to use pvcreate explicitely before vgextend command. When using vgextend, it creates pv automatically.
  • ALi Nezamifar
    ALi Nezamifar almost 5 years
    this is work on centos 7 when installed directadmin .
  • mirzmaster
    mirzmaster about 4 years
    It should be mentioned that the filesystem is displayed in /etc/fstab. That's how it's determined to use xfs_growfs rather than resize2fs.
  • harperville
    harperville over 3 years
    One can find their filesystem type using mount | column -t (among many other ways).
  • karatedog
    karatedog almost 3 years
    xfs_growfs is for XFS filesystem. If someone were to install the CentOS with another filesystem (ext4), xfs_growfs will fail. Use fsadm which handles xfs, ext4 and a few filesystem.
  • Alexandre Germain
    Alexandre Germain almost 3 years
    Worked for me too on CentOS VM with LVM partitions resized.
  • Alois Mahdal
    Alois Mahdal over 2 years
    You need to spevify mount point, not block device. xfs_growfs version 5.1.0, Fedora 31, Usage: xfs_growfs [options] mountpoint
  • foddex
    foddex over 2 years
    This answer is mostly correct, but xfs_growfs expects a MOUNT POINT, not a DEVICE! So "xfs_growfs /dev/centos/root" is not correct, it'd be "xfs_growfs /wherever/you/mounted/it" This took me a while to figure out: linux.die.net/man/8/xfs_growfs At least on Fedora 31 specifying DEVICE did not work for me.
  • mascIT
    mascIT 10 months
    Worked on my ec2 instance, in my case I wanted to align the main volume to the new increased size. After using sudo growpart /dev/xvda 1, just issue sudo xfs_growfs /dev/xvda1. Now df -h will reflect the size of your volume, without need to refresh. Of course change your mount path accordingly
  • Mauricio Reyes
    Mauricio Reyes 9 months
    Your comment saved my servers!
  • Leśny Rumcajs
    Leśny Rumcajs 9 months
    Fedora Server 35 on Raspberry Pi, working as a charm. No other solution worked, thanks for the detailed steps!
  • enni707
    enni707 6 months
    works for Centos8 as well. thanks