Friday, May 3, 2013

Permissions broken on /bin/chmod

Imagine you have a Linux system and some administrator ran the following command:

# chmod a-x /bin/chmod

If you try reversing that after it's been done you'll get an error.

# chmod a+x /bin/chmod

-bash: /bin/chmod: Permission denied

I was asked this exact scenario in a Job Interview recently. The interesting thing to me is that one of the interviewers was leading me to believe that if you touched a new file (say /bin/changeme) then the default permissions for that new file would be rwxr-xr-x. This is incorrect. The default permissions for a new file on Linux are 666. After you apply the default root umask of 022, the permissions on that new file would be 644, or rw-r--r--. 

So how do you go about fixing this problem? The real resolution is to copy a file that already exists in /bin. For example the file /bin/touch. You can then use dd or cat to get the contents of the /bin/chmod command into the copy file. You will then be able to use the copy file to "chmod" the /bin/chmod file to the correct permissions. See the example below for the actual commands to do this.

# cp /bin/touch /bin/changeme
# cat /bin/chmod > /bin/changeme
Or:
# dd if=/bin/chmod of=/bin/changeme
# /bin/changeme a+x /bin/chmod

Your /bin/chmod command will now function as normal.

Monday, February 7, 2011

Storix and SAN storage detection

As noted in the comments, this issue no longer exists since version 7.2.3.1. I want to also make it clear that I have been very happy both with the Storix software and with their support.

I ran into an issue in using Storix backup software. When beginning a backup, Storix does a query to make sure that / is not on an exclude list. It will query LVM volume groups to get this information about /. I discovered (with the help of Storix support) that SBAdmin by default will only query /dev/sd[a-z] for the root filesystem.
If you have the LVM volume group that the root filesystem is on, on SAN storage, the Storix backup will give an error similar to the following:

The / filesystem exists on the system but is not included on the
backup because it is in a logical volume you did not select to
include. You must include volume group rootvg on a system backup.

In looking further you may notice this warning in your Storix logs:

Volume Group rootvg will be ignored because it contains physical
volume sdba, which is not a supported device type.

This gives you the physical volume name that is important in the next step.

To fix the problem, on the client that is being backed up edit the file:
/opt/storix/config/device_info
There will be a section that is called "Hard Disk". Inside that section look for the line that contains the disk that your root volume group is on. In our example above, it is physical volume sdba. So we look for the line that is:

#disk:sdb:a-z::1-15:SCSI disk

Uncomment this line so it reads as follows.

disk:sdb:a-z::1-15:SCSI disk

If our physical volume had been sdey. then we would have been looking for the line that looked like:

#disk:sde:a-z::1-15:SCSI disk

We would have uncommented that line so that it read:

disk:sde:a-z::1-15:SCSI disk

When you have made this change, save the changes and retry the backup. At this point it should succeed.

Friday, July 16, 2010

Timekeeping on Linux VMware Guests

Timekeeping on Linux VMware guests can be a cumbersome and frustrating experience. I'm creating this post to be able to remind myself of the various settings required to make things work. The bulk of this information is taken from VMware KB article #1006427 located at:
http://kb.vmware.com/kb/1006427.

VMware recommends using NTP and turning off VMware Tools periodic time synchronization in the guest. To turn this off, there are three options:

  1. Set tools.syncTime = "False" in the configuration file (.vmx file) of the virtual machine.

  2. OR

  3. Deselect Time synchronization between the virtual machine and the host operating system in the VMware Tools toolbox GUI of the guest operating system.

  4. OR

  5. Run the vmware-guestd --cmd "vmx.set_option synctime 1 0" command in the guest operating system.
To work properly in a VM, some vendor kernels require certain kernel parameters. In our environment, we only run SLES and RHEL so I'm only concerned about those two. If you run something different, check the VMware KB article linked to above.


Architecture

Linux Version

Kernel Parameters

Notes
64bitRHEL 5.4 and later
No additional kernel parameters.
32bitRHEL 5.4 and later
No additional kernel parameters.
64bitRHEL 5.3notsc divider=10
32bitRHEL 5.3divider=10 clocksource=acpi_pm
64bitSLES 10.2 and later
No additional kernel parameters.
32bitSLES 10.2 and later
Use a VMI enabled kernel.



You now want to make sure that NTP is configured correctly for your environment.

