Tuesday, August 20, 2013

git - uncommiting last commit

--soft : uncommit all changes and move back to stage state



Create a new file, stage it (add), commit it and do soft reset HEAD^

$ git branch
* master

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

$ git log --graph --decorate --oneline -n3
* 3d1bb52 (HEAD, master, a_branch) Noh has build ship
* bb7ebab this is john sermon

$ cal 2013 > a_test_file.txt

$ git status
# On branch a_branch
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       a_test_file.txt

$ git add a_test_file.txt

$ git status
# On branch a_branch
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   a_test_file.txt
#

$ git commit -m"a new change commited in a_test_file.txt"
[a_branch c1a194c] a new change commited in a_test_file.txt
 1 files changed, 35 insertions(+), 0 deletions(-)
 create mode 100644 a_test_file.txt

$ git log --graph --decorate --oneline -n3
* c1a194c (HEAD, a_branch) a new change commited in a_test_file.txt
* 3d1bb52 (master) Noh has build ship
* bb7ebab this is john sermon

$ git reset --soft HEAD^

$ git log --graph --decorate --oneline -n3
* 3d1bb52 (HEAD, master, a_branch) Noh has build ship
* bb7ebab this is john sermon


$ git status
# On branch a_branch
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   a_test_file.txt
#


--hard : discard all changes permanently ! 

All new files will be deleted and modification to all file will disappear (you cannot recover !)

Commit newly created import file and do --hard reset to make your life hell !

$ git commit -m"a new change commited in a_test_file.txt"
[a_branch 8a59c62] a new change commited in a_test_file.txt
 1 files changed, 35 insertions(+), 0 deletions(-)
 create mode 100644 a_test_file.txt

$ git log --graph --decorate --oneline -n3
* 8a59c62 (HEAD, a_branch) a new change commited in a_test_file.txt
* 3d1bb52 (master) Noh has build ship
* bb7ebab this is john sermon

$ git reset --hard HEAD^
HEAD is now at 3d1bb52 Noh has build ship
$ git log --graph --decorate --oneline -n3
* 3d1bb52 (HEAD, master, a_branch) Noh has build ship
* bb7ebab this is john sermon


