Friday, August 22, 2008

FTP client

Using a text based ftp client is not truly Linux specific, however there is a chance that you may need to download a file from an ftp server and don't want the overhead of installing a GUI based ftp client nor using a comparitively bloated webbrowser. Maybe you want to use some of the power and features available in a ftp client that for whatever reasons aren't supported in the webbrowsers.
Most text based ftp clients, regardless of the operating system they run on, use the same command set that you type in to instruct the client on what it is you want it to do - generally speaking you should be able to learn how to use a text based ftp client once and use that knowledge many times. I'm writing this under the assumption that you are using Linux to connect to ftp servers.

1. Logging in.
Firstly you will need to open a connection to the ftp server:

$ftp
ftp> open edge

This opens a connection to the ftp server running on my Linux box called 'edge' and could also have been done by typing

$ftp edge

After the client has connected to the server you will see a login banner and a username prompt. After typing in the user name you will be prompted for a password - if you want to log in to an 'anonymous' account you should enter youremail address as the password.
To log out, type 'quit'.
If you use ncftp as the ftp client and it has automatic anonymous logins enabled (which it does by default), then you won't be prompted for a username amd password.

2. Directories.
2.1 Initial directory.
If you log in as anonymous then your initial working directory will be the root dierctory, otherwise your initial working directory will be the home directory of the user that you logged in as.
2.2 Changing directories:
You will need to move to the appropiate directory once you have logged in. Doing this is the very same as changing directories within Linux - with the 'cd' command. Using 'cd' will move you around the directory structure of the ftp server, if you need to move around the directories of the PC that you are connecting with, then you should use the 'lcd' command.
Depending on which operating system the ftp server is running on it will most likly be case sensitive with regards to file and directory names.
2.3 Directory Listings.
As with Unix, the 'ls' command should be used if you want to get a general listing of what files are in the remote working directory.
There's a particular twist though, if you want a 'long' directory listing similar to what you get with 'ls -l' you can either type 'ls -l' itself or be slightly lazy about it and type 'dir'.
If you would like to keep a local copy of the directory listing, the 'mls' command should be used.
With regard to using mls, you have to specify which remote directory the listing should be of, so if you want a listing of the current directory you have to type '.' as the name of the directory.
You then have to specify the local file that you want the directory listing to be saved to and type 'y' in response to the 'output to local file' question that follows.
2.4 Modification date of a file.
The 'modtime' command is useful for when you need to know when a remote file was last modified.

3. Running a 'shell' command.
It can be useful at times to run a shell command from within an ftp connection. This is done by first typing an exclamation mark (!) followed by the command itself.
I do this quite often to ensure that I am in the correct local directory as it helps to make certain that I am not going to to overwrite a local file. To do this, you should type:

ftp> !pwd /home/ken

You can also use '!' on it's own to get to the command prompt without logging out from the ftp session. You can get back to the ftp prompt by typing 'exit'.

4. Transferring files.
Okay, so now that you know how to log in and change directories the next thing that you need to learn is how to transfer files.
Before you get around to transferring a file though it is important that you are in the correct transfer type.
4.1 Transfer type.
There are two transfer types that can be used to transfer files; ascii and binary.
To see which transfer type is currently active, use the 'type' command.

ftp> type
Using binary mode to transfer files.
ftp> ascii
200 Type set to A.
ftp> type
Using ascii mode to transfer files.
ftp> binary
200 Type set to I.
ftp> type
Using binary mode to transfer files.

As seen in the example above, type 'ascii' to change to the ascii type and 'binary' to change to the binary type.
4.2 Copying files.
To get a copy of a file from the server to the local computer you use the command 'get'.
Tp put a copy of a local file onto the sever you use the command 'put'.
4.3 Copying multiple files.
If you need to copy a number of files of the same transfer type from one remote directory to a local directory you can use the command 'mget', similarly 'mput' should be used to transfer a number of files of the same type onto the server.
You can be as specific or as general in your use of 'mget' or 'mput' as you like.
For example 'mget *' means that all remote files (both binary and ascii) will get copied down from the server. Similarly 'mget foo*' means that all files starting with 'foo' will be copied down from the server.
Each time that you use mget or mput you will be prompted to confirm the transfer. Typing anything other than 'n' means the file will be copied.
You can quit out of mget or mput and remain in the ftp session by pressing ctrl-c.
4.4 Resuming a 'get'.
One of the nice advantages that you get by using an ftp client over a web browser that supports the ftp protocol is that, if your connection to the server breaks for whatever reason, you can get the ftp client to start over again from where it left off. This is done by using the 'reget' command.