The following is a sample /etc/ntp.conf :

server ntp1.somedomain.org
server ntp2.somedomain.org
restrict 127.0.0.1
restrict default nomodify nopeer
driftfile /var/lib/ntp/drift

Wednesday, January 6, 2010

Remove LUNs from Linux

I have a previous post here on how to add SAN Presentations (LUNs) to Linux. This post uses the same QLogic Dynamic Target and LUN Discovery utilities as the previous post. The steps below apply to SLES 10 and RHEL 5 servers using QLogic HBAs and PowerPath. That is what we have at my workplace and so that is what I'm most familiar with. This post also assumes that you have put the qlogic utilities into /tmp/ql_utils as described in the other post.

To remove a LUN and all associated PowerPath and Linux devices from the host environment follow these steps. These steps must be run with root privileges. (Note that it is critical to follow the procedures in exact order because deviating from the procedures can cause the host to panic.) These steps were put together using steps from QLogic KB articles.

1. Stop any I/O to the device being removed. [Unmount the filesystem or make sure that the disk has been completely removed from within Oracle ASM control.] It is critical to stop all I/O on the device that is being removed.

2. Run the following command to determine which native SCSI devices are mapped to the pseudo device:

powermt display dev=all

Find the name of the LUN to be removed and match it up with the emcpower device name. This will need to be done on each server individually.

3. Run the command:

powermt remove dev=emcpower

Where corresponds to the LUN to be removed.

4. Run the command:

powermt release

Failing to run this command results in the pseudo device still being visible in /dev and /sys/block and may lead to some complications when the new devices are dynamically added.

