DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.
Unmirroring rootvg in AIX
Root Volume Group (rootvg) is a volume group containing the Base Operating System (BOS). Logical volume (lv) in rootvg may be doubled or more in copies with 2 or more physical volume (hard disk) for availability and reliability of the AIX system. The following steps are to unmirror a rootvg, if for whatever reason the rootvg needs to run on single logical volume (lv) on single physical volume (pv) only.
2. To update the booted disk link, enter the following command:
ln -f /dev/rhdisk01 /dev/ipldevice
Check and Determine if rootvg is Mirrored
In mirror mode, each logical volume in rootvg such as filesystems “/”, “/usr”, “/var”, “/tmp”, “/home”, “/opt” and default boot, paging and jfslog LVs should be mirrored. In AIX, mirrorvg will create additional copy of image for all logical volumes in the volume group.
Use the following command to check if a rootvg is mirrored:
# lsvg -l rootvg
If the output shows that for each LP there are 2 PPs then its mirrored.
Check and Determine Which Disks the Mirrored rootvg is Located
For each logical volume (LV) name listed in output of “lsvg -l rootvg” command, run the following command:
lslv -m
The output data will tell you on which disk each copy of each logical partitions for each LV.
Use the following command to check if a rootvg is mirrored:
# lsvg -l rootvg
If the output shows that for each LP there are 2 PPs then its mirrored.
Check and Determine Which Disks the Mirrored rootvg is Located
For each logical volume (LV) name listed in output of “lsvg -l rootvg” command, run the following command:
lslv -m
The output data will tell you on which disk each copy of each logical partitions for each LV.
Unmirror rootvg
Important: The following instructions have the risk of making your AIX system unbootable or corrupting the data. So make you have advanced system administration experience before running the process of unmirroring.
To unmirror the root volume group (rootvg), follow the steps below (scenario: rootvg is contained on hdisk01 and mirrored onto hdisk11, and the steps will remove the mirror on hdisk11 (regardless of the disk from which you previously booted)):
1. To unmirror the rootvg from hdisk11, enter the following command:
unmirrorvg rootvg hdisk11
This command turns quorum back on for rootvg. When unmirrorvg is executed, the default COPIES value for each logical volume becomes 1.
To unmirror the root volume group (rootvg), follow the steps below (scenario: rootvg is contained on hdisk01 and mirrored onto hdisk11, and the steps will remove the mirror on hdisk11 (regardless of the disk from which you previously booted)):
1. To unmirror the rootvg from hdisk11, enter the following command:
unmirrorvg rootvg hdisk11
This command turns quorum back on for rootvg. When unmirrorvg is executed, the default COPIES value for each logical volume becomes 1.
2. To update the booted disk link, enter the following command:
ln -f /dev/rhdisk01 /dev/ipldevice
3. To reduce the disk out of rootvg, type the following command:
reducevg rootvg hdisk11
reducevg rootvg hdisk11
4. To initilize the boot record of the remaining disk again, enter the following command:
bosboot -a -d /dev/hdisk01
bosboot command is a must to initialize the boot record on the remaining disk hdisk01 again.
bosboot -a -d /dev/hdisk01
bosboot command is a must to initialize the boot record on the remaining disk hdisk01 again.
5. To modify the boot list to remove the unmirrored disk, type the following command:
bootlist -m normal hdisk01
bootlist command is a must so that the system only boots to the disk remaining (hdisk01) in rootvg.
bootlist -m normal hdisk01
bootlist command is a must so that the system only boots to the disk remaining (hdisk01) in rootvg.
6. Restart AIX machine, as unmirroring turns quorum back on for rootvg, a reboot is required for this to take effect.
Note: The reducevg command in step 3 will fail if there are non-mirrored logical volumes such as raw logical volumes and system dump devices on the disk.
Note: The reducevg command in step 3 will fail if there are non-mirrored logical volumes such as raw logical volumes and system dump devices on the disk.
UNIX one-liners continued
These one liners may be of help to identify user or group info...
1. To extract only the userid from the /etc/passwd file based on a string sequence in the GECOS field.
cat /etc/passwd | awk -F":" '/\[I]/ { print $1 }'
OR
cat /etc/passwd | awk -F":" '/GB\/I/ { print $1 }'
2. To list records in /etc/passwd of users who are members of the staff group.
grep <groupname> /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd ; rm patFile;
grep staff /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd ; rm patFile;
3. To list userids and home directories of users of the staff group.
grep <groupname> /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd | awk -F ":" '{ print $1, $6}'; rm patFile;
grep staff /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd | awk -F ":" '{ print $1, $6}'; rm patFile;
4. To list all the groups of which a userid is a member of
grep <userid> /etc/group | awk -F":" '{ print $1 }'
grep sabari /etc/group | awk -F":" '{ print $1 }'
5. To list all users of a group and further grep them by a department signifier in the GECOS field.
grep <groupname> /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd | egrep \/I\/ | awk -F":" '{ print $1," ", $5 }'; rm patFile;
grep sys group.file | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd | egrep \/I\/ | awk -F":" '{ print $1," ", $5 }'; rm patFile;
6. To print only one particular field from a file
cat <filename> |awk '{ print $5 }'
1. To extract only the userid from the /etc/passwd file based on a string sequence in the GECOS field.
cat /etc/passwd | awk -F":" '/\[I]/ { print $1 }'
OR
cat /etc/passwd | awk -F":" '/GB\/I/ { print $1 }'
2. To list records in /etc/passwd of users who are members of the staff group.
grep <groupname> /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd ; rm patFile;
grep staff /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd ; rm patFile;
3. To list userids and home directories of users of the staff group.
grep <groupname> /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd | awk -F ":" '{ print $1, $6}'; rm patFile;
grep staff /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd | awk -F ":" '{ print $1, $6}'; rm patFile;
4. To list all the groups of which a userid is a member of
grep <userid> /etc/group | awk -F":" '{ print $1 }'
grep sabari /etc/group | awk -F":" '{ print $1 }'
5. To list all users of a group and further grep them by a department signifier in the GECOS field.
grep <groupname> /etc/group | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd | egrep \/I\/ | awk -F":" '{ print $1," ", $5 }'; rm patFile;
grep sys group.file | awk -F":" '{ print$4}' | sed 's/\,/ /g' | xargs -n1 echo > patFile ; grep -f patFile /etc/passwd | egrep \/I\/ | awk -F":" '{ print $1," ", $5 }'; rm patFile;
6. To print only one particular field from a file
cat <filename> |awk '{ print $5 }'
UNIX one liners - Very helpful in daily activities
In our day to day activities, we will be doing most of the routine tasks which needs many commands to run for completeing the task.
Below are few of the one-liner commands that can achieve our tasks.
These one liners may be of help to identify files to be acted upon by xargs.
1. To identify files in dir /tmp dated March with psx2 anywhere in the name :and remove them
find /tmp -type f -name *psx2* -ls | awk '$8=="Mar"' | awk -F" " ' { print $11 }' | xargs rm -rf
2. To identify multiple name formats dated Apr 10 and gzip them ...
cd /logs/of/surpriseme
find `pwd` -type f \( -name user1_log..txt -o -name system3_log.txt \) -ls | grep "Apr 10" | awk -F" " ' { print $11 }' | xargs gzip
3. To identify files dated March 20-31 and remove them.
find `pwd` -type f -ls | awk '$6=="Mar" && $7>19 && $7<32' | awk -F" " ' { print $11 }' | xargs rm -rf
find `pwd` -type f -ls | awk '$8=="Aug" && $9>19 && $9<22'
4. To find the total filespace used by User willy on a system.
find / -user willy -type f -ls 2> /dev/null | awk '{ sum += $7 } END { printf " %7.3f MB \n", (sum / (1024 * 1024)) }'
5. To find 20 biggest files on the /var filesystem showing their owner, group, size in MB and path:
find /var -type f -ls | sort -rn +6 | head -20 | awk -F " " '{ printf " %s \t %s \t %7.3f MB \t %s \n" , $5, $6, ( $2/1024), $11}'
6. To find files older than 12-Jan-2007 and move them to the /tmp dir. First identify a file with that date stamp in the file system. Then
find `pwd` -type f !-newer /absolute_path_to/file_with_cutoffpoint/datestamp - ls | awk -F " " '{ print $11 }' | xargs -I { } mv { } /tmp
7. To rename files names with extension .txt to .log
find $(pwd) -type f -name *.txt | xargs -i mv {} {}.log
Below are few of the one-liner commands that can achieve our tasks.
These one liners may be of help to identify files to be acted upon by xargs.
1. To identify files in dir /tmp dated March with psx2 anywhere in the name :and remove them
find /tmp -type f -name *psx2* -ls | awk '$8=="Mar"' | awk -F" " ' { print $11 }' | xargs rm -rf
2. To identify multiple name formats dated Apr 10 and gzip them ...
cd /logs/of/surpriseme
find `pwd` -type f \( -name user1_log..txt -o -name system3_log.txt \) -ls | grep "Apr 10" | awk -F" " ' { print $11 }' | xargs gzip
3. To identify files dated March 20-31 and remove them.
find `pwd` -type f -ls | awk '$6=="Mar" && $7>19 && $7<32' | awk -F" " ' { print $11 }' | xargs rm -rf
find `pwd` -type f -ls | awk '$8=="Aug" && $9>19 && $9<22'
4. To find the total filespace used by User willy on a system.
find / -user willy -type f -ls 2> /dev/null | awk '{ sum += $7 } END { printf " %7.3f MB \n", (sum / (1024 * 1024)) }'
5. To find 20 biggest files on the /var filesystem showing their owner, group, size in MB and path:
find /var -type f -ls | sort -rn +6 | head -20 | awk -F " " '{ printf " %s \t %s \t %7.3f MB \t %s \n" , $5, $6, ( $2/1024), $11}'
6. To find files older than 12-Jan-2007 and move them to the /tmp dir. First identify a file with that date stamp in the file system. Then
find `pwd` -type f !-newer /absolute_path_to/file_with_cutoffpoint/datestamp - ls | awk -F " " '{ print $11 }' | xargs -I { } mv { } /tmp
7. To rename files names with extension .txt to .log
find $(pwd) -type f -name *.txt | xargs -i mv {} {}.log
Converting ext2 filesystem to ext3 in Linux
The tune2fs allows you to convert an ext2 filesystem to ext3.
Note : Always use the e2fsck utility to check your filesystem before and after using tune2fs.
A default installation of Red Hat Enterprise Linux uses ext3 for all file systems.
To convert an ext2 filesystem to ext3, log in as root and type the following command in a terminal:
/sbin/tune2fs -j <block_device>
where <block_device> contains the ext2 filesystem you wish to convert.
A valid block device could be one of two types of entries:
• A mapped device — A logical volume in a volume group, for example, /dev/mapper/VolGroup00-LogVol02.
• A static device — A traditional storage volume, for example, /dev/hdbX, where hdb is a storage
device name and X is the partition number.
Issue the df command to display mounted file systems.
You must recreate the initrd image so that it will contain the ext3 kernel module. To create this,
run the mkinitrd program. For information on using the mkinitrd command, type man mkinitrd.
Also, make sure your GRUB configuration loads the initrd.
If you fail to make this change, the system still boots, but the file system is mounted as ext2 instead
of ext3.
Note : Always use the e2fsck utility to check your filesystem before and after using tune2fs.
A default installation of Red Hat Enterprise Linux uses ext3 for all file systems.
To convert an ext2 filesystem to ext3, log in as root and type the following command in a terminal:
/sbin/tune2fs -j <block_device>
where <block_device> contains the ext2 filesystem you wish to convert.
A valid block device could be one of two types of entries:
• A mapped device — A logical volume in a volume group, for example, /dev/mapper/VolGroup00-LogVol02.
• A static device — A traditional storage volume, for example, /dev/hdbX, where hdb is a storage
device name and X is the partition number.
Issue the df command to display mounted file systems.
You must recreate the initrd image so that it will contain the ext3 kernel module. To create this,
run the mkinitrd program. For information on using the mkinitrd command, type man mkinitrd.
Also, make sure your GRUB configuration loads the initrd.
If you fail to make this change, the system still boots, but the file system is mounted as ext2 instead
of ext3.
Converting back Linux ext3 file system to ext2 file system
If you wish to revert a partition from ext3 to ext2 for any reason, you must first unmount the partition
by logging in as root and typing,
umount /dev/mapper/VolGroup00-LogVol02
Next, change the file system type to ext2 by typing the following command as root:
/sbin/tune2fs -O ^has_journal /dev/mapper/VolGroup00-LogVol02
Check the partition for errors by typing the following command as root:
/sbin/e2fsck -y /dev/mapper/VolGroup00-LogVol02
Then mount the partition again as ext2 file system by typing:
mount -t ext2 /dev/mapper/VolGroup00-LogVol02/mount/point
In the above command, replace /mount/point with the mount point of the partition.
Next, remove the .journal file at the root level of the partition by changing to the directory
where it is mounted and typing:
rm -f .journal
You now have an ext2 partition.
If you want to permanently change the partition to ext2, remember to update the /etc/fstab file.
by logging in as root and typing,
umount /dev/mapper/VolGroup00-LogVol02
Next, change the file system type to ext2 by typing the following command as root:
/sbin/tune2fs -O ^has_journal /dev/mapper/VolGroup00-LogVol02
Check the partition for errors by typing the following command as root:
/sbin/e2fsck -y /dev/mapper/VolGroup00-LogVol02
Then mount the partition again as ext2 file system by typing:
mount -t ext2 /dev/mapper/VolGroup00-LogVol02/mount/point
In the above command, replace /mount/point with the mount point of the partition.
Next, remove the .journal file at the root level of the partition by changing to the directory
where it is mounted and typing:
rm -f .journal
You now have an ext2 partition.
If you want to permanently change the partition to ext2, remember to update the /etc/fstab file.
Disabling IPv6 support in Red Hat Enterprise Linux 6
Create a file /etc/modprobe.d/ipv6.conf with the following contents:
options ipv6 disable=1
For completeness, it is a good idea to configure the ip6tables service not to start at boot by issuing the following command:
# chkconfig ip6tables off
disable ipv6 support in the kernel through /etc/sysctl.conf :
# ipv6 support in the kernel, set to 0 by default
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
Reboot the system to disable IPv6 support.
Note: There is a special case where this might not work, please see The "ipv6 disable=1" option does not seem to work on Red Hat Enterprise Linux 6 system. Disabling ipv6 in the sysctl.conf will ensure ipv6 isn't used even if the ipv6 module is loaded and can work as a short term solution (until a full reboot).
"vmount: operation not permitted" Error From Linux NFS Server
While trying to mount a Linux NFS share in an AIX server, we get the below error.
Sometimes Linux NFS servers will do port checking and require that the NFS client use a reserved port.
nfso -o nfs_use_reserved_ports=1
If the mount is going to be permanent, then the change needs to survive across a reboot. The nfs option must be changed permanently. On AIX 4.x and 5.1, the command above should be added to the startup scripts (possibly /etc/rc.nfs). On AIX 5.2 and above, the change can be made permanent by adding the -p flag.
nfso -p -o nfs_use_reserved_ports=1
localhost:root:/#mount 10.1.1.1:/nfs_data /mnt/nfsShare
mount: 1831-008 giving up on:
10.1.1.1:/nfs_data
vmount: Operation not permitted.
Sometimes Linux NFS servers will do port checking and require that the NFS client use a reserved port.
nfso -o nfs_use_reserved_ports=1
If the mount is going to be permanent, then the change needs to survive across a reboot. The nfs option must be changed permanently. On AIX 4.x and 5.1, the command above should be added to the startup scripts (possibly /etc/rc.nfs). On AIX 5.2 and above, the change can be made permanent by adding the -p flag.
nfso -p -o nfs_use_reserved_ports=1
Top Netstat commands with examples
Netstat command displays various network related information such as
network connections, routing tables, interface statistics, masquerade
connections, multicast memberships etc.,
In this article, let us review 10 practical unix netstat command examples.
This also speeds up the output, as netstat is not performing any look-up.
In this article, let us review 10 practical unix netstat command examples.
1. List All Ports (both listening and non listening ports)
List all ports using netstat -a
# netstat -a | more Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:30037 *:* LISTEN udp 0 0 *:bootpc *:* Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 6135 /tmp/.X11-unix/X0 unix 2 [ ACC ] STREAM LISTENING 5140 /var/run/acpid.socket
List all tcp ports using netstat -at
# netstat -at Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:30037 *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 *:smtp *:* LISTEN tcp6 0 0 localhost:ipp [::]:* LISTEN
List all udp ports using netstat -au
# netstat -au Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 *:bootpc *:* udp 0 0 *:49119 *:* udp 0 0 *:mdns *:*
2. List Sockets which are in Listening State
List only listening ports using netstat -l
# netstat -l Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:ipp *:* LISTEN tcp6 0 0 localhost:ipp [::]:* LISTEN udp 0 0 *:49119 *:*
List only listening TCP Ports using netstat -lt
# netstat -lt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:30037 *:* LISTEN tcp 0 0 *:smtp *:* LISTEN tcp6 0 0 localhost:ipp [::]:* LISTEN
List only listening UDP Ports using netstat -lu
# netstat -lu Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 *:49119 *:* udp 0 0 *:mdns *:*
List only the listening UNIX Ports using netstat -lx
# netstat -lx Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 6294 private/maildrop unix 2 [ ACC ] STREAM LISTENING 6203 public/cleanup unix 2 [ ACC ] STREAM LISTENING 6302 private/ifmail unix 2 [ ACC ] STREAM LISTENING 6306 private/bsmtp
3. Show the statistics for each protocol
Show statistics for all ports using netstat -s
# netstat -s Ip: 11150 total packets received 1 with invalid addresses 0 forwarded 0 incoming packets discarded 11149 incoming packets delivered 11635 requests sent out Icmp: 0 ICMP messages received 0 input ICMP message failed. Tcp: 582 active connections openings 2 failed connection attempts 25 connection resets received Udp: 1183 packets received 4 packets to unknown port received. .....
Show statistics for TCP (or) UDP ports using netstat -st (or) -su
# netstat -st # netstat -su
4. Display PID and program names in netstat output using netstat -p
netstat -p option can be combined with any other netstat option. This will add the “PID/Program Name” to the netstat output. This is very useful while debugging to identify which program is running on a particular port.# netstat -pt Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 1 0 ramesh-laptop.loc:47212 192.168.185.75:www CLOSE_WAIT 2109/firefox tcp 0 0 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox
5. Don’t resolve host, port and user name in netstat output
When you don’t want the name of the host, port or user to be displayed, use netstat -n option. This will display in numbers, instead of resolving the host name, port name, user name.This also speeds up the output, as netstat is not performing any look-up.
# netstat -anIf you don’t want only any one of those three items ( ports, or hosts, or users ) to be resolved, use following commands.
# netsat -a --numeric-ports # netsat -a --numeric-hosts # netsat -a --numeric-users
6. Print netstat information continuously
netstat will print information continuously every few seconds.# netstat -c Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 ramesh-laptop.loc:36130 101-101-181-225.ama:www ESTABLISHED tcp 1 1 ramesh-laptop.loc:52564 101.11.169.230:www CLOSING tcp 0 0 ramesh-laptop.loc:43758 server-101-101-43-2:www ESTABLISHED tcp 1 1 ramesh-laptop.loc:42367 101.101.34.101:www CLOSING ^C
7. Find the non supportive Address families in your system
netstat --verboseAt the end, you will have something like this.
netstat: no support for `AF IPX' on this system. netstat: no support for `AF AX25' on this system. netstat: no support for `AF X25' on this system. netstat: no support for `AF NETROM' on this system.
8. Display the kernel routing information using netstat -r
# netstat -r Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.1.0 * 255.255.255.0 U 0 0 0 eth2 link-local * 255.255.0.0 U 0 0 0 eth2 default 192.168.1.1 0.0.0.0 UG 0 0 0 eth2Note: Use netstat -rn to display routes in numeric format without resolving for host-names.
9. Find out on which port a program is running
# netstat -ap | grep ssh (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 1 0 dev-db:ssh 101.174.100.22:39213 CLOSE_WAIT - tcp 1 0 dev-db:ssh 101.174.100.22:57643 CLOSE_WAIT -Find out which process is using a particular port:
# netstat -an | grep ':80'
10. Show the list of network interfaces
# netstat -i Kernel Interface table Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg eth0 1500 0 0 0 0 0 0 0 0 0 BMU eth2 1500 0 26196 0 0 0 26883 6 0 0 BMRU lo 16436 0 4 0 0 0 4 0 0 0 LRUDisplay extended information on the interfaces (similar to ifconfig) using netstat -ie:
# netstat -ie Kernel Interface table eth0 Link encap:Ethernet HWaddr 00:10:40:11:11:11 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Memory:f6ae0000-f6b00000