4.5 Visual confirmation.
If you are copying a large file and would like some form of visual indication of progress then the 'hash' command, which causes the hash mark (#) to be printed for each segment of the file which has been copied, will be of use to you.
You should use the 'hash' command before copying the file for which you want the visual indication.

5. Deleting files.
Once you have made a local copy of a file from the server you may want to delete the original file that you copied. Naturally, this will only work if you have the appropriate permissions to delete the file.
To do this, use the 'delete' command.
if you have a number of files to delete, I'd suggest you use the 'mdelete' command which can be aborted by pressing ctrl-c.

6. Macros.
I doubt this facility is available in all text based ftp clients but it is far too useful to not mention.
You can use 'macdef' to combine several commands into a macro, so that for example if you find that you always follow a 'pwd' with a '!pwd' then you could combine these into a macro called '2pwd' and use that instead. For example:

ftp> macdef 2pwd
Enter macro line by line, terminating it with a null line
pwd
!pwd


To indicate that you want to use a macro instead of a standard command you have to preceed the name of the macro with a dollar sign ($). For example:

ftp> $2pwd
pwd
257 "/home2/wolfhaven" is current directory.
!pwd
/home/ken

This is a very trivial example but you should be able to see how to apply this to a larger sequence of commands.

X. More Information.
If you would like to learn more of the ftp client's commands, I'd suggest you use the help command and also man ftp at the command prompt. Using 'help' on its own will present you with a list of commands that the ftp client supports, to get details of what a specific command does then add it as a parameter to the help command. For example:

ftp> help verbose
verbose toggle verbose mode

Monday, August 18, 2008

Linux Commands-Hardware Information

Running kernel and system information

# uname -a # Get the kernel version (and BSD version)
# lsb_release -a # Full release info of any LSB distribution
# cat /etc/SuSE-release # Get SuSE version
# cat /etc/debian_version # Get Debian version


Use /etc/DISTR-release with DISTR= lsb (Ubuntu), redhat, gentoo, mandrake, sun (Solaris), and so on. See also /etc/issue.

# uptime # Show how long the system has been running + load
# hostname # system's host name
# hostname -i # Display the IP address of the host. (Linux only)
# man hier # Description of the file system hierarchy
# last reboot # Show system reboot history


Hardware Informations

Kernel detected hardware

# dmesg # Detected hardware and boot messages
# lsdev # information about installed hardware
# dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8 # Read BIOS


Linux

# cat /proc/cpuinfo # CPU model
# cat /proc/meminfo # Hardware memory
# grep MemTotal /proc/meminfo # Display the physical memory
# watch -n1 'cat /proc/interrupts' # Watch changeable interrupts continuously
# free -m # Used and free memory (-m for MB)
# cat /proc/devices # Configured devices
# lspci -tv # Show PCI devices
# lsusb -tv # Show USB devices
# lshal # Show a list of all devices with their properties
# dmidecode # Show DMI/SMBIOS: hw info from the BIOS


FreeBSD

# sysctl hw.model # CPU model
# sysctl hw # Gives a lot of hardware information
# sysctl vm # Memory usage
# dmesg | grep "real mem" # Hardware memory
# sysctl -a | grep mem # Kernel memory settings and info
# sysctl dev # Configured devices
# pciconf -l -cv # Show PCI devices
# usbdevs -v # Show USB devices
# atacontrol list # Show ATA devices
# camcontrol devlist -v # Show SCSI devices


Load, statistics and messages

The following commands are useful to find out what is going on on the system.

# top # display and update the top cpu processes
# mpstat 1 # display processors related statistics
# vmstat 2 # display virtual memory statistics
# iostat 2 # display I/O statistics (2 s intervals)
# systat -vmstat 1 # BSD summary of system statistics (1 s intervals)
# systat -tcp 1 # BSD tcp connections (try also -ip)
# systat -netstat 1 # BSD active network connections
# systat -ifstat 1 # BSD network traffic through active interfaces
# systat -iostat 1 # BSD CPU and and disk throughput
# tail -n 500 /var/log/messages # Last 500 kernel/syslog messages
# tail /var/log/warn # System warnings messages see syslog.conf


Users

# id # Show the active user id with login and group
# last # Show last logins on the system
# who # Show who is logged on the system
# groupadd admin # Add group "admin" and user colin (Linux/Solaris)
# useradd -c "Colin Barschel" -g admin -m colin
# usermod -a -G # Add existing user to group (Debian)
# groupmod -A # Add existing user to group (SuSE)
# userdel colin # Delete user colin (Linux/Solaris)
# adduser joe # FreeBSD add user joe (interactive)
# rmuser joe # FreeBSD delete user joe (interactive)
# pw groupadd admin # Use pw on FreeBSD
# pw groupmod admin -m newmember # Add a new member to a group
# pw useradd colin -c "Colin Barschel" -g admin -m -s /bin/tcsh
# pw userdel colin; pw groupdel admin


Encrypted passwords are stored in /etc/shadow for Linux and Solaris and /etc/master.passwd on FreeBSD. If the master.passwd is modified manually (say to delete a password), run # pwd_mkdb -p master.passwd to rebuild the database.


To temporarily prevent logins system wide (for all users but root) use nologin. The message in nologin will be displayed (might not work with ssh pre-shared keys).

# echo "Sorry no login now" > /etc/nologin # (Linux)
# echo "Sorry no login now" > /var/run/nologin # (FreeBSD)



Limits

Some application require higher limits on open files and sockets (like a proxy
web server, database). The default limits are usually too low.
Linux

Per shell/script

The shell limits are governed by ulimit. The status is checked
with ulimit -a. For example to change the open files limit from
1024 to 10240 do:

# ulimit -n 10240 # This is only valid within the shell


The ulimit command can be used in a script to change the limits for the script only.

Per user/process

Login users and applications can be configured in /etc/security/limits.conf. For example:

# cat /etc/security/limits.conf
* hard nproc 250 # Limit user processes
asterisk hard nofile 409600 # Limit application open files


System wide

Kernel limits are set with sysctl. Permanent limits are set in /etc/sysctl.conf.

# sysctl -a # View all system limits
# sysctl fs.file-max # View max open files limit
# sysctl fs.file-max=102400 # Change max open files limit
# echo "1024 50000" > /proc/sys/net/ipv4/ip_local_port_range # port range
# cat /etc/sysctl.conf
fs.file-max=102400 # Permanent entry in sysctl.conf
# cat /proc/sys/fs/file-nr # How many file descriptors are in use



FreeBSD

Per shell/script

Use the command limits in csh or tcsh or as in Linux, use ulimit in an sh or bash shell.
Per user/process

The default limits on login are set in /etc/login.conf. An unlimited value is still limited by the system maximal value.
System wide

Kernel limits are also set with sysctl. Permanent limits are set in /etc/sysctl.conf or /boot/loader.conf. The syntax is the same as Linux but the keys are different.

# sysctl -a # View all system limits
# sysctl kern.maxfiles=XXXX # maximum number of file descriptors
kern.ipc.nmbclusters=32768 # Permanent entry in /etc/sysctl.conf
kern.maxfiles=65536 # Typical values for Squid
kern.maxfilesperproc=32768
kern.ipc.somaxconn=8192 # TCP queue. Better for apache/sendmail
# sysctl kern.openfiles # How many file descriptors are in use
# sysctl kern.ipc.numopensockets # How many open sockets are in use
# sysctl -w net.inet.ip.portrange.last=50000 # Default is 1024-5000
# netstat -m # network memory buffers statistics


See The FreeBSD handbook Chapter 11http://www.freebsd.org/handbook/configtuning-kernel-limits.html for details.

Solaris

The following values in /etc/system will increase the maximum file descriptors per proc:

set rlim_fd_max = 4096 # Hard limit on file descriptors for a single proc
set rlim_fd_cur = 1024 # Soft limit on file descriptors for a single proc



Runlevels

Linux

Once booted, the kernel starts init which then starts rc which starts all scripts belonging to a runlevel. The scripts are stored in /etc/init.d and are linked into /etc/rc.d/rcN.d with N the runlevel number.

The default runlevel is configured in /etc/inittab. It is usually 3 or 5:

# grep default: /etc/inittab
id:3:initdefault:


The actual runlevel (the list is shown below) can be changed with init. For example to go from 3 to 5:

# init 5 # Enters runlevel 5



* 0 Shutdown and halt

* 1 Single-User mode (also S)

* 2 Multi-user without network

* 3 Multi-user with network

* 5 Multi-user with X

* 6 Reboot


Use chkconfig to configure the programs that will be started at boot in a runlevel.

# chkconfig --list # List all init scripts
# chkconfig --list sshd # Report the status of sshd
# chkconfig sshd --level 35 on # Configure sshd for levels 3 and 5
# chkconfig sshd off # Disable sshd for all runlevels


Debian and Debian based distributions like Ubuntu or Knoppix use the command update-rc.d to manage the runlevels scripts. Default is to start in 2,3,4 and 5 and shutdown in 0,1 and 6.

# update-rc.d sshd defaults # Activate sshd with the default runlevels
# update-rc.d sshd start 20 2 3 4 5 . stop 20 0 1 6 . # With explicit arguments
# update-rc.d -f sshd remove # Disable sshd for all runlevels
# shutdown -h now (or # poweroff) # Shutdown and halt the system



FreeBSD

The BSD boot approach is different from the SysV, there are no runlevels. The final boot state (single user, with or without X) is configured in /etc/ttys. All OS scripts are located in /etc/rc.d/ and in /usr/local/etc/rc.d/ for third-party applications. The activation of the service is configured in /etc/rc.conf and /etc/rc.conf.local. The default behavior is configured in /etc/defaults/rc.conf. The scripts responds at least to start|stop|status.

# /etc/rc.d/sshd status
sshd is running as pid 552.
# shutdown now # Go into single-user mode
# exit # Go back to multi-user mode
# shutdown -p now # Shutdown and halt the system
# shutdown -r now # Reboot


The process init can also be used to reach one of the following states level. For example # init 6 for reboot.


* 0 Halt and turn the power off (signal USR2)

* 1 Go to single-user mode (signal TERM)

* 6 Reboot the machine (signal INT)

* c Block further logins (signal TSTP)

* q Rescan the ttys(5) file (signal HUP)



Reset root password

Linux method 1

At the boot loader (lilo or grub), enter the following boot option:

init=/bin/sh


The kernel will mount the root partition and init will start the bourne shell
instead of rc and then a runlevel. Use the command passwd at the prompt to change the password and then reboot. Forget the single user mode as you need the password for that.

If, after booting, the root partition is mounted read only, remount it rw:

# mount -o remount,rw /
# passwd # or delete the root password (/etc/shadow)
# sync; mount -o remount,ro / # sync before to remount read only
# reboot


FreeBSD method 1

On FreeBSD, boot in single user mode, remount / rw and use passwd. You can select the single user mode on the boot menu (option 4) which is displayed for 10 seconds at startup. The single user mode will give you a root shell on the / partition.

# mount -u /; mount -a # will mount / rw
# passwd
# reboot



Unixes and FreeBSD and Linux method 2

Other Unixes might not let you go away with the simple init trick. The solution is to mount the root partition from an other OS (like a rescue CD) and change the password on the disk.


* Boot a live CD or installation CD into a rescue mode which will give you a shell.

* Find the root partition with fdisk e.g. fdisk /dev/sda

* Mount it and use chroot:


# mount -o rw /dev/ad4s3a /mnt
# chroot /mnt # chroot into /mnt
# passwd
# reboot



Kernel modules

Linux

# lsmod # List all modules loaded in the kernel
# modprobe isdn # To load a module (here isdn)


FreeBSD

# kldstat # List all modules loaded in the kernel
# kldload crypto # To load a module (here crypto)


Compile Kernel

Linux

# cd /usr/src/linux
# make mrproper # Clean everything, including config files
# make oldconfig # Reuse the old .config if existent
# make menuconfig # or xconfig (Qt) or gconfig (GTK)
# make # Create a compressed kernel image
# make modules # Compile the modules
# make modules_install # Install the modules
# make install # Install the kernel
# reboot


FreeBSD

Optionally update the source tree (in /usr/src) with csup (as of FreeBSD 6.2 or later):

# csup


I use the following supfile:

*default host=cvsup5.FreeBSD.org # www.freebsd.org/handbook/cvsup.html#CVSUP-MIRRORS
*default prefix=/usr
*default base=/var/db
*default release=cvs delete tag=RELENG_7
src-all


To modify and rebuild the kernel, copy the generic configuration file to a new name and edit it as needed (you can also edit the file GENERIC directly). To restart the build after an interruption, add the option NO_CLEAN=YES to the make command to avoid cleaning the objects already build.

# cd /usr/src/sys/i386/conf/
# cp GENERIC MYKERNEL
# cd /usr/src
# make buildkernel KERNCONF=MYKERNEL
# make installkernel KERNCONF=MYKERNEL


To rebuild the full OS:

# make buildworld # Build the full OS but not the kernel
# make buildkernel # Use KERNCONF as above if appropriate
# make installkernel
# reboot
# mergemaster -p # Compares only files known to be essential
# make installworld
# mergemaster -i -U # Update all configuration and other files
# reboot


For small changes in the source you can use NO_CLEAN=yes to avoid rebuilding the whole tree. But use with care.

# make buildworld NO_CLEAN=yes # Don't delete the old objects
# make buildkernel KERNCONF=MYKERNEL NO_CLEAN=yes

Thursday, August 14, 2008

Linux commands

Running kernel and system information

# uname -a # Get the kernel version (and BSD version)
# lsb_release -a # Full release info of any LSB distribution
# cat /etc/SuSE-release # Get SuSE version
# cat /etc/debian_version # Get Debian version


Use /etc/DISTR-release with DISTR= lsb (Ubuntu), redhat, gentoo, mandrake, sun (Solaris), and so on. See also /etc/issue.

# uptime # Show how long the system has been running + load
# hostname # system's host name
# hostname -i # Display the IP address of the host. (Linux only)
# man hier # Description of the file system hierarchy
# last reboot # Show system reboot history


Hardware Informations

Kernel detected hardware

# dmesg # Detected hardware and boot messages
# lsdev # information about installed hardware
# dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8 # Read BIOS


Linux

# cat /proc/cpuinfo # CPU model
# cat /proc/meminfo # Hardware memory
# grep MemTotal /proc/meminfo # Display the physical memory
# watch -n1 'cat /proc/interrupts' # Watch changeable interrupts continuously
# free -m # Used and free memory (-m for MB)
# cat /proc/devices # Configured devices
# lspci -tv # Show PCI devices
# lsusb -tv # Show USB devices
# lshal # Show a list of all devices with their properties
# dmidecode # Show DMI/SMBIOS: hw info from the BIOS


FreeBSD

# sysctl hw.model # CPU model
# sysctl hw # Gives a lot of hardware information
# sysctl vm # Memory usage
# dmesg | grep "real mem" # Hardware memory
# sysctl -a | grep mem # Kernel memory settings and info
# sysctl dev # Configured devices
# pciconf -l -cv # Show PCI devices
# usbdevs -v # Show USB devices
# atacontrol list # Show ATA devices
# camcontrol devlist -v # Show SCSI devices


Load, statistics and messages

The following commands are useful to find out what is going on on the system.

# top # display and update the top cpu processes
# mpstat 1 # display processors related statistics
# vmstat 2 # display virtual memory statistics
# iostat 2 # display I/O statistics (2 s intervals)
# systat -vmstat 1 # BSD summary of system statistics (1 s intervals)
# systat -tcp 1 # BSD tcp connections (try also -ip)
# systat -netstat 1 # BSD active network connections
# systat -ifstat 1 # BSD network traffic through active interfaces
# systat -iostat 1 # BSD CPU and and disk throughput
# tail -n 500 /var/log/messages # Last 500 kernel/syslog messages
# tail /var/log/warn # System warnings messages see syslog.conf


Users

# id # Show the active user id with login and group
# last # Show last logins on the system
# who # Show who is logged on the system
# groupadd admin # Add group "admin" and user colin (Linux/Solaris)
# useradd -c "Colin Barschel" -g admin -m colin
# usermod -a -G # Add existing user to group (Debian)
# groupmod -A # Add existing user to group (SuSE)
# userdel colin # Delete user colin (Linux/Solaris)
# adduser joe # FreeBSD add user joe (interactive)
# rmuser joe # FreeBSD delete user joe (interactive)
# pw groupadd admin # Use pw on FreeBSD
# pw groupmod admin -m newmember # Add a new member to a group
# pw useradd colin -c "Colin Barschel" -g admin -m -s /bin/tcsh
# pw userdel colin; pw groupdel admin


Encrypted passwords are stored in /etc/shadow for Linux and Solaris and /etc/master.passwd on FreeBSD. If the master.passwd is modified manually (say to delete a password), run # pwd_mkdb -p master.passwd to rebuild the database.


To temporarily prevent logins system wide (for all users but root) use nologin. The message in nologin will be displayed (might not work with ssh pre-shared keys).

# echo "Sorry no login now" > /etc/nologin # (Linux)
# echo "Sorry no login now" > /var/run/nologin # (FreeBSD)



Limits

Some application require higher limits on open files and sockets (like a proxy
web server, database). The default limits are usually too low.
Linux

Per shell/script

The shell limits are governed by ulimit. The status is checked
with ulimit -a. For example to change the open files limit from
1024 to 10240 do:

# ulimit -n 10240 # This is only valid within the shell


The ulimit command can be used in a script to change the limits for the script only.

Per user/process

Login users and applications can be configured in /etc/security/limits.conf. For example:

# cat /etc/security/limits.conf
* hard nproc 250 # Limit user processes
asterisk hard nofile 409600 # Limit application open files


System wide

Kernel limits are set with sysctl. Permanent limits are set in /etc/sysctl.conf.

# sysctl -a # View all system limits
# sysctl fs.file-max # View max open files limit
# sysctl fs.file-max=102400 # Change max open files limit
# echo "1024 50000" > /proc/sys/net/ipv4/ip_local_port_range # port range
# cat /etc/sysctl.conf
fs.file-max=102400 # Permanent entry in sysctl.conf
# cat /proc/sys/fs/file-nr # How many file descriptors are in use



FreeBSD

Per shell/script

Use the command limits in csh or tcsh or as in Linux, use ulimit in an sh or bash shell.
Per user/process

The default limits on login are set in /etc/login.conf. An unlimited value is still limited by the system maximal value.
System wide

Kernel limits are also set with sysctl. Permanent limits are set in /etc/sysctl.conf or /boot/loader.conf. The syntax is the same as Linux but the keys are different.

# sysctl -a # View all system limits
# sysctl kern.maxfiles=XXXX # maximum number of file descriptors
kern.ipc.nmbclusters=32768 # Permanent entry in /etc/sysctl.conf
kern.maxfiles=65536 # Typical values for Squid
kern.maxfilesperproc=32768
kern.ipc.somaxconn=8192 # TCP queue. Better for apache/sendmail
# sysctl kern.openfiles # How many file descriptors are in use
# sysctl kern.ipc.numopensockets # How many open sockets are in use
# sysctl -w net.inet.ip.portrange.last=50000 # Default is 1024-5000
# netstat -m # network memory buffers statistics


See The FreeBSD handbook Chapter 11http://www.freebsd.org/handbook/configtuning-kernel-limits.html for details.

Solaris

The following values in /etc/system will increase the maximum file descriptors per proc:

set rlim_fd_max = 4096 # Hard limit on file descriptors for a single proc
set rlim_fd_cur = 1024 # Soft limit on file descriptors for a single proc



Runlevels

Linux

Once booted, the kernel starts init which then starts rc which starts all scripts belonging to a runlevel. The scripts are stored in /etc/init.d and are linked into /etc/rc.d/rcN.d with N the runlevel number.

The default runlevel is configured in /etc/inittab. It is usually 3 or 5:

# grep default: /etc/inittab
id:3:initdefault:


The actual runlevel (the list is shown below) can be changed with init. For example to go from 3 to 5:

# init 5 # Enters runlevel 5



* 0 Shutdown and halt

* 1 Single-User mode (also S)

* 2 Multi-user without network

* 3 Multi-user with network

* 5 Multi-user with X

* 6 Reboot


Use chkconfig to configure the programs that will be started at boot in a runlevel.

# chkconfig --list # List all init scripts
# chkconfig --list sshd # Report the status of sshd
# chkconfig sshd --level 35 on # Configure sshd for levels 3 and 5
# chkconfig sshd off # Disable sshd for all runlevels


Debian and Debian based distributions like Ubuntu or Knoppix use the command update-rc.d to manage the runlevels scripts. Default is to start in 2,3,4 and 5 and shutdown in 0,1 and 6.

# update-rc.d sshd defaults # Activate sshd with the default runlevels
# update-rc.d sshd start 20 2 3 4 5 . stop 20 0 1 6 . # With explicit arguments
# update-rc.d -f sshd remove # Disable sshd for all runlevels
# shutdown -h now (or # poweroff) # Shutdown and halt the system



FreeBSD

The BSD boot approach is different from the SysV, there are no runlevels. The final boot state (single user, with or without X) is configured in /etc/ttys. All OS scripts are located in /etc/rc.d/ and in /usr/local/etc/rc.d/ for third-party applications. The activation of the service is configured in /etc/rc.conf and /etc/rc.conf.local. The default behavior is configured in /etc/defaults/rc.conf. The scripts responds at least to start|stop|status.

# /etc/rc.d/sshd status
sshd is running as pid 552.
# shutdown now # Go into single-user mode
# exit # Go back to multi-user mode
# shutdown -p now # Shutdown and halt the system
# shutdown -r now # Reboot


The process init can also be used to reach one of the following states level. For example # init 6 for reboot.


* 0 Halt and turn the power off (signal USR2)

* 1 Go to single-user mode (signal TERM)

* 6 Reboot the machine (signal INT)

* c Block further logins (signal TSTP)

* q Rescan the ttys(5) file (signal HUP)



Reset root password

Linux method 1

At the boot loader (lilo or grub), enter the following boot option:

init=/bin/sh


The kernel will mount the root partition and init will start the bourne shell
instead of rc and then a runlevel. Use the command passwd at the prompt to change the password and then reboot. Forget the single user mode as you need the password for that.

If, after booting, the root partition is mounted read only, remount it rw:

# mount -o remount,rw /
# passwd # or delete the root password (/etc/shadow)
# sync; mount -o remount,ro / # sync before to remount read only
# reboot


FreeBSD method 1

On FreeBSD, boot in single user mode, remount / rw and use passwd. You can select the single user mode on the boot menu (option 4) which is displayed for 10 seconds at startup. The single user mode will give you a root shell on the / partition.

# mount -u /; mount -a # will mount / rw
# passwd
# reboot



Unixes and FreeBSD and Linux method 2

Other Unixes might not let you go away with the simple init trick. The solution is to mount the root partition from an other OS (like a rescue CD) and change the password on the disk.


* Boot a live CD or installation CD into a rescue mode which will give you a shell.

* Find the root partition with fdisk e.g. fdisk /dev/sda

* Mount it and use chroot:


# mount -o rw /dev/ad4s3a /mnt
# chroot /mnt # chroot into /mnt
# passwd
# reboot



Kernel modules

Linux

# lsmod # List all modules loaded in the kernel
# modprobe isdn # To load a module (here isdn)


FreeBSD

# kldstat # List all modules loaded in the kernel
# kldload crypto # To load a module (here crypto)


Compile Kernel

Linux

# cd /usr/src/linux
# make mrproper # Clean everything, including config files
# make oldconfig # Reuse the old .config if existent
# make menuconfig # or xconfig (Qt) or gconfig (GTK)
# make # Create a compressed kernel image
# make modules # Compile the modules
# make modules_install # Install the modules
# make install # Install the kernel
# reboot


FreeBSD

Optionally update the source tree (in /usr/src) with csup (as of FreeBSD 6.2 or later):

# csup


I use the following supfile:

*default host=cvsup5.FreeBSD.org # www.freebsd.org/handbook/cvsup.html#CVSUP-MIRRORS
*default prefix=/usr
*default base=/var/db
*default release=cvs delete tag=RELENG_7
src-all


To modify and rebuild the kernel, copy the generic configuration file to a new name and edit it as needed (you can also edit the file GENERIC directly). To restart the build after an interruption, add the option NO_CLEAN=YES to the make command to avoid cleaning the objects already build.

# cd /usr/src/sys/i386/conf/
# cp GENERIC MYKERNEL
# cd /usr/src
# make buildkernel KERNCONF=MYKERNEL
# make installkernel KERNCONF=MYKERNEL


To rebuild the full OS:

# make buildworld # Build the full OS but not the kernel
# make buildkernel # Use KERNCONF as above if appropriate
# make installkernel
# reboot
# mergemaster -p # Compares only files known to be essential
# make installworld
# mergemaster -i -U # Update all configuration and other files
# reboot


For small changes in the source you can use NO_CLEAN=yes to avoid rebuilding the whole tree. But use with care.

# make buildworld NO_CLEAN=yes # Don't delete the old objects
# make buildkernel KERNCONF=MYKERNEL NO_CLEAN=yes

Linux Applications

Apache is the Apache HyperText Transfer Protocol (HTTP) Linux program. A large portion of the Internet web sites you visit run Apache on the server the site is hosted on to serve your web pages. If you don’t know apache I suggest you learn the basics. Most Linux jobs will require you to at least dip your feet in some sort of apache administration.

At the Least, You Should Know:

How to install Apache.

How to configure Apache.

How to view Apache logs.

Must reads for Apache:

Official Apache HTTP Server Documentation
apt-get

apt-get is the command-line tool for handling packages, and may be considered the user’s “back-end” to other tools using the APT library. apt-get is used mainly on Debian and Ubuntu but is cross-platform and the actual APT library has many different front-ends built for it. Apt-get is a pretty simple tool to use, so theres not much to learn here, but you should still be familiar with how it works.

At the Least, You Should Know:

How to install a package.

How to remove a package.

Must reads for apt-get:

Apt-get Man Page

How to use apt-get
Bash - GNU Bourne-Again SHell

Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh).

