Category Archives: Linux

Linux LVM

Prepare physical volume (where diskname = sda, sdb, sdc,…)

  1. dd if=/dev/zero of=/dev/diskname bs=1k count=1 (NOTE: this is destructive to all data on this disk)
  2. blockdev –rereadpt /dev/diskname
  3. pvcreate /dev/diskname

Prepare Volume Group

  1. vgcreate –s 1g my_vol_group /dev/diskname

    1. you can modify the extent size during vg creation

Create Logical Volume

Defined Size

  1. lvcreate –Lsize-in-MB –n lv-name my_vol_group

oracle es: lvcreate –L 8g –n olp2_u01xplv olp2_archxpvg

Defined Size with Stripes

  1. lvcreate –istripe-count –Istripe-size –lsize-in-extents –nlv-name my_vol_group

oracle stripe ex: lvcreate –i 3 –I 8 –l 10 –n olp2_u07xplv olp2_u07xpvg

natcat stripe es: lvcreate –i 5 –I 8 –L 175g –n olp2_u37xplv olp2_data37xpvg

Full Physical volume

  1. vgdisplay my_vol_group |grep “Total PE”
  2. lvcreate  -l count-from-above my_vol_group –nlv-name

Create a file system

mkfs -t ext3 /dev/vg00/<volume name>

oracle stripe ex: mkfs –t ext3 –b 4096 –R stride=2 device (rhel3)

oracle stripe ex: mkfs –t ext3 –b 4096 –E stride=2 –T largefile  device(rhel4)

NOTE:  only specify –T largefile on /u02-/u09 file systems for oracle, allow default every where else

Modify a file system

Use tune2fs tp change the defaults of fsck every 30 mounts or 180 days

Activate Volume Group

  1. after a reboot or vgchange –an you will need to active the volume group
  2. vgchange –a y my_vol_group

Remove a volume group

  1. make the volume group inactive
    1. vgchange –a n my_vol_group
  2. remove the group
    1. vgremove my_vol_group

Adding Physical Device to Volume Group

  1. vgextend my_vol_group /dev/diskname

Removing Physical Device from Volume Group

  1. vgreduce my_vol_groupe /dev/diskname

Remove Logical Volume

  1. umount /file/sysmtem
  2. lvremove /dev/my_vol_group/lv-name

Extend a volume

Extend to defined size

  1. lvextend –L12G /dev/my_vol_group/lv-name

Extend by specific amount

  1. lvextend –L+1G /dev/my_vol_group/lv-name

Extend a filesystem

  1. resize2fs /dev/my_vol_group/lv-name

Extend volume and filesystem (1 command; not valid in 3.0 for online resize)

  1. e2fsadm –L+1G /dev/my_vol_group/lv-name

Extend a RHEL 4.0 file systems

  1. ext2online /mount-point will extend FS to end of the volume

Reduce a filesystem

  1. umount /filesystem
  2. resize2fs /dev/my_vol_group/lv-name size-in-blocks

Reduce a volume

  1. must be done umounted and after filesystem reduction
  2. lvreduce –L-1G /dev/my_vol_group/lv-name

Reduce both volume and fileystem (1 command; not valid 3.0)

  1. umount /filesystem
  2. e2fsadm –L-1G /dev/my_vol_group/lv-name
  3. mount /filesystem

Review summary of physical devices (4.0 only)

  1. pvs will show summary of physical device and volume groups

Review summary of volume group(4.0 only)

  1. vgs will show summary of volume group

Review summary of logical volume(4.0 only)

1.  lvs will show summary of volume information


  1. fdisk disk
  2. n to add a new disk
  3. choose your sizes
  4. t to change type
  5. w to write

swap space

  1. mkswap /dev/diskname
  2. swapon /dev/diskname
  3. fstab: /dev/diskname swap    swap    defaults 0 0

Decided mdadm would not do the job for you?

mdadm --create -f -lmp -n2 -x1 /dev/md0 /dev/<channela> /dev/<channelb>

This works in fail over mode by explicitly telling md to treat one as a spare. 

Helpful Volume Management Commands

  1. To get a full list of all volume groups in 3.0: vgdisplay –s
  2. to get a full list of all logical volumes in 3.0: lvscan

Example volume creation

I did this:

dd if=/dev/zero of=/dev/sda bs=1k count=1

