Main Menu

Search

Showing posts with label Linker Article Linux. Show all posts
Showing posts with label Linker Article Linux. Show all posts

LINUX - HOW TO MOUNT SYSTEM DISK IMAGE FILE OF UEK4 & LATER KERNELS OF ORACLE LINUX VM USING KPARTX COMMANDS AND RUN FSCK?


Below are steps for mounting VM System disk image file using the Logical volume (LVM based) and running fsck.

1. Kpartx command to mount system image file on the available device
 
# kpartx -av vm0-disk.img

add map loop2p1 (249:0): 0 1024000 linear /dev/loop2 2048
add map loop2p2 (249:1): 0 248479467 linear /dev/loop2 1026048
 
2. List the device mappers
 
# ls -lrt /dev/mapper/*

crw-rw---- 1 root root 10, 236 Jul 6 16:25 /dev/mapper/control
lrwxrwxrwx 1 root root 7 Nov 25 17:19 /dev/mapper/loop2p2 -> ../dm-1
lrwxrwxrwx 1 root root 7 Nov 25 17:19 /dev/mapper/loop2p1 -> ../dm-0
 
3. Run fsck command on the mounted logical volume

# fsck -vy /dev/mapper/loop2p1

fsck from util-linux-ng 2.17.2
e2fsck 1.43-WIP (20-Jun-2013)
/boot: clean, 52/126000 files, 147492/512000 blocks
# fsck -vy /dev/mapper/loop2p1
fsck from util-linux-ng 2.17.2
e2fsck 1.43-WIP (20-Jun-2013)
/boot: clean, 52/126000 files, 147492/512000 blocks
# fsck -vy /dev/mapper/loop2p2
fsck from util-linux-ng 2.17.2
fsck: fsck.LVM2_member: not found
fsck: Error 2 while executing fsck.LVM2_member for /dev/mapper/loop2p2
# fsck -vy /dev/mapper/loop2p1
fsck from util-linux-ng 2.17.2
e2fsck 1.43-WIP (20-Jun-2013)
/boot: clean, 52/126000 files, 147492/512000 blocks
 
4. Remove the mounted logical volume device.
 
# kpartx -dv /dev/loop2
del devmap : loop2p2
del devmap : loop2p1
 
# losetup -dv /dev/loop2
 
# ls -lrt /dev/mapper/*
crw-rw---- 1 root root 10, 236 Jul 6 16:25 /dev/mapper/control
#
 

LINUX: MOUNT COMMAND TO MOUNT NFSV4 SHARE

Following is mount command to mount NFSv4 share

mount -t nfs4 192.168.XX.XX:/export/common/testshare testsharenfsv4


LINUX: PS COMMAND / SCRIPT TO CHECK PROCESSES USING PARTICULAR CPU CORE OR VCPU


Following command can be used to find processes using particular, core. In below command example we are finding processes running on CPU core 4. Replace CPU/Core Number as needed for CORENUM argument

CORENUM=4; ps -e -o pid,psr,cpu,cmd | grep -E  "^[[:space:]][[:digit:]]+[[:space:]]+${CORENUM}


Below is sample output of above command.
 

 1027   4   - [scsi_eh_6]

 1779   4   - /bin/bash /usr/sbin/OSWatcher -i 30 -m 48 -l /var/log/oswatcher/log /var/log/oswatcher

 3002   4   - [kworker/4:1H]

 3620   4   - [alias_guid1]

 3651   4   - [mcast_wq]

 4187   4   - [krds_cp_wq_14]

 5542   4   - [fcoethread/4]

 5563   4   - [bnx2fc_thread/4]

 5643   4   - [o2net]

 5702   4   - [nfsiod]

 7114   4   - /usr/bin/python /usr/lib64/python2.6/site-packages/agent/daemon/stats.py

 7372   4   - /sbin/mingetty /dev/tty3

LINUX: SORT Command To Print Only Unique Lines In a File

Below SORT command can be used to print only unique lines in a file.

sort -u <filename>

LINUX: Sort Command To Sort Output On Specific Column Numerically In Ascending Order (How To)

For e.g. if you want to sort output from a file in ascending order on specific column numerically, in this e.g. lets assume column 5, below command can be used.

cat filename | sort -n -k5

Replace 5 in above command with whatever column name you want to sort.

LINUX: Sort Command To Sort Output On Specific Column in Descending Order (How To)

For e.g. if you want to sort output from a file in descending order on specific column, in this e.g. lets assume column 5, below command can be used.

cat filename | awk {'print $5'} | sort -n

Replace 5 in above command with whatever column name you want to sort.

LINUX: Find Command To Search Files Owned By Particular User in Local File Systems (Excluding NFS Shares)

Below is find command to use Search Files Owned By Particular User in Local File Systems (Excluding NFS Shares)
find / -xdev -user username
Replace Username in above command as needed.

Products to which Article Applies
All Linux Operating Systems

Article Author: Tarun Boyella

