Tuesday, November 17, 2015

git - demonstrating merge conflict management : Merge conflict - Automatic merge failed

Let us take example of Romeo and Juliet love story. They decided to write their story.


PART-1: Initial draft of Romeo and Juliet story in master branch


--All big Love stories start with a tiny story !

$ git branch
* master


--This is initial short story

$ cat >story.txt
Romeo and Juliet are writting their love story
Love is ever lasting and Life is not
Our soul had been together and will remain always
As we are not Two, we are one ...
^D
$
$ git status
# On branch master
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       story.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       new file:   story.txt
#

$ git commit -m "Romeo and Juliet - our story - first draft"
[master 978e583] Romeo and Juliet - our story - first draft
 1 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100644 story.txt
$ git log
* 978e583 (HEAD, master) Romeo and Juliet - our story - first draft
* 52d4c41 inital repo - commit zero
$ cat -n story.txt
     1  Romeo and Juliet are writting their love story
     2  Love is ever lasting and Life is not
     3  Our soul had been together and will remain always
     4  As we are not Two, we are one ...
$



PART-2: Romeo and Juliet - updated their stories separately


Fact is, no two people think say way, even they Love each other like Romeo and Juliet ! So, both have updated story, in their own way.

--from master branch, Romeo has created a branch

$ git checkout -b romeo_branch
Switched to a new branch 'romeo_branch'


--from master branch, Juliet create another branch

$ git checkout master
Switched to branch 'master'
$ git checkout -b juliet_branch
Switched to a new branch 'juliet_branch'
$
$ git branch
* juliet_branch
  master
  romeo_branch


--Juliet did following changes and did commit
  --On line 2, replaced 'not' with 'temporary'
  --Added a line 5 at the end of story 'World see us seprate but we do not feel so ..'

$ vi story.txt
$ git add .
$ git commit -m "Juliet - modified line 2 and added line 5"
[juliet_branch 4ffd429] Juliet - modified line 2 and added line 5
 1 files changed, 2 insertions(+), 1 deletions(-)
$ cat -n story.txt
     1  Romeo and Juliet are writting their love story
     2  Love is ever lasting and Life is temporary
     3  Our soul had been together and will remain always
     4  As we are not Two, we are one ...
     5  World see us seprate but we do not feel so ..
$


--Romeo did following change and did commit

  --On line 2, appended 'permanent' after last word 'not'
  --Added a line 5 at the end of story 'Does life have any meaning without love ?!'

$ git checkout romeo_branch
$ vi story.txt
$ git add .
$ git commit -m "Romeo - modified line 2 and added line 5"
[romeo_branch c990508] Romeo - modified line 2 and added line 5
 1 files changed, 2 insertions(+), 1 deletions(-)
$
$ cat -n story.txt
     1  Romeo and Juliet are writting their love story
     2  Love is ever lasting and Life is not permanent
     3  Our soul had been together and will remain always
     4  As we are not Two, we are one ...
     5  Does life have any meaning without love ?!



PART-3 : Conflict in story - Yep, even lovers need to know how to manage conflict !


--Understand existing commits:

$ git log
* c990508 (HEAD, romeo_branch) Romeo - modified line 2 and added line 5
| * 4ffd429 (juliet_branch) Juliet - modified line 2 and added line 5
|/
* 978e583 (master) Romeo and Juliet - our stries - first draft
* 52d4c41 inital repo - commit zero


978e583 is common ancestor - parent. From this parent, 2 child commits 4ffd429 and c990508.


--Romeo, time to time, merge stories and update master branch. Romeo, merge Juliet story on top of his own story. And, merge failed !!

$ git co romeo_branch
Switched to branch 'romeo_branch'
$ git merge juliet_branch
Auto-merging story.txt
CONFLICT (content): Merge conflict in story.txt
Automatic merge failed; fix conflicts and then commit the result.
$ git s
# On branch romeo_branch
# Unmerged paths:
#   (use "git add/rm ..." as appropriate to mark resolution)
#
#       both modified:      story.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
$
$ cat story.txt
Romeo and Juliet are writting their love story
<<<<<<< HEAD
Love is ever lasting and Life is not permanent
Our soul had been together and will remain always
As we are not Two, we are one ...
Does life have any meaning without love ?!
=======
Love is ever lasting and Life is temporary
Our soul had been together and will remain always
As we are not Two, we are one ...
World see us seprate but we do not feel so ..
>>>>>>> juliet_branch
$


