Linux tips & techniques for developers and system administrators.


367 views

Add “Delete on Reboot” to Right Click Menu

By jbayer - Last updated: Wednesday, October 2, 2013

Horrors!  I’m actually talking about Windows.

I use Windows for my desktop, because my company uses a number of Windows-based products which we (the sysops team) also need to use.

I recently tried to delete a file which was in use.  So I hunted around and found the following code.  Please note that I did NOT write this, but am putting it here as a reference and documentation.  The original site where I got this from is:  Add Delete on Reboot

He says that this is for XP Home, Pro, and Win2K, but it also seemed to work on Windows 7.

Backup your registry first!!!

 

Open notepad, and copy/paste the text below. Save the file as whatever.reg
Double clicking the whatever.reg file will add it to the registry, and give you the option to: “Delete on Reboot” when you right click a file or folder.

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Delete on reboot\command]
@="CMD /E:OFF /C REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Currentversion\\RunOnce /v \"Del %1 OnNextReboot\" /d ^\"cmd.exe /c DEL /F /Q \\\"%1\\\"\" /f\""
[HKEY_CLASSES_ROOT\*\shell\Open]
[HKEY_CLASSES_ROOT\Folder\shell\Delete on reboot\command]
@="CMD /E:OFF /C REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Currentversion\\RunOnce /v \"Del %1 OnNextReboot\" /d ^\"cmd.exe /c RD /S /Q \\\"%1\\\"\" /f\""
Filed in Desktop, Windows • Tags:
3,338 views

Zabbix template generator for Dell Openmanage

By jbayer - Last updated: Wednesday, September 18, 2013

Our hosting company uses Dell systems exclusively.  Strangely enough, they don’t bother to monitor the disks in the systems, which lead to a triple drive failure on one of our RAID 5 systems;  total loss of data, and the backups weren’t complete.

 

I’ve developed the attached set of files which will address this.

The tar file contains the following files:

  zabbixopenmanage.tar.gz (6.0 KiB, 848 hits)

 

Filed in Zabbix • Tags:
646 views

Locking and unlocking a user account

By jbayer - Last updated: Wednesday, September 18, 2013

This is a script that someone whipped up.  It wasn’t myself, and I have been unable to find an author.  I find it extremely useful when locking down a server.  I cleaned it up a bit and added some error checking before posting here.

There are times when you need to disable a user’s access to a server, yet not delete that user for various reasons.  This script will do that for you.

There are two ways a user can log on to a system.  The first is with the traditional userid/password, which is stored in /etc/passwd and /etc/shadow.  The second is with ssh keys.  Both have to be addressed.

This script will use the passwd command to disable the login in the /etc/shadow file.  It also renames the .ssh directory in the user’s home directory so that ssh keys won’t work.

Usage is very simple.  To lock an account:

userlock -l userid

To unlock an account:

userlock -u userid

If you try to lock an already locked account, it will warn you and exit.  Similarly, if you try to unlock an already-unlocked account, you will be warned.

  userlock.gz (646 bytes, 264 hits)

Filed in Administration • Tags: , , ,
777 views

Adding Space to Linux Partitions

By jbayer - Last updated: Thursday, August 8, 2013

Sometimes after you make a virtual machine, you find that you need to add more space to it.  You are left with two options:

  1. Build a new VM and copy everything over
  2. Expand the existing VM

The first option is slow and subject to error.  It is very easy to miss copying over a file or directory which isn’t obvious.

The second option, while better, still has it’s problems.  It really depends on how the virtual machine is set up.

These instructions address both simple VMs (stored in a disk file), VMs which are stored in an LVM partition, and VMs which are controlled by Ganeti

Resize a partiton/filesystem in a VM which is stored in a disk image file

  1. Stop the VM
  2. If on RHEL6/CentOS 6:

Resize using:

qemu-img resize vmdisk.img +40G

If on RHEL5/CentOS 5:

Resize using:

dd if=/dev/zero of=hdd.img seek=N obs=1MB count=0″

where hdd.img is the raw format image that you want to resize and N is the new size that you want the image to be, in megabytes. To change the units of N, change obs to something else such as 1GB for units in gigabytes (1000x1000x1000).

Pasted from <http://superuser.com/questions/24838/is-it-possible-to-resize-a-qemu-disk-image>

 

  1. Start vmanager, mount gparted ISO and make it the boot drive
  2. Delete & re-create LVM partition using fdisk
  3. Shutdown, and then boot the gparted cd again
  4. Resize the LVM physical volume:

pvresize /dev/vda2

 

Resizing an LVM Logical Volume

