Thursday, 26 January 2017

Logical Volume Manager (LVM)

Below is the Practical steps of LVM concept:

1. Create 3 partition of size 200MB, 300MB, and 400MB

2. Convert the partition into physical volumes

3. Combine the first 2 physical volumes (200MB, and 300MB)
   into a volume group.

4. Create a logical volume from this volume group of size 450MB.

****************************************************
Last login: Tue Mar  8 21:45:12 2016 from 192.168.224.1
[root@keshavkummari ~]#
[root@keshavkummari ~]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a1858

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39         914     7031808   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3             914        1045     1048576   82  Linux swap / Solaris

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb6683521

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          14      112423+  83  Linux
/dev/sdb2              15          15        8032+  83  Linux
/dev/sdb3              16          16        8032+  83  Linux

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xde3e26fe

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1           1        8001   83  Linux
[root@keshavkummari ~]#
[root@keshavkummari ~]# fdisk /dev/sdc

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (2-130, default 2):
Using default value 2
Last cylinder, +cylinders or +size{K,M,G} (2-130, default 130): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (28-130, default 28):
Using default value 28
Last cylinder, +cylinders or +size{K,M,G} (28-130, default 130): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (54-130, default 54):
Using default value 54
Last cylinder, +cylinders or +size{K,M,G} (54-130, default 130): +300M

Command (m for help): p

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xde3e26fe

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1           1        8001   83  Linux
/dev/sdc2               2          27      208845   83  Linux
/dev/sdc3              28          53      208845   83  Linux
/dev/sdc4              54          92      313267+  83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@keshavkummari ~]# partprobe /dev/sdc



*********************************************************
Step 1: Create physical volumes:
Syntax: pvcreate <partition1> <partition2> <partition3>
*********************************************************
[root@keshavkummari ~]# pvcreate /dev/sdc2 /dev/sdc3 /dev/sdc4
  Physical volume "/dev/sdc2" successfully created
  Physical volume "/dev/sdc3" successfully created
  Physical volume "/dev/sdc4" successfully created


*********************************************************
Step 2: To see the physical volumes:
*********************************************************
[root@keshavkummari ~]# pvdisplay  or pvs
  "/dev/sdc2" is a new physical volume of "203.95 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc2
  VG Name
  PV Size               203.95 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               XGcKMj-T11u-kZ4d-N2UA-NdrJ-cuNI-oE3Ttp

  "/dev/sdc3" is a new physical volume of "203.95 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc3
  VG Name
  PV Size               203.95 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               4xWrEA-zhpS-6KII-5kOb-jO21-9mGF-Pzlwgg

  "/dev/sdc4" is a new physical volume of "305.93 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc4
  VG Name
  PV Size               305.93 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               aqKZ8V-nniQ-4pUS-OfwY-jKmm-CktX-pcCVB4

*********************************************************
Step 3: Create a volume group
Syntax: vgcreate <volume_group_name> <physical_volume1> <physical_volume2>

*********************************************************
 
[root@keshavkummari ~]# vgcreate data /dev/sdc2 /dev/sdc3
  Volume group "data" successfully created

*********************************************************
Step 4: To see the volume group :
*********************************************************
 
[root@keshavkummari ~]# vgdisplay
  --- Volume group ---
  VG Name               data
  System ID
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               400.00 MiB
  PE Size               4.00 MiB
  Total PE              100
  Alloc PE / Size       0 / 0
  Free  PE / Size       100 / 400.00 MiB
  VG UUID               S5L3xc-tasb-JL69-jPNG-gRib-lSfA-Kw1s3y


*********************************************************
Step 5: Create a logical volume
Syntax: lvcreate -L <size> <volume_group_name> -n <logical volume name>

*********************************************************

[root@keshavkummari ~]# lvcreate -L 150mb data -n backupdata
  Rounding up size to full physical extent 152.00 MiB
  Logical volume "backupdata" created

*********************************************************
Step 6: To see the logical volume:
*********************************************************
 
[root@keshavkummari ~]# lvdisplay  or lvs
  --- Logical volume ---
  LV Path                /dev/data/backupdata
  LV Name                backupdata
  VG Name                data
  LV UUID                tcOHbt-MTDv-jVgV-ftgC-mVfa-SySR-PW5Ye9
  LV Write Access        read/write
  LV Creation host, time keshavkummari.localdomain, 2016-03-08 23:30:07 -0800
  LV Status              available
  # open                 0
  LV Size                152.00 MiB
  Current LE             38
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

*********************************************************
Step 7: Format the logical volume and mount it:
*********************************************************

[root@keshavkummari ~]# mkfs.ext3 /dev/data/backupdata
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
38912 inodes, 155648 blocks
7782 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
19 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@keshavkummari ~]# mkdir /backup
[root@keshavkummari ~]# mount /dev/data/backupdata /backup/

*********************************************************
Step 8:
1. The size of the logical volume is to be increased by 400MB.
2. The volume group does not have sufficient free space.
So first extend the volume group.

Extending the volume group:
Syntax: vgextend <volume_group_name> <physical_volume_name>

*********************************************************