--what does it mean :
   -There is no conflict in line 1 - all good
   -HEAD is pointer to branch where you are. In this care HEAD is pointing to romeo_branch
   -git says that
       --line betweeen <<<<<<< and ======= are from the file in present branch ( HEAD that is romeo_branch)
       --line between ======= and >>>>>>> are from ther branch you are mearging ( that is - juliet_branch)


--Rome dicidess to fix conflicts following way :
  -delete line <<<<<<< , ======= and >>>>>>>
  -Combine feelings of both and update line 2 as
        "Love is ever lasting and Life is not permanent, it is temporary"
   -Keep last line of both - so it will make line 5 and line 6


-- Final story after manually editing file is :

$ cat -n story.txt
     1  Romeo and Juliet are writting their love story
     2  Love is ever lasting and Life is not permanent, it is temporary
     3  Our soul had been together and will remain always
     4  As we are not Two, we are one ...
     5  Does life have any meaning without love ?!
     6  World see us seprate but we do not feel so ..
$


--Finally, commit it - new commit is 9dc72f2 - new commit have ha been created by merging Juliet's commit 4ffd429 on top of Romeo's old commit c990508

$ git status
# On branch romeo_branch
# Unmerged paths:
#   (use "git add/rm ..." as appropriate to mark resolution)
#
#       both modified:      story.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
$
$ git add .
$ git commit -m "Romeo and Juliet combined story"
[romeo_branch 9dc72f2] Romeo and Juliet combined story
$


--how does commit log looks like ?

$ git log
*   9dc72f2 (HEAD, romeo_branch) Romeo and Juliet combined story
|\
| * 4ffd429 (juliet_branch) Juliet - modified line 2 and added line 5
* | c990508 Romeo - modified line 2 and added line 5
|/
* 978e583 (master) Romeo and Juliet - our stries - first draft
* 52d4c41 inital repo - commit zero



PART-4 - Finally merge Romeo branch onto master


$ git checkout master
Switched to branch 'master'
$
$ git merge romeo_branch
Updating 978e583..9dc72f2
Fast-forward
 story.txt |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
$

--It is hassle free, Fast-forward merge
    -Fast-forward - No conflict while mearging - hence move (master) from second last line ( common ancesotor) to top line.

$ git log
*   9dc72f2 (HEAD, romeo_branch, master) Romeo and Juliet combined story
|\
| * 4ffd429 (juliet_branch) Juliet - modified line 2 and added line 5
* | c990508 Romeo - modified line 2 and added line 5
|/
* 978e583 Romeo and Juliet - our stries - first draft
* 52d4c41 inital repo - commit zero
$


--Get rid of romeo_branch and juliet_branch.

$ git branch -D romeo_branch juliet_branch
Deleted branch romeo_branch (was 9dc72f2).
Deleted branch juliet_branch (was 4ffd429).
$ git branch
* master 9dc72f2 Romeo and Juliet combined story



--Love stories have no end - so Romeo and Juliet will create a new branch from master branch and repeat this whole cycle - again and again!



Reference :  https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Tuesday, November 10, 2015

keytool - deleting and installing SSL certificate in java certificate store

keytool  is Key and Certificate Management Tool. It is provided by development  package e.g. java-1.6.0-sun-devel-1.6.0.85-1jpp.2.el6.x86_64

Java KeyStore file is /etc/alternatives/java_sdk/jre/lib/security/cacerts (/etc/alternatives/java_sdk is link to default java base directory e.g. /usr/lib/jvm/java-1.6.0-sun.x86_64/ ). keytool utility is used to interact with this binary keystore database file.


How to find currently installed certificate, delete a certificate and import new one



--find existing certificate alias

# keytool -keystore /etc/alternatives/java_sdk/jre/lib/security/cacerts  -list \
 -storepass changeit


--delete an exising alias

$ keytool -keystore /etc/alternatives/java_sdk/jre/lib/security/cacerts  -delete \
 -alias  -storepass changeit


