Print service provided by iDogiCat: http://www.idogicat.com/
home logo





Home > IT > System Administration > iDog's Linux Operation How-to

iDog's Linux Operation How-to

Disk

Partition

Following commands can be used to manipulate partitions:

  • fdisk
  • parted
  • partx

Format Disks

Format into EXT3:


mke2fs -j /dev/hda1

Mount

Mount Floppy Disk (MS-DOS format)

mount -t msdos /dev/fd0 /mnt/floppy

Mount CD-ROM

mount -r -t iso9660 /dev/cdrom /mnt/cdrom

Mount image file as CD-ROM

mount -o loop /mydir/my_cd_image.iso /mnt/cdrom

Mount Windows FAT partition

mount -t vfat /dev/hda1 /harddisk/vfat

Mount Windows NTFS partition

mount -r -t ntfs /dev/hda1 /harddisk/ntfs

NOTE: need to enable NTFS support in Linux kernal. "-r" option is recommended as of now (Nov 2006).

Mount Linux EXT3 partition

mount -t ext3 /dev/hda1 /harddisk/ext3

Mount iPod smile

mount -t vfat /dev/sda2 /mnt/ipod

NOTE: my iPod is a G5 video 80GB one. Not sure of other ones.

Frequently used partition types

OS/mediatypetype in mount
Win 95/98FAT32/16vfat
Win NT/2000/XPNTFSntfs
LinuxEXT3ext3
LinuxEXT2ext2
CD-ROMISO9660iso9660

Email

Sendmail

Sendmail starts slow

Usually with error message like "My unqualified host name (<local_host_name>) unknown; sleeping for retry".

This is usually caused by the config of /etc/hosts. You need to put a local host name with a trailing '.', since sendmail needs the dot:

192.168.0.2  coolserver  coolserver.

Internationalization

Convert encoding of a file:


iconv -f gb2312 -t utf8 filename > filename

ssh in script

To use ssh in script, we need to make it not asking for password or passphrase.

Supposing we logged in hostname1 as username1, we want to access hostname2 as username2. The idea is to generate a public key in hostname1 and put it in hostname2.

1. Generate public key


username1@hostname1:~/> ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/username1/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username1/.ssh/id_dsa.
Your public key has been saved in /home/username1/.ssh/id_dsa.pub.
The key fingerprint is:
62:05:5a:6f:16:14:29:13:fe:05:0d:b7:48:37:0f:2a username1@hostname1

id_dsa.pub is the public key. Note that we need to make passphrase empty, otherwise it will be required when you connect to hostname2.

2. Add public key

Open /home/username1/.ssh/id_dsa.pub, copy the block that looks like follows, paste it in /home/username2/.ssh/authorized_keys file.


ssh-dss AAAAB3Nz...ZyLw= username1@hostname1

3. Make the initial access

When you access a box using ssh for the first time, ssh asks you a question, and if 'yes' is answered, it adds the destination to known host list. Since this blocks the script, so we should do it manually before deploying the script.

4. Use ssh in script

We can exec a command in a remote box as follows:


command="ls"
result=`ssh -l username2 hostname2 $command`
...