LVM: Howto increase the size of a filesystem on-the-fly

Oops, that is not good :-(
/dev/mapper/database_vg-db_vol 690G 655G 12K 100% <the SHADOW database filesystem>
This happened at 4am. What can you do in case that this happens to you? Praying is always a solution. The better solution is checking your free physical space.

[root@mymachine ~]# pvs
  Found duplicate PV fFza0t96dLLdVGnklCVRvIFacmJ1Kd4I: using /dev/sdc not /dev/sdq
  PV             VG           Fmt  Attr PSize   PFree
  /dev/emcpowera audit_vg     lvm2 a--    2.00t  548.00g
  /dev/emcpowerb logs_vg      lvm2 a--  500.00g 1020.00m
  /dev/emcpowerc database_vg  lvm2 a--    1.46t  600.00g
  /dev/sda3      vg_scloshad2 lvm2 a--  127.93g       0

Phew 600GB available. So let’s see how the logical drive can be extended by 200GB.

[root@mymachine ~]# lvextend -L +200G /dev/mapper/database_vg-db_vol /dev/emcpowerc
  Found duplicate PV fFza0t96dLLdVGnklCVRvIFacmJ1Kd4I: using /dev/sdc not /dev/sdq
  Extending logical volume db_vol to 900.00 GiB
  Logical volume db_vol successfully resized

That was quick. Now we have to resize the filesystem and we can do this while the database is still up and running :-)

[root@mymachine ~]# resize2fs /dev/mapper/database_vg-db_vol
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/database_vg-db_vol is mounted on /trak/sclo/SHADOW/db/data; on-line resizing required
old desc_blocks = 44, new_desc_blocks = 57
Performing an on-line resize of /dev/mapper/database_vg-db_vol to 235929600 (4k) blocks.
The filesystem on /dev/mapper/database_vg-db_vol is now 235929600 blocks long.

…. 5 minutes later.
/dev/mapper/database_vg-db_vol 886G 655G 187G 78% /trak/sclo/SHADOW/db/data

It is quite possible that you already used up all the physical space for your virtual drives. In that case you can easily add more physical disks or LUNs to the disk group in using the ‘vgextend’ command. E.g. vgextend database_vg /dev/emcpowerd

Posted in Apps, Beginner, Linux | Leave a comment

Copy large files between servers

If you have to copy large files between systems and security is not an issue you could use netcat. Netcat is a tool that has been developed in 1996 but it is still one of the best tools for this type of job. It is the Swiss army knife for stuff that can be done in using a dedicated network connection. This article will use it to copy files over the network in an easy and fast way.
Let’s say that you have a file huge_file.db that you want to copy from server1 to server2.

  1. open a server socket on server2 (file will go to the /temp directory)
    [root@server2 ~]# nc -l -p 11221 > /test/huge_file.db
  2. copy the file to the remote socket
    [root@server1 ~]# dd if=/root/Downloads/huge_file.db | nc server2 11221
    3900979+1 records in
    3900979+1 records out
    1997301556 bytes (2.0 GB) copied, 169.821 s, 11.8 MB/s

You will not see any output until the process has finished. To see the progress you can use pv. PV is a tool to look into a pipe and see the data transfer. It is not installed by default but is included in most of the repositories.
[root@server1 ~]# dd if=/root/Downloads/huge_file.db | pv | nc server2 11221
3900979+1 records inMB/s] [                  ]
3900979+1 records out
1997301556 bytes (2.0 GB) copied, 169.903 s, 11.8 MB/s
1.86GB 0:02:49 [11.2MB/s] [                  ]

Posted in Bash, Beginner | Leave a comment

Conditions in BASH scripts Pt. 1

This is just a reminder for myself. Usually I have to look this up in Google whenever I want to use it :-(
Check if string A contains string B:

if [[ $A == *"$B"* ]] then echo We have a hit else echo No hit fi

Check if a variable A is a number:

if [ "$A"=~"^[0-9]+$" ] then echo Variable contains only digits else echo This is not a number fi

Posted in Bash, Beginner | Leave a comment

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

… or how to resize a file system on CentOS 7. Due to moving my home partition to a new disk I gained some space back from the logical volume home. After deleting it I thought that it would be a good idea to add those additional 10GB to the my root disk.
I started with:

[root@jcdesk Desktop]# lvdisplay --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID jxyjgx-veql-Hzxk-1ynz-b6i2-BQoe-xGhrCb LV Write Access read/write LV Creation host, time jc-desk.luht.scot.nhs.uk, 2015-06-11 .... LV Status available # open 1 LV Size 105.00 GiB Current LE 26879 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0

The size of the root volume was 105GiB. The additional space should be 10GiB.

[root@jcdesk Desktop]# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 105.00 GiB (26879 extents) to 115.00 GiB (29440 extents). Logical volume root successfully resized

That added all the free space in the volume group to my root volume.

[root@jcdesk ~]# lvdisplay /dev/centos/root --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID jxyjgx-veql-Hzxk-1ynz-b6i2-BQoe-xGhrCb LV Write Access read/write LV Creation host, time jc-desk.luht.scot.nhs.uk, 2015-06-11 ... LV Status available # open 1 LV Size 115.00 GiB Current LE 29440 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0

Strike !!! So far so good. Now lets resize the file system.

[root@jcdesk Desktop]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 105G 7.0G 98G 7% /

I tried to resize the file system to the new size.

[root@jcdesk Desktop]# resize2fs /dev/mapper/centos-root 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.

Oops !!!!! 8-o
I took me a while to find out that LVM is using xfs as their file system.

[root@jcdesk ~]# mount | grep centos-root /dev/mapper/centos-root on / type xfs (rw,relatime,...

Xfs comes with its own command set.

[root@jcdesk ~]# xfs [tab][tab] xfs_admin xfs_copy xfsdump xfs_freeze xfs_growfs xfsinvutil xfs_logprint xfs_metadump xfs_ncheck xfs_repair xfs_rtcp xfs_bmap xfs_db xfs_estimate xfs_fsr xfs_info xfs_io xfs_mdrestore xfs_mkfile xfs_quota xfsrestore

So instead of using the resize2fs command I had to use the xfs_growfs command.

[root@jcdesk ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize= 6881024 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=27524096, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=13439, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 27524096 to 30146560

A final check:

[root@jcdesk ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 115G 7.0G 108G 7% /

….. done.

Posted in Beginner, Linux | 25 Comments