This list of linux commands, scripts, and tips was created by me (Ryan) over 10 years ago. They were useful when working with various hardware components, such as peripheral buses (e.g., FC, SCSI, SAS) and devices (e.g., SES, SATA, SAS). There are also general purpose commands mixed in there as well. Since I created this list back over 10 years ago, some commands may not be valid any more or there may be a more modern way of doing things.. However, it should provide a nice starting point.
Linux in a Nutshell book (ch 9 is boot parms):
http://www.kernel.org/pub/linux/kernel/people/gregkh/lkn/lkn_pdf/
Cool tutorial on Linux kernel:
http://free-electrons.com/doc/training/linux-kernel/slides.pdf
How to configure networking
sudo ifconfig eth0 192.168.1.50 netmask 255.255.255.0 up
sudo route add default gw 172.16.236.0
dhclient -r
(release current ip)
dhclient
(get new dhcp ip address)
http://www.cyberciti.biz/faq/howto-linux-renew-dhcp-client-ip-address/
Building a kernel module:
http://www.cyberciti.biz/tips/build-linux-kernel-module-against-installed-kernel-source-tree.html
http://tldp.org/HOWTO/html_single/Module-HOWTO/
Updates the apt-cache database:
apt-get update
apt-cache search <what you want>
this will search the repository cache
/etc/apt/sources.list
these are the repositories to use
apt-get install linux-headers-$(uname -r)
ln -s /usr/src/linux /lib/modules/$(uname -r)/build
To see the Linux and architecture you are running on:
uname -a
Linux server 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:14 EST 2007 x86_64 x86_64 x86_64 GNU/Linuxarch
x86_64
UPGRADING DRIVE FW:
Here is how you upgrade drive firmware using sg_write_buffer:
sg_write_buffer --in=X_BA1E_4TB.bin --mode=0x7 --length=500000 /dev/sdf
sg_write_buffer --in=X_BA1E_4TB.bin --mode=0x7 --length=500000 --off=500000 --skip=500000 /dev/sdf
sg_write_buffer --in=X_BA1E_4TB.bin --mode=0x7 --length=21440 --off=1000000 --skip=1000000 /dev/sdf
Look at /sys/block/sdf/queue/max_sectors_kb
to see the max size command you can send to the drive.
Also note that after upgrading f/w it may not show the right version unless you do a fresh inquiry to the drive (such as sg_inq).
Upgrading an SSD I think just takes mode page 0x5:
sg_write_buffer --in=fwfile.bin --mode=0x5 /dev/sdm
Download: http://sg.danny.cz/sg/sg3_utils.html (or run “yum install sg3_utils” or similar)… then you can use sg_write_buffer
Run “lsscsi -g” to find out which sg device has the LSI dongle you want to upgrade (note that LSI just presents the drive that is behind it). Just run the sg_logs command below on each device if you aren’t sure and see if you get back a response with “LSI” in it and the firmware output. You can also use “sg_scan -i” if you don’t have lsscsi installed.
READ CURRENT FW REVISIONS
# sg_logs /dev/sg7 --page=0x35 --raw
505x0AB00E42A161110 PºP8PºP9PºP:iL3-11794-00B LSISS9253-03 03112010SSCIT 08_00_05_00 07_00_00_00 A-GEN011X
08_00_05_00 = Firmware
07_00_00_00 = Bootloader
UPGRADE THE BOOTLOADER CODE (DAB)
# sg_write_buffer --in=bootloader_asic.bin --mode=7 --id=0xaf /dev/sg7
UPGRADE THE FIRMWARE CODE (DFW or BIN)
# sg_write_buffer --in=/tmp/fw_image_vXYZ.bin --mode=7 --id=0x1 /dev/sg7
READ THE FW REVISIONS AGAIN TO DOUBLE CHECK UPGRADES TOOK
# sg_logs /dev/sg7 --page=0x35 --raw
505x0AB00E42A161110 PºP8PºP9PºP:iL3-25194-00B LSISS9253-03 03112010SSCIT 08_00_05_00 07_00_00_00 A-GEN011X
benchmark is a good memory or network performance tool (http://caladan.tk)
memtest86+ is a good memory tester
To see all the SMART attributes (UDMA errors, etc) on a drive:
smartctl -i -A -T permissive /dev/sdg
To see the settings on a disk:
/sbin/hdparm /dev/sda
This will show you readahead, writeback cache settings. You should be able to set it form here too.
Show cached reads: /sbin/hdparm -tT /dev/sda
More info:
dt tool to test devices on linux (e.g., get stats from a drive)
Example command:
./dt of=/mnt/data/text bs=64k capacity=1g
https://web.archive.org/web/20160304170727/http://www.scsifaq.org/rmiller_tools/dt.html
To see CPU usage:
top
To see disk usage:
iostat 1
(the 1 has it update on the screen every second)
To enable/disable services:
setup
This is a nice Text Based UI to enable/disable services including the firewall.
chkconfig
This is a text based tool to list or change services from the command line.
chkconfig --list
This will list all services
To connect to the serial port:
minicom
CTRL+Z to enter help menu
The first serial port is typically /dev/ttyS0
minicom -s
(to go directly into the setup of)
If you are having problems connecting to the serial port you may want to check if the serial port is in use right now:
dmesg | grep ttyS
This will show the startup messages. See if you see Xen using it. If so, you may need to disable Xen:
Open /boot/grub.conf and add “xencons=off” to the end of the “module /vmlinuz..” line.
This will create a tar and zip up a given folder (this is a good way to preserve permissions):
tar cfz mynewtar.tar.gz folder/
To unzip and untar a given tar.gz file run this:
tar xzf mynewtar.tar.gz
To allow root access to telnet:
vi /etc/securetty
add the following
pts/0
pts/1
…
pts/10
Using vi editor (commands):
yy yank the current line
y# copy # of lines where # represents a number like 1-100, etc
p paste the yanked (copied lines)
A append at the end of the line
a append after the cursor
i insert where the cursor is at
x delete where the cursor is at
#dd delete the # of lines specified by # starting at the current line
dd delete the entire line where your cursor is at
#G goto the line number specified before G
:w will save the document you are editting
:w! add a ! to force it to save (for example, if the document is read only)
To find a file in the filesystem:
find / -name "whatfileyouwant" -print
you can have wildcards (*) in the file you want to find
you can substitute / with a relative or full path if you want, otherwise / will search the entire file system
To search files for text you are looking for:
find . -type f | xargs grep <what you want to find> | more
To find text within files:
grep -r "searchstring" *
To do an NFS mount:
first create your mount point folder (in below example, our mount point folder is rentwalk)
mount -t cifs -ousername="ryan" -opassword="password" \\\\192.168.0.102\\myshare ./myfolder
where username is equal to your Windows box username/password
**********************************************************
To do a simple performance test on Linux:
dd if=/dev/zero of=/dev/sdg obs=2000000
dd if=/dev/sdg of=/dev/null ibs=2000000
to see current mount points with total capacity and available capacity
df -h
to see the size of the disk
fdisk -l /dev/sdg
to see all the disk drives and it’s partitions:
fdisk -l
to make an image file of a raw disk drive:
dd if=/dev/sda of=/mnt/mymount/myimageofsda.img
linux modules are typically located here:
/lib/modules/
How to tell the driver version you have loaded
modinfo <driver name>
How to make Linux scan for new SCSI LUNs:
Doesn’t take away LUNs that are gone. Run this at the command line:
for hostdir in /sys/class/scsi_host/host*; do echo "- - -" > $hostdir/scan; done;
To remove or add a SCSI LUN (the old proc way):
echo "scsi remove-single-device <scsi #> <channel #> <id #> <lun #>" > /proc/scsi/scsi
echo "scsi add-single-device <scsi #> <channel #> <id #> <lun #>" > /proc/scsi/scsi
Get the #’s from the cat /proc/scsi/scsi output.
More info: http://www.linuxjournal.com/article/7321
Issuing a LIP on FC HBAs:
echo 1 > /sys/class/fc_host/host<ID>/issue_lip
To let Linux see a resized LUN:
echo 1 > /sys/bus/scsi/devices/<host#>:<channel#>:<tid#>:<lun#>/rescan
To get updates on Redhat:
yum
You must run rhn_register first (if on Redhat).
To get more info on this: http://www.cyberciti.biz/faq/rhel-centos-fedora-linux-yum-command-howto/
RPM Commands:
General information:
rpm -qa <package>
All file contents:
rpm -ql <package>
Which RPM package it belongs to:
rpm -qf <file>
To get 0x80 or 0x83 data (inquiry serial info) [using udev]:
scsi_id -g -p 0x83 -s /block/sd<n>
To get 0x83 data (inquiry serial info) [using sg3_utils – not loaded by default:sg3_utils]:
sg_inq -h -e -o=<page> /dev/sd<n>
Another way to get a serial number from a disk:
smartctl -a /dev/sdb
Script to print devices
for i in {b..z};do smartctl -a /dev/sd$i | grep Serial; echo $i; done
List all HBA’s on the system:
for i in `ls /sys/class/scsi_host`;do echo "**** HOST $i ****";grep -H . /sys/class/scsi_host/$i/* 2>/dev/null;done;
===============
Some useful sys filesystem locations:
/sys/bus/scsi/drivers/sd
– Gives you insight into which controller is used and how many expanders are involved between you and the drive
lrwxrwxrwx 1 root root 0 Sep 20 15:41 4:0:0:0 -> ../../../../devices/pci0000:00/0000:00:09.0/0000:0a:00.0/host4/port-4:0/expander-4:0/port-4:0:0/end_device-4:0:0/target4:0:0/4:0:0:0 lrwxrwxrwx 1 root root 0 Sep 20 15:41 4:0:10:0 -> ../../../../devices/pci0000:00/0000:00:09.0/0000:0a:00.0/host4/port-4:0/expander-4:0/port-4:0:10/end_device-4:0:10/target4:0:10/4:0:10:0 lrwxrwxrwx 1 root root 0 Sep 20 15:41 4:0:11:0 -> ../../../../devices/pci0000:00/0000:00:09.0/0000:0a:00.0/host4/port-4:0/expander-4:0/port-4:0:11/end_device-4:0:11/target4:0:11/4:0:11:0
/sys/bus/scsi/drivers/ses
– this is available in newer kernels and gives you easy file system access to get SES information
/sys/class/sas_phy
– this gives you a good look at the phy’s for all controllers and expanders in your SAS domain
===============
List hardware on your system:
lshw -C
List all sd/sg devices:
lsscsi -g
To list all the sg devices and see the inquiry data with it:
sg_scan -i
List disks on your system:
lshw -C disk
To list disk usage in a given directory:
du -h --max-depth=1
Various Linux testing utilities:
http://www.linuxtested.com/linux_tools.html
Bonnie (disk drive testing):
http://sourceforge.net/projects/bonnie/
http://code.google.com/p/bonnie-64/
To rescan for SCSI devices (disruptive):
modprobe -l <driver>
<– this way you can see where the driver is in case of when you add it, it is not in your path
modprobe -r <driver>
<— remove the driver
modprobe <driver>
<— re-install it
How to tell what driver version you have:
cat /sys/module/<driver>/version
How to run a bad block check on a device (I saw a note saying you should do this when the disk is not mounted):
badblocks -f <block device> (e.g., /dev/sdd)
To get SES information from a SCSI device (this may be part of the sg3_utils)
sg_ses /dev/sg12 --page=1
(inquiry page)
sg_ses /dev/sg12 --page=2
(status page)
sg_ses /dev/sg12 --page=0xE
(this is used to upload a f/w image)
A lot of SCSI device linux commands (READ MORE HERE):
This talks about the sg3 tools, changing mode pages with sdparm
More on sdparm:
http://sg.torque.net/sg/sdparm.html
More on sg3 utils:
Old invalid link: http://sg.torque.net/sg/sg3_utils.html
New valid link: http://sg.danny.cz/sg/sg3_utils.html
To get a serial number for a disk drive (using sg3 utils):
sg_vpd --page=sn /dev/sde
To get info about a SATA drive (using sg3 utils):
sg_vpd --page=ai /dev/sde
To get mode page info on a drive:
sginfo /dev/sg0 -a
To map devices to the /proc/scsi/scsi output:
sg_scan -i
This will show the mapping of sg to sd devices and inquiry data:
sg_map -i
To get the grown defects list from a disk:
sginfo /dev/sde -G
To get error info, SMART info, etc, this is a good command:
sg_logs /dev/sde
To see how the given SD device maps to sysfs, sg, etc you can use this command:
sg_map26 /dev/sde -r <#>
To turn on write cache on a SATA drive:
sg_sat_set_feature --feature=2 /dev/sdd
Read more about sg_dd (similar to the dd command):
http://sg.torque.net/sg/sg_dd.html
More info on dealing with SCSI devices on linux (using the SG_IO interface)
There is good info in here about the size of commands sent by Linux
http://sg.torque.net/sg/sg_io.html
Look at how big the IO being sent to the disk drive is:
/sys/block/sd<x>/queue/max_hw_sectors_kb
To look at SES information:
sg_ses /dev/sg0
To list all SCSI devices thru the proc filesystem:
cat /proc/scsi/scsi
To list all drivers (aka modules) installed on the system, run this:
lsmod
When transferring files between systems it is helpful to do a checksum on the file to verify it’s the same:
sum <filename>
or…
md5sum <filename>
To run a 32 bit binary on a 64 bit linux try this:
linux32 <32 bit binary file>
ia32el package might do the trick too (this RPM package should be on the RH Enterprise Linux Extras CD).
http://www.centos.org/docs/4/html/release-notes/as-itanium/
Also do a rpm -qa | grep “compat” for compatibility packages
To see what hardware architecture you are running on such as 32 bit or 64 bit:
uname -i
or you can run (uname -a) to see a little more info
To install gcc (or any program) from Linux:
yum install gcc
To enable FTP on Linux:
Change directory into /etc/xinetd.d
Run this:
ls -l | grep ftp
This will show you which FTP programs you have…typically tftp, gssftp, or similar
edit whichever ftp file you want to modify (e.g., vi gssftp)
Change “disable = yes” to “disable = no”
Save your changes
Run this: service gssftp restart
Replace “gssftp” in the above command with whichever FTP program you enabled
TBD
To tell more information about a file (like if it’s 32 bit or 64 bit):
file <name of binary/file>
To tell which RPM package provides the given filename:
rpm -qf <filename>
To tell which libraries are dynamically linked by a given executable:
ldd <binary>
SMP/SAS interfaces on Linux:
/sys/class/scsi_host/host0
<– the # on the end is the host interface. On this server, host0 should be the onboard 1064
You can download SMP tools to send SMP commands:
http://sg.danny.cz/sg/smp_utils.html
To find expander SAS addresses:
find /sys -name "sas_device:expander*"
cat "<any_found_path>/sas_address"
You might be able to run something similar to this (sg6 is the EM card):
sg_vpd --page=di_port --quiet /dev/sg6
0x51150bc101a3ca1e,0x1
In my case, the expander is one value higher ..ca1f
I got this to report back info on an EBOD expander:
smp_rep_general --sa=0x51150bd101100060 /dev/mptctl,2
I got data from the server’s 1064 by issuing this on my system. For some reason my /sys/class_scsi_host/host0 showed the 1064 but only ,1 would work with this command:
smp_discover --multiple --sa=
0x51150bd101100060
/dev/mptctl,1
How to output multiple files found:
for i in `find . -name sas_address`; do echo "$i: `cat $i`"; done;
How to output multiple files found and search for specific output (e.g., look for 28ab):
for i in `find . -name sas_address`; do echo "$i: `cat $i`" | grep 28ab; done;
To print the 5th column of a directory listing:
ls -l | awk '{ print $5 }'
This is how to display the filename along with the contents:
grep -H . * 2>/dev/null
========================================
Hope you gained something from this!
I have been around IT since I was in high school (running a customized BBS, and hacking) and am not the typical person that finds one area of interest at work; I have designed databases, automated IT processes, written code at the driver level and all the way up to the GUI level, ran an international software engineering team, started an e-commerce business that generated over $1M, ran a $5B product marketing team for one of the largest semiconductor players in the world, traveled as a sales engineer for the largest storage OEM in the world, researched and developed strategy for one of the top 5 enterprise storage providers, and traveled around the world helping various companies make investment decisions in startups. I also am extremely passionate about uncovering insights from any data set. I just like to have fun by making a notable difference, influencing others, and to work with smart people.