The following instructions assume that the LVM volume being resized is LogVol00

 

  1. Resize the LVM Logical Volume
  1. Get number of free PE using command:  pvdisplay
  2. lvresize /dev/VolGroup00/LogVol00 -l +numFree

 

Resizing an EXT3 filesystem

 

  1. Do an fsck of the filesystem, and then resize it

e2fsck -f /dev/VolGroup00/LogVol00

resize2fs -p /dev/VolGroup00/LogVol00

 

Final Steps if in a VM

  1. Shutdown VM
  2. Unmount gparted ISO
  3. Boot VM and test

References

http://serverfault.com/questions/324281/how-do-you-increase-a-kvm-guests-disk-space

http://itsignals.cascadia.com.au/?p=28

http://www.tcpdump.com/kb/os/linux/lvm-resizing-guide/expand.html

 

To add space to a Ganeti system:

 

These instructions assume the following:

partition layout is simple partitions, no LVM

The partition to be resized is the last one, in the instructions below

The fileystem of the resized partition is either ext3 or ext4

The amount of space to be added is 25 gig

 

  1. On master ganeti system:

gnt-instance grow-disk ins27.a3k 0 25G

The syntax for the gnt-instance for this is:

gnt-instance grow-disk [–no-wait-for-sync] [–submit] [–absolute]

{instance} {disk} {amount}

 

  1. Shut down VM (has to be a full shutdown, not a reboot)
  2. Start VM
  3. Log on as root
  4. Using fdisk:
  1. Type “u” to change the units to sectors, necessary in case partition wasn’t lined up properly
  2. Type “p” to print the current partition layout

The following is an example, used for the instructions:


Disk /dev/vda: 247.0 GB, 246960619520 bytes
255 heads, 63 sectors/track, 30024 cylinders, total 482344960 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *          63      208844      104391   83  Linux
/dev/vda2          208845     4417874     2104515   82  Linux swap / Solaris
/dev/vda3         4417875   482335559   238958842+  83  Linux

  1. Record the start sector of vda3, in the example, it is 4417875
  2. Type “d” to delete a partition, when asked, enter “3” to delete vda3
  3. Type “n” to create a partition. use the following answers:
Partition type:                p (for primary)
Partition number:        3
First sector:                enter start sector recorded above
Last sector;                press <cr>
  1. Type “w” to write the updated partition table to the disk
  1. Reboot the VM
  2. after VM has rebooted, log on as root and type:
resize2fs  /dev/vda3

 

Filed in Linux Installations, Open Source, Virtulization • Tags: , ,
439 views

Updated Zabbix install script as of 6/26/2013

By jbayer - Last updated: Wednesday, June 26, 2013

Here is the latest update to my zabbix installation script.  It now installs Zabbix 2.0.6, along with everything else necessary.

 

  install_zabbix.tar.gz (16.0 KiB, 511 hits)

Filed in Zabbix
616 views

Detecting hardware virtualization in Linux

By jbayer - Last updated: Friday, May 10, 2013

For historical reasons, most systems which ship have the virtualization flag turned off.  If you aren’t expecting this, and try to install KVM in a Linux system, you can get unusual errors which don’t necessarily indicate the problem.

This script performs a few simple tests to see if virtualization is active or not.  I can’t guarantee that it is complete, but it works on the systems I’ve tested it on.  Please use it, and if you find an exception, please let me  know so I can update it.

#!/bin/bash
cpuinfo=`egrep '^flags.*(vmx|svm)' /proc/cpuinfo`
if [ "$cpuinfo" = "" ]; then
 echo "There doesn't appear to be any hardware support for virtualization"
 exit
fi
hardware=`dmesg | grep kvm | grep -i 'no hardware support'`
bios=`dmesg | grep kvm | grep -i 'disabled by bios'`
if [ "$hardware" != "" ]; then
 echo "No hardware support for KVM"
 exit
fi
if [ "$bios" != "" ]; then
 echo "KVM disabled by bios"
 exit
fi

   
Filed in Bash, Virtulization • Tags: , , ,
2,200 views

Zabbix – Automatic Filesystem Discovery Update

By jbayer - Last updated: Saturday, May 4, 2013

On our systems, we use a standard Linux template.  However, many of our systems have different filesystem layouts, and I didn’t want to have to customize each system as it was installed into Zabbix.

I wrote the attached script to solve this problem.  Once the Zabbix client is installed and configured, simply run the attached script and the host will be updated on the Zabbix server.  The script is written in Python, a

 

It requires that two packages (Redhat packages are listed) be installed, using the following command:

yum -y install python-simplejson python-hashlib

 

It also requires the following file:

https://github.com/gescheit/scripts/blob/master/zabbix/zabbix_api.py