--import a certificate

$ keytool -import -noprompt -trustcacerts \
 -alias  \
 -file /var/tmp/your.company.com.crt \
 -keystore /etc/alternatives/java_sdk/jre/lib/security/cacerts \
 -storepass changeit


--display details of certificate

$ keytool -list -v -keystore /etc/alternatives/java_sdk/jre/lib/security/cacerts  \
 -alias   
 -storepass changeit


(changeit - your keystore password)


Reference:

https://www.sslshopper.com/article-most-common-java-keytool-keystore-commands.html

Monday, November 2, 2015

Extend logical drive of HP Smart Array P410i using hpacucli by adding a new SAS disk

I have an RAID5 Logical Disk. So, add a new disk of same size of existing disk. ( Note: If disk size is larger than others as in 2I:1:5 - 600 GB - only 300 GB will be used, rest is not usable)


--Add a 300GB hot plug SAS disk into one of emply bay. After few seconds, Smar Array controller -detects a new 'unassigned' disk - 2I:1:6

# hpacucli ctrl all show config

Smart Array P410i in Slot 0          (sn: 5001438013123456)

   array A (SAS, Unused Space: 0 MB)

      logicaldrive 1 (1.1 TB, RAID 5, OK)

      physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 300 GB, OK)
      physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 300 GB, OK)
      physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 300 GB, OK)
      physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 300 GB, OK)
      physicaldrive 2I:1:5 (port 2I:box 1:bay 5, SAS, 600.1 GB, OK)

   unassigned

      physicaldrive 2I:1:6 (port 2I:box 1:bay 6, SAS, 300 GB, OK)



--Add all unassigned disk in Logical Drive 1 ( logicaldrive 1 size is 1.1 TB) by specifying logical drive id

# hpacucli ctrl slot=0 ld 1 add drives=allunassigned



--Extend Smart Array Logical Drive. ( I have tested on RHEL 5.8)

# hpacucli ctrl slot=0 ld 1 modify size=max

Warning: Extension may not be supported on certain operating systems.
         Performing extension on these operating systems can cause data to
         become inaccessible. See ACU documentation for details. Continue?
         (y/n) y



--Is logical drive extended ? Yes, it is extended from 1.1 TB to 1.4 TB.

# hpacucli ctrl all show config

Smart Array P410i in Slot 0          (sn: 5001438013EDECA0)

   array A (SAS, Unused Space: 0 MB)

      logicaldrive 1 (1.4 TB, RAID 5, OK)

      physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 300 GB, OK)
      physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 300 GB, OK)
      physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 300 GB, OK)
      physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 300 GB, OK)
      physicaldrive 2I:1:5 (port 2I:box 1:bay 5, SAS, 600.1 GB, OK)
      physicaldrive 2I:1:6 (port 2I:box 1:bay 6, SAS, 300 GB, OK)



--OS will now recognize new size of disk as 1499.8 GB. Let us extend last partition to use recently added 300GB. Delete second partition and extend it in single session. It will alter partition table in MBR. Change ending secotor to new sector that is bigger than older one.
   [ CAUTION - below delete and extend operation MUST be done in single fdisk session and write operation MUST be only once at the end ]

# fdisk /dev/cciss/c0d0

Disk /dev/cciss/c0d0: 1499.8 GB, 1499830990848 bytes
255 heads, 63 sectors/track, 182344 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          33      265041   83  Linux
/dev/cciss/c0d0p2              34      145875  1171475865   83  Linux


Command (m for help): d
Partition number (1-4): 2

Command (m for help): p

Disk /dev/cciss/c0d0: 1499.8 GB, 1499830990848 bytes
255 heads, 63 sectors/track, 182344 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          33      265041   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (34-182344, default 34):
Using default value 34
Last cylinder or +size or +sizeM or +sizeK (34-182344, default 182344):
Using default value 182344

Command (m for help): p

Disk /dev/cciss/c0d0: 1499.8 GB, 1499830990848 bytes
255 heads, 63 sectors/track, 182344 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          33      265041   83  Linux
/dev/cciss/c0d0p2              34      182344  1464413107+  83  Linux



--New End for partition is now 182344 (older was 145875 ). So partition is extended.