LINUX - FInd Command to FInd and Replace Particular String in All files Inside A Directory (SED Command) (How To Doc)

Below is find command to find and replace particular string in all files in current directory.

In this command example we are replacing host1 inside all files which has it in current directory with host2 word.


find ./ -type f -exec sed -i 's/host1/host2/g' {} \;



Products to which Article Applies
All Linux Operating Systems

Article Author: Tarun Boyella

LINUX: mlx4_vnic_info command to list all details of Ethernet Interface (MTU, Link Status, VLAN, PKEY, MAC, Switch It is Associated etc.)

Below mlx4_vnic_info command on Linux node will list all details of Ethernet Interface (MTU, Link Status, VLAN, PKEY, MAC, Switch It is Associated etc.)
mlx4_vnic_info -i
Below is exanple output of above command.
NETDEV_REGIST yes 
NETDEV_NAME   eth1286_1.324 
NETDEV_LINK   up 
NETDEV_OPEN   yes 
NETDEV_QSTOP  no 
NETDEV_MTU    1500 
IOA_PORT      mlx4_0:1 
IOA_NAME      MT25408 ConnectX Mellanox Technologies-P1 
IOA_LID       0x007d 
IOA_GUID      91:9b:f9:97:XXXXXXXX
IOA_LOG_LINK  up 
IOA_PHY_LINK  active 
IOA_MTU       2048 
EPORT_STATE   up 
EPORT_NAME    0A-ETH-1 
EPORT_QPN     0x800000 
EPORT_LID     0x0011 
EPORT_ID      1286 
BX_NAME       switch01 
BX_GUID       00:10:e0:62:XXXXXXXX
GW_TYPE       LEGACY 
SW_RSS        no 
SW_RSS_SIZE   1 
RX_RINGS_NUM  1 
RX_RINGS_LIN  no 
TX_RINGS_NUM  1 
TX_RINGS_ACT  1 
NDO_TSS       no 
NDO_TSS_SIZE  1 
MCAST_PROMISC no 
MCAST_MASK    48 
PKEY          0x8007 
PKEY_INDEX    0x000b 
PKEY_MEMBER   full 
SL_DATA       1 
SL_CONTROL    2 
LRO           yes 
LRO_NUM       32 
NAPI          yes 
NAPI_WEIGHT   32 
QPN           0x5c0748 
MAC           00:21:f6:XXXXXX
ADMIN_MODE    network 
VLAN          0x144 
SHARED_MAC    N/A 
SHARED_IP     N/A 

Products to which Article Applies
All Linux Hosts using Mellanox mlx4 stack

Article Author: Tarun Boyella

LINUX: How to Switch Active Slave for Particular Network Interface on Linux host?

Below command can be used to flip active slave on the network interface on Linux host.
ifenslave -c <interface name> <slave name which you want to have as active slave>
For e.g. if you have bond0 interface with 2 slaves eth0 and eth1 and if you want to set eth1 as active slave for bond0, Below is the command you have to run.
ifenslave -c bond0 eth1
Products to which Article Applies
All Linux Operating Systems

Article Author: Tarun Boyella

LINUX: How to list Ethernet Interfaces (mlx4_vnic_info)

Following commands can be used for listing the Ethernet interfaces on Linux hosts.
mlx4_vnic_info -l 
mlx4_vnic_info -S

Products to which Article Applies
All Linux hosts using Ethernet interfaces

Article Author: Tarun Boyella

LINUX: PING command to do PING test over a specific Network interface (How To Doc)

Following PING command can be used to do ping test over a specific network interface.
ping -I <interface> <destination host/IP>
For example if you want to ping destination IP 10.10.10.10 over eth0 interface of the machine from machine you are doing PING test, your command will look like below.
ping -I eth0 10.10.10.10
Products to which Article Applies
All Linux Operating Systems

Article Author: Tarun Boyella

LINUX: How to capture TCPDUMPs on specific IP and Port number?

Below is tcpdump command to run capture packets on specific IP and port.
tcpdump -i any host  and port  -w /tmp/filename.pcap 
In above command replace IP and Port number with the IP and port on which you want to capture the packets. Above command captures the tcpdumps to /tmp/filename.pcap file.

Products to which Article Applies
All Linux Operating Systems

Article Author: Tarun Boyella

LINUX: How To Create New Sudo User And Give Sudo Root Access To Newly Created User?

Following are steps for creating new sudo user and give sudo root access to newly created user.
1. If you want to add new sudo root user and group with same name for e.g. ss1 user and ss1 group, run below command.
useradd -d /home/ss1 -s /bin/bash -m ss1
In case you want to use different group for newly added user (with group name different than user name), Run groupadd command to create new group followed by useradd command to add new user to the newly created group.
2. Change password of newly created sudo root user as follows. In this example the user is ss1.
passwd ss1
3. Add newly created user to /etc/sudoers files. For this make below changes to /etc/sudoers file and save it.
(a) visudo
(b)  Search for below line
username ALL=(ALL) NOPASSWD: ALL
Just below above line add below line. Replace ss1 username as needed. With this we are giving sudo root access to ss1 user (without being prompted for password when running sudo command)
ss1 ALL=(ALL) NOPASSWD: ALL
4. Now login to Linux node using newly created sudo user, in this example ss1.
5. sudo to root as follows
sudo su -
You should be logged into root user without being prompted for password.

