Wednesday, March 20, 2013

how to rename the interface in linux


Rename network interfaces
Prerequisites
§  ifrename tool which is a part of the wireless_tools package.
§  udev package, which is already installed, of course.
Generic network interfaces
Option 1: udev
Create /etc/udev/rules.d/10-network.rules file with content like following:
 SUBSYSTEM=="net", ATTR{address}=="00:1e:58:48:33:08", NAME="lan"
 SUBSYSTEM=="net", KERNEL=="tap1", NAME="vpn"
 SUBSYSTEM=="net", KERNEL=="tap5", NAME="qemu"
Note: Make sure to use the lower-case hex values in your udev rules. It doesn't like uppercase.
Note: Note that the example above avoids names such as eth0, eth1, etc... and instead uses names that are not initially assigned. Trying to rename using names like eth0, eth1, etc... may fail.
Note: If using systemd, you may find it necessary to inform your network service to hold until the network device has been renamed. This may be achieved by adding the following to the [Unit] section of your network.service file:
 Requires=systemd-udev-settle.service
 After=systemd-udev-settle.service
Option 2: ifrename
Run ifrename directly
 # ifrename -i eth0 -n lan
or create config file (/etc/iftab), for example:
lan            mac 00:0C:6E:C6:94:81
internet       mac 00:0C:6E:C6:94:82
and run
 # ifrename -c /etc/iftab
Example:
How to rename the interface in linux using ifrename 


__tmp469514561 Link encap:Ethernet  HWaddr 00:1F:29:60:B6:A5
__tmp1982053100 Link encap:Ethernet  HWaddr 00:26:55:D6:91:1B


Create a iftable file and include the new NIc with mac address and execute the ifrename command mentioned below

itab - 
eth12 mac 00:26:55:d6:91:1b
eth14 mac 00:1f:29:60:b6:a5



ifrename -i eth0 -n lan
ifrename -i __tmp469514561 -n eth14
ifrename -i __tmp1982053100 -n eth12




PPP interfaces
Add into /etc/ppp/ip-up script the following lines:
 IF=$1
 ip link set dev $IF down
 /usr/sbin/ifrename -i $IF -n <NEWNAME>
 ip link set dev <NEWNAME> up
where <NEWNAME> is the new name for the ppp interface





Wednesday, February 13, 2013

Removing multipath disks


Removing multipath disks

in one of our RHEL4 blade servers, i need to remove
1x500G HP XP1000 LUN:
PV         VG             Fmt  Attr PSize   PFree
  /dev/dm-17 lx0080apps00vg lvm2 a-   200.00G  11.50G
  /dev/dm-18 lx0080apps00vg lvm2 a-   200.00G  11.50G
  /dev/dm-19 lx0080apps02vg lvm2 a-   500.00G 100.00G
  /dev/dm-20 lx0080apps01vg lvm2 a-   250.00G  50.00G
  /dev/dm-21 lx0080apps01vg lvm2 a-   100.00G  50.00G
  /dev/dm-22 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/dm-23 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/dm-24 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/sda2  vg00           lvm2 a-    67.88G   4.47G
[root@lx0080 ~]# pvdisplay /dev/dm-19
--- Physical volume ---
  PV Name               /dev/dm-19
  VG Name               lx0080apps02vg
  PV Size               500.00 GB / not usable 1.25 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              128000
  Free PE               25600
  Allocated PE          102400
  PV UUID               O9b3hw-oSUO-pUpe-oGJw-zEBp-tKXo-3ba2g9
so here's how to do it without causing disruptions on the machine:
btw, this machine hosts a test environment.

