Archive for the ‘RAID and LVM’ Category


Learn to create lvm inside RedHat Enterprise Linux. This tutorial is all about lvm creation in Linux and with creation we also learn how to delete lvm,how to delete volume group and how to delete physical volume in Linux. We learn the complete lvm creation and deletion process in just few simple steps.

For this LVM Lab we have total 5 Hard Drive /dev/sda ,dev/sdb,/dev/sdc ,/dev/sdd and /dev/sde


Out of these 5 only 4 Drives are taking part in this LVM Creation Lab

and those Drives are: /dev/sdb,/dev/sdc,/dev/sdd and /dev/sde

Related Articles for You:

How to extend size of LVM Disk

How to Reduce or shrink the size of LVM Disk

How to create and configure STRIPPED LOGICAL VOLUME in Linux

How to create and configure MIRRORED LOGICAL VOLUME in Linux

How to create and configure SNAPSHOT LOGICAL VOLUME in Linux

(more…)

Advertisements

We have already learnt how to increase the size of lvm using lvextend command in linux.But Now here in this tutorial we will learn the reverse process i.e how to Reduce the lvm size in linux and we will do this in few simple steps.So this is basically an example lab showing how to reduce size of lvm in linux.

reduce lvm size

STEP 1:Check the mounted file system using df -h

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 25G 2.1G 22G 9% /
tmpfs 1014M 0 1014M 0% /dev/shm
/dev/mapper/vg00-lv1 1.5G 34M 1.4G 3% /lvmdata
[root@localhost ~]#

STEP 2:Unmount the file system using umount command

[root@localhost ~]# umount /dev/mapper/vg00-lv1

STEP 3:Now run e2fsck command to check if any file system errors.

[root@localhost ~]# e2fsck -f /dev/mapper/vg00-lv1
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/vg00-lv1: 11/196608 files (9.1% non-contiguous), 14766/390144 blocks
[root@localhost ~]#

STEP 4:shrink size of /lvmdata to desire size whatever you want.

As you can see above i am going to reduce the size to 1G from 1.5 GB

[root@localhost ~]# resize2fs /dev/mapper/vg00-lv1 1G
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mapper/vg00-lv1 to 262144 (4k) blocks.
The filesystem on /dev/mapper/vg00-lv1 is now 262144 blocks long.

STEP5: Now reduce the size using lvreduce command

root@localhost ~]# lvreduce -L 1G /dev/mapper/vg00-lv1
 WARNING: Reducing active logical volume to 1.00 GB
 THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv1? [y/n]: y
 Reducing logical volume lv1 to 1.00 GB
 Logical volume lv1 successfully resized

STEP 6: Now for safer side check the file system error again.

[root@localhost ~]# e2fsck -f /dev/mapper/vg00-lv1
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/vg00-lv1: 11/131072 files (9.1% non-contiguous), 12805/262144 blocks
STEP 7: Now mount the file system and check the size.
[root@localhost ~]# mount /dev/mapper/vg00-lv1 /lvmdata/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 25G 2.1G 22G 9% /
tmpfs 1014M 0 1014M 0% /dev/shm
/dev/mapper/vg00-lv1 1008M 34M 934M 4% /lvmdata
[root@localhost ~]#
Hence now you can see we have successfully reduced the size of LVM.
root@localhost ~]# lvs
 LV VG Attr LSize Origin Snap% Move Log Copy% Convert
 lv1 vg00 -wi-ao 1.00G
[root@localhost ~]# lvdisplay
 --- Logical volume ---
 LV Name /dev/vg00/lv1
 VG Name vg00
 LV UUID gx22Pn-9YAe-th6G-jGw7-vD2X-Qhov-bi05Ox
 LV Write Access read/write
 LV Status available
 # open 1
 LV Size 1.00 GB
 Current LE 256
 Segments 2
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:0
[root@localhost ~]#


If you are working as a Linux System Admin then resizing the file system size is an important task for you and you must know that.Here in this tutorial we are going to learn how to increase or extend lvm partition size.As we all know LVM provides us the facility to increase or reduce the of partition.

So here we will learn to increase lvm size using lvextend command,but before that we will create lvm first and mount it so that it is ready for use.

STEP1: Create Physical Volumes using pvcreate command.

[root@localhost ~]# pvcreate /dev/sda{5,6,7}
 Physical volume "/dev/sda5" successfully created
 Physical volume "/dev/sda6" successfully created
 Physical volume "/dev/sda7" successfully created

now check the create physical volume using pvscan.

[root@localhost ~]# pvscan
 PV /dev/sda5 lvm2 [964.81 MB]
 PV /dev/sda6 lvm2 [964.81 MB]
 PV /dev/sda7 lvm2 [831.46 MB]
 Total: 3 [2.70 GB] / in use: 0 [0 ] / in no VG: 3 [2.70 GB]

STEP2: create Volume Group using vgcreate command

[root@localhost ~]# vgcreate vg00 /dev/sda{5,6,7}
 Volume group "vg00" successfully created
[root@localhost ~]# vgs
 VG #PV #LV #SN Attr VSize VFree
 vg00 3 0 0 wz--n- 2.69G 2.69G
[root@localhost ~]# pvscan
 PV /dev/sda5 VG vg00 lvm2 [964.00 MB / 964.00 MB free]
 PV /dev/sda6 VG vg00 lvm2 [964.00 MB / 964.00 MB free]
 PV /dev/sda7 VG vg00 lvm2 [828.00 MB / 828.00 MB free]
 Total: 3 [2.69 GB] / in use: 3 [2.69 GB] / in no VG: 0 [0 ]
 [root@localhost ~]#