The script assumes that it and the zabbix_api.py file both live in /etc/zabbix/python;  if you install it somewhere else, adjust line 9 appropriately.

This works and has been tested on Zabbix 2.0.  It _should_ work on 1.8, but I haven’t tested it there.

It requires a username and password for a Zabbix user who has access to the JSON interface.

You will need to update the three lines near the top of the file which list the username, password and Zabbix server.

 

  zabbix_updatefs.py (1.9 KiB, 448 hits)

 

Filed in Zabbix • Tags: , ,
1,825 views

Bacula & WeBacula Installation Script

By jbayer - Last updated: Thursday, April 25, 2013

Note:  The script was updated on 5/17/2013 due to a typo.

We recently had an issue where we lost 3 drives in a RAID 5 array, causing the entire system to be lost.  Unfortunately, some data was lost due to the hosting service’s backups  not being complete.

As a result of this, we decided to implement our own backup systems as a secondary backup.  We decided to use Bacula to do the backups, and WeBacula for a user interface.

Since we have two sites, we needed to set up a backup server in each location.  The main intention of the new systems are to do local backups of all the virtual machines which we’ve set up in the past year.  Unfortunately, a production VM was on the server which was lost, and we lost some data permanently.

Our environment is a combination of RHEL5, RHEL6, and the equivilant versions of CentOS.  We have a local repository set up, so in order to be able to built RPMs for each environment, I wrote an installation script which builds RPMs for each environment.  You have to run the script in each environment in order to build the binaries properly.

The script builds the following RPMs for client installs, they should all be installed:

bacula-client.x86_64 – binaries
bacula-client-conf.noarch – Initial config file
bacula-client-redhat.noarch – Startup scripts

For server installs, it builds the following:

bacula-server.x86_64 – binaries
bacula-server-conf.noarch – Initial config file
bacula-server-redhat.noarch – Startup scripts

Since I use the Checkinstall program (be sure to read this about a problem on 64 bit systems), I set it up to build these three RPMs to make it easier to update the binaries.

It has the following limitations:

  1. PostreSql is forced, there is no option to install MySql
  2. It assumes either RedHat or CentOS. Any other RHEL-based system will require modifications, search for “centos” in the code
  3. The database installation code assumes the database is being built and used on the current system

This script was written and tested on both Redhat and CentOS systems.

  installbacula.tar.gz (9.2 KiB, 480 hits)

Filed in Backup, Bash, Open Source
682 views

Ganeti 2.6.2

By jbayer - Last updated: Friday, December 21, 2012

RPMs for RHEL6/CentOS6/SL6 are available here:

 

  Ganeti 2.6.2 (2.8 MiB, 420 hits)

  Ganeti 2.6.2 debug (507.0 KiB, 367 hits)

 

Also,

I’ve uploaded my set of scripts which I wrote and use in administering Ganeti.

They are available at:
http://code.google.com/p/ganeti-scripts/

I’d appreciate any feedback.  Suggestions, patches, etc are welcome.

This is a description of the scripts:

The following are additional shell scripts to support the use of ganeti:

gnt-createins

Create a new instance from an existing variant or by installing from an ISO image.
Call with new instance name on cmd line, if not there you will be prompted for it, as well as all other necessary information

gnt-newvariant

Create a new variant from an existing instance. If necessary, the instance is shut down first.  Specify the instance on the command
line

gnt-installos

Install an os from an ISO image onto an existing, not-running instance.  You can specify the instance name on the command line, otherwise you will be prompted.

gnt-start

Start an instance, display the VNC info for it, and then start the console.
Specify the instance name on the command line

gnt-sync-cluster

Simple shell script to sync various files across all nodes.
Files and directories to be synced are listed in /etc/ganeti/syncfiles.txt
Currently copies various ganeti files in /etc, as well as the various Ganeti directories and /usr/local.

gnt-diskimage

Create a tarball from a QEMU disk image file

gnt-help

This file.  For detailed help on a specific command, type the command name as an option.  For example:

gnt-help gnt-createins

Filed in Networking, Virtulization
831 views

Zabbix install script updated to v1.9

By jbayer - Last updated: Sunday, October 14, 2012

Here is the latest update to my zabbix installation script.  It defaults to Zabbix 2.0.1, but it checks to see what the latest version is and gives you the option to install it, along with everything else necessary.

I noticed that when doing an upgrade, that the config files aren’t always updated properly.  In some cases, old files get deleted.  This usually happens when upgrading from an older set of RPMs where the config files are in different RPMs than the current.

To protect against this, the script will back up the zabbix directories before perform the upgrade.

Filed in Bash, Building packages, Open Source, Zabbix
asd