How to Increase the Size of Logical Volume (LVM) on Linux

There are eight(8) functional steps to resize the logical volume in linux.

1. Increase A VMware Disk Size (VMDK) Formatted As Linux LVM
2. In VM OS, Create Partition
3. Reboot the VM
4. Format the new partition
5. Creates the physical volumes using pvcreate
6. Add physical volumes to a volume group using vgextend. vgextend allows you to add one or more initialized physical volumes to an existing volume group to extend it in size.
7. Extend the size of a logical volume using lvextend
8. Resize the logical volume size using resize2fs. The resize2fs program will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located on device.

    [root@server ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           20G  173M   19G   1% /opt
    
    [root@server ~]# fdisk -lu
    
    Disk /dev/sda: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *          63      208844      104391   83  Linux
    /dev/sda2          208845     2313359     1052257+  82  Linux swap / Solaris
    /dev/sda3         2313360    14667344     6176992+  8e  Linux LVM
    /dev/sda4        14667345    41929649    13631152+  8e  Linux LVM
    
    Disk /dev/sdb: 26.8 GB, 26843545600 bytes
    255 heads, 63 sectors/track, 3263 cylinders, total 52428800 sectors
    Units = sectors of 1 * 512 = 512 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1              63    41929649    20964793+  8e  Linux LVM
    
    [root@server ~]# fdisk /dev/sdb
    
    The number of cylinders for this disk is set to 3263.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
       (e.g., DOS FDISK, OS/2 FDISK)
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First cylinder (2611-3263, default 2611):
    Using default value 2611
    Last cylinder or +size or +sizeM or +sizeK (2611-3263, default 3263):
    Using default value 3263
    
    Command (m for help): t
    Partition number (1-4): 2
    Hex code (type L to list codes): 8e
    Changed system type of partition 2 to 8e (Linux LVM)
    
    Command (m for help): p
    
    Disk /dev/sdb: 26.8 GB, 26843545600 bytes
    255 heads, 63 sectors/track, 3263 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        2610    20964793+  8e  Linux LVM
    /dev/sdb2            2611        3263     5245222+  8e  Linux LVM
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table.
    The new table will be used at the next reboot.
    Syncing disks.
    [root@server ~]# reboot
    
    [root@server ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           20G  173M   19G   1% /opt
    

After the new partition table has been written, format the new partition.

    [root@server ~]# mke2fs -j /dev/sdb2
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    656000 inodes, 1311305 blocks
    65565 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=1346371584
    41 block groups
    32768 blocks per group, 32768 fragments per group
    16000 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736
    
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 20 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    

Creates the physical volumes using command below:

    [root@server ~]# pvcreate /dev/sdb2
      Physical volume "/dev/sdb2" successfully created
    

Scan all disks for physical volumes.

    [root@server ~]# pvscan
      PV /dev/sdb1   VG VolGroup01      lvm2 [19.99 GB / 0    free]
      PV /dev/sda4   VG VolGroup00      lvm2 [13.00 GB / 0    free]
      PV /dev/sdb2                      lvm2 [5.00 GB]
      Total: 3 [37.99 GB] / in use: 2 [32.99 GB] / in no VG: 1 [5.00 GB]
    

Add physical volumes to a volume group. This example add /dev/sdb2 to VolGroup01

    [root@server ~]# vgextend VolGroup01 /dev/sdb2
      Volume group "VolGroup01" successfully extended
    
    [root@server ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           20G  173M   19G   1% /opt
    

Extend the size of a logical volume using lvextend.

    [root@server ~]# lvextend -l +100%FREE /dev/VolGroup01/optvol
      Extending logical volume optvol to 24.99 GB
      Logical volume optvol successfully resized
    

Resize the logical volume size using resize2fs.

    [root@server ~]# resize2fs /dev/mapper/VolGroup01-optvol
    resize2fs 1.39 (29-May-2006)
    Filesystem at /dev/mapper/VolGroup01-optvol is mounted on /opt; on-line resizing required
    Performing an on-line resize of /dev/mapper/VolGroup01-optvol to 6551552 (4k) blocks.
    The filesystem on /dev/mapper/VolGroup01-optvol is now 6551552 blocks long.
    
    [root@server ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           25G  173M   24G   1% /opt
    

How to Setup Additional LVM in CentOS 5.5

In this post, i will share on how to setup additional LVM in CentOS 5.5.

1. Assumed that new hard disk 2 (sdb) has been added in this CentOS 5.5 server.
2. Print the current partition table of the hard disk :

    [root@server ~]# fdisk -lu
    
    Disk /dev/sda: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *          63      208844      104391   83  Linux
    /dev/sda2          208845     2313359     1052257+  82  Linux swap / Solaris
    /dev/sda3         2313360    14667344     6176992+  8e  Linux LVM
    /dev/sda4        14667345    41929649    13631152+  8e  Linux LVM
    
    Disk /dev/sdb: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    
    Disk /dev/sdb doesn't contain a valid partition table
    

3. Create new partition for /dev/sdb using below command.

    [root@server ~]# fdisk /dev/sdb
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel. Changes will remain in memory only,
    until you decide to write them. After that, of course, the previous
    content won't be recoverable.
    
    
    The number of cylinders for this disk is set to 2610.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
       (e.g., DOS FDISK, OS/2 FDISK)
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-2610, default 1):
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):
    Using default value 2610
    
    Command (m for help): t
    Selected partition 1
    Hex code (type L to list codes): 8e
    Changed system type of partition 1 to 8e (Linux LVM)
    
    Command (m for help): p
    
    Disk /dev/sdb: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        2610    20964793+  8e  Linux LVM
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
    [root@server ~]# mke2fs -j /dev/sdb1
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    2621440 inodes, 5241198 blocks
    262059 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=0
    160 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
            4096000
    
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 24 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    

4. Next create the new partitions for this LVM.

    [root@server ~]# pvcreate /dev/sdb1
      Physical volume "/dev/sdb1" successfully created
    

5. Display the Physical Volume using command below:

    [root@server ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda4
      VG Name               VolGroup00
      PV Size               13.00 GB / not usable 3.67 MB
      Allocatable           yes (but full)
      PE Size (KByte)       4096
      Total PE              3327
      Free PE               0
      Allocated PE          3327
      PV UUID               JgYuxF-UJiB-t148-g5WQ-Lx05-Ozk1-13UwAR
    
      "/dev/sdb1" is a new physical volume of "19.99 GB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb1
      VG Name
      PV Size               19.99 GB
      Allocatable           NO
      PE Size (KByte)       0
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               246F8V-FMTR-WNK0-9305-q2sf-PKtC-VQXOQr
    

6. Create new volume group for /dev/sdb1. Assumed that previous volume goup is VolGroup00. So next volume group will be VolGroup01.

    [root@server ~]# vgcreate VolGroup01 /dev/sdb1
      Volume group "VolGroup01" successfully created
    

7. Display the existing Volume Group.

    [root@server ~]# vgdisplay
      --- Volume group ---
      VG Name               VolGroup01
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  1
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                0
      Open LV               0
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               19.99 GB
      PE Size               4.00 MB
      Total PE              5118
      Alloc PE / Size       0 / 0
      Free  PE / Size       5118 / 19.99 GB
      VG UUID               tvLVhu-6Nzo-jB0b-oZQ4-VY30-9TP4-Dhxvvm
    
      --- Volume group ---
      VG Name               VolGroup00
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  2
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               13.00 GB
      PE Size               4.00 MB
      Total PE              3327
      Alloc PE / Size       3327 / 13.00 GB
      Free  PE / Size       0 / 0
      VG UUID               3XozzT-3A3w-6eXs-XoEb-yRN1-v9FM-N0YheL
    

8. Create logical volumes with the name of optvol into VolGroup01 volume group.

    [root@server ~]# lvcreate --name optvol -l 100%FREE VolGroup01
      Logical volume "optvol" created
    

9. Display the logical volumes.

    [root@server ~]# lvdisplay
      --- Logical volume ---
      LV Name                /dev/VolGroup01/optvol
      VG Name                VolGroup01
      LV UUID                YXkMnR-l7gH-tj0r-dCUt-Ncl7-aTmb-Vas4Tp
      LV Write Access        read/write
      LV Status              available
      # open                 0
      LV Size                19.99 GB
      Current LE             5118
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:1
    
      --- Logical volume ---
      LV Name                /dev/VolGroup00/datavol
      VG Name                VolGroup00
      LV UUID                KowzAO-WWMj-O0xw-IY31-Gfqv-sjaE-nYvdhk
      LV Write Access        read/write
      LV Status              available
      # open                 1
      LV Size                13.00 GB
      Current LE             3327
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:0
    

10. creating a file with the mke2fs command

    [root@server ~]# mke2fs -j /dev/VolGroup01/optvol
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    2621440 inodes, 5240832 blocks
    262041 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=0
    160 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
            4096000
    
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 38 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    
    [root@server ~]# e2label /dev/VolGroup01/optvol /opt
    
    [root@server ~]# vi /etc/fstab
    
    [root@server ~]# mount /opt
    
    [root@server ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           20G  173M   19G   1% /opt
    
    [root@server ~]# fdisk -lu
    
    Disk /dev/sda: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *          63      208844      104391   83  Linux
    /dev/sda2          208845     2313359     1052257+  82  Linux swap / Solaris
    /dev/sda3         2313360    14667344     6176992+  8e  Linux LVM
    /dev/sda4        14667345    41929649    13631152+  8e  Linux LVM
    
    Disk /dev/sdb: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1              63    41929649    20964793+  8e  Linux LVM
    

References:

    https://wiki.archlinux.org/index.php/LVM
    http://vr.org/docs/centos/5/html/Cluster_Logical_Volume_Manager/LV_create.html
    http://serverfault.com/questions/41904/volume-group-out-of-space-how-do-i-reclaim-it
    http://www.idevelopment.info/data/Unix/Linux/LINUX_ManagingPhysicalLogicalVolumes.shtml
    http://en.gentoo-wiki.com/wiki/Root_filesystem_over_LVM2,_DM-Crypt_and_RAID
    http://wingloon.com/2009/01/16/setup-additional-lvm-in-centos-52/
    http://rute.2038bug.com/node22.html.gz
    

How to Top up Paypal Account in Malaysia

In this post, i will share on how to top up your paypal account. I have chosen the RHB bank for example.

1. Make sure that your RHB bank account has been registered with paypal related email address.
Paypal0
2. Log into your paypal account. Please go to “My Account” menu and press the “Top UP” to proceed with the transaction.
Paypal1
3. If you use RHB bank, please press the “Continue” under the “RHB Bank”. If you wish to use other bank accounts, CIMB, Bank Islam or Maybank2u, please press the “Continue” under “Other Banks”.
Paypal2
4. Automatically, you will be log out from a paypal account and will be entering selected site where you will be asked to provide amount and currency for top up.
Paypal3
5. Select your currency, USD or MYR. Enter the amount of money to be transferred. Press the “Recalculate” to update the amount of money. Press the “Proceed” to proceed with the transaction.
Paypal4
6. Now you will be redirected to RHB Merchant portal. Enter your RHB account’s username.
Paypal5
7. Please press the “Preview” to proceed with the transaction.
Paypal6
8. Enter your One Time Password (OTP). Click Submit to proceed.
Paypal8
9. If success, you will received “Transaction is Successfully Completed”.
Paypal8
10. Login to your paypal account again and check your recent transactions. The screen captured below shows that RM 10 payment has been received in paypal account.
Paypal9

How to Remove the “This site may harm your computer” warning?

Symptoms:
When you do google search to certain website or blog, google puts the warning flag in its search results for pages which to notify the surfers. Google users were redirected to page that warned: “This site may harm your computer.” The purpose of the warning is to help protect web surfers who are using Google search results.

This site may harm your computer

Possible Reasons:

1. Your site was hacked and this is the most common reason. Someone had modified files in your site and maybe put the injected code.
2. One of your backlink or website’s link is reported as a bad link or maybe having the malicious code.

Findings:
When i opened my google webmaster tool, It shows “This site may be distributing malware.”
Problematic URLs shows that the websites has the suspected injected code.

Solutions and Actions:
1. Find and remove the suspected injected code in the website or blog.
2. After you have removed all harmful code from your site and addressed the underlying vulnerability that caused it to be compromised, you can request a review of your site from google webmaster tool.