STEP3: Create Logical Volume(lvm) name lv1 using lvcreate command.

[root@localhost ~]# lvcreate -L +1G -n lv1 vg00
 Logical volume "lv1" created
 [root@localhost ~]# lvs
 LV VG Attr LSize Origin Snap% Move Log Copy% Convert
 lv1 vg00 -wi-a- 1.00G
 [root@localhost ~]#
[root@localhost ~]# lvdisplay
 --- Logical volume ---
 LV Name /dev/vg00/lv1
 VG Name vg00
 LV UUID YYXZk0-bs6F-wE8z-88P3-f67R-G4vj-IrohD2
 LV Write Access read/write
 LV Status available
 # open 0
 LV Size 1.00 GB
 Current LE 256
 Segments 2
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:0
 [root@localhost ~]#
[root@localhost ~]# pvscan
 PV /dev/sda5 VG vg00 lvm2 [964.00 MB / 0 free]
 PV /dev/sda6 VG vg00 lvm2 [964.00 MB / 904.00 MB free]
 PV /dev/sda7 VG vg00 lvm2 [828.00 MB / 828.00 MB free]
 Total: 3 [2.69 GB] / in use: 3 [2.69 GB] / in no VG: 0 [0 ]
 [root@localhost ~]#

STEP4: Format and Mount it so that it is ready for use.

First format the file system using mkfs.ext3 command.

[root@localhost ~]# mkfs.ext3 /dev/vg00/lv1

Then create a directory to mount newly created File System.

[root@localhost ~]# mkdir /lvmdata
Now mount newly created file system using mount command to use.
[root@localhost ~]# mount /dev/vg00/lv1 /lvmdata

STEP5: View it’s size using lvs, lvdisplay or df -Th command.

[root@localhost ~]# df -h
 Filesystem Size Used Avail Use% Mounted on
 /dev/sda1 25G 2.1G 22G 9% /
 tmpfs 1014M 0 1014M 0% /dev/shm
 /dev/mapper/vg00-lv1 1008M 34M 924M 4% /lvmdata
 [root@localhost ~]#
[root@localhost ~]# lvs
 LV VG Attr LSize Origin Snap% Move Log Copy% Convert
 lv1 vg00 -wi-ao 1.00G
 [root@localhost ~]#

STEP6:Before making change to lvm check the free available space in the volume group “vg00”.

[root@localhost ~]# vgdisplay vg00
 --- Volume group ---
 VG Name vg00
 System ID
 Format lvm2
 Metadata Areas 3
 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 3
 Act PV 3
 VG Size 2.69 GB
 PE Size 4.00 MB
 Total PE 689
 Alloc PE / Size 256 / 1.00 GB
 Free PE / Size 433 / 1.69 GB
 VG UUID vBYPKn-9Bpk-jvK2-tc2e-e78U-V5jq-lgbcbZ
 [root@localhost ~]#

STEP7:Use lvextend command to increase the size of lvm named “lv1”

[root@localhost ~]# lvextend -L +500M /dev/vg00/lv1
 Extending logical volume lv1 to 1.49 GB
 Logical volume lv1 successfully resized

STEP8:check file system size using lvs or lvdisplay.

[root@localhost ~]# lvs
 LV VG Attr LSize Origin Snap% Move Log Copy% Convert
 lv1 vg00 -wi-ao 1.49G
 [root@localhost ~]#

You can see above output the file size increased here.

STEP9:Check Mounted file system size using df -h

[root@localhost ~]# df -Th
 Filesystem Type Size Used Avail Use% Mounted on
 /dev/sda1 ext3 25G 2.1G 22G 9% /
 tmpfs tmpfs 1014M 0 1014M 0% /dev/shm
 /dev/mapper/vg00-lv1
 ext3 1008M 34M 924M 4% /lvmdata
 [root@localhost ~]#

but you can see File system size not updated here because to update it we need to run resize2fs command.

STEP10:Run resize2fs command to resize the file system size.

[root@localhost ~]# resize2fs /dev/vg00/lv1
 resize2fs 1.39 (29-May-2006)
 Filesystem at /dev/vg00/lv1 is mounted on /lvmdata; on-line resizing required
 Performing an on-line resize of /dev/vg00/lv1 to 390144 (4k) blocks.
 The filesystem on /dev/vg00/lv1 is now 390144 blocks long.
 [root@localhost ~]#
STEP11: Again check mounted file system size using df -h.
[root@localhost ~]# df -h
 Filesystem Size Used Avail Use% Mounted on
 /dev/sda1 25G 2.1G 22G 9% /
 tmpfs 1014M 0 1014M 0% /dev/shm
 /dev/mapper/vg00-lv1 1.5G 34M 1.4G 3% /lvmdata
 [root@localhost ~]#

 In this tutorial we will learn how to manually fail a device used in raid and how to add a new to device to existing raid. we will also learn how to use spare device and how to stop and remove software raid completely from our linux machine. But before we starting removing any devices from existing  raid device first check the built topology of created raid.check the number of disk and name of disk used in raid as active device and find out the device name used as spare device using below linux command line tools. (more…)


This tutorial is all about software raid-1 creation in linux.We will learn how to configure software raid-1 in linux having spare devices.In this lab we are going to use RedHat Enterprise Linux 5 to configure software raid-1 with spare device.We use spare device as a reserved disk which is used only when any of disk used in raid-1 failed.

As we know RAID-1 needs minimum of two disk and when any of disk among those two failed or crashes spare device replaces itself with that failed device or disk.

raid1 configuration in linux

 

(more…)