Linux Problems and Solutions

How to read e-mail as root
You received the message "you have new mail /var/spool/mail/root" and do not know what to do ?

Just read the mail using the command below. Of course you can use the application pine to read it.

$ cat /var/spool/mail/root | less

How to list devices
If you need to know which devices were identified in the boot startup process, execute the command dmesg that shows all the boot messages. For example, if you need to list the hard disk devices that were recognized, type:

$ dmesg | grep hd

Compiling the Linux kernel
When compiling the kernel all output files will per default be stored together with the kernel source code.

Using the option "make O=output/dir" allow you to specify an alternate place for the output files (including .config).

Example: kernel source code:	/usr/src/linux-2.6.N build directory:	/home/name/build/kernel

To configure and build the kernel use:

$ cd /usr/src/linux-2.6.N $ make O=/home/name/build/kernel menuconfig $ make O=/home/name/build/kernel $ sudo make O=/home/name/build/kernel modules_install install

If you want to carry your existing configuration to a new version with minimal work, use "make oldconfig", which will only ask you for the answers to new questions.

Alternate configuration commands are:
 * "make config":     Plain text interface.
 * "make menuconfig": Text based color menus, radiolists & dialogs.
 * "make xconfig": X windows (Qt) based configuration tool.
 * "make gconfig": X windows (Gtk) based configuration tool.
 * "make oldconfig": Default all questions based on the contents of your existing ./.config file and asking about new config symbols.
 * "make silentoldconfig": Like above, but avoids cluttering the screen with questions already answered.
 * "make defconfig": Create a ./.config file by using the default symbol values from arch/$ARCH/defconfig.
 * "make allyesconfig": Create a ./.config file by setting symbol values to 'y' as much as possible.
 * "make allmodconfig": Create a ./.config file by setting symbol values to 'm' as much as possible.
 * "make allnoconfig": Create a ./.config file by setting symbol values to 'n' as much as possible.
 * "make randconfig": Create a ./.config file by setting symbol values to random values.

Copying files using SSH
To copy large files between PCs using unix, you can use the command scp.

Let's begin and assume the following information:
 * Server A is our host where the original files are located.
 * Server B is where we need to copy files to.

1. Make sure on Server A you have enabled Shell access for the user account you are going to use. Let's say our files are in. In this case, make sure you enable user1 shell access.

2. Login SSH on Server B, login as root "su", or as user1 should work too so long as you stick the files in the same place.

3. Type this command: where xx.xx.xx.xx is the IP address of Server A

$ scp -rv user1@xx.xx.xx.xx:/home/user1/public_html/myfiles/ /home/user1/public_html/myfiles/

notice there is a *SPACE* after and

You will be prompted for the SSH password of user1 at Server A. Enter this, and the copy process will start.

the -r option copies everything in the directory tree, e.g.: /home/user1/public_html/myfiles/dir1/ /home/user1/public_html/myfiles/dir2/ /home/user1/public_html/myfiles/dir3/moredir1/ etc.....

the -v option is verbose, lets you see the transfer in action in your ssh terminal.

The scp command is just like the cp command only it uses SSH intertwined with it all. Very slick if you need to copy whole directory trees from server to server.

Copy and paste using the mouse in the console
To activate the copy and paste using the mouse in the console type:

$ gpm -m /dev/psaux -t imps2

You can substitue to your mouse device and imps2 to ps2 as your mouse configuration. Take a look in the file.

Filesystem Recovery Procedures
If your Linux filesystem stucks and gets odd try one of the following solutions:

1) Stop the filesystem checking procedure during the boot

During the boot time, press ESC (optional) to see the boot process in the background. If the system forces the check process of the partition that has problems, press CTRL+C to stop the process. This partition will not be mounted by the system. You have to mount it again:

$ mount /dev/sda6

2) Try to mount manually your system

Use the mount command for this purpouse. Examples:

$ mount -t ext3 /dev/sda6 /mnt/custom -o ro $ mount -t ext2 /dev/sda6 /mnt/custom -o ro

If it works, copy your files to a secure place.

3) Backup your partition first

If you are using VMware or other Virtualization system, copy the vm files to a secure place first.

If you are using linux, backup your partition to other partition in the same or remote computer. Try, for example, to mount a network shared directory using Samba and execute the following command to

make a backup of your partition:

$ dd if=/dev/sda6 of=/mnt/windows2/mybackup.bak.dd

4) Use Rescue CDs and their recovery tools

An example is the program TestDisk Data Recovery Utility that comes with the rescue CD called System Rescue CD.

After initializing the system choose the following options:


 * [No Log]
 * Use arrow keys and select the correct disk drive.
 * [Intel] Intel / PC partition
 * [Analyse]
 * [Proceed]
 * Press N (No) if you do not want find Vista partitions.
 * Press Enter and finally select [Quit]
 * [Advanced] Filesystem Utils
 * Choose each partition with problems and select the option [Superblock].
 * [Quit]

Other good example to recover or undelete file in Windows is the program PC Inspector File Recovery that comes with the rescued CD called Ultimate Boot CD.

If your filesystem is of the type ext3 execute the commands:

$ tune2fs -O ^has_journal /dev/sda6 $ tune2fs -j /dev/sda6

Continue executing the commands below:

$ debugfs -w /dev/sda6 debugsfs: open -c /dev/hda1 debugsfs: stat debugsfs: stats

mke2fs re-writes all of the superblocks and group descriptors and I was able to mount in RO mode and copy off the data. After that I was able to fsck and remount the original parition with no problems!

$ mke2fs -S /dev/sda6

For ext2 partitions:

$ fsck.ext2 -y /dev/sda6 $ mount -t ext2 /dev/sda6 /mnt/custom -o ro

for ext3 partitions:

$ fsck.ext3 -y /dev/sda6 $ mount -t ext3 /dev/sda6 /mnt/custom -o ro

Mounting NTFS for read and write operations
The NTFS-3G driver is a freely and commercially available and supported read/write NTFS driver for Linux, FreeBSD, Mac OS X, NetBSD, Solaris, Haiku, and other operating systems. It provides safe and fast handling of the Windows XP, Windows Server 2003, Windows 2000, Windows Vista, Windows Server 2008 and Windows 7 file systems.

The NTFS volume can be mounted in read-write mode for everybody as follows.

mount -t ntfs-3g /dev/sda1 /mnt/ntfs

You can also make NTFS to be mounted during boot by adding the following line to the end of the file:

/dev/sda1 /mnt/windows ntfs-3g defaults 0 0

Problems and Solutions related to Linux or Unix systems 