Friday, February 7, 2014

My Linux notes --

Disable Network Managers system-ca-certs to connect to wpa2 Ent. not using /wout cert in Arch Linux.

1) Comment out system-ca-certs =true in

#vim /etc/NetworkManager/systemconnections/<ssid>

 

Sunday, February 2, 2014

Remap CapLock key to Shift Gnome 3

I can not stand the Caps Lock key. I tend to press the Caps Lock key when I intend to press the shift key. Thankfully there is an easy to remap this key in Gnome 3. This can also be used in KDE with slight modifications.

First, remap the Caps Lock key using xmodmap:

$ xmodmap -e "keycode 66 = Shift_L NoSymbol Shift_L"

Next export your current key mapping to .xmodmap

$ xmodmap -pke > .xmodmap


That is it. If you need to revert the Caps_Lock key back you can run the following command.

$ xmodmap -e "keycode 66 = Cap_Lock NoSymbol Caps_Lock"

Thursday, January 9, 2014

Extend LVM and filesystem on RHEL 6

If disks have been added when the system is running you will need have the kernel scan for new drives by running.


#'for i in `ls -1 /sys/class/scsi_host/`; do echo "- - -" > /sys/class/scsi_host/$i/scan;

Next run dmesg to get the name of the device.

 #dmesg
 scanning ...
 scsi 0:2:2:0: Direct-Access     DELL     PERC H700        2.10 PQ: 0 ANSI: 5
 sd 0:2:2:0: Attached scsi generic sg0 type 0
 sd 0:2:2:0: [sde] 875298816 512-byte logical blocks: (448 GB/417 GiB)
 sd 0:2:2:0: [sde] Write Protect is off
 sd 0:2:2:0: [sde] Mode Sense: 1f 00 00 08
 sd 0:2:2:0: [sde] Write cache: enabled, read cache: enabled, doesn't support    DPO or FUA
  sde: unknown partition table
  sd 0:2:2:0: [sde] Attached SCSI disk
  scsi 0:0:0:0: Direct-Access     ATA      Crucial_CT960M50 MU02 PQ: 0 ANSI: 5
  scsi 0:0:1:0: Direct-Access     SEAGATE  ST91000640SS     AS03 PQ: 0 ANSI: 6
  scsi 0:0:2:0: Direct-Access     SEAGATE  ST91000640SS     AS03 PQ: 0 ANSI: 6
  scsi 0:0:3:0: Direct-Access     SEAGATE  ST91000640SS     AS03 PQ: 0 ANSI: 6
  scsi 0:0:4:0: Direct-Access     ATA      Crucial_CT960M50 MU02 PQ: 0 ANSI: 5
  ...
You can verify you device with the following command.

#fdisk -l /dev/sde 

   Disk /dev/sde: 448.2 GB, 448152993792 bytes
  255 heads, 63 sectors/track, 54484 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: 0x00000000
 ~                        

Next you can view the current volume group as shown below.

# vgs
 VG         #PV #LV #SN Attr   VSize   VFree  
 VolGroup00   1   3   0 wz--n- 476.25g 256.00m
 VolGroup01   1   1   0 wz--n-   4.55t 507.79g

Now we will create a physical volume on /dev/sde
# pvcreate /dev/sde    
Physical volume "/dev/sde" successfully created  

 Then you will need to add the Physical Volume to the Volume Group.

 # vgextend VolGroup00 /dev/sde
   Volume group "VolGroup00" successfully extended

Now the vgs command show that our Volume Group has been extended.
 # vgs     
   VG         #PV #LV #SN Attr   VSize   VFree    
   VolGroup00   2   3   0 wz--n- 893.59g 417.59g  
   VolGroup01   1   1   0 wz--n-   4.55t 507.79g
 Now you can view the Logical Volume that needs to be extended.
   
 #  lvs   
   LV       VG         Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync    Convert   
   LogVol00 VolGroup00 -wi-ao---  12.00g                                                
   LogVol01 VolGroup00 -wi-ao---   1.00g                                                
   LogVol02 VolGroup00 -wi-ao--- 463.00g                                                
   LogVol00 VolGroup01 -wi-ao---   4.05t