# fdisk -l /dev/cciss/c0d0

Disk /dev/cciss/c0d0: 1499.8 GB, 1499830990848 bytes
255 heads, 63 sectors/track, 182344 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          33      265041   83  Linux
/dev/cciss/c0d0p2              34      182344  1464413107+  83  Linux



--Did you mess up anything ? If yes, you are gone ! Filesystems may be gone or corrupt. If file list complete sucessully, you  are out of risk now !

# ls -lR /u01



--Now, resize PV and extend LV, resize filesystem

# df -hP /u01
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/volume_grp-u01vol  783G  452G  291G  61% /u01

# pvs /dev/cciss/c0d0p2
  PV                VG         Fmt  Attr PSize   PFree
  /dev/cciss/c0d0p2 volume_grp lvm2 a-   837.81G    0

# pvresize /dev/cciss/c0d0p2
  Physical volume "/dev/cciss/c0d0p2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

# pvs /dev/cciss/c0d0p2
  PV                VG         Fmt  Attr PSize PFree
  /dev/cciss/c0d0p2 volume_grp lvm2 a-   1.09T 279.38G

# pvscan
  PV /dev/cciss/c0d0p2   VG volume_grp   lvm2 [1.09 TB / 279.38 GB free]
  Total: 1 [1.09 TB] / in use: 1 [1.09 TB] / in no VG: 0 [0   ]


# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "volume_grp" using metadata type lvm2

#    vgs volume_grp
  VG         #PV #LV #SN Attr   VSize VFree
  volume_grp   1   5   0 wz--n- 1.09T 279.38G

# lvextend -L +20G /dev/mapper/volume_grp-root_volume
  Extending logical volume root_volume to 21.94 GB
  Logical volume root_volume successfully resized


--Resize filesystems 

# resize2fs /dev/mapper/volume_grp-root_volume
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/volume_grp-root_volume is mounted on /; on-line resizing required
Performing an on-line resize of /dev/mapper/volume_grp-root_volume to 5750784 (4k) blocks.
The filesystem on /dev/mapper/volume_grp-root_volume is now 5750784 blocks long.

# df -hP /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/volume_grp-root_volume   22G  1.6G   19G   8% /
#


Reference: Hpacucli Utility for Linux - All Commands Guide

http://h20565.www2.hpe.com/hpsc/doc/public/display?sp4ts.oid=435422&docId=emr_na-c03493210&docLocale=en_US

Sunday, November 1, 2015

How to find ALL available versions of a package in yum repository?


--I have 1.6.0-sun-1.6.0.45-1jpp.1.el5_9 version of java installed on my systems

# rpm -q java-1.6.0-sun
java-1.6.0-sun-1.6.0.45-1jpp.1.el5_9



--I need to downgrade or upgrade to specific version of java-1.6.0-sun. Now I need to find what i have in my repository.Simple list and search does not help here.

  --Command list       : show installed version and most recent version (for all arch).
  --Command search : shows all package matching with search string - demo, develp, src, jdbc etc.


# yum list java-1.6.0-sun
Installed Packages
java-1.6.0-sun.x86_64             1:1.6.0.45-1jpp.1.el5_9                    installed
Available Packages
java-1.6.0-sun.i586               1:1.6.0.81-1jpp.1.el5_10                   rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64             1:1.6.0.81-1jpp.1.el5_10                   rhel-x86_64-5-oracle_java
#
#
# yum search  java-1.6.0-sun
============= Matched: java-1.6.0-sun ===================
java-1.6.0-sun.x86_64 : Sun Java Runtime Environment
java-1.6.0-sun.i586 : Sun Java Runtime Environment
java-1.6.0-sun-demo.x86_64 : Demonstration files for Sun JDK
java-1.6.0-sun-demo.i586 : Demonstration files for Sun JDK
java-1.6.0-sun-devel.x86_64 : Sun Java Development Kit
java-1.6.0-sun-devel.i586 : Sun Java Development Kit
java-1.6.0-sun-jdbc.x86_64 : Sun Java JDBC/ODBC bridge driver
java-1.6.0-sun-jdbc.i586 : Sun Java JDBC/ODBC bridge driver
java-1.6.0-sun-plugin.i586 : Sun Java browser plugin
java-1.6.0-sun-plugin.x86_64 : Sun Java browser plugin
java-1.6.0-sun-src.x86_64 : Source files for Sun JDK
java-1.6.0-sun-src.i586 : Source files for Sun JDK




