UnixServerAdmin

Server Administration & Management

How to Shrink or reduce size of LVM partitons in RHEL/CentOS

1. Check disk partitions size

# df -hT

Filesystem    Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 ext3 34G 6.6G 26G 21% /
/dev/mapper/VolGroup00-LogVol03 ext3 34G 29G 27G 52% /usr
/dev/mapper/VolGroup00-LogVol04 ext3 97G 89G 2.7G 98% /var
/dev/sda1 ext3 99M 27M 67M 29% /boot
tmpfs tmpfs 56G 0 56G 0% /dev/shm
/dev/mapper/VolGroup00-LogVol02 ext3 56G 9.1G   65G 13% /backup

2. Unmount the partitions that want to shrink or reduce

# umount /dev/mapper/VolGroup00-LogVol02

3. Check a Linux ext2/ext3/ext4 file system partition.

# /sbin/e2fsck -f /dev/mapper/VolGroup00-LogVol02

e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found.  Create<y>? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup00-LogVol02: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/VolGroup00-LogVol02: 2887/20971520 files (14.9% non-contiguous), 3019764/20971520 blocks

4. Resize the partition to 30 GB

# /sbin/resize2fs -p /dev/mapper/VolGroup00-LogVol02 30G

resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mapper/VolGroup00-LogVol02 to 7864320 (4k) blocks.
Begin pass 2 (max = 1690914)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 640)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 201)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup00-LogVol02 is now 7864320 blocks long.

5. Reduce the size of a logical volume upto 30 GB

# /usr/sbin/lvreduce -L 30G /dev/mapper/VolGroup00-LogVol02

  WARNING: Reducing active logical volume to 30.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Do you really want to reduce LogVol02? [y/n]: y
  Reducing logical volume LogVol02 to 30.00 GB
  Logical volume LogVol02 successfully resized

6. Recheck  again, Linux ext2/ext3/ext4 file system partition.

# /sbin/e2fsck -f /dev/mapper/VolGroup00-LogVol02

e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup00-LogVol02: 2887/7864320 files (14.9% non-contiguous), 2606289/7864320 blocks

7. Resize the partition to 30 GB

# /sbin/resize2fs -p /dev/mapper/VolGroup00-LogVol02

resize2fs 1.39 (29-May-2006)
The filesystem is already 7864320 blocks long.  Nothing to do!

8. Now, Mount the partition.

# mount /dev/mapper/VolGroup00-LogVol02  /backup

9. Again, Check disk partitions size

# df -hT

Filesystem    Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 ext3 34G 6.6G 26G 21% /
/dev/mapper/VolGroup00-LogVol03 ext3 34G 29G 27G 52% /usr
/dev/mapper/VolGroup00-LogVol04 ext3 97G 89G 2.7G 98% /var
/dev/sda1 ext3 99M 27M 67M 29% /boot
tmpfs tmpfs 56G 0 56G 0% /dev/shm
/dev/mapper/VolGroup00-LogVol02 ext3 30G 9.1G   19G 33% /backup

Its Done !!!

October 30, 2013 Posted by | LVM, Tips & Tricks, Unix/Linux | , , , | Leave a comment

Difference between RAID and LVM

 S.No.  RAID  LVM
 1.  RAID is used for redundancy.  LVM is a way in which you partition the hard disk logically and it contains its own advantages.
 2.  A RAID device is a physical grouping of disk devices in order to create a logical presentation of one device to an Operating System for redundancy or performance or a combination of the two.  LVM is a logical layer that that can be anipulated in order to create and, or expand a logical presentation of a disk device to an Operating System.
 3.  RAID is a way to create a redundant or striped block device with redundancy using other physical block devices.  LVM usually sits on top of RAID blocks or even standard block devices to accomplish the same result as a partitioning, however it is much more flexible than partitions. You can create multiple volumes crossing multiple physical devices, remove physical devices without loosing data, resize the volumes, create snapshots, etc
 4.  RAID is either a software or a hardware technique to create data storage redundancy across multiple block devices based on required RAID levels.  LVM is a software tool to manage large pool of storage devices making them appear as a single manageable pool of storage resource. LVM can be used to manage a large pool of what we call Just-a-bunch-of-Disk (JBOD) presenting them as a single logical volume and thereby create various partitions for software RAID.
 5.  RAID is NOT any kind of Data backup solution. Its a solution to prevent one of the SPOFs (Single Point of Failure) i.e. DISK failure. By configuring RAID you are just providing an emergency substitute for the Primary disk. It NEVER means that you have configured DATA backup.  LVM is a disk management approach that allows us to create, extend, reduce, delete or resize the volume groups or logical volumes.

October 20, 2013 Posted by | LVM, RAID, Tips & Tricks, Unix/Linux | , , , | Leave a comment

How to add multiple IP range in RHEL/CentOS

For example, if you want to add the following different ip pool ranges in the server on the Ethernet port eth0. Here are few simple steps to add the ip pool ranges in few minutes.

IP Pool Block: 192.168.10.2-6
IP Pool Block: 192.168.10.10-14
IP Pool Block: 192.168.10.18-22
IP Pool Block: 192.168.10.26-30
IP Pool Block: 192.168.10.130-134

The above example has around 5 ranges with different ip sets. You can make use of the “ifcfg-eth0-rangeX” feature to get this done simply.

1. SSH the server as root Login.

# cd /etc/sysconfig/network-scripts/

2. Create a file named ifcfg-eth0-range0

# vim ifcfg-eth0-range0

Add the following lines as below to add the first set of range (ie..192.168.10.2-6)

ONBOOT=yes
IPADDR_START=192.168.10.2
IPADDR_END=192.168.10.6
NETMASK=255.255.255.248
CLONENUM_START=1

3. Save your works and exit. Restart the network service.

# /etc/init.d/network restart

4. To add the second range you need to create another file called “ifcfg-eth0-range1” with the CLONENUM_START start with 5 (setting up the number in CLONENUM_START is very important here to avoid the ip overwritten, as the first range will use up to the eth0:4 the second range should start with eth0:5 to work properly).

ONBOOT=yes
IPADDR_START=192.168.10.10
IPADDR_END=192.168.10.14
NETMASK=255.255.255.248
CLONENUM_START=5

5. Save your works and restart the network service. You can do the same for the other ip ranges left with carefully numbering the CLONENUM_START. Use the ifconfig command to check the eth0:X number everytime you restarts. After adding all the ranges, use ping to check the ips to make sure they are added properly.

ONBOOT=yes
IPADDR_START=192.168.10.10
IPADDR_END=192.168.10.14
NETMASK=255.255.255.248
CLONENUM_START=10

6. So on …

October 10, 2013 Posted by | Tips & Tricks, Unix/Linux | , , | Leave a comment