It’s important to know how to program in Bash. There are a million ways to save time and energy if you can whip up a little bash script that automates something on the command line for you.

At the Least, You Should Know:

How to write a basic Bash script.

How to configure Bash to execute jobs during login or logout.

Must reads for Bash:

Bash Man Page

Bash Guide for Beginners

Advanced Bash Scripting

Bash by Example

Bash Tutorial
chmod

chmod changes the permissions of each given file according to mode, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new permissions.

Chmod is vital to any Linux user. If you don’t understand how to change permissions on files then you really shouldn’t be using Linux.

At the Least, You Should Know:

How to set file and folder permissions with chmod.

Must reads for chmod:

Chmod Man Page

Linux File Permissions
Crontab

crontab is the program used to install, deinstall or list the tables used to drive the cron(8) daemon in Vixie Cron. Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly.

Crontab is important to know if you want to execute a sort of “scheduled task” command that cron manages.

At the Least, You Should Know:

How to schedule tasks with crontab.

How to edit each users crontab.

How to allow and disallow users to use crontab.

Crontab format.

Must reads for Crontab:

Crontab Man Page

Understanding Cron Jobs in 5 Minutes

Crontab: Scheduling Tasks
Find

GNU find searches the directory tree rooted at each given file name by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name.

Using find is crucial to saving time and energy on the Linux command line. You’ll find that the more you know about the awesome capabilities of find, the better off you are.