Products to which Article Applies
Oracle Linux. Steps in this Article also works on other flavors of Linux other.


Article Author: Tarun Boyella

LINUX: How To Remove & Reload Particular Network Bond on Linux Hosts?

Below are steps for removing and reloading particular network bond on Linux hosts

1. Bring down the network bond using below command. Replace bondX with the bond number you want to remove and reloading.

ifdown bondX

2. Run below command to remove the bonding during the runtime. This command just removes the loaded bonds during runtime, it does not complete remove the bonds.
modprobe -r bonding

3. Bring up the network bond again using below command. Replace bondX with the bond number.

ifup bondX

Products to which Article Applies

All Linux Operating Systems

Additional Reference

https://wiki.linuxfoundation.org/networking/bonding

 

LINUX: How To Read TCPDUMP File ("tcpdump" command)

Below tcpdump -r command can be used to read the tcpdumps files.
tcpdump -r <TCPDUMP FILE>

Below is example snippet of above command.

tcpdump -r test-net-capture.pcap
reading from file test-server_2019-02-09-07_3A17_3A21.pcap, link-type LINUX_SLL (Linux cooked)
15:17:21.989054 IP 10.10.21.240.958 > 10.10.21.17.nfs: Flags [P.], seq 681528850:681528990, ack 544193837, win 24576, options [nop,nop,TS
 val 9880026 ecr 239296542], length 140: NFS request xid 2055647236 136 read fh Unknown/ZZYYXX0A00040000000
000678F0000 4096 bytes @ 5436645376
15:17:21.999201 IP 10.10.21.240.958 > 10.10.21.17.nfs: Flags [P.], seq 140:280, ack 4229, win 24576, options [nop,nop,TS val 9880036 ecr
239296543], length 140: NFS request xid 2072424452 136 read fh Unknown/ZZYYXX0A00040000000000678F0000 4096
bytes @ 5436649472
15:17:22.009024 IP 10.10.21.240.958 > 10.10.21.17.nfs: Flags [P.], seq 280:420, ack 8457, win 24576, options [nop,nop,TS val 9880046 ecr

Products to which Article Applies

All Linux Operating Systems
 

Additional Reference

https://www.tecmint.com/12-tcpdump-commands-a-network-sniffer-tool/


LINUX: SSH Command To Login without Strict Host Key Checking and Host IP Checking (How To) ("ssh" Command)

Below SSH command can be used to login to remote host without Strict Host Key Checking and Host IP Checking.

ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oCheckHostIP=no root@<remotehost IP>

 

Products to which Article Applies

All Linux Operating Systems

LINUX: How To Setup SSH Keys To Enable Passwordless SSH Between Linux Hosts? (RSA)

This article provides detailed steps on setting up SSH keys to enable passwordless SSH between Linux hosts.

For example lets assume you want to enable passwordless SSH between two Linux hosts source-vm and target-vm, where source-vm is the host from which you want to connect to target-vm host via SSH without password prompt, below are steps to follow.

1. On source-vm cd .ssh directory inside user home directory. Below command can be used.
cd $HOME/.ssh

2. Create SSH rsa keypair using below command.
ssh-keygen -t rsa

Below is example output of above command.
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0b:12:45:53:31:78:64:7d:68:b9:1c:54:36:2d:51:3e root@source-vm
The key's randomart image is:
+--[ RSA 2048]----+
|     .++*+.+=+.  |
|     ..o..*.oo.  |
|    .  . o + .E  |
|     .    o    . |
|    . . S        |
|     . . .       |
|        .        |
|                 |
|                 |
+-----------------+

Once above command is executed, we will see below files inside <user home>/.ssh directory on source-VM.

authorized_keys 
id_rsa 
id_rsa.pub 
known_hosts

3. Now copy the public key id_rsa.pub  from source-vm <userhome>/.ssh directory to target-vm <user_home> directory. This can be done using scp command.
ssh-copy-id -i $HOME/.ssh/id_rsa.pub <user>@target-vm

Other option is to copy public key from source-vm to target-vm as authorized_keys in ~/.ssh/ directory. For this below command can be used.
scp $HOME/.ssh/id_rsa.pub <user>@target-vm:~/.ssh/authorized_keys

4. Now test passwordless ssh from source-vm to target-vm using ssh command as follows on source-vm.
ssh <user>@target-vm

You should be logged into target-vm from source-vm without being prompted for password.


Products to which Article Applies



All Linux Operating Systems. The steps in this article should also work on other UNIX bases Operating systems.


Additional References