Wednesday, July 23, 2008

Linux Hard Disk Format Command

Q. I've installed a new 250GB SATA hard disk on our office CentOS Linux server. How do I format a hard disk under Linux operating system from a shell prompt?


A.. There are total 4 steps involved for hard disk upgrade and installation procedure:

Step #1 : Partition the new disk using fdisk command

Following command will list all detected hard disks:


# fdisk -l | grep '^Disk'
Output:

Disk /dev/sda: 251.0 GB, 251000193024 bytes
Disk /dev/sdb: 251.0 GB, 251000193024 bytes
A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings.

To partition the disk - /dev/sdb, enter:
# fdisk /dev/sdb

The basic fdisk commands you need are:
  • m - print help
  • p - print the partition table
  • n - create a new partition
  • d - delete a partition
  • q - quit without saving changes
  • w - write the new partition table and exit

Step#2 : Format the new disk using mkfs.ext3 command

To format Linux partitions using ext2fs on the new disk:
# mkfs.ext3 /dev/sdb1


Step#3 : Mount the new disk using mount command

First create a mount point /disk1 and use mount command to mount /dev/sdb1, enter:
# mkdir /disk1
# mount /dev/sdb1 /disk1
# df -H


Step#4 : Update /etc/fstab file

Open /etc/fstab file, enter:
# vi /etc/fstab
Append as follows:

/dev/sdb1               /disk1           ext3    defaults        1 2

Save and close the file.


Task: Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backup, enter
# e2label /dev/sdb1 /backup
You can use label name instead of partition name to mount disk using /etc/fstab:
LABEL=/backup /disk1 ext3 defaults 1 2

How To Find Hard Disk Revolutions Per Minute (RPM) Speed From A Shell Prompt

Q. How do I find out my SCSI hard disk RPM speed from a Linux shell prompt without opening my server case? How do I find out hard disk model and serial number from a shell prompt?