pvcreate /dev/sda

vgcreate -s 8M vg_oralp01_u01 /dev/sda

lvcreate -L 13.74G -n lvu01 vg_oralp01_u01

vgchange -a y vg_oralp01_u01

mkfs -t ext3 /dev/vg_oralp01_u01/lvu01

Example volume extension

Note: RHEL3 does not support online resizing of ext3 filesystems, RHEL4 does

dd if=/dev/zero of=/dev/sdj bs=1k count=1

blockdev –rereadpt /dev/sdj

pvcreate /dev/sdj

vgextend  vg_oralp01_u01 /dev/sdj

vgdisplay vg_oralp01_u01|grep Free

umount /u01

e2fsadm -L+size_from_above /dev/vg_oralp01_u01/lvu01

mount /u01

Business Copy Procedures

  1. following a split, the volume group showed up and seemed valid
  2. the logical volume showed up but was flagged as inactive
  3. ran vgchange –ay <vgname>
    1. now volume is live and mounted
  4. looking good to go
  5. testing how to export/import volume group
    1. vgchange –an <vgname>
    2. vgexport <vgname>
    3. vgimport <vgname>
    4. vgchange –ay <vgname>

How to Get the Partition Number on AIX Partitions ?

The uname command has been enhanced to show the partition number using the -L option. If you run uname -L on an AIX partition, you will see the following output:

1 lpar01


1 Partition number (unique for each partition)
lpar01 Partition name

If you run this command on AIX that is not running in a partitioned environment, you will see the following output:

nt-family: arial,helvetica,sans-serif;”>

NULL host_name

If you need to write a shell script to determine the partition number, it is advised that you use the following code fraction example:

LANG=C uname -Ls |
read junk partition_number partition_name

The -L option of the uname command only returns the partition number and partition name on AIX 5L Version 5.2 or AIX 5L Version 5.1 Recommended Maintenance Level 5100-03 or later, but it returns one additional string (“AIX”) on AIX 5L Version 5.1 Recommended Maintenance Level 5100-02, as shown in the following example:

AIX 1 lpar01

Therefore, if you add the -s option of uname, it ensures that you always receive the consistent output from uname, regardless of the AIX maintenance level.

What Happens When a User Logs In?

Well environment variables used to customize a user’s login environment can be defined from the command line, they are more commonly defined by several scripts that execute during the login process. Typically, three scripts execute during the login process to initialize the user’s environment.

The first is a system-wide script maintained by the system administrator to define general environment variables required by all users.

The second is a local login script maintained by each user. Local login scripts can override or modify the system defaults on a user-by-user basis.

The optional additional local login script can define additional environment variables or set additional shell features. In the POSIX shell, this additional script is often used to define shell aliases.

The login script names vary from shell to shell. A detailed discussion of the login scripts used by the POSIX, Korn, and C shells follows:

Shell Environment Initialization Sequence

  • The shell runs the appropriate system login script, which initializes the user’s environment. The system login scripts define a default environment, and can be customized by the system administrator.
    The System Login Script is…
If the Shell is… The System Login Script is…
Bourne (/usr/old/bin/sh) /etc/profile
Korn (/usr/bin/ksh) /etc/profile
POSIX (/usr/bin/sh) /etc/profile
Restricted (/usr/bin/rsh , /usr/bin/rksh) /etc/profile
C (/usr/bin/csh) /etc/csh.login



As shipped, these scripts define and export for shell use the environment variables PATH, TZ, and TERM. Inside these scripts, the files /etc/PATH, /etc/MANPATH, /etc/TIMEZONE, /etc/SHLIB_PATH are sourced. Since the system login scripts are run for all users at login, the system administrator can modify these files to set global defaults for all users.  This is useful for ensuring that each user runs essential commands at login.

  • Displays the contents of the /etc/copyright and /etc/motd file.
  • Notifies the user of unread news with the prompt:

news: news_filename

  • The shell runs the user’s local login script (if it exists) in the user’s home (login) directory:
