Tuesday, October 25, 2011

Small script to test perl module

To test any perl module, just put below lines in a file, make it executable (chmod +x) and run it (./).

#!/usr/bin/perl
use DBD-Pg;
print "No errors!\n"
where DBD-Pg is example of perl module. This script will return "No errors!" if the module is available. If the module is not installed, an error like "Can't locate ...." will appear instead.

Thursday, October 6, 2011

Extending LVM logical volume

To extend the lv (logical volume), the command is lvextend. Please check beforehand that you have free disk space to be extended to.

Check which volume group the partition belongs to:

# df -lh
Filesystem Size Used Avail Use% Mounted on
...
/dev/mapper/vg01-db 6.0T 6.0T 20K 100% /var/lib/hwbackup/db
...

# lvdisplay vg01
--- Logical volume ---
LV Name /dev/vg01/db
VG Name vg01
LV UUID 2LvWW6-5TIG-ovrl-GUJt-1y3N-M6ME-3LgtUY
LV Write Access read/write
LV Status available
# open 1
LV Size 5.99 TB
Current LE 1569792
Segments 5
Allocation inherit
Read ahead sectors auto
- currently set to 4096
Block device 253:2

So, our lv belongs to vg01

Now let's check how much space we have for vg01:

# vgdisplay vg01
...
Alloc PE / Size 4059648 / 15.49 TB
Free PE / Size 232788 / 909.33 GB
VG UUID iaFnIb-hKjs-q3fQ-yuTy-tKKl-uqSp-EXGyHF
...

So we know that it got 909.33 GB unused space.

Lets do the extension, let's say we want to extend by 300GB. Run a test run first:

# lvextend -t -v -L +300G /dev/mapper/vg01-db
Test mode: Metadata will NOT be updated.
Finding volume group vg01
Using stripesize of last segment 512.00 KB
Test mode: Skipping archiving of volume group.
Extending logical volume db to 6.28 TB
Found volume group "vg01"
Found volume group "vg01"
Found volume group "vg01"
Test mode: Skipping volume group backup.
Logical volume db successfully resized
Test mode: Wiping internal cache
Wiping internal VG cache
[root@hitw-gc-backup-1 ~]# lvextend -v -L +300G /dev/mapper/vg01-db
Finding volume group vg01
Using stripesize of last segment 512.00 KB
Archiving volume group "vg01" metadata (seqno 19).
Extending logical volume db to 6.28 TB
Found volume group "vg01"
Found volume group "vg01"
Loading vg01-db table (253:2)
Suspending vg01-db (253:2) with device flush
Found volume group "vg01"
Resuming vg01-db (253:2)
Creating volume group backup "/etc/lvm/backup/vg01" (seqno 20).
Logical volume db successfully resized
where -t is for test mode, -v for verbose and -L is for the size that you want to extend

If we are OK with the test, proceed to the real extension by removing -t:
# lvextend -v -L +300G /dev/mapper/vg01-db
Finding volume group vg01
Using stripesize of last segment 512.00 KB
Archiving volume group "vg01" metadata (seqno 19).
Extending logical volume db to 6.28 TB
Found volume group "vg01"
Found volume group "vg01"
Loading vg01-db table (253:2)
Suspending vg01-db (253:2) with device flush
Found volume group "vg01"
Resuming vg01-db (253:2)
Creating volume group backup "/etc/lvm/backup/vg01" (seqno 20).
Logical volume db successfully resized

Check your new lv size, it is now being extended by 300GB:
# lvdisplay /dev/mapper/vg01-db
...
LV Size 6.28 TB
...

To make your filesystem aware of the extension, run resize2fs (for ext3 filesystem). Please unmount the partition beofre you run resize2fs
# umount /dev/mapper/vg01-db
# resize2fs /dev/mapper/vg01-db

# mount /dev/mapper/vg01-db /var/lib/hwbackup/db
For xfs, you can resize it on the fly without unmounting it:
# xfs_growfs /var/lib/hwbackup/db
Now you can enjoy your newly extended lv:
# df -lh
Filesystem Size Used Avail Use% Mounted on
...
/dev/mapper/vg01-db 6.3T 5.7T 608G 91% /var/lib/hwbackup/db
...