A. A typical desktop hard disk rotate at 7,200 revolutions per minute (RPM). A typical server hard disk spin at 10,000 or 15,000 rpm to achieve sequential media transfer speeds. You can use hard disk model number to obtain disk RPM. For example, a typical Seagat disk Model # ST373455SS can provide following information:
  • ST - Brand identity
  • 3 - Form Factor (3 = 3.5")
  • 73 - Disk size / Capacity in GB i.e. 73GB
  • 4 - Reserved for future use
  • 5 - RPM ( 5 = 15k and 0 = 10K)
  • 5 - Generation
  • SS - Indicates interface i.e Serial Attached SCSI

How do I find out hard disk model and serial number?

Use any one of the following command from shell prompt to find out hard disk model number:
$ cat /proc/scsi/scsi
OR use scsi_id command to querys a SCSI device via the SCSI INQUIRY vital product data (VPD) page 0x80 or 0x83 and uses the resulting data to generate a value that is unique across all SCSI devices that properly support page 0x80 or page 0x83.
$ /sbin/scsi_id -g -p 0x80 -s /block/sdd
OR
$ sudo grep -i sdd /var/log/boot.log
OR use sginfo / scsiinfo command from sg3_utiles package, enter:
# sginfo -a /dev/sdd | more

scsiinfo or sg3_utils package

sg3_utils is a collection of Linux utilities for devices that use the SCSI command set. You can install by typing following command:
# yum install sg3_utils
If you are using Debian / Ubuntu Linux, enter:
$ sudo apt-get install sg3-utils

WARNING! Some of these tools access the internals of your hard disk system and the incorrect usage of them may render your system inoperable or loss of data possible.


Now you can use command sginfo with the -g switch to obtain information about hard disk cylinders, heads and RPM:
# sginfo -g /dev/sdd
Sample output:

Rigid Disk Geometry mode page (0x4)
-----------------------------------
Number of cylinders 74340
Number of heads 2
Starting cyl. write precomp 0
Starting cyl. reduced current 0
Device step rate 0
Landing Zone Cylinder 0
RPL 0
Rotational Offset 0
Rotational Rate 15015

Finding out your hard disk RPM speed using manufactures website / product page

Once obtained hard disk model number, directly go to manufactures website and search for model to get detailed information.


Further readings:

  • man sginfo
  • How Do I interpret DRIVE MODEL NUMBERS?

Monday, July 14, 2008

What Software does Linux Support?

All of the standard open source utilities, like GCC, (X)Emacs, the X
Window System, all the standard Unix utilities, TCP/IP (including SLIP
and PPP), and all of the hundreds of programs that people have
compiled or ported to it.

There is a DOS emulator, called DOSEMU. The latest stable release is
0.98.3. The FTP archives are at ftp://ftp.dosemu.org/ The Web
site is http://www.dosemu.org.

The emulator can run DOS itself and some (but not all) DOS
applications. Be sure to look at the README file to determine which
version you should get. Also, see the DOSEMU-HOWTO (slightly dated at
this point--it doesn't cover the most recent version of the program),
at ftp://metalab.unc.edu/pub/Linux/docs/HOWTO.

Work has been progressing on an emulator for Microsoft Windows
binaries. ("Can Linux Run Microsoft Windows Programs?")

iBCS2 (Intel Binary Compatibility Standard) emulator code for SVR4 ELF
and SVR3.2 COFF binaries can be included in the kernel as a
compile-time option. There is information at
ftp://tsx-11.mit.edu/pub/linux/BETA/ibcs2/.

For more information see the INFO-SHEET, which is one of the HOWTO's
("Where Is the Documentation?" and "How To Port XXX to Linux.")

Some companies have commercial software available. They often announce
their availability on comp.os.linux.announce-- try searching the
archives. ("Are the News Groups Archived Anywhere?")

Sunday, July 13, 2008

Red Hat Linux Certification Program (Newbies)

The Red Hat Certification Program is Red Hat's professional certification program for Red Hat and general Linux related skills such as system administration on Red Hat Enterprise Linux. Red Hat certifications are indisputably regarded as the best in Linux, and perhaps, according to some, in all of IT. The tests are hands-on and involve troubleshooting, installation, and system administration. There are no multiple-choice questions, and everything is done on a live system. Often there is more than one way to configure a service or troubleshoot a problem, and the exam focuses on the end results, not the process that was taken to achieve that result. The most common and well-known Red Hat certification is the Red Hat Certified Engineer.
About Red Hat Certifications
  1. Red Hat Certified Technician (RHCT) The entry-level RHCT certification focuses on single-system administration. RHCT is the best first step in establishing Linux credentials and is an ideal initial certification for those transitioning from non-UNIX®/ Linux environments.
  2. Red Hat Certified Engineer (RHCE) program expands the RHCT with a focus on services and security. RHCE is called the crown jewel of Linux certifications, independent surveys have ranked the RHCE program #1 in all of IT.
  3. Red Hat Certified Architect (RHCA) requires an additional five endorsements to the RHCE that adds an enterprise-level focus. From clustering to deploying systems, these five exams ensure the student can deploy systems at the Enterprise level. Red Hat offers a four-day class for each course that can include the exam on the fifth day.
  4. Red Hat Certified Security Specialist (RHCSS). This certification includes two endorsement exams from the RHCA plus an SELinux exam. It has been offered since 2005-10-13.

Choosing the right certification depends on your background and goals. Whether you have advanced, minimal, or no UNIX or Linux experience whatsoever, Red Hat Training has a training and certification path that is right for you.

Benefits of becoming Red Hat Certified

  • Confidence and competence: RHCEs report greater confidence in their skills and better success at building and managing Linux servers. The actual quality of their work and their professionalism improve. They are better at performing their jobs for their employers, can take on more challenging assignments, and they receive recognition for this.
  • Career results: RHCEs interviewed also report one or more of the following within 90 days of earning the RHCE certificate: a new job, a raise, a promotion, increased responsibility, assignment to lead or supervisory role, increased recognition and/or prestige among colleagues.
  • Benefits provided directly by Red Hat: Verification services for all certificate holders are provided at Certification Central. RHCEs have exclusive access to RHCE Connection, a special site for RHCEs to receive special offers, discounts and benefits, as well as technical updates and access to resources. Certain other discretionary benefits of certification, such as partner programs between Red Hat and the company at which you may be employed, may require you to maintain certification on the most recent major release or otherwise on a more frequent basis than Red Hat GLS stated policy for individuals.
  • Hard dollars: RHCE earn more because of their RHCE, as shown by two recent independent surveys: Computer Reseller News, and Certification Magazine.

Red Hat Exam Structure
Red Hat Courses Covering These Skills

  • RH033 Red Hat Linux Essentials covers prerequisite skills, with the exception of TCP/IP fundamentals. The Network Essentials series covers TCP/IP fundamentals
  • RH133 Red Hat Linux System Administration covers RHCT-level skills.
  • RH253 Red Hat Linux Networking Services and Security covers RHCE-specific skills in networking services and security. Attendees should attend RH133 first.
  • Red Hat RHCE Fast Track Course condenses material from RH133 and RH253. Only experienced Linux and UNIX system administrators with background in networking services should attend.

The RHCT exam is a subset of the RHCE exam, and is organized as follows:

  • Troubleshooting and System Maintenance — 1 hour
  • Installation and Configuration — 2 hours
  • In order to earn RHCT, one must successfully complete all the requirements in Troubleshooting and System Maintenance, and must achieve a score of 70 or higher on Installation and Configuration.

For RHCE exams given on Red Hat Enterprise Linux 3 and higher, the exam is organized as follows:

  • Troubleshooting and System Maintenance — 2.5 hours
  • Installation and Configuration — 3.0 hours
  • In order to earn RHCE, one must successfully complete all the RHCT-level Troubleshooting and System Maintenance requirements, and successfully complete enough additional RHCE items to earn a score of 80 or higher overall on the section.In addition, one must score 70 or higher on the RHCT items of Installation and Configuration, and 70 or higher on the RHCE components of that section.

Howto: Linux Add User To Group

Q. How can I add a user to a group under Linux operating system?

A. You can use useradd or usermod commands to add a user to a group. useradd command creates a new user or update default new user information. usermod command modifies a user account i.e. it is useful to add user to existing group. There are two types of group. First is primary user group and other is secondary group. All user account related information is stored in /etc/passwd, /etc/shadow and /etc/group files to store user information.


useradd example - Add a new user to secondary group

Use useradd command to add new users to existing group (or create a new group and then add user). If group does not exist, create it. Syntax:

useradd -G {group-name} username

Create a new user called vivek and add it to group called developers. First login as a root user (make sure group developers exists), enter:

# grep developers /etc/group

Output:
developers:x:1124:
If you do not see any output then you need to add group developers using groupadd command:

# groupadd developers

Next, add a user called vivek to group developers:

# useradd -G developers vivek

Setup password for user vivek:

# passwd vivek

Ensure that user added properly to group developers:

# id vivek
Output:
uid=1122(vivek) gid=1125(vivek) groups=1125(vivek),1124(developers)

Please note that capital G (-G) option add user to a list of supplementary groups. Each group is separated from the next by a comma, with no intervening whitespace. For example, add user jerry to groups admins, ftp, www, and developers, enter:

# useradd -G admins,ftp,www,developers jerry

useradd example - Add a new user to primary group

To add a user tony to group developers use following command:

# useradd -g developers tony

# id tony

uid=1123(tony) gid=1124(developers) groups=1124(developers)
Please note that small -g option add user to initial login group (primary group). The group name must exist. A group number must refer to an already existing group.

usermod example - Add a existing user to existing group

Add existing user tony to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option :

# usermod -a -G ftp tonyChange existing user tony primary group to www:

# usermod -g www tony

Sunday, July 6, 2008

Basic Linux Commands

ls - Short listing of directory contents
-a list hidden files
-d list the name of the current directory
-F show directories with a trailing '/'
executable files with a trailing '*'
-g show group ownership of file in long listing
-i print the inode number of each file
-l long listing giving details about files and directories
-R list all subdirectories encountered
-t sort by time modified instead of name
cp - Copy files
cp myfile yourfile
Copy the files "myfile" to the file "yourfile" in the current working directory. This command will create the file "yourfile" if it doesn't exist. It will normally overwrite it without warning if it exists.
cp -i myfile yourfile
With the "-i" option, if the file "yourfile" exists, you will be prompted before it is overwritten.
cp -i /data/myfile
Copy the file "/data/myfile" to the current working directory and name it "myfile". Prompt before overwriting the file.
cp -dpr srcdir destdir
Copy all files from the directory "srcdir" to the directory "destdir" preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir
ln - Creates a symbolic link to a file.
ln -s test symlink
Creates a symbolic link named symlink that points to the file test Typing "ls -i test symlink" will show the two files are different with different inodes. Typing "ls -l test symlink" will show that symlink points to the file test.
locate - A fast database driven file locator.
slocate -u
This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically on most systems.locate whereis Lists all files whose names contain the string "whereis". directory.
more - Allows file contents or piped output to be sent to the screen one page at a time
less - Opposite of the more command
cat - Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.
whereis - Report all known instances of a commandwc - Print byte, word, and line counts
bg
bg jobs Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.
cal month year - Prints a calendar for the specified month of the specified year.
cat files - Prints the contents of the specified files.
clear - Clears the terminal screen.
cmp file1 file2 - Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.
diff file1 file2 - Compares two files, reporting all discrepancies. Similar to the cmp command, though the output format differs.
dmesg - Prints the messages resulting from the most recent system boot.
fg
fg jobs - Brings the current job (or the specified jobs) to the foreground.
file files - Determines and prints a description of the type of each specified file.
find path -name pattern -print
Searches the specified path for files with names matching the specified pattern (usually enclosed in single quotes) and prints their names. The find command has many other arguments and functions; see the online documentation.
finger users - Prints descriptions of the specified users.
free - Displays the amount of used and free system memory.
ftp hostname
Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers; see the online documentation.
head files - Prints the first several lines of each specified file.
ispell files - Checks the spelling of the contents of the specified files.
kill process_ids
kill - signal process_ids
kill -l
Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.
killall program
killall - signal program
Kills all processes that are instances of the specified program or sends the specified signal to all processes that are instances of the specified program.
mail - Launches a simple mail client that permits sending and receiving email messages.
man title
man section title - Prints the specified man page.
ping host - Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.
reboot - Reboots the system (requires root privileges).
shutdown minutes
shutdown -r minutes
Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.
sleep time - Causes the command interpreter to pause for the specified number of seconds.
sort files - Sorts the specified files. The command has many useful arguments; see the online documentation.
split file - Splits a file into several smaller files. The command has many arguments; see the online documentation
sync - Completes all pending input/output operations (requires root privileges).
telnet host - Opens a login session on the specified host.
top - Prints a display of system processes that's continually updated until the user presses the q key.
traceroute host - Uses echo requests to determine and print a network path to the host.
uptime - Prints the system uptime.
w - Prints the current system users.
wall - Prints a message to each user except those who've disabled message reception. Type Ctrl-D to end the message.

Basic Linux Commands (Contd..)

chown - change file owner and group
Usage
chown [OPTION] OWNER[:[GROUP]] FILE
chown [OPTION] :GROUP FILE
chown [OPTION] --reference=RFILE FILE
Options
Change the owner and/or group of each FILE to OWNER and/or GROUP. With --reference, change the owner and group of each FILE to those of RFILE.
-c, changes like verbose but report only when a change is made
-dereference affect the referent of each symbolic link, rather than the symbolic link itself
-h, no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can change the ownership of a symlink)
-from=CURRENT_OWNER:CURRENT_GROUP
change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute.
-no-preserve-root do not treat `/' specially (the default)
-preserve-root fail to operate recursively on `/'
-f, -silent, -quiet suppress most error messages
-reference=RFILE use RFILE's owner and group rather than the specifying OWNER:GROUP values
-R, -recursive operate on files and directories recursively
-v, -verbose output a diagnostic for every file processed
The following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one takes effect.
-H if a command line argument is a symbolic link to a directory, traverse it
-L traverse every symbolic link to a directory encountered
-P do not traverse any symbolic links (default)
chmod - change file access permissions
Usage
chmod [-r] permissions filenames
r Change the permission on files that are in the subdirectories of the directory that you are currently in. permission Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha numeric format.filenames File or directory that you are associating the rights with Permissions
u - User who owns the file.
g - Group that owns the file.
o - Other.
a - All.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.
Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody

Basic Linux Commands

mkdir - make directories
Usage
mkdir [OPTION] DIRECTORY
Options
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, mode=MODE set permission mode (as in chmod), not rwxrwxrwx - umask
-p, parents no error if existing, make parent directories as needed
-v, verbose print a message for each created directory
-help display this help and exit
-version output version information and exit
cd - change directories
Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.
mv- change the name of a directory
Type mv followed by the current name of a directory and the new name of the directory.
Ex: mv testdir newnamedir
pwd - print working directory
will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page
rmdir - Remove an existing directory
rm -r
Removes directories and files within the directories recursively.