If the Shell is … The Local Login Script is …
Bourne (/usr/old/bin/sh) .profile
Korn (/usr/bin/ksh ) .profile
Posix (/usr/bin/sh .profile
Restricted (/usr/bin/rsh .profile
C (/usr/bin/csh) .login


NOTE: Typically, the system administrator initially creates a local login script for each user. If SAM or useradd is used to add a user, it copies the default local login script (the /etc/skel/.profile) to the user’s home directory. Users can further customize their environments by modifying these files to suit their needs.
In addition to the above scripts, the POSIX, Korn and C shells may (and usually do) have additional local login scripts:

— POSIX and Korn shell – if the ENV variable is defined, the shell runs the file defined by ENV (typically, .shrc whenever a new shell is started. Many programs (for example, vi and mailx) allow users to start a shell from within the program; this is called a shell escape. The ENV file is re-run for a shell escape, whereas .profile is run only at login. The ENV file (either .kshrc or .shrc) will be executed after .profile executes upon login.
— C shell – Runs the .cshrc file whenever a new C shell is started. This is similar to how the Korn shell ENV file works. The .login file is run only at login, whereas .cshrc is rerun for every new C shell. The .cshrc file will be executed before the .login upon login.

  • Once all initialization is complete, the shell displays a prompt and waits for input from the user.

Changing User Passwords from the Command Line

bash-3.00# passwd stfa
Changing password for “stfa”
stfa’s New password:
Enter the new password again:

Any time a password needs to be changed, whether by a regular user or the superuser, the passwd command is used. Normally an ordinary user on the system can change his or her own password (but nobody else’s). When invoked, the user is prompted to enter the existing password. Upon entering the correct password, the user is prompted to enter the new password. After the new password is entered, the user is prompted to enter it again. This is done for verification purposes and to ensure the user didn’t make a typing error. If the second password does not match the first, the password is not changed and the user is returned to the shell.

If a user forgets his or her password, the user must seek the assistance of the administrator. The administrator can change any other user’s password by invoking passwd with an argument of the user’s login name.

As mentioned previously, there is an option when creating an account to disallow user changes to his or her password. In this case only the administrator, as super-user, can change the user password.

If, for some reason the root password needs to be changed, the administrator should invoke passwd while logged in as superuser. When changing or assigning a password as a user, note the following:

  • Passwords must contain at least 6 characters. Though a password may be assigned more characters, only the first eight are significant.
  • Passwords must contain at least two alpha characters (upper or lower case) and at least one numeric or special character. This enforces a certain level of security within the password structure.
NOTE: When you use the passwd command, a copy of the old /etc/passwd file is saved in /etc/opasswd.

You can also use the passwd command to change password aging for an account.

passwd -f -n min -x max name

min and max are expressed in days but will be rounded up to the nearest week. The -f option forces a user to change his or her password at the next login.

Enforce password aging for the account font:

passwd -n 7 -x 35 font

Force the user buddy to change his password at the next login:
passwd -f buddy

Linux RedHat Bare Metal Restore on diffrent Server

When doing a system recovery often the things that can break your recovery procedures is having a new system that is new and completely dissimilar from the old system. This recovery procedure will walk you thru the process of  creating the backup image and image restoration. Describe the recovery problem and its fixes.


I will be using RedHat ES 4 in this exercise. I will be using an NFS server to store the backup image and restore from it. You can also burn the backup image onto a CD or DVD but that this beyond the scope of this procedure. If you have a tape drive gathering dust, you can use it too.


The first step is to prepare your server for backup.

cp /boot/grub/grub.conf /boot/grub/grub.conf.backup
cp /etc/modprobe.conf /etc/modprobe.conf.backup

These two files is the main problem is restoring linux system images to a dissimilar systems. We don’t want them to be included in our backup image.

Mount the nfs file server under the /mnt directory.

mount nfsserver:/backups /mnt

Then finally we make the backup image with the tar command.

tar –create –verbose –preserve –ignore-failed-read –gzip –exclude=/proc –exclude=/sys –exclude=/var/run –exclude=/boot/grub/grub.conf –exclude=/etc/modprobe.conf –file=/mnt/backup.image.tgz /

It’s safe to ignore these warnings:

tar: Removing leading `/’ from member names
tar: /dev/gpmctl: socket ignored
tar: /dev/log: socket ignored
tar: Removing leading `/’ from hard link targets


Once you got your new system, you need to install the RedHat on it. You only need to install the minimum package. You will need CD 1 & 2. When asked for the package installation, choose custom. The next menu will present with the minimum option on the very bottom, check on that. This will be a quick installation. Depending on your system, my test system took about 5 minutes.

After the installation, reboot the new system. The crucial part is to check that the newly installed OS can see all your devices (NIC, RAID & DRIVES). Once you have verfied that every devices drivers is installed and working you are now ready to do the system restoration.

Mount the nfs file server under the /mnt directory.

mount nfsserver:/backups /mnt

Make a copy of the file /etc/fstab.

cp /etc/fstab /etc/fstab.backup

You are now ready to do the actual system recovery using the tar command.

tar –gunzip –extract –verbose –preserve –file=/mnt/backup.image.tgz

At this point you may reboot the system to check if it still can boot with restored images.

You need to create a new ramdisk image for your new system. Your old ramdisk images will probably not have the correct devices drivers.

mkinitrd /boot/new-initrd-2.6.9-42.0.10.ELsmp 2.6.9-42.0.10.ELsmp

Next you need to merge the files /boot/grub/grub.conf and /boot/grub/grub.conf.backup. The file /boot/grub/grub.conf is new working grub configuration file while the file /boot/grub/grub.conf.backup is old grub configuration file. The problem with old grub configuration file is that it is pointing to old lame ramdisk image, you need to change that to point to the newly created ramdisk image. You just can’t use the new working grub configuration because that is probably not configured to use the recent installed kernel.

If your old grub configuration looks like this:

# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
title Red Hat Enterprise Linux ES (2.6.9-42.0.10.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-42.0.10.ELsmp ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.9-42.0.10.ELsmp.img
title Red Hat Enterprise Linux ES (2.6.9-42.0.10.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.9-42.0.10.EL.img

You should change it to:

# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
title Red Hat Enterprise Linux ES (2.6.9-42.0.10.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-42.0.10.ELsmp ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.9-42.0.10.ELsmp.img
title Red Hat Enterprise Linux ES (2.6.9-42.0.10.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.9-42.0.10.EL.img

title Red Hat Enterprise Linux ES (2.6.9-42.0.10.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-42.0.10.ELsmp ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /new-initrd-2.6.9-42.0.10.ELsmp.img

Now, compare the files /etc/fstab and /etc/fstab.backup. You need to check that root and /boot files are mounted correctly and not mounted like the old system.

/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
/dev/VolGroup00/LogVol01 swap swap defaults 0 0

The restoration is almost complete, the next thing to do is reboot the system. Once it boot up kudzu (Red Hat Linux hardware probing library) should be triggered. Remove all old drivers and configure newly found devices.

The last thing to configure is the network configuration. Your old NIC configuration will not work since the MAC address is hard coded on the NIC startup scripts. (see /etc/sysconfig/network-scripts/ifcfg-eth0)

You should now have fully recovered your system.

How can I reduce the size of /var/adm/wtmp ?

The file /var/adm/wtmp grows with each login, but is never reduced.
The contents of wtmp is used (only?) by the command “last”,
which shows, in reverse order, all the logins and reboots that
happened since the start of the wtmp file.

The file should not be deleted, but the contents can be discarded using
the following command:
# > /var/adm/wtmp

Alternatively the freeware utility “tidysys” can remove all the entries
from wtmp that are older than (say) 15 days. Tidysys was written by
Terry Murray for AIX 3.2 and is available

How can I log information about ftp accesses to a file?

1) In /etc/syslog.conf, add the line:
daemon.debug /tmp/daemon.log

2) # touch /tmp/daemon.log
# refresh -s syslogd

3) Modify your inetd.conf so that ftpd is called with the “-l” flag.
You may also want the “-d” flag. This can be done with ‘smit inetdconf’.

All the syslog messages from various system daemons should now appear in
the file “/tmp/daemon.log”.

How do I get rid of the verbose error messages?

Many of the messages from the Unix commands are available in different languages. This is controlled by the LANG environment variable, the default being En_US meaning English in the US. All the default messages have a message number associated with them, e.g.:

$ cat no-such-file

cat: 0652-050 Cannot open no-such-file.

If you prefer the terser Unix-looking error message, set your environment variable LC_MESSAGES to C, and you will get:

$ cat no-such-file

cat: Cannot open no-such-file.

By default LC_MESSAGES is the same as your environment LANG. Setting LANG does also work, but should be avoided since it changes app-defaults lookup etc. See locale(): LC_ALL

From: Bjorn P. Brox <brox@corena.n>