Then we can exttend the Logival Volume by running the following
# lvresize -L 830g /dev/VolGroup00/LogVol02   
     Extending logical volume LogVol02 to 830.00 GiB
       Logical volume LogVol02 successfully resized
  
 I like to vie my changed to insure every thing worked as I hoped.
# lvs
   LV       VG         Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync    Convert  
     LogVol00 VolGroup00 -wi-ao---  12.00g                                               
     LogVol01 VolGroup00 -wi-ao---   1.00g                                               
     LogVol02 VolGroup00 -wi-ao--- 830.00g                                               
     LogVol00 VolGroup01 -wi-ao---   4.05t                    
 ~                                                         
 All that is left is to extend our file system.with the command:
 # resize2fs  /dev/VolGroup00/LogVol02
 resize2fs 1.41.12 (17-May-2010)  
 Filesystem at /dev/VolGroup00/LogVol02 is mounted on /var/lib/mysql_ssd; on-    line resizing required
 old desc_blocks = 29, new_desc_blocks = 52
 Performing an on-line resize of /dev/VolGroup00/LogVol02 to 217579520 (4k)      blocks.
 The filesystem on /dev/VolGroup00/LogVol02 is now 217579520 blocks long.
All done. 

Friday, December 6, 2013

Linux Immutable resolv.conf.

I often find that dhcp overwrites my resolv.conf not in the most optimal way. One example of this is when logging into more than one vpn tunnels that both set search domains. The simple answer to resolve this issue is to create the resolve.conf files and then set it as immutable.


Setup resov.conf:
/etc/resov.conf
options timeout:1 attempts:2
domain domain1.com domain2.net ... ... 
nameserver <work dns server>
nameserver <vpn dns server>
nameserver <home dns server>
nameserver 8.8.8.8 #googles dns server

Set /etc/resov.conf immutable:
#chattr +i /etc/resolv.conf


View files attributes:
$lsattr /etc/resolv.conf ----i--------e-- /etc/resolv.conf

The output shows that my resolv.conf file is set immutable (i) and and the it is on an ext4 filesystem (e).

To edit the file do the following:
#chattr -i /etc/resolv.conf


Side note about chattr:
I also use the append (chattr +a) attribute often. By setting the append attribute content can be added to the file but not altered. 

An example of using the append attribute is as follows:
#touch test.txt ; chattr +a ./test.txt; lsattr ./test.txt; 

 -----a-------e-- ./test.txt

We now can add to the file but can not replace the current file.
#echo test >> ./test.txt 

#sudo echo test > ./test.txt 
bash: ./test.txt: Operation not permitted

Thursday, November 28, 2013

Vim Windows and Tabs

 I truly love vim, a my first blog post I can not think of a better subject to talk about. A few was I use vim as a time saving tool are the below.

Vim Windows and Tabs

I administer several Nagios servers where I may need to open four or five host files and make a few quick changes. At times I use sed scripts but more often I open all the files with vim in vertical windows suing the following.

 vim -o webserver0{1..5}.cfg

-o opens each file in stacked  windows.
-O opens each file in side by side windows.
-p opens each file in its' own tab.

Then you can use regex replacments across all tabs or windows using windo or tabdo. A nice use of this is changing all http checks to https for webserver01-5. This change can be done suing the followind command.

:windo %s /check_http/check_https:g

To only make the change on your active window omit windo. In order to cycle through windows use ctfl+w w to move down a window or ctrl+w W to move up a window. All windows can be closed and saved using windo as well.

:windo x

If you are using tabs rather then windows tabdo can be used in place of windo. Using :tabn and :tabp to cycle the the next or prior tabs.