CAUTION: DON'T DO THIS IN PRODUCTION ENVIRONMENT ON A REGULAR
BUSINESS DAY (Even if you are sure it won't cause any problems)

make sure no i/o activity on the disk
- i've removed it from nfs exports
- unmounted the FS
remove from VG group
remove from multipath definitions
delete from system

below here are the actual steps.

1. remove from VG group

[root@lx0080 ~]#
 vgremove lx0080apps02vg
Found duplicate PV O9b3hwoSUOpUpeoGJwzEBptKXo3ba2g9: using /dev/sdb1 not /dev/sdq1
Do you really want to remove volume group "lx0080apps02vg" containing 1 logical volumes? [y/n]: y
Do you really want to remove active logical volume "lx0080apps02LV"? [y/n]: y
  Logical volume "lx0080apps02LV" successfully removed
  Volume group "lx0080apps02vg" successfully removed

pvs
PV         VG             Fmt  Attr PSize   PFree
  /dev/dm-17 lx0080apps00vg lvm2 a-   200.00G  11.50G
  /dev/dm-18 lx0080apps00vg lvm2 a-   200.00G  11.50G
  /dev/dm-19                lvm2 --   500.00G 500.00G 
/dev/dm-20 lx0080apps01vg lvm2 a-   250.00G  50.00G
  /dev/dm-21 lx0080apps01vg lvm2 a-   100.00G  50.00G
  /dev/dm-22 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/dm-23 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/dm-24 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/sda2  vg00           lvm2 a-    67.88G   4.47G
as you can see - /dev/dm-19 is now an orphan. since its the only 500G
LUN in the server, its easy to identify.

2. remove from multipath

from multipath -ll (other entries removed):
mpath8 (360060e8004a51a000000a51a00000200)
[size=500 GB][features="1 queue_if_no_path"][hwhandler="0"]
\_ round-robin 0 [active]
 \_ 3:0:0:0 sdb 8:16   [active][ready]
 \_ 4:0:0:0 sdq 65:0   [active][ready]
it has two active paths.

multipath -f mpath8

(-f flush a multipath device map specified as parameter, if unused)

[root@lx0080 ~]#
 multipath -f mpath8
[root@lx0080 ~]#
 multipath -ll | grep 360060e8004a51a000000a51a00000200


360060e8004a51a000000a51a00000200 is the UUID of the disk from
scsi_id -gus /block/sdb (or /block/sdq)

now the multipath map is removed. but the disk is still in the system.

[root@lx0080 ~]#
 fdisk -l /dev/sdq
Disk /dev/sdq: 536.8 GB, 536877465600 bytes
255 heads, 63 sectors/track, 65271 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdq1               1       65271   524289276   8e  Linux LVM
[root@lx0080 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 536.8 GB, 536877465600 bytes
255 heads, 63 sectors/track, 65271 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       65271   524289276   8e  Linux LVM
[root@lx0080 ~]#

[root@lx0080 ~]#
 pvs
Found duplicate PV O9b3hwoSUOpUpeoGJwzEBptKXo3ba2g9: using /dev/sdb1 not /dev/sdq1
  PV         VG             Fmt  Attr PSize   PFree
  /dev/dm-17 lx0080apps00vg lvm2 a-   200.00G  11.50G
  /dev/dm-18 lx0080apps00vg lvm2 a-   200.00G  11.50G
  /dev/dm-20 lx0080apps01vg lvm2 a-   250.00G  50.00G
  /dev/dm-21 lx0080apps01vg lvm2 a-   100.00G  50.00G
  /dev/dm-22 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/dm-23 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/dm-24 lx0080apps01vg lvm2 a-   200.00G  10.00G
  /dev/sda2  vg00           lvm2 a-    67.88G   4.47G
  /dev/sdb1                 lvm2 --   500.00G 500.00G

3. delete from the system

[root@lx0080 ~]#
 echo 1 > /sys/block/sdb/device/delete
[root@lx0080 ~]#
 echo 1 > /sys/block/sdq/device/delete
[root@lx0080 ~]#
 dmesg
Synchronizing SCSI cache for disk sdb:
Synchronizing SCSI cache for disk sdq:
[root@lx0080 ~]# fdisk -l /dev/sdb
[root@lx0080 ~]#
 fdisk -l /dev/sdq


here are some entries generated thru syslog:

- when multipath -f was run:
Apr 22 09:17:20 lx0080 multipathd: dm map mpath8 removed
Apr 22 09:17:20 lx0080 udevd[2444]: udev done!
- when deleting sdb
Apr 22 09:22:52 lx0080 kernel: Synchronizing SCSI cache for disk sdb:
Apr 22 09:22:52 lx0080 multipathd: remove sdb path checker
Apr 22 09:22:52 lx0080 udevd[2444]: udev done!

- when deleting sdq
Apr 22 09:22:57 lx0080 kernel: Synchronizing SCSI cache for disk sdq:
Apr 22 09:22:57 lx0080 multipathd: remove sdq path checker
Apr 22 09:22:57 lx0080 udevd[2444]: udev done!
Apr 22 09:23:02 lx0080 udevd[2444]: udev done!

our storage admin can now remove the disk definition from storage
server.

Monday, October 1, 2012

df –h mismatch size in linux


df –h mismatch size in linux


while I was running df to check the disk space I found that there is huge different in free size.
# df -h /dev/sda2
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              90G   79G  7.3G  92% /

I noticed that there was a huge gap between the total space (79 used + 7.3 available = 88.3) and the actual size of the file system. According to me this was due to the reserved block count, which is set to five percent by default in ext2 and ext3 file systems—clearly a legacy from a time where disks were smaller.

# dumpe2fs /dev/sda2|grep -i 'reserved block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Reserved block count:     1196559

# dumpe2fs /dev/sda2|grep 'Block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Block count:              23931180

# echo 'scale = 2; 1196559 / 23931180'|bc
.05

I changed the reserved block count with tune2fs:
# tune2fs -m 1 /dev/sda2
tune2fs 1.40.8 (13-Mar-2008)
Setting reserved blocks percentage to 1% (239311 blocks)
# dumpe2fs /dev/sda2|grep -i 'reserved block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Reserved block count:     239311

# df -h /dev/sda2
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              90G   79G   11G  88% /

Now, the reserved blocks take up roughly 934 MiB; I’ve freed 3.7 GiB with this little file system tweak. 

 use at your own risk :)

Friday, September 14, 2012

Solaris: Check hme ethernet link speed, duplex, and status


When troubleshooting networking issues, it is often helpful to determine the state of an ethernet interface. Solaris offers access to many configurable networking parameters through ndd.

To determine the ethernet interface link status, duplex, and speed on hme0, run the following commands as superuser:
ndd -set /dev/hme instance 0 ndd -get /dev/hme link_status
ndd -get /dev/hme link_mode
ndd -get /dev/hme link_speed

If you have only one ethernet interface, you can leave out the instance command. Otherwise, you can specify the hme instance number there. The results of the next three commands are either 1 or 0. In each case, the value means:
link_status: 0=down 1=up
link_mode: 0=half duplex 1=full duplex
link_speed: 0=10Mbps 1=100Mbps

Monday, September 3, 2012

Sudo/setfacl/getfacl –Info examples


How to assign rights to start/stop/reload  Application services like httpd,mysql/sendmail via sudo and using assigning rights via getfacl/setfacl

1.    Log on to server XXX server
2.    Assign  rights to normal Account user in linux: baskar + JJ:
* Rights for Fetchmail & Procmail to change/stop/start the application/
*  Rights to stop/start httpd  and  mysqld

  1. Edit sudo file using visudo and append the line  below end of the file and save the file and close it.
baskar   ALL=NOPASSWD:/etc/init.d/fetchmail stop,/etc/init.d/fetchmail start, /etc/init.d/sendmail stop,/etc/init.d/sendmail start,/etc/init.d/httpd stop, /etc/init.d/httpd start,/etc/init.d/mysqld stop,/etc/init.d/mysqld start
jj   ALL=NOPASSWD:/etc/init.d/fetchmail stop ,/etc/init.d/fetchmail start, /etc/init.d/sendmail stop,/etc/init.d/sendmail start,/etc/init.d/httpd start,/etc/init.d/httpd stop, /etc/init.d/mysqld stop,/etc/init.d/mysqld start

4.Using getfacl/setfacl we can assign the rights to individual user

 Rights to change files in /backup/baskar  and  /backup/jj
#setfacl -m user: baskar:rwx /opt/RT, /opt/RT
#setfacl -m user: jj:rwx /backup/baskar, /backup/jj

* Rights to change files in  /var/www/html/*
#setfacl -m user: baskar:rwx  /var/www/html/
#setfacl -m user: jj:rwx  /var/www/html/


* Rights to read files in /var/log/
#setfacl -m user: baskar:r /var/log
#setfacl -m user: jj:r /var/log

  1. Create separate group like baskarjjrwx and baskarjjr and assign the rights accordingly
setfacl -m group: baskarjjrwx:rwx /var/www/html/  /backup/baskar /backup/jj
setfacl -m group: baskarjjr:r /var/log

Wednesday, July 25, 2012

Unmount filesystem when device is busy


When you unmount a filesystem, you may get "device is busy error" sometimes.  Using the following steps, you can unmount safely.


# umount  /testsrv1/rman
umount: /testsrv1/rman: device is busy
umount: /testsrv1/rman: device is busy


# fuser -m /testsrv1/rman
/testsrv1/rman:         31477c


# ps -eaf | grep 31477
oracle  31477 31448  0 09:52 pts/0    00:00:00 /bin/ksh



# df -h /testsrv1/rman
Filesystem            Size  Used Avail Use% Mounted on
testsrv1:/miszpool/mis
                      2.5T  1.9T  560G  78% /testsrv1/rman


# ps -eaf | grep 31477
oracle  31477 31448  0 09:52 pts/0    00:00:00 /bin/ksh


# ps -eaf | grep 31448
dbauser1 31448 31447  0 09:51 pts/0    00:00:00 -ksh
oracle  31477 31448  0 09:52 pts/0    00:00:00 /bin/ksh


# kill -9 31477
# ps -eaf | grep 31448
dbauser1 31448 31447  0 09:51 pts/0    00:00:00 -ksh


# umount -f /testsrv1/rman


# mount /testsrv1/rman


# df -h /testsrv1/rman
Filesystem            Size  Used Avail Use% Mounted on
testsrv1:/miszpool/mis
                      2.5T  1.9T  560G  78% /testsrv1/rman