System info
$ getconf -a ;query system configuration.
how to identify 32bit or 64 bit OS?
# uname -m ; i686=32bit, x86_64=64bit
how to check ubuntu version
# cat /etc/issue
# cat /etc/lsb-release
# lsb_release -a
File management
# rdev ;show root device
# last ;list last users login and logout
# ulimit ;determine resource limit
# date +%y-%m-%d ;formatting date
# hdparm -v /dev/sda ;show or set hard drive parameters
# hdparm -tT /dev/sda ;test speed of hard drive
# rpm -i ;install .rpm
# rpm -e ;erase .rpm
# dpkg -i ;install .deb
# dpkg -r ;remove .deb
# dpkg -l
# ifconfig eth0 netmask 255.255.255.128 192.168.203.7
# route −n
# vi /etc/resolv.conf ;DNS config
System boot
Bootloader is the first software to execute from disk, the purpose is to start Linux Kernel. The most common used is GRUB & LILO.
The init process is the first process started by the Linux kernel during boot. The init process is responsible for starting processes during boot up and when changing runlevels.
The rc subsystem is run by init at each runlevel to start and stop the processes for that runlevel. We examine the concept of runlevels in this chapter. init is the parent of every other process.
# cat /boot/grub/menu.lst ;for REDHAT, the file is grub.conf in same folder.
When a Linux system is booted, the first process that the kernel starts is /sbin/init. It is always process id (PID) 1 and has a parent process id (PPID) of 0. The init process is always running.
The /etc/inittab file is the configuration file for /sbin/init.
/etc/inittab identifies the processes that init starts, and it can be customized as desired. Few environment variables are set when a process is started by init. The inittab lines have four colon-separated fields:
<id>:<runlevels>:<action>:<command>
Table 1-2. Runlevels
Run Level Meaning
----------------------------
0 System halt
1 Single user mode
2 Local multiuser without remote network (e.g., NFS)
3 Multiuser with network
4 Not used
5 Multiuser with network and xdm
6 System reboot
# who -r ;check the run level
# whoami ;current user
OS hangs
The first step in troubleshooting an interruptible hang is obtaining a stack trace of the offending process or processes by using the Magic SysRq keystroke.
# cat /proc/sys/kernel/sysrq
# echo 1 > /proc/sys/kernel/sysrq
To make this setting persistent, just put an entry into the configuration file:
# /etc/sysctl.conf
kernel.sysrq=1
To view the processor stacks, simply execute the dmesg command or view the syslog.
Performance tools
# top
Its fields can be added or removed, and sorted.
there are some sub-command to customize display, press[f] to select, [q] to quit.
# sar -u 1 1 ;cpu
# sar -d 1 1 ;disk
# sar -n 1 1 ;network
# vmstat -m 1 1 ; [-m] show slabinfo
# iostat
# free ;show in kilo-bytes
# swapon -s ;
# lshw ;list hardware info.
# ipcs ;show info. about IPC
# vmstat
# mpstat
# cat /proc/stat
# cat /proc/loadavg
Disk & Partition
# dd if=/dev/disk_device_file of=/tmp/disk_device_file.out bs=512 count=1
where disk_device_file is equal to /dev/sdX or /dev/hdX depending on IDE or SCSI devices. Then, after using bvi, the partition info under the MBR should look similar to the following:
EFI is nothing more than a firmware interface for the system's firmware (BIOS) that has the capability to call an OS's bootloader.
# partx /dev/sda ;review partition table
# parted /dev/sda ;interactive command same as above, normanlly use [p] sub-command and help, this command are easy to read
# cfdisk -P rst /dev/sda ;also display MBR
# e2fsck -b 8193 /dev/sda3 ;check ext2/3 partition
# cat /proc/partitions
The /proc filesystem is generated by the kernel and its modules. As such, the layout of the /proc filesystem can change as you install and remove modules. The layout can differ from one system to another because of differences in hardware (say, the presence or absence of a SCSI host adapter) and because of differences in the kernel. Even given the same hardware, different kernels may produce different /proc filesystems.
The most common use for /proc is to deliver information to you on a computer's configuration.
If filesystem corrupt,
# debugfs -w /dev/sda3 ;it take sub-commands
# resize2fs /dev/sda3 200000 ;ony used for ext2fs or ext3fs
SWAP
How to mount a new swap partition
# swapon /dev/sda4 ;manually mount
如果让swap开机就加载,应该改 /etc/fstab文件,加类似如下一行;
/dev/sda4 swap swap defaults 0 0
或者把命令行直接写入 /etc/rc.d/rc.local中也行:
swapon /dev/sda6
如果您的硬盘不能再分区,您可以创建一个swap文件:
# dd if=/dev/zero of=/tmp/swap bs=1024 count=524288 ;创建一个大小为512M 的swap 文件,在/tmp目录中;
;您可以根据自己的需要的大小来创建swap 文件.
# swapon -s ;display swap used, seem as # cat /proc/swap
Devices
dmesg is a command that reads the kernel ring buffer, which holds the latest kernel messages. dmesg reports the current errors detected by the kernel with respect to the hardware or application.
# dmesg | less ;less is oppose to more command
# lspci ;[-v] show more details, [-t] in tree style
# insmod ;insert new program into kernel
# rmmod ;remove
# lsmod ;list
# modprobe ;load the driver
# modinfo
# cat /proc/modules ;show modules loaded in kernel
Process
As described previously, the UNIX process model places its threads within the process structure. This structure contains the process's state, process ID (PID), parent process ID (PPID), file table, signal table, thread(s), scheduling, and other information. Thus, there is only one PID for a process that can have many threads. However, when a process calls the pthread_create() subroutine in Linux, it creates another task/PID, which just happens to share the same address space.
# ps
# pstree
# top
# echo $$ ;show shell PID
# strace -o /tmp/ll.strace -f -p 16935 ;system call trace
# lsof ;list opend files by..
# kill -l ;list signals
# man 7 signal
# ulimit -a ;show limits
Backup/Recovery
# tar cvzf /dev/st0 /work
The cvzf switches denote create archive (c), verbose output (v), compress the output file (z), and specified device file (f).
# tar tvzf /dev/st0
The tvzf switches denote list archive (t), verbose output (v), compress the output file (z), and specified device file (f).
# tar xvzf /dev/st0 work/vmware/installer.sh
The tvzf switches denote extract archive (x), verbose output (v), compress the output file (z), and specified device file (f).
# cpio -itv < /dev/st0
# cpio -i "*installer.sh" < /tmp/foo3.out
# /sbin/dump -0uf /tmp/foo4.out /work
# dd if=/dev/hda1 of=/dev/st0 bs=10k
Another possibility is to use tar to zip up the files or directories first and then make them into an ISO and burn them to CD/DVD.
# tar -cvzWf /tmp/home_backup.tar.gz /home/
# mkisofs -o home_backup.iso -JrVv /m_backup.tar.gz
# cdrecord -v -eject -multi speed=8 dev=0,1,0 home_backup.is
rsync is typically used to mirror data between two servers. Here are two examples:
# rsync -e ssh -av [email protected]_domain.com::/home/Backup/xfer/* /destination/xfer
A bare metal backup and recovery utility enables you to make bootable recovery media. Four common utilities are available for Linux:
# mondo / mindi
# partimage
# systemimager
# g4u (Ghost for UNIX)
I Have a Tape, and I Don't Know What It Is . . .
# dd if=/dev/st0 of=/tmp/foo5.out bs=1k count=4
# file /tmp/foo5.out
Printer
Various Printing Needs and the Corresponding lp Commands
Printing Need Command
-----------------------------------------------------------------
Submit a print request to the default printer lp/etc/hosts
Submit a print request to a specific printer lp -d printera/etc/hosts
Submit two copies of a print request lp -n 2 /etc/hosts
Submit a print request to print landscape lp -o landscape/etc/hosts
Send mail after printing lp -m /etc/hosts
Omit printing the banner page lp -o nb /etc/hosts
Print a banner page lp -o yb/etc/hosts
Print two pages side by side on the paper lp -o 2up /etc/hosts
Print on both sides of the paper lp -o duplex /etc/hosts
Print raw output to the printer lp -o raw /home/user/afile.pcl
Print request from paper tray 2 lp -o tray2/etc/hosts
Various Printing Needs and the Corresponding lpadmin Commands
Printing Need Command
------------------------------------------------------------------
Change the system default printer lpadmin d printqueue
Remove a print queue lpadmin -xprintqueue
# lpstat -t
# lpoptions
for Serial port attached printer
# stty -F /dev/ttyS0 -a ;get serial port info.
# stty -F /dev/ttyS0 onlcr
# stty -F /dev/ttyS0 -onlcr
# stty -F /dev/ttyS0 9600
for USB attached printer
# lspci -v | grep USB
# cat /proc/bus/usb/devices
for Parallel attached printer
# cat /proc/sys/dev/parport/parport0/autoprobe
# dmesg |grep -i lp
for HP JetDirect*****************************
http://localhost:631/
select administration and find new printer...
Networking
# sudo iptables --list
# mii-tool ;media independant interface
# ethtool ;??
# ifdown
# ifup
# arp -vn
# ethereal ;??
Next you disable ICMP:
# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
Before we cover the IP address model, we should mention a few Linux kernel parameters, which are listed here.
# ls /proc/sys/net/ipv4/ip*
/proc/sys/net/ipv4/ip_autoconfig
/proc/sys/net/ipv4/ip_default_ttl
/proc/sys/net/ipv4/ip_dynaddr
/proc/sys/net/ipv4/ip_forward
/proc/sys/net/ipv4/ipfrag_high_thresh
/proc/sys/net/ipv4/ipfrag_low_thresh
/proc/sys/net/ipv4/ipfrag_time
/proc/sys/net/ipv4/ip_local_port_range
/proc/sys/net/ipv4/ip_nonlocal_bind
/proc/sys/net/ipv4/ip_no_pmtu_disc
#ipcalc ;??, calcate ip address
#netstat -rn ;kernel route table
#netstat -us ;UDP, statistics
We attempted to increase the network buffer, as indicated here.
# sysctl -w net.core.rmem_max=524288 ;confgure kernel parameters in runtime
# sysctl -w net.core.wmem_max=524288
# sysctl -w net.core.rmem_default=524288
# sysctl -w net.core.wmem_default=524288
# tcpdump -i interface -s 1500 -w /tmp/trace.out
# ip address show
# ip link show ;check manual
Login
# chage -l username ;check aging time
# usermod ;user modify
# sudo pwck ;check problem with the password file
Profiles:
1. /etc/profile
2. ~/.bash_profile
3. ~/.bash_login
4. ~/.profile
# sudo su ;temporarily login as root, the prompt will be #
# sudo -i ;hand over to root enviroment
Press [CTRL+ALT+F1~F7] to switch different console from TTY1 to TTY6, TTY7 is exit to desktop.
X windows
# type X ;The type command (a built-in shell command) is used to find programs in the PATH variable
# /usr/X11R6/bin/Xorg -version ;
# cat /proc/iomem ;show the video card and the user-space address range mapped to the device, also use [lspci] to check
# xterm -display testmachine.atl.hp.com:0 ;Xclient
# cat ~/.gnome2/*
# sudo X ;activate X