Friday, April 25, 2014

fsadm, lvresize, resize2fs command usage Red Hat Linux

Hi Friends,

I never like reducing the File system in Redhat Linux or Linux. As it needs un-mounting of the file system. That most of the time is very tidy and asking downtime for it doesn't look good to me. Where increasing file system size can be done online.

Learned about a "FSADM" utility in HP UNIX 11i V3 that comes with Online JFS. which allows to reduce the file system size in Hp Unix online that is without un-mounting a file system. That removes the headache of downtime. Searching for the same kind in RedHat Linux found fsadm and learned about it, tried the same and thought to share with all.

Below are the steps including creation, extension and reduction of the size of an Logical Volume {LV named as Test in VG named as VolGroup}.

Creating an LV of 500 MB size naming as  test in VG VolGroup.



[root@localhost /]# lvcreate -L 500M -n test VolGroup
  WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
  Logical volume "test" created


for me lvmetd message was coming due to lvmetd daemon and cfdisk which worked for recovery of  external USB for me. It helped me in saving my data on USB. so for now please ignore above warning, It happened in my case only.

Command "lvs"showing the output of the available LV. it shows to which Volume Group an LV belongs and of what size.




[root@localhost /]# lvs
  WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
  LV      VG       Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_home VolGroup -wi-ao--- 100.10g                                             
  lv_root VolGroup -wi-ao---  50.00g                                            
  lv_swap VolGroup -wi-ao---   3.91g                                            
  test    VolGroup -wi-a---- 500.00m                                             
[root@localhost /]#
[root@localhost /]# mkf
mkfifo        mkfontscale   mkfs.cramfs   mkfs.ext3     mkfs.ext4dev  mkfs.msdos   
mkfontdir     mkfs          mkfs.ext2     mkfs.ext4     mkfs.gfs2     mkfs.vfat    
[root@localhost /]# mkfs.ext4
mkfs.ext4     mkfs.ext4dev 
[root@localhost /]# mkfs.ext4 /dev/mapper/VolGroup-
VolGroup-lv_home  VolGroup-lv_root  VolGroup-lv_swap  VolGroup-test    
[root@localhost /]# mkfs.ext4 /dev/mapper/VolGroup-test
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
      8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done                           
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost /]# 
above created a EXT4 file system using mkfst.ext4 command. 

[root@localhost /]# mount /dev/mapper/VolGroup-test /test1/
[root@localhost /]#
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      477M  2.3M  445M   1% /test1
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# pwd
/
[root@localhost /]# man fsadm
[root@localhost /]#
[root@localhost /]# fsadm -e -y /dev/mapper/VolGroup-test 1000M
fsadm: Wrong argument "/dev/mapper/VolGroup-test". (see: fsadm --help)
[root@localhost /]# man fsadm
[root@localhost /]# 
Here I tried with increasing the test file system size online using fsadm to 1000MB size. It failed. 
[root@localhost /]# fsadm -e -y resize /dev/mapper/VolGroup-test 1000M
Do you want to unmount "/test1"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/VolGroup-test: 11/128016 files (0.0% non-contiguous), 26666/512000 blocks
resize2fs 1.41.12 (17-May-2010)
The containing partition (or device) is only 512000 (1k) blocks.
You requested a new size of 1024000 blocks.

fsadm: Resize ext4 failed

[root@localhost /]# fsadm -e -y resize /dev/mapper/VolGroup-test 400M
Do you want to unmount "/test1"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/VolGroup-test: 11/128016 files (0.0% non-contiguous), 26666/512000 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-test to 409600 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 409600 blocks long.

[root@localhost /]# 
It allowed reduction within the size given to it at the time of creation. Lets see can we increase the size back to 500MB with this command or not.
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      380M  2.3M  354M   1% /test1

[root@localhost /]#
[root@localhost /]#
[root@localhost /]# fsadm -e -y resize /dev/mapper/VolGroup-test 500M
Do you want to unmount "/test1"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/VolGroup-test: 11/101600 files (0.0% non-contiguous), 23338/409600 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-test to 512000 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 512000 blocks long.

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      477M  2.3M  445M   1% /test1
[root@localhost /]#

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      477M  2.3M  445M   1% /test1
[root@localhost /]#
[root@localhost /]# 
As seen above the file system size increase without using lvextend command and resize2fs command, but it did it to the limits of 500MB only, which we have given to it at the time of creation. 
Now Back to old method of extending the Logical Volume using lvextend command. 

[root@localhost /]# lvextend -L +500M /dev/mapper/VolGroup-test
  WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
  Extending logical volume test to 1000.00 MiB
  Logical volume test successfully resized
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      477M  2.3M  445M   1% /test1
[root@localhost /]#
The size after extending through LVEXTEND command will not be visible until we resize the file system, where this was not in the case of fsadm command shown above.
[root@localhost /]# resize
resize2fs   resizecons 
[root@localhost /]# man resizecons
[root@localhost /]#
[root@localhost /]# resize2fs /dev/mapper/VolGroup-test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-test is mounted on /test1; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/VolGroup-test to 1024000 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 1024000 blocks long.

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      961M  2.5M  910M   1% /test1

[root@localhost /]# 
Size Increased.
[root@localhost /]# fsadm -y resize /dev/mapper/VolGroup-test 800M
Do you want to unmount "/test1"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/VolGroup-test: 11/254000 files (0.0% non-contiguous), 42797/1024000 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-test to 819200 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 819200 blocks long.

[root@localhost /]# 
Now we have reduced the size of 1000MB extended above using lvextend and resize2fs with fsadm command to size 800MB. 

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      767M  2.5M  725M   1% /test1
[root@localhost /]# man fsadm
[root@localhost /]#
[root@localhost /]# e2fsck /dev/mapper/VolGroup-test
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/VolGroup-test is mounted.
e2fsck: Cannot continue, aborting.



[root@localhost /]# resize2fs /dev/mapper/VolGroup-test 700M
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-test is mounted on /test1; on-line resizing required
On-line shrinking from 819200 to 716800 not supported.

[root@localhost /]#
[root@localhost /]# lvre
lvreduce  lvremove  lvrename  lvresize 
[root@localhost /]# lvresize -L +2G /dev/mapper/VolGroup-test
  WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
  Extending logical volume test to 2.98 GiB
  Logical volume test successfully resized

[root@localhost /]#
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      767M  2.5M  725M   1% /test1
[root@localhost /]# resize2fs /dev/mapper/VolGroup-test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-test is mounted on /test1; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 12
Performing an on-line resize of /dev/mapper/VolGroup-test to 3121152 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 3121152 blocks long.

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      2.9G  3.2M  2.8G   1% /test1
[root@localhost /]# 
... lvresize command with resize2fs command increased the size similarly as lvextend and resize2fs command. So it showed both of these worked similarly. Now we can come to a conclusion below.


Command "fsadm" allows you to reduce the file system without manually un-mounting a file system and also running e2fsck or file system check and then resizing or lvreduce command and then mounting back, but within the file system size given at the creation time of Logical Volume. It skipped 
a. UMOUNT
b. FSCK
c. resize2fs {LV} SIZE
d. lvreduce
e. Mount the File system. 


Will be adding in other post about how we can use the space of the LV reduced using this method. 


 


No comments: