Solved: How to extend or grow a linux filesystem under LVM

In this post we will see how to grow a Linux filesystem without reboot.

  • Let’s check our current filesystem. We want to extend this filesystem by 200MB.
[root@cloudvedas CVFS1]# df -h /CVFS1
Filesystem                  Size Used Avail Use% Mounted on
/dev/mapper/cvsvg-cldvdsvol1 47M 12M    32M  26%   /CVFS1
[root@cloudvedas CVFS1]#
  • First check if we have free space in VG
[root@cloudvedas /]# vgs
 VG    #PV    #LV    #SN    Attr    VSize    VFree
 cvsvg  1      1      0      wz--n- 196.00m  144.00m
 rhel   1      3      0      wz--n- 7.51g    36.00m
[root@cloudvedas /]#
  • Since we don’t have 200MB free in “cvsvg” so we will add a new disk to it. First label the disk for LVM and get it under LVM control using pvcreate.
[root@cloudvedas CVFS1]# pvcreate /dev/sdb2
 Physical volume "/dev/sdb2" successfully created
[root@cloudvedas CVFS1]#
  • Add the new partition to our VG.
[root@cloudvedas CVFS1]# vgextend cvsvg /dev/sdb2
 Volume group "cvsvg" successfully extended
[root@cloudvedas CVFS1]#
  • Check the VG size again.
[root@cloudvedas CVFS1]# vgs
 VG    #PV   #LV    #SN    Attr    VSize    VFree
 cvsvg  2     1      0     wz--n-  444.00m  392.00m
 rhel   1     3      0     wz--n-  7.51g    36.00m
[root@cloudvedas CVFS1]#
  • Now we have the required space so, let’s extend the volume first.
[root@cloudvedas CVFS1]# lvextend -L +200M /dev/cvsvg/cldvdsvol1
 Size of logical volume cvsvg/cldvdsvol1 changed from 52.00 MiB (13 extents) to 252.00 MiB (63 extents).
 Logical volume cldvdsvol1 successfully resized
  • On checking the LV we can see it’s now extended as is now of 252MB.
[root@cloudvedas CVFS1]# lvs
 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
 cldvdsvol1 cvsvg -wi-ao---- 252.00m
 root rhel -wi-ao---- 6.67g
 swap rhel -wi-ao---- 820.00m
 testvol1 rhel -wi-a----- 4.00m
[root@cloudvedas CVFS1]#
  • Let’s increase the filesystem now using resize2fs.
[root@cloudvedas CVFS1]# resize2fs /dev/cvsvg/cldvdsvol1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/cvsvg/cldvdsvol1 is mounted on /CVFS1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/cvsvg/cldvdsvol1 is now 258048 blocks long.
  • Check the file system now.
[root@cloudvedas CVFS1]# df -h /CVFS1
Filesystem                   Size Used Avail Use% Mounted on
/dev/mapper/cvsvg-cldvdsvol1 241M  13M  217M  6%   /CVFS1
[root@cloudvedas CVFS1]#

Great so we have now extended the filesystem.

Solved: How to label a disk in Linux

In this post we will see how to label a new disk in Linux and create a new LVM partition.

Step 1 Scan the new LUNS.

Step 2 List the available disks and identify the one you want to use.

  fdisk -l |grep /dev/ |grep -v dm

Step 3 Use fdisk to label the disk. Here we are using disk sdb .

[root@cloudvedas scsi_host]# fdisk /dev/sdb
 Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
 Be careful before using the write command.

Device does not contain a recognized partition table
 Building a new DOS disklabel with disk identifier 0x909f2c7b.

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x909f2c7b

Device Boot Start End Blocks Id System

Command (m for help):

Step 4 Create Primary partition using option “n” of size 200MB.

Command (m for help): n
 Partition type:
 p primary (0 primary, 0 extended, 4 free)
 e extended
 Select (default p): p
 Partition number (1-4, default 1):
 First sector (2048-2097151, default 2048):
 Using default value 2048
 Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +200M
 Partition 1 of type Linux and of size 200 MiB is set

(Don’t miss the + used before 200M. It’s very critical else it won’t work as expected)

Step 4 Now let’s check our new partition

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0xc1c8c781

Device Boot Start End Blocks Id System
 /dev/sdb1 2048 411647 204800 83 Linux

Command (m for help):

Step 5 In the above output we can see that the new partition is a standard linux partition.  Let’s Change the partition type to Linux LVM. Here we will use “8e” which is a Hex code for LVM. You can type L to list all codes.

Command (m for help): t
 Selected partition 1
 Hex code (type L to list all codes): 8e

-Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0xc1c8c781

Device Boot Start End Blocks Id System
 /dev/sdb1 2048 411647 204800 8e Linux LVM

Command (m for help):

Step 6 Finally save the changes with option “w”

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Step 7 Let’s list the partition table to cross check that our partition table is saved correctly.

[root@cloudvedas /]# fdisk -l /dev/sdb

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x0aa5ab95

Device Boot Start End Blocks Id System
 /dev/sdb1 2048 411647 204800 8e Linux LVM
 [root@cloudvedas /]#

Cool! So, we have now a LVM partition which we can bring under LVM control using pvcreate. Learn more about LVM in this crash course.

LVM Crash course

In this post we will give you a crash course on Linux LVM (Logical Volume Manager). This post will cover the most used LVM commands in a Linux Admin life.

Before we start first let’s go through the concepts.

Physical Volumes (PVs): Storage devices (physical hard disks, partitions, RAID arrays etc.) provides raw storage
Volume Groups (VGs): Combine multiple PVs to create a group. They can be mirror or concatenation of PVs.
Logical Volumes (LVs): Create smaller volumes from the Volume Group(VG) as per your size requirement. You can can use the LVs to create filesystem on them.

Below commands are for RHEL 7.

All the below commands will require root access. You can either run them with sudo  or switch to root user as mentioned below.

sudo su -

Install LVM

[root@cloudvedas ~]# yum install lvm2*

Check LVM version

[root@cloudvedas ~]# lvm version

Label the new disk and bring it under LVM using pvcreate

Create PV (Physical Volume)

[root@cloudvedas ~]# pvcreate /dev/sdb1

Show PV

[root@cloudvedas ~]# pvs /dev/sdb1

Create VG (Volume Group)

[root@cloudvedas ~]# vgcreate cvsvg /dev/sdb1

Show VG

[root@cloudvedas ~]# vgs cvsvg

Display VG

[root@cloudvedas ~]# vgdisplay cvsvg

Extend VG

[root@cloudvedas ~]# vgextend cvsvg /dev/sdb2

Create LV (Logical Volume)

[root@cloudvedas ~]# lvcreate -L 500M cvsvg -n cldvdsvol1

Display LV 

[root@cloudvedas ~]# lvdisplay /dev/cvsvg/cldvdsvol1

Create mirror volume

 lvcreate -L 100M -m1 -n cvmirrorvol1 cvsvg

Create striped volume

[root@cloudvedas ~]# lvcreate -L 50M -i 3 -I 64 -n stripevol cvsvg


-i|–stripes (Number of disks in stripe)
-I|Stripe size

Extend LV

lvextend -L +20M /dev/cvsvg/stripevol

De-activate volume

lvchange -an /dev/cvsvg/stripevol

Activate volume

lvchange -ay /dev/cvsvg/stripevol

Remove LV

Ensure filesystem is unmounted before running this

lvremove /dev/cvsvg/stripevol

Create filesystem

mkfs -t ext4 /dev/cvsvg/cldvdsvol1

Create directory

mkdir /CVFS1

Mount filesystem

mount /dev/cvsvg/cldvdsvol1  /CVFS1

All the available LVM commands

[root@cloudvedas ~]# lvm help
 Available lvm commands:
 Use 'lvm help <command>' for more information