At the Least, You Should Know:

How to find files throughout the whole system.

How to find only directories.

How to find files owned by a certain user.

Must reads for Find:

Study of Find

CLI Magic: Searching with Find

10 Useful uses of the find command
Iptables

Iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains.

With iptables you have the ability to create firewall rules on your Linux computer to allow or restrict access in and out through each network interface.

At the Least, You Should Know:

How to list iptables rules.

How to filter an IP from hitting your interface.

How to remove rules.

Must reads for iptables:

Iptables Man Page

Linux Firewalls using iptables

Designing a firewall using Iptables for the home user

Using iptables
MySQL

mysql is a simple SQL shell (with GNU readline capabilities). It supports interactive and non-interactive use. When used interactively, query results are presented in an ASCII-table format. When used non-interactively (for example, as a filter), the result is presented in tab-separated format. The output format can be changed using command options.

As a Linux user looking to land a Linux job, there is a strong possibility that you will be working in an environment that uses Linux-Apache-MySQL-PHP (LAMP). You should be familiar with administrating a mysql server.

At the Least, You Should Know:

How to install MySQL.

How to configure MySQL.

How to view MySQL error logs.

How To Add and Remove MySQL users.

Must reads for MySQL:

MySQL Man Page

Official MySQL Documentation
OpenSSH and SSH

Ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. You’ll probably find yourself using SSH on a daily basis if you land a Linux job.