$ git status
# On branch a_branch
nothing to commit (working directory clean


You file has been permanently deleted by Mr   --hard !

Saturday, August 17, 2013

php-gd installation fails because of libjpeg.so.62 though it is installed

Problem : php-gd installation fails on rhel6 because of libjpeg.so.62 though libjpeg-6b-46.el6.x86_64 is installed.


# /usr/bin/yum -d 0 -e 0 -y install php-gd-5.3.3-22.el6
Error: Package: php-gd-5.3.3-22.el6.x86_64 (qa-redhat-x86_64-6-repository)
           Requires: libjpeg.so.62(LIBJPEG_6.2)(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
#rpm -qf /usr/lib64/libjpeg.so.62
libjpeg-6b-46.el6.x86_64



Solution : Install libjpeg-turbo along with other installed package since libjpeg-6b-4 is replaced with libjpeg-turbo

# yum install php-gd libjpeg-turbo


Referencehttps://access.redhat.com/site/solutions/324053

Did it help you ?

Thursday, August 15, 2013

xhost command hangs

Problem : On a unix system LinuxSystem below xhost command hangs forever.
   
         LinuxSystem # xhost +


Situation : You have already exported DISPLAY variable and some Xservers is already running on RemoteSystem
 
   LinuxSystem# export DISPLAY=RemoteSystem:0.0


Solution : xhost use outgoing tcp port 6000 to connect to RemoteSystem. Your firewall is blocking is. Run strace to confirm.

LinuxSystem# strace xhost + | tail -10
socket(PF_NETLINK, SOCK_RAW, 0)         = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=33705, groups=00000000}, [12]) = 0
sendto(3, "\24\0\0\0\26\0\1\3\361\256\rR\0\0\0\0\0\0\0\0", 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0\361\256\rR\251\203\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 20
close(3)                                = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0

connect(3, {sa_family=AF_INET, sin_port=htons(6000), sin_addr=inet_addr("RemoteSystem")}, 16 <unfinished ...>

Wednesday, August 14, 2013

git clone : "not a Gerrit project" OR "Could not read from remote repository" fatal error

First try to follow this document. If you are still  getting below error while you are cloning a git repo, it indicates that you or your group do not have permission (we are using gerrit to manage repository permission and code review) on repository.

$ git clone
ssh://UserName@MyGitServer.MyCompany.com:29418/MyGitRepo.git
Cloning into 'MyGitRepo'...
fatal: '/MyGitRepo.git': not a Gerrit project
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists
.

Surprisingly, below command shows that user is partof group that have rw permission.

$ id UserName|grep GroupNameOfUser
uid=512(UserName) gid=503(GroupNameOfUser)

BUT, query against  GroupNameOfUser on windows AD shows that it is not !

$ ldapsearch -h MyLDAPserver -p 389 -D 'CN=svc_UNIX_LDAP,OU=Standard Service Accounts,OU=Service Accounts,DC=MyCompany,DC=com' -w w82A4CCXq6A -x -b 'DC=MyCompany,DC=com' 'CN=GroupNameOfUser'


Solution : We were able to resolve it by removing user from group in AD and adding it again in the group. Run ldapsearch to crosscheck and did successful clone the repo. Is this page was useful for anyone ?

Thursday, May 2, 2013

TFTP - Fails with timeout

PROBLEM

On my Linux system:
* dhcp and tftp is running on same system  - tftp-dhcp-server
* tftp-dhcp-client is able to get IP address from DHCP server but tftp fails with below message

 $ tcpdump |grep ICMP

3:54:09.379106 IP tftp-dhcp-server > tftp-dhcp-client: ICMP host tftp-dhcp-server unreachable - admin prohibited, length 80
03:54:19.320800 IP tftp-dhcp-server > tftp-dhcp-client: ICMP host tftp-dhcp-server unreachable - admin prohibited, length 85
03:54:55.351027 IP tftp-dhcp-server > tftp-dhcp-client: ICMP host tftp-dhcp-server unreachable - admin prohibited, length 85

FIX
$ service iptables status
$ service iptablesstop
$ chkconfig iptables off

* If above did not help, checkif firewal is blocking tftp request.

Wednesday, February 20, 2013

Linux : Deleting Multiple Multipath Devices


How to delete multiple Linux DM-MPIO (Device Mapper - Multi Path IO ) devices from a Linux system?


From below command output, find wwid of multipath devices you want to remove and list them in a file.

  multipath -l |grep dm-
  vi /tmp/wwid_of_multipath_devices_to_delete.txt
  cat /tmp/wwid_of_multipath_devices_to_delete.txt


Verify the details of devices you are going to remove

  while read i ; do multipath -ll $i ; done </tmp/wwid_of_multipath_devices_to_delete.txt

Collect LUN's scsi ID of multipath devices you are going to delete
  
   while read i ; do
     multipath -l $i|grep -E "[0-9]{1,2}:{1,4}"|awk '{print $2}'|awk '{print $2}'
   done </tmp/wwid_of_multipath_devices_to_delete.txt | sort -u > /tmp/disks_scsi_id.txt
   cat /tmp/disks_scsi_id.txt


Ensure multipath devices are not used on system. Flush multipath device information

   multipath -ll > multipath-output-pre.txt
       multipath -ll | grep -E "$(cat wwid_of_multipath_devices_to_delete.txt |grep -v "^$"|tr '\n' '|')xxxxyyy"|awk '{print $1}' | tee multipath_disk_alias_name.txt
     cat multipath_disk_alias_name.txt
   while read i ; do
        multipath -f $i
        echo "$i flushed"
   done </tmp/multipath_disk_alias_name.txt
       multipath -ll > multipath-output-post.txt
       diff multipath-output-pre.txt multipath-output-post.txt 


Now they should NOT be seen in multipath output
  
    while read i ; do 
         multipath -ll $i
   done </tmp/wwid_of_multipath_devices_to_delete.txt

Delete LUN details from the Linux Kernel

   while read j ; do
     echo 1 > /sys/bus/scsi/drivers/sd/$j/delete
     echo "$j deleted"
   done </tmp/disks_scsi_id.txt


Delete the device information from /etc/multipath.conf

  cp -a /etc/multipath.conf /etc/multipath.conf.ORG
  vi /etc/multipath.conf


Restart multipathd and verify that the disks have been deleted and no more recognized by multipathd. Below should not list any device

  service multipathd restart
  while read i ; do multipath -ll |grep $i ; done </tmp/wwid_of_multipath_devices_to_delete.txt
  while read i; do ls -l /dev/mapper/|grep $i; done </tmp/wwid_of_multipath_devices_to_delete.txt


Unmask LUN from system on Storage SAN Switch/Frame


If you decide to add the LUNs again on same system, mask the LUN on system, rescan the BUS and add them in multipath.conf

  for i in $(ls /sys/class/scsi_host/) ; do echo - - - > /sys/class/scsi_host/$i/scan ; done
  service multipathd restart
  multiptah -ll | grep dm-
  vi /etc/multipath.conf
  service multipathd reload



References
http://www.kernel.org/doc/ols/2005/ols2005v1-pages-155-176.pdf
http://en.wikipedia.org/wiki/Linux_DM_Multipath


Saturday, February 16, 2013

Linux : Extending filesystem on expanded SAN LUN

An existing disk has been extended by +60GB to extend filesystem. To reduce operational risk, I'll recommend adding a new disk to extend VG and filesystem instead of increasing size of existing disk. Anyway, let us see howto do this ..


We will take three different cases when a Disk is expanded from 15 GB to 75GB

Case-1: Filesystem created on LV and PV is whole disk /dev/sdb

1.1 What is existing PV,VG,LV and filesystem size ?

# fdisk -l /dev/sdb

Disk /dev/sdb: 12.9 GB, 12890275840 bytes
5 heads, 37 sectors/track, 136088 cylinders
Units = cylinders of 185 * 512 = 94720 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4b38f4fe

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      136077    12587008   8e  Linux LVM
# df -hP /testfilesystem
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup02-Vol0201  4.0G  932M  2.9G  25% /testfilesystem
# vgs
  VG         #PV #LV #SN Attr   VSize  VFree
  VolGroup02   1   4   0 wz--n- 12.00g    0
# lvs
  LV      VG         Attr   LSize Origin Snap%  Move Log Copy%  Convert
  Vol0201  VolGroup02 -wi-ao 4.00g
# fdisk -l /dev/sdb|grep GB
Disk /dev/sdb: 12.9 GB, 12890275840 bytes
# pvs
  PV         VG         Fmt  Attr PSize  PFree
  /dev/sdb1  VolGroup02 lvm2 a-   12.00g    0


1.2 Expand the LUN.  Then rescan disk or HBA to allow kernel to know read new disk size

1.2.1 If there is only one path of disk
 # echo 1 > /sys/block/sdb/device/rescan

1.2.2 if disk there are multiple path of disk
 # for i in $(ls /sys/class/scsi_host/) ; do echo - - - > /sys/class/scsi_host/$i/scan ; done

1.3 Verify new size

# fdisk -l /dev/sdb|grep GB
Disk /dev/sdb: 75.2 GB, 75161927680 bytes
# grep -w capacity /var/log/messages
Apr 25 22:21:27 mysystem kernel: sdb: detected capacity change from 12890275840 to 75161927680


1.4 Resize PV and extend LV
  pvs /dev/sdb ( 15GB )
  pvresize /dev/sdb (resize PV from 15G to 65G)
  pvscan
  pvs /dev/sdb ( 65GB )
  vgscan
   vgs VolGroup02 
   lvextend -l +100%FREE /dev/VolGroup02/Vol0201

1.5. Extend filesystem

# df -hP /testfilesystem
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup02-Vol0201  4.0G  932M  2.9G  25% /testfilesystem
# resize2fs -p /dev/mapper/VolGroup02-Vol0201
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup02-Vol0201 is mounted on /testfilesystem; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/VolGroup02-Vol0201 to 16250880 (4k) blocks.
The filesystem on /dev/mapper/VolGroup02-Vol0201 is now 16250880 blocks long.

-Filesystem has been extended from 4GB to 62GB using all spaces of extended disk.
# df -hP /testfilesystem
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup02-Vol0201   62G  937M   58G   2% /testfilesystem



Case-2: Filesystem created on LV and PV is disk partition /dev/sdb1

Assuming a single partition (sdb1) was created on disk. We have 2 option here.

Option-2A:
Increase size of sdb1 to  cover new size. In thsi case, we nee to extend the partition before resizing PV. First execute 1.1 and 1.2.

2.1 This step will preserve your existing data, though be careful ! Delete existing partition and create a new primary to cover whole disk WITHOUT EXITING fdisk.  ( Key sequence - m, d, 1, n, p, 1 <last sector size>, w)

  fdisk /dev/sdb 

>>Now complete 1.4 and 1.5 by replacing sdb to sdb1.

Option-2B:
Create a new partition sdb2 in extended space and add it as new PV.

# fdisk -l /dev/sdb

Disk /dev/sdb: 75.2 GB, 75161927680 bytes
5 heads, 37 sectors/track, 793516 cylinders
Units = cylinders of 185 * 512 = 94720 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4b38f4fe

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      136077    12587008   8e  Linux LVM
/dev/sdb2          136077      793516    60813158   8e  Linux LVM

>> What's this ? Corresponding device file has not been created !
# ll /dev/sdb2
ls: cannot access /dev/sdb2: No such file or directory

>> Re-reading new partition table using partprob failed with following message.
# partprobe /dev/sdb
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.


>> partprobe has problem in rhel6 (see Note-1 below). Use partx to reread partition. ( ignore below mention error).

# partx -v -a /dev/sdb
device /dev/sdb: start 0 size 146800640
gpt: 0 slices
dos: 4 slices
# 1:       128- 25174143 ( 25174016 sectors,  12889 MB)
# 2:  25174144-146800459 (121626316 sectors,  62272 MB)
# 3:         0-       -1 (        0 sectors,      0 MB)
# 4:         0-       -1 (        0 sectors,      0 MB)
BLKPG: Device or resource busy
error adding partition 1
added partition 2

>> Now, device file is created.
# ll /dev/sdb2
brw-rw---- 1 root disk 8, 18 Apr 25 22:24 /dev/sdb2

>> Now, do usual stuff, pvcreate, vgextend, lvextend, resize2fs
# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created
# vgextend VolGroup02 /dev/sdb2
  Volume group "VolGroup02" successfully extended
# vgs
  VG         #PV #LV #SN Attr   VSize  VFree
  VolGroup02   2   4   0 wz--n- 69.99g 57.99g
# lvextend -l +100%FREE  /dev/mapper/VolGroup02-Vol0201
  Extending logical volume Vol0201 to 61.99 GiB
  Logical volume Vol0201 successfully resized
# vgs
  VG         #PV #LV #SN Attr   VSize  VFree
  VolGroup02   2   4   0 wz--n- 69.99g    0
# lvs
  LV      VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  Vol0201  VolGroup02 -wi-ao 61.99g


>>Now complete 1.5

Case-3: Filesystem created on /dev/sdb1

Execute 1.1 and 1.2. Then execute 2.1(Option-2A) and finally 1.5


References 


  • How to see extended size in LVM after extending vmdk disk / datastore on ESX 
    • https://access.redhat.com/knowledge/solutions/118783
  • Increasing/reducing filesystem on a disk
    • http://www.howtoforge.com/linux_resizing_ext3_partitions
  • Increasing the size of a virtual disk in VMware
    • http://kb.vmware.com/kb/1004047
  • Extending a logical volume in a virtual machine running Red Hat or Cent OS
    • http://kb.vmware.com/kb/1006371
  • How to use a new partition in RHEL6 without reboot? (Note-1)
    • https://access.redhat.com/solutions/57542
  • Increasing the size of a disk partition
    • http://kb.vmware.com/kb/1004071