devtypes Display recognised built-in block device types
 dumpconfig Dump configuration
 formats List available metadata formats
 help Display help for commands
 lvchange Change the attributes of logical volume(s)
 lvconvert Change logical volume layout
 lvcreate Create a logical volume
 lvdisplay Display information about a logical volume
 lvextend Add space to a logical volume
 lvmchange With the device mapper, this is obsolete and does nothing.
 lvmdiskscan List devices that may be used as physical volumes
 lvmsadc Collect activity data
 lvmsar Create activity report
 lvreduce Reduce the size of a logical volume
 lvremove Remove logical volume(s) from the system
 lvrename Rename a logical volume
 lvresize Resize a logical volume
 lvs Display information about logical volumes
 lvscan List all logical volumes in all volume groups
 pvchange Change attributes of physical volume(s)
 pvresize Resize physical volume(s)
 pvck Check the consistency of physical volume(s)
 pvcreate Initialize physical volume(s) for use by LVM
 pvdata Display the on-disk metadata for physical volume(s)
 pvdisplay Display various attributes of physical volume(s)
 pvmove Move extents from one physical volume to another
 pvremove Remove LVM label(s) from physical volume(s)
 pvs Display information about physical volumes
 pvscan List all physical volumes
 segtypes List available segment types
 tags List tags defined on this host
 vgcfgbackup Backup volume group configuration(s)
 vgcfgrestore Restore volume group configuration
 vgchange Change volume group attributes
 vgck Check the consistency of volume group(s)
 vgconvert Change volume group metadata format
 vgcreate Create a volume group
 vgdisplay Display volume group information
 vgexport Unregister volume group(s) from the system
 vgextend Add physical volumes to a volume group
 vgimport Register exported volume group with system
 vgmerge Merge volume groups
 vgmknodes Create the special files for volume group devices in /dev
 vgreduce Remove physical volume(s) from a volume group
 vgremove Remove volume group(s)
 vgrename Rename a volume group
 vgs Display information about volume groups
 vgscan Search for all volume groups
 vgsplit Move physical volumes into a new or existing volume group
 version Display software and driver version information
[root@cloudvedas ~]#

Solved: How to schedule a cron job in Linux or Solaris

In this post we will see what’s a cron job and how we can set it.

Cron is managed by a crontab file. Its a configuration file in which we can schedule shell command to run periodically.

Scheduling cron

For modifying a cron you use a utility called crontab .

Before you can execute any crontab command you will have to set environment variables by executing below commands in your linux or unix command prompt.

export TERM
export EDITOR

Now let’s see the different crontab commands.

Display current cron jobs

crontab -l

Edit cron file

crontab -e

Remove cron file (Be extremely careful with this command)

crontab -r

Cron format

You have to follow a specific format to schedule a cron job. See e.g. below:

30 22 * * 6 /home/cldvds/scripts/

Let’s learn more about the asterisk (*) .

*       *        *        *         *        /
–       –        –        –        –
|        |         |        |         |
|        |         |        |        +—– day of week (0 – 6) (Sunday=0)
|        |         |       +——- month (1 – 12)
|        |        +——— day of month (1 – 31)
|       +———– hour (0 – 23)
+————– min (0 – 59)

From the table above we can interpret that the  cron job will execute file at 22:30 every saturday

Let’s take a few more examples

Execute every 5 mins

*/5 * * * *    /home/cldvds/scripts/

Execute every hour

0 * * * *     /home/cldvds/scripts/

Execute in every 3 hours

0 */3 * * *    /home/cldvds/scripts/

Execute every Sunday at 1 am

0 1 * * 0    /home/cldvds/scripts/


What if you want the cron to run at 22:30:30 i.e exact to seconds.

In such case at the start of your shell script put a sleep command as below

sleep 30

So, now the script will wait for 30 secs before executing.

Log redirection

30 22 * * 6 /home/cldvds/scripts/ >> /home/cldvds/scripts/logs.txt 2>&1

With the above command stderr (standard error) and stdout (standard output) will go to your logs.txt file.

Saving a cron file

Once you are done with cron schedule modification don’t forget to save the file.

You can save the file using standard save method of vi editor. The command sequence to save is  Esc :wq!

Solved: How to get Provisional Interest Certificate for housing loan from PNB (Punjab National Bank)

You can get the Provisional Interest Certificate from Punjab National bank both offline and online. Below we will discuss the process of both the methods.

Offline method:-

  • To get the Provisional Interest Certificate offline you will have to visit the branch from which your home loan is disbursed. But this can be a problem if you have shifted to another city.
  • If you cannot visit the branch, you can also try to get the certificate on mail. For this you will have to drop a mail to the email id of the branch from which you got loan. You may also have to make some follow-up calls. You can get the email id and contact number of branch from this link of PNB website. But, this may take time as some people in branch are not aware of this email facility and will simply tell you to visit the branch.

Best way to avoid any hassles is to follow online method discussed below.

Online method:-

You can also get the Provisional Interest Certificate online. For this you will have to login to the internet banking of Punjab National bank. Below we will show you the steps involved.

  • Once you login to PNB internet banking. Click on Manage Accounts. Under the E-Interest Certificates select Housing Loan.

  • It will ask you to select the account number for which you need Provisional Interest Certificate. Once you select  the account you can either download or email the Provisional Interest Certificate.

Hope this helps. Do let us know if you have any query.