At the Least, You Should Know:

How to connect to a server with SSH.

How to set up key based authentication for SSH.
Perl

Perl is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It’s also a good language for many system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).

You’ll find administration tasks that you can create Perl scripts for will save you a ton of work in the long run if you know Perl.

At the Least, You Should Know:

How to execute a perl script.

How to troubleshoot perl errors.

Must reads for Perl:

Perl Man Page

Official Perl Documentation

Simple Perl Scripts
Postfix

Postfix is a mail transfer agent (MTA) used on Linux as an alternative to Qmail and Sendmail. It handles the routing and delivery of email. Chances are you’ll run into some sort of postfix work in your Linux career, so why not learn what you can?

At the Least, You Should Know:

How to configure the postfix main.cf and master.cf files.

How to troubleshoot postfix errors and issues.

Must reads for Postfix:

Postfix Man Page

Official Postfix Documentation

Postfix Wiki

Postfix config How To
PHP

PHP (recursive acronym for “PHP: Hypertext Preprocessor”) is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Learning a bit about PHP as well as Apache and MySQL is essential to your Linux career and landing that Linux job.

At the Least, You Should Know:

How to install and configure PHP on Linux.

How to debug and troubleshoot a PHP error.

Must reads for PHP:

Official PHP Documentation

How To Write PHP Scripts
Qmail

Qmail is a secure, reliable, efficient, simple message transfer agent. If your Linux job isn’t running Postfix or Sendmail, you’re probably going to need to know Qmail.

At the Least, You Should Know:

How to Install and Configure Qmail.

How to find and interpret the Qmail log files.

How to debug and troubleshoot Qmail errors.

Must reads for Qmail:

Qmail Man Page

The Qmail Documentation Project

Qmail HowTo

Life With Qmail
RPM

rpm is a powerful Package Manager, which can be used to build, install, query, verify, update, and erase individual software packages. If you’re trying to land a Linux job with a large corporation, theres a good chance they run Red Hat, which uses RPM as it’s default package manager.

At the Least, You Should Know:

How to install RPM packages.

How to remove RPM packages.

How to check for RPM dependencies.

Must reads for RPM:

RPM Man Page

Official RPM Documentation
rsync

rsync uses the rsync remote-update protocol to greatly speed up file transfers when the destination file is being updated. Rsync basically only copies the diffs of files that have been changed.

Rsync is great for backing up files to another Linux host. If you plan on landing a Linux job you’ll definitely need to know rsync.

At the Least, You Should Know:

The syntax of using rsync to copy files to another host machine.

Must reads for rsync:

rsync Documentation

rsync Tips and Tricks

Using rsync and SSH
Samba

The Samba software suite is a collection of programs that implements the Server Message Block (commonly abbreviated as SMB) protocol for UNIX systems. This protocol is sometimes also referred to as the Common Internet File System (CIFS). For a more thorough description, see http://www.ubiqx.org/cifs/. Samba also implements the NetBIOS protocol in nmbd.

Most large companies that run a Linux and Windows environment use Samba to share files across the network. You should be familiar with Samba as much as possible.

At the Least, You Should Know:

How to install and configure Samba.

How to set up Samba users.

How to set up Samba shares.

Must reads for Samba:

Samba Man Page

Official Samba Documentation

Samba Setup Guide for Linux
SCP

scp copies files between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides the same security as ssh. scp will ask for passwords or passphrases if they are needed for authentication.

SCP is important to know if you need to copy files between Linux hosts over a public or private network with security in mind.

At the Least, You Should Know:

The syntax for copying a file from one host to another host.

Must reads for SCP:

SCP Man Page

SCP Tricks
Sendmail

Sendmail is another Mail Transfer Agent, similar to Qmail and Postfix, that sends a message to one or more recipients, routing the message over whatever networks are necessary. Sendmail does internetwork forwarding as necessary to deliver the message to the correct place. A majoriy of servers run Sendmail as their MTA so it’s important to know.

At the Least, You Should Know:

How to Install Sendmail.

How to configure Sendmail to send and receive Email.

How to view Sendmail logs.

Must reads for Sendmail:

Sendmail Man Page

Official Sendmail Documentation
Tar

Tar is an archiving program designed to store and extract files from an archive file known as a tarfile. You most defenitley need to know tar if you plan on landing any Linux job.

At the Least, You Should Know:

How to extract a tarball and tar/gzip file.

How to create a tar file.