--I need to use  list and search with --showduplicates  options.


# yum list   'java-1.6.0-sun' --showduplicates
Installed Packages
java-1.6.0-sun.x86_64   1:1.6.0.45-1jpp.1.el5_9     installed
Available Packages
java-1.6.0-sun.x86_64   1:1.6.0.5-1jpp.2.el5_1      rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.5-1jpp.2.el5_1      rhel-x86_64-server-supplementary-5
java-1.6.0-sun.x86_64   1:1.6.0.6-1jpp.1.el5        rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.6-1jpp.1.el5        rhel-x86_64-server-supplementary-5
      . . . . . .
java-1.6.0-sun.x86_64   1:1.6.0.25-1jpp.1.el5       rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.25-1jpp.1.el5       rhel-x86_64-server-supplementary-5
java-1.6.0-sun.i586     1:1.6.0.26-1jpp.1.el5       rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.26-1jpp.1.el5       rhel-x86_64-5-oracle_java
      . . . . . .
java-1.6.0-sun.x86_64   1:1.6.0.75-1jpp.3.el5_10    rhel-x86_64-5-oracle_java
java-1.6.0-sun.i586     1:1.6.0.81-1jpp.1.el5_10    rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.81-1jpp.1.el5_10    rhel-x86_64-5-oracle_java




# yum search   'java-1.6.0-sun' --showduplicates|less
================= Matched: java-1.6.0-sun ===================
1:java-1.6.0-sun-1.6.0.10-1jpp.2.el5.x86_64 : Sun Java Runtime Environment
1:java-1.6.0-sun-1.6.0.10-1jpp.2.el5.x86_64 : Sun Java Runtime Environment
1:java-1.6.0-sun-1.6.0.11-1jpp.1.el5.x86_64 : Sun Java Runtime Environment
1:java-1.6.0-sun-1.6.0.11-1jpp.1.el5.x86_64 : Sun Java Runtime Environment
      . . . . . .
1:java-1.6.0-sun-1.6.0.81-1jpp.1.el5_10.i586 : Sun Java Runtime Environment
1:java-1.6.0-sun-1.6.0.81-1jpp.1.el5_10.x86_64 : Sun Java Runtime Environment
      . . . . . .
      . . . . . .
1:java-1.6.0-sun-devel-1.6.0.10-1jpp.2.el5.x86_64 : Sun Java Development Kit
1:java-1.6.0-sun-devel-1.6.0.10-1jpp.2.el5.x86_64 : Sun Java Development Kit
      . . . . . .
1:java-1.6.0-sun-devel-1.6.0.81-1jpp.1.el5_10.i586 : Sun Java Development Kit
1:java-1.6.0-sun-devel-1.6.0.81-1jpp.1.el5_10.x86_64 : Sun Java Development Ki
      . . . . . .
      . . . . . .
1:java-1.6.0-sun-plugin-1.6.0.10-1jpp.2.el5.i586 : Sun Java browser plugin
1:java-1.6.0-sun-plugin-1.6.0.10-1jpp.2.el5.i586 : Sun Java browser plugin
      . . . . . .
1:java-1.6.0-sun-plugin-1.6.0.81-1jpp.1.el5_10.i586 : Sun Java browser plugin
1:java-1.6.0-sun-plugin-1.6.0.81-1jpp.1.el5_10.x86_64 : Sun Java browser plugin
      . . . . . .
      . . . . . .
1:java-1.6.0-sun-src-1.6.0.10-1jpp.2.el5.x86_64 : Source files for Sun JDK
1:java-1.6.0-sun-src-1.6.0.10-1jpp.2.el5.x86_64 : Source files for Sun JDK
      . . . . . .
1:java-1.6.0-sun-src-1.6.0.81-1jpp.1.el5_10.i586 : Source files for Sun JDK
1:java-1.6.0-sun-src-1.6.0.81-1jpp.1.el5_10.x86_64 : Source files for Sun JDK