[root@keshavkummari ~]# vgextend data /dev/sdc3
  Physical volume '/dev/sdc3' is already in volume group 'data'
  Unable to add physical volume '/dev/sdc3' to volume group 'data'.

*********************************************************
Step 9: Resizing the logical value:
Syntax: lvresize -L <+size> <logical_volume_name>

*********************************************************
To extend the logical volume by 200MB:
 
[root@keshavkummari ~]# lvresize -L +200M /dev/data/backupdata
  Extending logical volume backupdata to 352.00 MiB
  Logical volume backupdata successfully resized

Resize the filesystem:
**********************
 
[root@keshavkummari ~]# resize2fs /dev/data/backupdata
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/data/backupdata is mounted on /backup; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/data/backupdata to 360448 (1k) blocks.
The filesystem on /dev/data/backupdata is now 360448 blocks long.

*********************************************************
Step 10: To see the logical volume:
*********************************************************

[root@keshavkummari ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/data/backupdata
  LV Name                backupdata
  VG Name                data
  LV UUID                tcOHbt-MTDv-jVgV-ftgC-mVfa-SySR-PW5Ye9
  LV Write Access        read/write
  LV Creation host, time keshavkummari.localdomain, 2016-03-08 23:30:07 -0800
  LV Status              available
  # open                 1
  LV Size                352.00 MiB
  Current LE             88
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

*********************************************************
Step 11: Removing the logical volume:
Syntax: lvremove <logical_volume_name>
*********************************************************
 
[root@keshavkummari ~]# umount /backup/
[root@keshavkummari ~]# lvremove /dev/data/backupdata
Do you really want to remove active logical volume backupdata? [y/n]: n
  Logical volume backupdata not removed
Note: If "y"
then : Logical volume backupdata has been  removed successfully.


*********************************************************

NOTE : LVREDUCE IS NOT WORK WITH XFS FILES SYSTEM

Stpe 12: Reducing Logical Volume (LVM)
*********************************************************
To Reduce a logical volume there are 5 steps needed to be done very carefully.

While extending a volume we can extend it while the volume under mount status (online),
but for reduce we must need to unmount the file system before reducing.

5 steps below:

1. unmount the file system for reducing.
[root@keshavkummari ~]# umount /backup/

2. Check the file system after unmount.
[root@keshavkummari ~]# e2fsck -ff /dev/data/backupdata

[root@server ~]# e2fsck -ff /dev/data/backupdata
e2fsck 1.42.9 (28-Dec-2013)
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/data/backupdata: 11/13328 files (9.1% non-contiguous), 6823/53248 blocks

Note: Must pass in every 5 steps of file-system check if not there might be
some issue with your file-system.

3. Reduce the file system.

[root@server ~]# resize2fs /dev/data/backupdata
resize2fs 1.42.9 (28-Dec-2013)
The filesystem is already 53248 blocks long.  Nothing to do!

4. Reduce the Logical Volume size than Current size.
[root@server ~]# lvreduce -L -20M  /dev/data/backupdata
Logical volume lvm-minnu successfully resized

5. Recheck the file system for error.
[root@server ~]# e2fsck -ff /dev/data/backupdata

6. Remount the file-system back to stage.
[root@server ~]# mount /dev/data/backupdata /backup

******************** Keshav Kummari ******************** 

RHCSA & RHCE Lab Environment Details

RHCSA & RHCE Lab Details:
*************************

Open a terminal in foundation and check below details:

# hostname
foundation0.ilt.example.com

#ifconfig
172.25.254.250
***************************************************
Now, in the terminal of foundation, issue below command to reset "Server" & "Desktop":

# rht-vmctl fullreset server
# rht-vmctl fullreset desktop
or
# rht-vmctl fullreset all
Note: Above command will reset at time "server & desktop".

To start "server & desktop":

# rht-vmctl start server
# rht-vmctl start desktop
or
# rht-vmctl start all
Note: Above command will start at time "server & desktop".

To view or bring graphical window in foreground:

# rht-vmctl view server
# rht-vmctl view desktop
or
# rht-vmctl view all
Note: Above command will bring "server & desktop" to foreground at time.

***************************************************
Go to server and desktop and check "hostname" and "ipaddress":
Open a terminal in server:
# hostname
server0.example.com

# ifconfig
172.25.0.11

Open a terminal in desktop:
# hostname
desktop0.example.com

# ifconfig
172.25.0.10

***************************************************
Now, go to foundation and open terminal and try connecting "server & desktop":

Server steps:
# ssh root@server0
or
# ssh root@server0.example.com
or
# ssh root@172.25.0.11

To come out from the server:
# exit

Desktop steps:
# ssh root@desktop0
or
# ssh root@desktop0.example.com
or
# ssh root@172.25.0.10

To come out from the desktop:
# exit

***************************************************
Now, go to "server" and try to connect "foundation":
# ssh root@foundation0.ilt.example.com
or
# ssh root@172.25.254.250

To come out from the "foundation":
# exit


Now, go to "desktop" and try to connect "foundation":
# ssh root@foundation0.ilt.example.com
or
# ssh root@172.25.254.250

To come out from the "foundation":
# exit
******************** Keshav Kummari *******************************

LOCAL YUM REPOSITORY CREATION IN LINUX (Distributions - Redhat/Centos & Versions - 4 / 5 / 6 & 7)


Step 1: Now, check the mounted dvd or iso details in the server:

[root@onlineucator ~]# df -TH
If it is not showing,
then >> go to >> vmware >> settings >> cd/dvd >> add iso

After adding iso then check the details and mount as below:
[root@onlineucator ~]# df -TH

[root@onlineucator ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only


Step 2: Now, create directory :

[root@onlineucator ~]# mkdir /rhel7


Step 3: Now, go to mounted directory:

[root@onlineucator ~]# cd /mnt/Packages/

Copy the files from /mnt/Packages/* to "/rhel7" directory:

Note: * means all files

[root@onlineucator Packages]# cp -prv * /rhel7/  

Cross check the size of the copied files:

[root@onlineucator Packages]# du -sh /rhel7/
3.1G    /rhel7/
------------------------------------------------------------

Step 4: Go to mounted path "/mnt/repodata/" and copy a file "76a190afa1c59e14d3a03f9b03c3eee31df0099f1193528ebb87d4d493d2b686-comps-Server.x86_64.xml /rhel7/comps-Server.x86_64.xml" to "/rhel7":

Step 5: Copy a file from "/rhel7/repodata/" and rename as below in "rhel7":
[root@onlineucator mnt]# cp -pv /mnt/repodata/76a190afa1c59e14d3a03f9b03c3eee31df0099f1193528ebb87d4d493d2b686-comps-Server.x86_64.xml /rhel7/comps-Server.x86_64.xml
------------------------------------------------------------

Step 6: Now, we need to install "createrepo" package.

Search below ".rpm" in "/rhel7/" directory:

ls -l deltarpm-3.6-3.el7.x86_64.rpm
ls -l python-deltarpm-3.6-3.el7.x86_64.rpm
ls -l createrepo-0.9.9-23.el7.noarch.rpm

Now, we need to install above 3 ".rpm" packages:

[root@onlineucator rhel7]# rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm
warning: deltarpm-3.6-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:deltarpm-3.6-3.el7               ################################# [100%]

[root@onlineucator rhel7]# rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm
warning: python-deltarpm-3.6-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:python-deltarpm-3.6-3.el7        ################################# [100%]

[root@onlineucator rhel7]# rpm -ivh createrepo-0.9.9-23.el7.noarch.rpm
warning: createrepo-0.9.9-23.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:createrepo-0.9.9-23.el7          ################################# [100%]


Step 7: Create the repo database:

[root@onlineucator rhel7]# createrepo -vg comps-Server.x86_64.xml /rhel7/


Step 8: Now, go to following path "/etc/yum.repos.d/", 
and create a file and add the details as below: 

# vim test.repo

[rhel7_dvd]
name=test.repo
baseurl=file:///rhel7/
gpgcheck=0
enable=1

Step 9: Now, check the "yum" configuration:

[root@onlineucator ~]# yum clean all

[root@onlineucator ~]# yum group list

Try to install any one package and cross check your yum configuration:

[root@onlineucator ~]# yum install telnet* -y

Note: If you have installed the CUI server, then install "GUI" packages:

[root@onlineucator ~]# yum group list

[root@onlineucator ~]# yum group install "Server with GUI" -y

Now, restart the server, then your PC will load in GUI mode.

*************************** Keshav Kummari ***************************

RECOVER ROOT USER PASSWORD - LINUX

*************************************************************************
How to reset the root password on RHEL 7 ?
*************************************************************************

Here we will see that how we can recover the lost root password on RHEL 7.

1. Reboot the system .

left hand >> with fingers >> one you have hold ctrl button and other one is alt button press together and release it >> and select the mouse on the screen and press e button when you see kernel


2. In the grub menu, press escape key to prevent the system from booting.
Edit the grub menu by pressing “e” .

3. Press the arrow keys to get the “linux16” line and press “end” key.
This will take you to the end of the line.
Here add "rd.break" or "rd.break  console=tty1"  and
Press control-x to boot the system.

4. You will get the “switch-root” prompt like below.

5. When you boot the system using “rd.break”,
system will be directly mounted on /sysroot in read-only mode.
Let me remount it in read/write mode.

switch_root:/# mount -o remount,rw /sysroot

6. Switch into a chroot jail, where /sysroot is treated as the root of the filesystem tree.

switch_root:/# chroot /sysroot

7. Set the new root password. (please update the CMDB immediately !)

sh-4.2# passwd root
New password:
Retype new password:
passwd:all authentication tokens updated successfully.

8.By default, SE-Linux will be enabled on RHEL7.
So create a blank file with the a name of “.autorelabel” under root.

sh-4.2# touch /.autorelabel

9. Exit from the chroot jail and exit from the initramfs.

10. System will reboot and perform a full SELinux relabel, then  reboot again.

11. once the system is rebooted,
you will be able to login with new root password which you have set it .

************************* Keshav Kummari *****************************