Must reads for Tar:

Tar Man Page

GNU tar Documentation
VI/Vim

Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs.

It’s important to know vim because it is the one text editor that is almost always available by default on most Linux distributions. You can’t say the same for the simpler editors like pico and nano. Learn vim!

At the Least, You Should Know:

How to open a file and make a change.

How to save a file.

How to exit vim.

Must reads for Vim:

Vi/Vim Man Page

Official Vim Documentation

The Vim Commands Cheat Sheet

Vim Graphical Cheat Sheet based Tutorial
vsftpd

vsftpd is the Very Secure File Transfer Protocol Daemon. Most Linux servers that run an FTP daemon use vsftpd.

At the Least, You Should Know:

How to install vsftpd.

How to configure vsftpd.

How to view vsftpd logs and troubleshoot issues.

Must Reads for vsftpd:

Vsftpd.conf Man Page

A vsftpd Guide

I’ve covered all the applications I believe you should be familiar with if you’re trying to land a Linux job. You may not use all of them in an everyday Linux job, but these applications are the most widely used with Linux administration and Linux engineering jobs.

Do you have any other applications you feel should be on this list? Let us know by leaving a comment below.
Posted by Serious Blogger at 12:20 PM 0 comments Links to this post
Linux Commands -Hardware Informations

Running kernel and system information

# uname -a # Get the kernel version (and BSD version)
# lsb_release -a # Full release info of any LSB distribution
# cat /etc/SuSE-release # Get SuSE version
# cat /etc/debian_version # Get Debian version


Use /etc/DISTR-release with DISTR= lsb (Ubuntu), redhat, gentoo, mandrake, sun (Solaris), and so on. See also /etc/issue.

# uptime # Show how long the system has been running + load
# hostname # system's host name
# hostname -i # Display the IP address of the host. (Linux only)
# man hier # Description of the file system hierarchy
# last reboot # Show system reboot history


Hardware Informations

Kernel detected hardware

# dmesg # Detected hardware and boot messages
# lsdev # information about installed hardware
# dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8 # Read BIOS


Linux

# cat /proc/cpuinfo # CPU model
# cat /proc/meminfo # Hardware memory
# grep MemTotal /proc/meminfo # Display the physical memory
# watch -n1 'cat /proc/interrupts' # Watch changeable interrupts continuously
# free -m # Used and free memory (-m for MB)
# cat /proc/devices # Configured devices
# lspci -tv # Show PCI devices
# lsusb -tv # Show USB devices
# lshal # Show a list of all devices with their properties
# dmidecode # Show DMI/SMBIOS: hw info from the BIOS


FreeBSD

# sysctl hw.model # CPU model
# sysctl hw # Gives a lot of hardware information
# sysctl vm # Memory usage
# dmesg | grep "real mem" # Hardware memory
# sysctl -a | grep mem # Kernel memory settings and info
# sysctl dev # Configured devices
# pciconf -l -cv # Show PCI devices
# usbdevs -v # Show USB devices
# atacontrol list # Show ATA devices
# camcontrol devlist -v # Show SCSI devices


Load, statistics and messages

The following commands are useful to find out what is going on on the system.

# top # display and update the top cpu processes
# mpstat 1 # display processors related statistics
# vmstat 2 # display virtual memory statistics
# iostat 2 # display I/O statistics (2 s intervals)
# systat -vmstat 1 # BSD summary of system statistics (1 s intervals)
# systat -tcp 1 # BSD tcp connections (try also -ip)
# systat -netstat 1 # BSD active network connections
# systat -ifstat 1 # BSD network traffic through active interfaces
# systat -iostat 1 # BSD CPU and and disk throughput
# tail -n 500 /var/log/messages # Last 500 kernel/syslog messages
# tail /var/log/warn # System warnings messages see syslog.conf


Users

# id # Show the active user id with login and group
# last # Show last logins on the system
# who # Show who is logged on the system
# groupadd admin # Add group "admin" and user colin (Linux/Solaris)
# useradd -c "Colin Barschel" -g admin -m colin
# usermod -a -G # Add existing user to group (Debian)
# groupmod -A # Add existing user to group (SuSE)
# userdel colin # Delete user colin (Linux/Solaris)
# adduser joe # FreeBSD add user joe (interactive)
# rmuser joe # FreeBSD delete user joe (interactive)
# pw groupadd admin # Use pw on FreeBSD
# pw groupmod admin -m newmember # Add a new member to a group
# pw useradd colin -c "Colin Barschel" -g admin -m -s /bin/tcsh
# pw userdel colin; pw groupdel admin


Encrypted passwords are stored in /etc/shadow for Linux and Solaris and /etc/master.passwd on FreeBSD. If the master.passwd is modified manually (say to delete a password), run # pwd_mkdb -p master.passwd to rebuild the database.


To temporarily prevent logins system wide (for all users but root) use nologin. The message in nologin will be displayed (might not work with ssh pre-shared keys).

# echo "Sorry no login now" > /etc/nologin # (Linux)
# echo "Sorry no login now" > /var/run/nologin # (FreeBSD)



Limits

Some application require higher limits on open files and sockets (like a proxy
web server, database). The default limits are usually too low.
Linux

Per shell/script

The shell limits are governed by ulimit. The status is checked
with ulimit -a. For example to change the open files limit from
1024 to 10240 do:

# ulimit -n 10240 # This is only valid within the shell


The ulimit command can be used in a script to change the limits for the script only.

Per user/process

Login users and applications can be configured in /etc/security/limits.conf. For example:

# cat /etc/security/limits.conf
* hard nproc 250 # Limit user processes
asterisk hard nofile 409600 # Limit application open files


System wide

Kernel limits are set with sysctl. Permanent limits are set in /etc/sysctl.conf.

# sysctl -a # View all system limits
# sysctl fs.file-max # View max open files limit
# sysctl fs.file-max=102400 # Change max open files limit
# echo "1024 50000" > /proc/sys/net/ipv4/ip_local_port_range # port range
# cat /etc/sysctl.conf
fs.file-max=102400 # Permanent entry in sysctl.conf
# cat /proc/sys/fs/file-nr # How many file descriptors are in use



FreeBSD

Per shell/script

Use the command limits in csh or tcsh or as in Linux, use ulimit in an sh or bash shell.
Per user/process

The default limits on login are set in /etc/login.conf. An unlimited value is still limited by the system maximal value.
System wide

Kernel limits are also set with sysctl. Permanent limits are set in /etc/sysctl.conf or /boot/loader.conf. The syntax is the same as Linux but the keys are different.

# sysctl -a # View all system limits
# sysctl kern.maxfiles=XXXX # maximum number of file descriptors
kern.ipc.nmbclusters=32768 # Permanent entry in /etc/sysctl.conf
kern.maxfiles=65536 # Typical values for Squid
kern.maxfilesperproc=32768
kern.ipc.somaxconn=8192 # TCP queue. Better for apache/sendmail
# sysctl kern.openfiles # How many file descriptors are in use
# sysctl kern.ipc.numopensockets # How many open sockets are in use
# sysctl -w net.inet.ip.portrange.last=50000 # Default is 1024-5000
# netstat -m # network memory buffers statistics


See The FreeBSD handbook Chapter 11http://www.freebsd.org/handbook/configtuning-kernel-limits.html for details.

Solaris

The following values in /etc/system will increase the maximum file descriptors per proc:

set rlim_fd_max = 4096 # Hard limit on file descriptors for a single proc
set rlim_fd_cur = 1024 # Soft limit on file descriptors for a single proc



Runlevels

Linux

Once booted, the kernel starts init which then starts rc which starts all scripts belonging to a runlevel. The scripts are stored in /etc/init.d and are linked into /etc/rc.d/rcN.d with N the runlevel number.