5. In the /tmp/ql_utils directory, there should be a script to rescan the qlogic hbas. (If this script doesn't exist, see the previous post for the steps to get the script.) The script is called ql-dynamic-tgt-lun-disc.sh. Run the script:

/tmp/ql_utils/ql-dynamic-tgt-lun-disc.sh

6. You will now remove the device from the storage array using your array admin utilities. On the Linux server, run powermt display to verify that the device has been removed.

7. Now remove the LUN from the Storage Group (CLARiiON) or unmap it from the FA ports (DMX).

Display WWN in SLES 9

I have another post regarding how to do this on SLES 10, so I decided to create a post on how to do this in SLES 9. In SLES 9 you can easily find the WWN for QLogic HBA's by running:

# cat /proc/scsi/qla2xxx/* | grep node

Monday, May 11, 2009

Setup SAN presentation on Linux

The steps below are to scan for new LUNs from a SAN after the LUNs have been presented from the storage side when using QLogic HBA's . This post uses the QLogic Dynamic Target and LUN Discovery utilities which can be downloaded from:

http://driverdownloads.qlogic.com/QLogicDriverDownloads_UI/SearchByProduct.aspx?ProductCategory=39&Product=935&Os=126

The steps below will work on SUSE Linux Enterprise Server (SLES) 10 and Red Hat Enterprise Linux (RHEL) 5.
You can discover what version of Linux you are on by running:

cat /etc/*ease

Create a directory to hold the utilites. In this examle we will use the /tmp/ql_utils directory:

mkdir /tmp/ql_utils

Change to the /tmp/ql_utils directory:

cd /tmp/ql_utils

Retrieve the utilities from the download above and extract them from the zip file into the /tmp/ql_utils directory.
This will put five files into /tmp/ql_utils:

ql-dynamic-tgt-lun-disc.sh
README.ql-dynamic-tgt-lun-disc.txt
Copying
revision.qldynamic.txt
sg3_utils-1.23.tgz

The file that we are going to be using is the ql-dynamic-tgt-lun-disc.sh file. We need to ensure that it is set to executable:

chmod a+x /tmp/ql_utils/ql-dynamic-tgt-lun-disc.sh


The ql-dynamic-tgt-lun-disc.sh script has several options available. You can see what these options are by running:

/tmp/ql_utils/ql-dynamic-tgt-lun-disc.sh -h

The commands to scan for new LUNs are listed below. After the commands we'll describe what each command does. These commands should be run with root priveledges while inside the /tmp/ql_utils directory.

powermt display dev=all | egrep "Pseudo|Logical" > before
./ql-dynamic-tgt-lun-disc.sh
Please make sure there is no active I/O before running this script
Do you want to continue: (yes/no)? yes
powermt config
powermt display dev=all | egrep "Pseudo|Logical" > after
diff after before
powermt save

The first line outputs the current list of LUNs to the file named before. This is optional, but, makes it easy to see what new LUNs have been discovered later on.
The second line actually does the scan for new LUNs and prompts you to make sure that it's ok to run the script. Answer yes to the prompt.
The fifth line (powermt config) creates the emcpower devices in /dev.
The sixth line outputs the new list of LUNs to the file named after.
The seventh line runs a command to compare the list of new LUNs to the list of old LUNs. The differences will be displayed on screen. Make sure that names of the new LUNs show up in the output.
The last line saves the configuration.

After this is done, the LUNs can be setup with LVM. (see LVM post)

Wednesday, April 8, 2009

Slides from SLLUG PAM training

I taught a training session at the daytime Salt Lake Linux Users Group meeting today. I wanted to make the slides available to those that attended. They probably won't make a whole lot of sense if you didn't attend the meeting.
Slides from Pam Training presentation

Wednesday, November 26, 2008

Clear Swap Space in Linux

There have been times where it has been necessary for me to clear out the swap space on a Linux system. In order to do this, you must first make sure that you have enough free memory to hold what is being used by swap.
I usually do this in a few steps. You do need to be root to do this. First I want to see what is currently being used.
free

Then I run the actual commands that empty the swap:
swapoff -a && swapon -a

Then I check what is being used after doing this.
free

I have these three steps in a script and then I just run the script, but, the commands could easily be run from the command line.

Tuesday, November 18, 2008

Create Solaris Package from Source

For this example I will use stunnel since I had to create this package at work today. This software will be compiled from source and created as a package.

First we create a directory structure for our new package. In this example, I'll use /var/tmp/src, but it can be created anywhere.

# cd /var/tmp/src
# mkdir LDSstunnel InfoPath

In the InfoPath directory which we just created, use your favorite text editor (vi) to create a file named pkginfo with the following contents.

ARCH=SPARC
CATEGORY=application
NAME=stunnel
PKG=LDSstunnel
VERSION=4.26
DESC=allows to encrypt arbitrary TCP connections inside SSL
VENDOR=stunnel source taken from http://www.stunnel.org
- ARCH - is the architecture this package is built for. Can be sparc, i386 or ppc
- CATEGORY - list under which category to display the package
- NAME - short name of the package
- PKG - name of package. It is customary to make the first four letters unique to your company, such as a stock symbol.
- VERSION - version of package. In this case this is the version of stunnel
- DESC - descriptive information about the package
- VENDOR - used to describe the vendor that holds the software copyright
More information about these fields and other fields that can be used is in the pkginfo(4) man page.


Configure, compile, and install the software in a unique place

# ./configure --prefix=/opt/LDSstunnel
# make
# make install
# cd /opt/LDSstunnel
# mv * /
var/tmp/src/LDSstunnel/
# cd ..
# rmdir LDSstunnel

Make any changes that need to be made to config files, etc.
I copied a default configuration file into /var/tmp/src/LDSstunnel/etc/stunnel/

In the InfoPath directory create a file named prototype. This file can be created manually, however, it is much easier to use the pkgproto tool.
# cd /var/tmp/src
# pkgproto ./LDSstunnel > InfoPath/prototype

Add a line to the end of the prototype file with information about the pkginfo file
# echo "i pkginfo=/var/tmp/src/InfoPath/pkginfo" >> InfoPath/prototype

Use the pkgmk tool to create the package
# pkgmk -f InfoPath/prototype -b /var/tmp/src

We can now use the pkginfo command to get information about this new package which is in the /var/spool/pkg directory
# cd /var/spool/pkg
# pkginfo -d .
application LDSstunnel stunnel

Our package is located in the /var/spool/pkg directory. We could copy the contents of this directory to an nfs export or tarball it and copy it to the destination server and install.

Monday, November 17, 2008

vsftp and /etc/shells

I discovered today that there are a couple of issues with using local accounts with VSFTP. The first issue which is obvious is that local_enable=YES needs to be set in the vsftpd.conf file. The other issue that is not as obvious is that if you have a local user that has a shell set to /bin/false or /sbin/nologin, that user will get a incorrect login error when they try to login. The thing I did to fix this problem was added /sbin/nologin to /etc/shells. This worked on a SUSE Linux Enterprse Server 10 (SLES 10) server. The simple command that I used to do this was:

#echo /sbin/nologin >> /etc/shells

Thursday, September 11, 2008

Display WWN in SLES 10

A key component of setting up a server to a SAN is knowing what the World Wide Name (WWN) is. I was very accustomed to doing this in SLES 9. With SLES 10, the location of finding the WWN has changed and it is now in the file /sys/class/fc_host/host#/node_name. Where # is the number of the host that you want to find the WWN of. 

An even easier way to find this information is to use the systool command:
systool -c fc_host -A node_name

Friday, March 7, 2008

Switch from LSI Logic to BusLogic driver

At the place where I work, we run several SUSE Linux Enterprise Server (SLES) 9.3 VMs on VMWare ESX 3.0.2 servers. When running the LSI Logic driver that ships with SLES 9.3, if there is an interrupt to the disk the disks on the VM can go read-only. This interrupt can be due to SAN fail-over, high I/O, or other issues. This bug has been fixed and doesn't exist in SLES 10.1 or later.
Because of this, we have had the need to switch these from using the LSI Logic driver to use the BusLogic driver. The problem is that the original initial ram disk (initrd) is built with the LSI Logic driver and must be changed. I decided to document the steps required to do this. If you don't take these steps, the server will encounter a kernel panic on reboot after changing the VM to use the BusLogic HBA.

1) Update /etc/sysconfig/kernel with the BusLogic driver. Change the line that reads:

INITRD_MODULES="mptspi reiserfs dm_mod"

to read:

INITRD_MODULES="BusLogic reiserfs dm_mod"

2) Make a backup copy of the initrd file that is currently in use.

cp initrd-2.6.5.77-default initrd-2.6.5.77-default.preBusLogic

3) Rebuild the initial ram disk file to incorporate the changes made to /etc/sysconfig/kernel by running mkinitrd as root.

mkinitrd

Note: You can pass additional options to the mkinitrd command to use a specific kernel. By default it will build an initrd for all the kernel versions in /boot. This is sufficient for the servers in my environment.

4) Update the virtual machine to use the BusLogic HBA

Use the VirtualCenter Client
- Shutdown the VM
- Right click on the VM and select Edit Settings
- Select SCSI Controller 0 and click the Change Type button
- Select the BusLogic radio button and click OK
- Click OK to exit the Virtual Machine Properties
- Power on the VM
- Answer the "change the adapter type for scsi0:0 disk" by selecting the Yes radio button and clicking OK

Thursday, January 24, 2008

What's that line in /proc/mounts?

When I view the /proc/mounts file, the first line looks like: rootfs / rootfs rw 0 0 I found myself wondering what this line was. Today I figured it out. My first thought was that this is my mounted / directory, however, this is not the case. My mounted / directory appears in /proc/mounts as: /dev/root / ext3 rw,data=ordered 0 0 The first line is actually the initial ram disk (initrd). When the system boots up, this initial ram disk is mounted as the root filesystem. Many Linux systems then just mount the actual root filesystem over top of that. I found this page, http://lwn.net/Articles/156098/, to be very helpful in explaining this.

How to add disk space with LVM on Linux

I have often had the need to add disk space to a server. The newer distributions of Linux (SUSE Linux Enterprise Server - "SLES" 9 and greater, Red Hat Enterprise Linux - "RHEL" 4 and greater) use Logical Volume Manager (LVM) which makes this a fairly simple task.
The general steps are:
  1. Physically put the disk in the server and make it available either in an array or some other way.
  2. Use fdisk to create new partition on the disk.
  3. Extend existing volume group onto new partition.
  4. Extend existing logical volume onto new space.
  5. Extend filesystem.
I'll go into more detail how to do each of these steps on SLES and RHEL. For this example we are going to assume that our new disk that has been added to our server is /dev/sdc. We will also assume that we have a volume group named rootvg and a logical volume on that volume group named homelv. Also in this example, /dev/rootvg/homelv is mounted on our Linux system as /home. Let's get started.
  1. Physically put the disk in the server and make it available either in an array or some other way.
    • This can vary widely depending on what hardware you are on, so we will not cover this portion in this tutorial. You may want to use Google to search for how to do this on your hardware.
  2. Use fdisk to create new partition on the disk.
    • As root run fdisk on the new disk. For example you would run fdisk /dev/sdc.
    • On this new disk you will create a new partition. Inside of the fdisk program you create a new partition by typing the letter "n" followed by the enter key.
    • It will then ask you if you want it to be a primary partition or an extended partition. For this example we will just assume we want it to be a primary partition. To do this we type the letter "p" followed by the enter key.
    • Next it will ask for the starting point and ending point of this partition. For this example, we will simply select the defaults by hitting the enter key twice.
    • If you want to view the details of the new partition, you can type the letter "p" from the fdisk prompt.
    • Next we need to change the type for this new partition. We do this by typing the letter "t" followed by the enter key.
    • It asks to enter in what type we want it to be. We need it to be of the Linux LVM type. The Hex code for Linux LVM is 8e. We type in "8e" followed by the enter key and it will tell us that it changed the system type for this partition to Linux LVM.
    • We then need to save these changes and exit fdisk. We do this by typing the letter "w" (for write) followed by the enter key.
  3. Use pvcreate to lay down the "setup" on the physical partition.
    • This sets up physical extents and other things that LVM needs. The command we run is "pvcreate /dev/sdc1"
  4. Extend existing volume group onto new partition.
    • For this example we are going to assume that we have an existing volume group named rootvg. We can display information about this volume group using the vgdisplay command. If we type "vgdisplay" without any arguments, it will display all the volume groups. If we just want information about the "rootvg" volume group, we would type "vgdisplay rootvg".
    • To extend the rootvg volume group onto the new partition, we use the vgextend command. Type "vgextend rootvg /dev/sdc1" followed by the enter key. This will extend the rootvg volume group onto the new partition, /dev/sdc1.
  5. Extend existing logical volume onto new space.
    • For this example we are going to assume that we have an existing logical volume on the rootvg volume group that is named homelv. The full path to this logical volume would be "/dev/rootvg/homelv". We can view information about this logical volume by typing "lvdisplay /dev/rootvg/homelv".
    • To extend this existing logical volume onto the new space we use the lvextend command. Type "lvextend -L +20G /dev/rootvg/homelv /dev/sdc1". This command says that we want to increase the /dev/rootvg/homelv logical volume by 20GB. This is only possible if /dev/sdc1 is a member of volume group rootvg and there is enough free disk space on it.
  6. The last thing we need to do is increase the filesystem.
    • Which command we use to increase the filesystem depends on what filesystem type we are currently using. If we are using reiserfs, we will use the "resize_reiserfs" command. If we are using ext3, we will use either the "ext2online" or the "resize2fs" command. On RHEL 5, we can use the "resize2fs" command, which will recognize that the filesystem is currently mounted and perform an "on-line" resize.
    • On both resize_reiserfs and ext2online, the size is optional. If we want the filesystem to take up all the available space on our logical volume, we don't need to put the size. To extend the filesystem type either "ext2online /dev/rootvg/homelv" or "resize_reiserfs /dev/rootvg/homelv".
You should now be able to run "df -h" and see the additional disk space available in the /home directory.

Monday, November 26, 2007

Wrong permissions breaks ssh.

I learned something interesting today. In Linux, if group or others has the writable permission on a users home directory, ssh will not allow the use of key based authentication. It will prompt for a password. The next time you are not able to ssh using key based authentication, you may want to check permissions on the home directory.

Wednesday, March 7, 2007

Automatically unlock the default keyring on FC6

If you have NetworkManager in use on Fedora Core 6, you have probably seen this dialog box:

keyring.jpg

I got tired of entering my password every morning to unlock the default keyring, so I went looking for a solution. What I found was a module for use with PAM that would supply my system password to gnome-keyring for me. The module is called pam_keyring.so.

On Fedora Core 6 the steps that I used to implement this were:

1) As root install the module and it's documentation:
# yum install pam_keyring

2) Insert the following two lines into /etc/pam.d/gdm:
auth optional pam_keyring.so try_first_pass
session optional pam_keyring.so

Note that order is important in the gdm file. This is what my /etc/pam.d/gdm file looks like with the additions:

auth required pam_env.so
auth optional pam_keyring.so try_first_pass
auth include system-auth
account required pam_nologin.so
account include system-auth
password include system-auth
session optional pam_keyinit.so force revoke
session include system-auth
session required pam_loginuid.so
session optional pam_console.so
session optional pam_keyring.so

Now the system no longer prompts me for the default keyring password when I log in.