Sunday, 5 April 2015

Reverting LVM changes

On test1 create a 2GB Logical volume resizeme in vgsrv volume group and create a ext4 file-system, then mount your file-system and create some test files.

[root@test1 ~]# vgs
  VG    #PV #LV #SN Attr   VSize  VFree
  vgsrv   1   1   0 wz--n- 20.00g 16.00g
[root@test1 ~]# lvcreate -n resizeme -L2G vgsrv
  Logical volume "resizeme" created


[root@test1 ~]# mkfs -t ext4 /dev/vgsrv/resizeme
[root@test1 ~]# mount /dev/vgsrv/resizeme /mnt
[root@test1 ~]# touch /mnt/file{0..9}
[root@test1 ~]# umount /mnt

You want to resize your filesystem to 1GB, but accidently you forget to resize the file system first[resize2fs].

[root@test1 ~]# lvresize -L1G /dev/vgsrv/resizeme
  WARNING: Reducing active logical volume to 1.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce resizeme? [y/n]: y
  Size of logical volume vgsrv/resizeme changed from 2.00 GiB (512 extents) to 1.00 GiB (256 extents).
  Logical volume resizeme successfully resized

[root@test1 ~]# mount /dev/vgsrv/resizeme /mnt
mount: wrong fs type, bad option, bad superblock on /dev/mapper/vgsrv-resizeme,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

Locate the archive files and find a file  it created just before that LVM shrink, then restore it.

[root@test1 ~]# vgcfgrestore -l vgsrv
  
  File:        /etc/lvm/archive/vgsrv_00000-582231926.vg
  VG name:        vgsrv
  Description:    Created *before* executing 'vgcreate vgsrv /dev/xvda3'
  Backup Time:    Wed Apr  1 12:18:57 2015

  
  File:        /etc/lvm/archive/vgsrv_00001-1338397565.vg
  VG name:        vgsrv
  Description:    Created *before* executing 'lvcreate -n storage -L 4G vgsrv'
  Backup Time:    Wed Apr  1 12:19:26 2015

  
  File:        /etc/lvm/archive/vgsrv_00002-1702898714.vg
  VG name:        vgsrv
  Description:    Created *before* executing 'lvcreate -n resizeme -L2G vgsrv'
  Backup Time:    Mon Apr  6 06:04:56 2015

  
  File:        /etc/lvm/archive/vgsrv_00003-2028074156.vg
  VG name:        vgsrv
  Description:    Created *before* executing 'lvresize -L1G /dev/vgsrv/resizeme'
  Backup Time:    Mon Apr  6 06:10:03 2015

Here we select file vg it created before executing lvresize,

[root@test1 ~]# vgcfgrestore -f /etc/lvm/archive/vgsrv_00003-2028074156.vg vgsrv
  Restored volume group vgsrv


[root@test1 ~]# mount /dev/vgsrv/resize  /mnt
[root@test1 ~]# ls -la /mnt
total 24
drwxr-xr-x  3 root root  4096 Apr  6 06:17 .
dr-xr-xr-x 23 root root  4096 Apr  1 12:16 ..
-rw-r--r--  1 root root     0 Apr  6 06:17 file0
-rw-r--r--  1 root root     0 Apr  6 06:17 file1
-rw-r--r--  1 root root     0 Apr  6 06:17 file2
-rw-r--r--  1 root root     0 Apr  6 06:17 file3
-rw-r--r--  1 root root     0 Apr  6 06:17 file4


No comments:

Post a Comment