The default runlevel is configured in /etc/inittab. It is usually 3 or 5:

# grep default: /etc/inittab
id:3:initdefault:


The actual runlevel (the list is shown below) can be changed with init. For example to go from 3 to 5:

# init 5 # Enters runlevel 5



* 0 Shutdown and halt

* 1 Single-User mode (also S)

* 2 Multi-user without network

* 3 Multi-user with network

* 5 Multi-user with X

* 6 Reboot


Use chkconfig to configure the programs that will be started at boot in a runlevel.

# chkconfig --list # List all init scripts
# chkconfig --list sshd # Report the status of sshd
# chkconfig sshd --level 35 on # Configure sshd for levels 3 and 5
# chkconfig sshd off # Disable sshd for all runlevels


Debian and Debian based distributions like Ubuntu or Knoppix use the command update-rc.d to manage the runlevels scripts. Default is to start in 2,3,4 and 5 and shutdown in 0,1 and 6.

# update-rc.d sshd defaults # Activate sshd with the default runlevels
# update-rc.d sshd start 20 2 3 4 5 . stop 20 0 1 6 . # With explicit arguments
# update-rc.d -f sshd remove # Disable sshd for all runlevels
# shutdown -h now (or # poweroff) # Shutdown and halt the system



FreeBSD

The BSD boot approach is different from the SysV, there are no runlevels. The final boot state (single user, with or without X) is configured in /etc/ttys. All OS scripts are located in /etc/rc.d/ and in /usr/local/etc/rc.d/ for third-party applications. The activation of the service is configured in /etc/rc.conf and /etc/rc.conf.local. The default behavior is configured in /etc/defaults/rc.conf. The scripts responds at least to start|stop|status.

# /etc/rc.d/sshd status
sshd is running as pid 552.
# shutdown now # Go into single-user mode
# exit # Go back to multi-user mode
# shutdown -p now # Shutdown and halt the system
# shutdown -r now # Reboot


The process init can also be used to reach one of the following states level. For example # init 6 for reboot.


* 0 Halt and turn the power off (signal USR2)

* 1 Go to single-user mode (signal TERM)

* 6 Reboot the machine (signal INT)

* c Block further logins (signal TSTP)

* q Rescan the ttys(5) file (signal HUP)



Reset root password

Linux method 1

At the boot loader (lilo or grub), enter the following boot option:

init=/bin/sh


The kernel will mount the root partition and init will start the bourne shell
instead of rc and then a runlevel. Use the command passwd at the prompt to change the password and then reboot. Forget the single user mode as you need the password for that.

If, after booting, the root partition is mounted read only, remount it rw:

# mount -o remount,rw /
# passwd # or delete the root password (/etc/shadow)
# sync; mount -o remount,ro / # sync before to remount read only
# reboot


FreeBSD method 1

On FreeBSD, boot in single user mode, remount / rw and use passwd. You can select the single user mode on the boot menu (option 4) which is displayed for 10 seconds at startup. The single user mode will give you a root shell on the / partition.

# mount -u /; mount -a # will mount / rw
# passwd
# reboot



Unixes and FreeBSD and Linux method 2

Other Unixes might not let you go away with the simple init trick. The solution is to mount the root partition from an other OS (like a rescue CD) and change the password on the disk.


* Boot a live CD or installation CD into a rescue mode which will give you a shell.

* Find the root partition with fdisk e.g. fdisk /dev/sda

* Mount it and use chroot:


# mount -o rw /dev/ad4s3a /mnt
# chroot /mnt # chroot into /mnt
# passwd
# reboot



Kernel modules

Linux

# lsmod # List all modules loaded in the kernel
# modprobe isdn # To load a module (here isdn)


FreeBSD

# kldstat # List all modules loaded in the kernel
# kldload crypto # To load a module (here crypto)


Compile Kernel

Linux

# cd /usr/src/linux
# make mrproper # Clean everything, including config files
# make oldconfig # Reuse the old .config if existent
# make menuconfig # or xconfig (Qt) or gconfig (GTK)
# make # Create a compressed kernel image
# make modules # Compile the modules
# make modules_install # Install the modules
# make install # Install the kernel
# reboot


FreeBSD

Optionally update the source tree (in /usr/src) with csup (as of FreeBSD 6.2 or later):

# csup


I use the following supfile:

*default host=cvsup5.FreeBSD.org # www.freebsd.org/handbook/cvsup.html#CVSUP-MIRRORS
*default prefix=/usr
*default base=/var/db
*default release=cvs delete tag=RELENG_7
src-all


To modify and rebuild the kernel, copy the generic configuration file to a new name and edit it as needed (you can also edit the file GENERIC directly). To restart the build after an interruption, add the option NO_CLEAN=YES to the make command to avoid cleaning the objects already build.

# cd /usr/src/sys/i386/conf/
# cp GENERIC MYKERNEL
# cd /usr/src
# make buildkernel KERNCONF=MYKERNEL
# make installkernel KERNCONF=MYKERNEL


To rebuild the full OS:

# make buildworld # Build the full OS but not the kernel
# make buildkernel # Use KERNCONF as above if appropriate
# make installkernel
# reboot
# mergemaster -p # Compares only files known to be essential
# make installworld
# mergemaster -i -U # Update all configuration and other files
# reboot


For small changes in the source you can use NO_CLEAN=yes to avoid rebuilding the whole tree. But use with care.

# make buildworld NO_CLEAN=yes # Don't delete the old objects
# make buildkernel KERNCONF=MYKERNEL NO_CLEAN=yes
Posted by Serious Blogger at 12:05 PM 0 comments Links to this post
Work on Linux from your Browser
Just visit the site

http://cb.vu/


To work on linux from your Browser

Killer Development tool from Linux Foundation

Ask any independent software vendor what he hates most about developing for Linux and he'll tell you that it's having to develop for SUSE and for Red Hat and for Ubuntu and ... you get the idea. The Linux Foundation has just released a beta of a new program, Linux Application Checker (AppChecker), that's going to make ISVs and other programmers start to love developing for Linux.
AppChecker, now in beta 3, is a downloadable open source Linux program. Once installed, the program shows you a Web page, the LSB Database Navigator. Here, you click on the Application Check link. This presents you with a Web form interface to fill out. In this form, you'll enter a name for your report and Name field, and in the Components field you'll enter the file path for your application. Next, enter the application's individual files, directories, installed RPM packages (prepended with pkg:),; RPM and .deb package files, and tar.gz and tar.bz2 archives. To make this manageable, click on the Select Application Components button so you can enter each item in a separate field. Next, select the LSB Version and LSB Profile you want to test against.


You then let AppChecker rip. It will automatically decompress archives and start testing. The program will check out your ELF (Executable and Linking Format, a.k.a. binary files), Perl, Python, and shell scripts. So far, this doesn't sound much more than just another fancied-up version of the forerunner of all program checkers, lint, but it's what AppChecker does next that will make it a must for any Linux software developer.



AppChecker then checks your program not only against different versions of the Linux Standard Base (LSB), but also against all the Linux distributions in the LSB Database. After the test is done it will present you with a report. It's this report that makes AppChecker special.



In the Web-based report, you're shown the compatibility status of your application with the various distributions, and which external libraries and interfaces your program uses. If all goes well, it gives you the option of putting your program in for LSB certification straight from the test program. It doesn't just give you a thumbs-up or thumbs-down for your application on any particular distribution, according to Amanda McPherson, Linux Foundation vice president of marketing and developer programs -- it "gives you the details you need to get your program running on a particular distribution."



McPherson warns, "This is a beta program and there's no guarantee, but yes, if AppChecker says your program should work with, say, Ubuntu 7.10 and 8.04, then your application should work on these distributions. The results can get very granular. It will tell you this library or this interface isn't available in this distribution. It can also recommend some replacements. For example, OpenSSL is often a problem and you should use different SSL library."



The program's initial idea came from McPherson and Ted T'so, the Linux Foundation's CTO and noted Linux kernel developer. AppChecker was then put together by T'so and the Russian Academy of Science. The program is licensed under the GPLv2.



According to AppChecker's technical documentation, AppChecker works by analyzing your "program's C/C++ symbols -- mostly functions with some global variables -- and libraries required by an application that are satisfied by dynamically linked libraries provided by a distribution."



AppChecker isn't a debugger. It doesn't check that the "type information expected by the application matches the type of the object provided by the distribution's libraries. For example, the layout of a data structure might have changed, or the function parameter that had previously been a 32-bit integer may have been changed to a 64-bit integer. Another problem that cannot be detected by the AppChecker is if the details of a function's behavior changes from one version to another."



What it does do is spell out for you what libraries and interfaces are provided by any given distribution, and make suggestions on which ones you might use as replacements to work on a particular version of Linux, or that will work on several different Linux distributions, McPherson explains. With this tool, you can quickly see what you need to do with your application to make it more portable across different Linux distributions.



It isn't perfect, of course. Not only is the program still in beta, but some libraries and interfaces aren't in the LSB databases. Still, it's a huge step forward in enabling developers to see exactly what they're dealing with in writing an application for multiple different versions of Linux.



AppChecker users can keep their test results to themselves, but McPherson hopes that they'll share their results with the Linux Foundation. "If you choose choose to share your results with us, it helps the Linux platform and helps the LSB get better. For example, it tells us what libraries Linux developers are using that aren't in LSB. We can then include [them] in the LSB, and that will make the LSB better."

Windows apps on Linux the CrossOver way

Who says you have to give up your must-have Windows applications when you migrate to Linux? If you can't leave some crucial Windows program behind, you can run it using CodeWeavers' latest version of CrossOver Linux.


Though today there are many great Linux end-user applications, some people still have "must-have" Windows applications -- Quicken instead of GnuCash, for instance, or Photoshop instead of the GIMP. That's where CrossOver Linux 7 comes in.


With this new version, you can run more Windows programs on Linux than ever. Such popular Windows programs as Microsoft Office -- from 97 to 2007 -- Internet Explorer 6, and Quicken run almost as well on Linux as they do on Windows. Other programs, like Adobe Photoshop CS3, run decently albeit not perfectly on Linux with CrossOver.



CrossOver is based on the open source project Wine, an implementation of the Windows API on top of the Unix/Linux operating system family. Wine is a very mature project, which, after 15 years of development, has reached the 1.0 mark.


You don't need CrossOver Linux to run Windows applications on Linux. Wine alone is enough. Wine, however, requires more technical expertise to use properly. What CrossOver gives you is an automated Windows application installation and technical support. For most users, who just want to run their Windows programs and not bother with the nuts and bolts of Wine, CrossOver Linux, which retails for $40, is worth the money. CodeWeavers also offers CrossOver Mac, which brings the same functionality to Intel-powered Macs.


To see how well this Wine 1.0-powered edition of CrossOver Linux works I tested it on two systems. The first was my main openSUSE 11 desktop, a Hewlett-Packard Pavilion A6040N Desktop PC powered by a 1.86GHz Intel Core 2 Duo E6320 dual-core processor with 2GB of 533MHz RAM and a 320GB SATA (Serial ATA) hard drive running at 7200 RPM. It's a good 2007-era PC.


I also put CrossOver 7 through its paces on an older Gateway 503GR running Ubuntu 8.04. It comes with a 3GHz Pentium 4 CPU, 2GB of RAM, an ATI Radeon 250 graphics card, and a 300GB SATA drive. Both systems had more than enough raw horsepower power to run Linux, CrossOver Linux, and multiple Windows and Linux applications simultaneously.


CrossOver requires very little from a system. CodeWeavers claims that any 32-bit system that runs at 200MHz can run CrossOver. The program will run on 64-bit systems, but only if they have the 32-bit compatibility library installed. CrossOver also requires that your Linux includes Glibc 2.3.x or greater and X11R6 3.3 or greater. XFree86 4 with XRender and FreeType support is recommended. The bottom line is any modern Linux can run CrossOver.


The program can be installed in several different ways. The sure-fire way of installing it on any Linux is to use its shell script. Once you have it installed, CrossOver presents you with a GUI that works equally well with both KDE and GNOME. Here, you choose which Windows applications you want to install from a supplied list of supported applications.


Installing Windows applications is a snap. It's a pick and clip operation. You can also install non-supported applications. Some, such as my favorite HTML editor, NoteTab, even though not technically supported, will run, albeit with some problems.


You should also keep in mind that, while CodeWeavers is trying to support the most popular Windows applications on Linux, it doesn't support every program. Check the company's compatibility pages to see if anyone has tried to run your particular favorite program with CrossOver and how well it has gone for them.


Once in place, the supported Windows applications ran without a hitch. I spent most of my time working on Word 2003 documents, Excel 2003 spreadsheets, IE 6, and fairly complicated Quicken 2006 financial statements. The programs ran well. As a matter of fact they ran better on Linux than they did on Vista. Quicken, in particular, took better to CrossOver than it did to Vista. With a little research I found out that this was not just me. Vista is known to have trouble with several versions of Quicken.


Some Windows software runs better on Linux than it does on the latest version of Windows -- who knew?


CrossOver isn't perfect of course. While I was able to run Photoshop CS3, I sometimes had trouble rendering the CS3 interface. A screen refresh usually took care of the problem, but some users will doubtlessly find that annoying.


I would also sometimes need to force a screen refresh when one Windows application's window covered up another. When I'd reveal the "lower" application, the part of it that had been covered by the other Windows application wouldn't render properly. After doing anything with the new foreground application, such as running a command, the foreground program's screen reappeared as it should.


CodeWeavers also offers CrossOver Linux Professional, which costs $70, can be used for multiple users, and comes with CrossOver Games. This addition includes advanced support for DirectX, Microsoft's graphics application programming interfaces for games. With this, many Windows games will run well on Linux. I can personally attest that zapping your enemies and other baddies in World of Warcraft and Guild Wars is just as much fun on Linux as it on Windows. CrossOver Games is also available separately for $40.


Not sure if CrossOver is right for you? You can download a free 30-day trial version of CrossOver Linux and a seven-day trial edition of CrossOver Games. You should find that more than enough time to see if these programs deliver the Windows goods for you.

Mounting partitions with the script

Acquiring the script

The script must be downloaded before it can be used. Type the following lines.

cd
wget http://media.ubuntu-nl.org/scripts/diskmounter

The file diskmounter will now be in the current user's home directory.

Using the script

The script is non-interactive, and usage is simple. Type the following line.

sudo bash diskmounter

This will execute the script with administrative rights.

The script will generate some output, regardless of whether it succeeds or not. Read the output as it will indicate errors and things you should read.

Cleaning up

The script is no longer needed, so type the following line to get rid of it.

rm diskmounter

All partitions on the system should now be accessible.

To verify access, open Gnome's file browser and direct it to /media/, which can be found by clicking 'File System' under 'Places', and then double-clicking 'media'. Double-click any partition to be examined. If it contains files, the modifications were successful. If no files are found, read the next section.

If the script worked for you, don't stop reading yet! Some tips exist at the end of this article in the Hints, Tips, and Technical Information section to help make your Ubuntu experience even more enjoyable.