Your Ad Here
Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, March 17, 2011

Restrict/Limit Users using (/etc/security/)

User limitations are set in the following files:
  • File: /etc/security/limits.conf :
    • core - limits the core file size (KB)
    • data - max data size (KB)
    • fsize - maximum filesize (KB)
    • memlock - max locked-in-memory address space (KB)
    • nofile - max number of open files
    • rss - max resident set size (KB)
    • stack - max stack size (KB)
    • cpu - max CPU time (MIN)
    • nproc - max number of processes
    • as - address space limit
    • maxlogins - max number of logins for this user
    • priority - the priority to run user process with
    • locks - max number of file locks the user can hold
    •  
  • File: /etc/security/access.conf : 
    Limit access by network or local console logins.

  • File: /etc/security/group.conf : 
    Grant/restrict group device access. 

 
  • File: /etc/security/time.conf : 
    Restrict user access by time, day.

System Monitor Commands

Basic command line:
pstreeProcesses and parent-child relationships
topShow top processes
iostatReport CPU statistics and input/output statistics for devices and partitions.
ps -auxwprocess status
uname -aprint system information
cat /proc/versionDisplay Linux kernel version in use.
cat /etc/redhat-releaseDisplay Red Hat Linux Release. (also /etc/issue)
uptimeTell how long the system has been running. Also number of users and system's load average.
wShow who is logged on and what they are doing.
/sbin/lsmodList all currently loaded kernel modules.
Same as cat /proc/modules
/sbin/runlevelDisplays the system's current runlevel.
hostnameDisplays/changes the system's node name. (Must also manually change hostname setting in /etc/sysconfig/network. Command will change entry in /etc/hosts)
serviceRed Hat/Fedora command to display status of system services.
Example: service --status-all
Help: service --help
GUI/Graphical:
gnome-system-monitorOperating system monitor and usage graphing.
gkrellmGraphical system monitor. (Additional RPM package: gkrellm)
ps33D load meter. Very cool 3-D graphics.
xosviewOperating system monitor: load, memory, swap, net, disk, ...
List of tools:

Monday, March 14, 2011

Activating a VG when quorum is lost

Normally, volume groups are automatically activated during system startup. Unless you intentionally deactivate a volume group using vgchange, you will probably not need to reactivate a volume group.
However, LVM does require that a "quorum" of disks in a volume group be available. During normal system operation, LVM needs a quorum of more than half of the disks in a volume group for activation. If, during run time, a disk fails and causes quorum to be lost, LVM alerts you with a message to the console, but keeps the volume group active.

If there is no other way to make a quorum available, the -q option to the vgchange command will override the quorum check.

EXAMPLE:
vgchange -a y -q n /dev/vg01

 When you replace a disk that was not online when you originally activated the volume group, use the activation command again to attach the now accessible disks to the volume group.

EXAMPLE:
vgchange -a y /dev/vg01

Friday, January 28, 2011

Reinstall GRUB using Ubuntu 9.10 livecd or higher

Here assuming the Ubuntu partition is sda7,and /boot partition is sda6 (if you have a separate /boot partition).
Boot up ubuntu from the livecd,open terminal and run:

sudo -i
mount /dev/sda7 /mnt
mount /dev/sda6 /mnt/boot  #skip this one if not have a separate /boot partition
grub-install --root-directory=/mnt/ /dev/sda


If you miss “grub.cfg” file,use following to recreate:

mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
chroot /mnt update-grub
umount /mnt/sys
umount /mnt/dev
umount /mnt/proc
exit

Sunday, December 5, 2010

Changing Hostname on RHEL

1. Change the ^HOSTNAME line in /etc/sysconfig/network

2. Change the hostname (FQDN and alias) in /etc/hosts

3. Run /bin/hostname new_hostname for the hostname change to take effect immediately.

4. Run /sbin/service syslog restart for syslog to log using the new hostname.

A reboot is not required to change the system hostname.

Thursday, December 2, 2010

Understanding /proc/cpuinfo

 Example:

$ uname -r
2.6.18-8.el5

How many physical processors are there?

$ grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l
2

How many virtual processors are there?

$ grep ^processor /proc/cpuinfo | wc -l
4

Are the processors dual-core (or multi-core)?

$ grep 'cpu cores' /proc/cpuinfo
cpu cores       : 2
cpu cores       : 2
cpu cores       : 2
cpu cores       : 2

"2" indicates the two physical processors are dual-core, resulting in 4 virtual processors.

If "1" was returned, the two physical processors are single-core. If the processors are single-core, and the number of virtual processors is greater than the number of physical processors, the CPUs are using hyper-threading. Hyper-threading is supported if ht is present in the CPU flags and you are using an SMP kernel.

Are the processors 64-bit?

A 64-bit processor will have lm ("long mode") in the flags section of cpuinfo. A 32-bit processor will not.

flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8legacy ts fid vid ttp tm stc

Friday, November 26, 2010

How can I create a disk partition on a disk that is greater than 2TB in size?

  • The fdisk command only supports the legacy MBR partition table format (also known as msdos partition table)
    • MBR partition table do not support disks greater than 2.1TB, and therefore fdisk is also unable to create partition tables on these devices.
    • Note that some older versions of fdisk may permit a larger size to be created but the resulting partition table will be invalid.
  • The parted command can create disk labels using MBR (msdos), GUID Partition Table (GPT), SUN disk labels and many more types.
    • The GPT disk label overcomes many of the limitations of the DOS MBR including restrictions on the size of the disk, the size of any one partition and the overall number of partitions.
    • Note that booting from a GPT labelled volume requires firmware support and this is not commonly available on non-EFI platforms (including x86 and x86_64 architectures).

    Procedure:
  • Use the parted tool to access the partition table of the device:
    # parted /dev/sdj
    Using /dev/sdj
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted)
    
    
  • Once at the parted prompt, create a GPT label on the disk:
    (parted) mklabel
    Warning: The existing disk label on /dev/sdj will be destroyed and all data on this disk will be lost. Do you want to continue?
    Yes/No? Yes                                                                 
    New disk label type?  [gpt]? gpt                                          
    (parted)
    Note: This will remove any existing partition table and partitions on the device.
  • Use the print command to show the size of the disk as reported by parted.  We need this later:
    (parted) print                                                            
    
    Model: Linux device-mapper (dm)
    Disk /dev/sdj: 5662310.4MB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
    Number  Start  End  Size  File system  Name  Flags
    
    
  • Create a primary partition on the device.  In this example, the partition will encompass the entire disk (using size from the step above):
    (parted) mkpart primary 0 5662310.4MB
    
    
  • Unlike fdisk, you do not have to write out the partition table changes with parted.  Display your new partition and quit.
    (parted) print
    
    Model: Linux device-mapper (dm)
    Disk /dev/mapper/VolGroup00-gpttest: 5662310.4MB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
    Number  Start   End          Size         File system  Name     Flags
     1      17.4kB  5662310.4MB  5662310.4MB               primary       
    
    (parted) quit                                                             
    Information: Don't forget to update /etc/fstab, if necessary.
    
    
  • You can now create a filesystem on the device /dev/sdj1

Tuesday, April 13, 2010

View System Logs Live

If you want to monitor the system logs in a live environment, you can use the tail command with an option -f or -F.
This will work in any Linux/UNIX environment.
To exit from the view, you can use Ctrl + C. The same option can be used with any text based files to find the updation to the file in live environment.

Usage:

# tail -f /var/log/messages

or

# tail -F /var/adm/messages


tail -f will work as long as the underlying file we’re trying to read doesn’t change. If you’re trying to read a link to a file and the original file (and thus the link) changes, tail -f will not work.

For that reason, its better to use tail -F for such files as described above … or tail -f –retry

Run Levels of various Operating Systems

The term runlevel refers to a mode of operation in one of the computer operating systems that implement Unix System V-style initialization. Conventionally, seven runlevels exist, numbered from zero to six; though up to ten, from zero to nine, may be used. S is sometimes used as a synonym for one of the levels.




In standard practice, when a computer enters runlevel zero, it halts, and when it enters runlevel six, it reboots. The intermediate runlevels (1-5) differ in terms of which drives are mounted, and which network services are started. Lower run levels are useful for maintenance or emergency repairs, since they usually don’t offer any network services at all. The particular details of runlevel configuration differ widely among operating systems, and slightly among system administrators.



The runlevel system replaced the traditional /etc/rc script used in Version 7 Unix.



Run Levels in Solaris

S, s

Single user mode. Doesn’t require properly formated /etc/inittab. Filesystems required for basic system operation are mounted.



0

Go into firmware (sparc)



1

System Administrator mode. All local filesystems are mounted. Small set of essential system processes are running. Also a single user mode.



2

Put the system in multi-user mode. All multi-user environment terminal processes and daemons are spawned.



3

Extend multi-user mode by making local resources available over the network.



4

Is available to be defined as an alternative multi-user environment configuration. It is not necessary for system operation and is usually not used.



5

Shut the machine down so that it is safe to remove the power. Have the machine remove power, if possible.



6

Reboot



a, b, c

Process only those /etc/inittab entries having the a, b, or c run level set. These are pseudo-states, which may be defined to run certain commands, but which do not cause the current run level to change.



Q, q

Re-examine /etc/inittab.



Run Levels in HP-UX

0

System is completely shut down. All processes are terminated and all file systems are unmounted.



1,s,S

Single-user mode. All system services and daemons are terminated and all file systems are unmounted.



2

Multi-user mode, except NFS is not enabled.



3

Multi-user mode. This is the normal operational default state. NFS is enabled.



4

Multi-user mode with NFS and VUE. (VUE is HP’s desktop, kinda like CDE)



6

Reboot.



Run Levels in OpenBSD

-1

Permanently insecure mode – always run system in level 0 mode.



0

Insecure mode – immutable and append-only flags may be changed. All devices may be read or written subject to their permissions.



1

Secure mode – system immutable and append-only flags may not be turned off; disks for mounted filesystems, /dev/mem, and /dev/kmem are read-only.



2

Highly secure mode – same as secure mode, plus disks are always read-only whether mounted or not and the settimeofday(2) system call can only advance the time.



Run Levels in ULTRIX, Digital UNIX / Tru64

0

System is completely shut down. All processes are terminated and all file systems are unmounted.



1

Single-user mode. All system services and daemons are terminated and all file systems are unmounted.



2

Multi-user mode, except NFS is not enabled.



3

Multi-user mode. This is the normal operational default state. NFS is enabled.



4

Not Used



5

Not Used



6

Reboot



Run Levels in Irix

0

Shut the machine down so it is safe to remove the power. Have the machine remove power if it can.



1

Put the system into system administrator mode. All filesystems are mounted. Only a small set of essential kernel processes run. This mode is for administrative tasks such as installing optional utilities packages. All files are accessible and no users are logged in on the system.



2

Put the system into multi-user state. All multi-user environment terminal processes and daemons are spawned. Default.



3

Start the remote file sharing processes and daemons. Mount and advertise remote resources. Run level 3 extends multi-user mode and is known as the remote-file-sharing state.



4

Define a configuration for an alternative multi-user environment. This state is not necessary for normal system operations; it is usually not used.



5

Stop the IRIX system and enter firmware mode.



6
Stop the IRIX system and reboot to the state defined by the initdefault entry in inittab.



a,b,c

Process only those inittab entries for which the run level is set to a, b, or c. These are pseudo-states that can be defined to run certain commands but do not cause the current run level to change.



Q,q

Re-examine inittab.



S,s

Enter single-user mode. When the system changes to this state as the result of a command, the terminal from which the command was executed becomes the system console.



Run Levels in SYSV

The following is from a SYSV text book, it’s the generally used run level for SYSV systems.



0

Power-down state. Shuts machine down gracefully so that it can be turned off. Some models turn off automatically.



s

Single user state. This run level should be used when installing or removing software utilities, checking file systems, or using Maintenance (/install) file system. It is similar to run level 1; however, in run level s, multi-user file systems are unmounted and daemons are stopped. The terminal issuing the init s becomes the console.



1

Administrative state. In run level 1, file systems required for multi-user operations are mounted. And loggias requiring access to multi-user file systems can be used.



2

Multi-user state. File systems are mounted and normal user services are started.



3

Network File System (NFS) state. Prepares your system to use NFS.



4

User-defined



5

Virtually the same as System State 6. See /sbin/rc0 script for details. Early versions of UNIX used this as an entry to a firmware interface.



6

Power-down and reboot to the state defined by the initdefault entry in the /etc/inittab file.



Run Levels in Linux

0

Halt the system.



1

Single-user mode.



2-4

Multi-user modes. Usually identical. Level 2 or 3 is default (dependent on distro).



5

Multi-user with graphical environment. This applies to most (but not all) distros.



6

Reboot the system and return to default run level.

Thursday, April 8, 2010

Manage a Linux RAID 10 Storage Server

Linux Software RAID10

Creating RAID Arrays in Linux during installation is an easy task (using the disk druid or any such graphical installers).  it's best to keep your root filesystem out of both RAID and LVM for easier management and recovery.



Linux RAID and Hardware

 

I've seen a lot of confusion about Linux RAID, so let's clear that up. Linux software RAID has nothing to do with hardware RAID controllers. You don't need an add-on controller, and you don't need the onboard controllers that come on most motherboards. In fact, the lower-end PCI controllers and virtually all the onboard controllers are not true hardware controllers at all, but software-assisted, or fake RAID. There is no advantage to using these, and many disadvantages. If you have these, make sure they are disabled.
Ordinary PC motherboards support up to six SATA drives, and PCI SATA controllers provide an easy way to add more. Don't forget to scale up your power and cooling as you add drives.
If you're using PATA disks, only use one per IDE controller. If you have both a master/slave on a single IDE controller, performance will suffer and any failure risks bringing down both the controller and the second disk.

 

GRUB Follies

 

GRUB Legacy's (v. 0.9x) lack of support for RAID is why we have to jump through hoops just to boot the darned thing. Beware your Linux's default boot configuration, because GRUB must be installed to the MBRs of at least the first two drives in your RAID1 array, assuming you want it to boot when there is a drive failure. Most likely your Linux installer only installs it to the MBR of the drive that is first in the BIOS order, so you'll need to manually install it on a secondary disk.
First open the GRUB command shell. This example installs it to /dev/sdb, which GRUB sees as hd1 because it is the second disk on the system:


root@uberpc ~# grub
GNU GRUB version 0.97 (640K lower / 3072K upper memory)

Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename.

grub> root (hd1,0)
Filesystem type is ext2fs, partition type 0xfd

grub> setup (hd1)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd1)"... 17 sectors are embedded. succeeded
Running "install /boot/grub/stage1 (hd1) (hd1)1+17 p (hd1,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done. 


You can do this to every disk in your RAID 1 array. /boot/grub/menu.lst should have a default entry that looks like something like this:

title Ubuntu 7.10, kernel 2.6.22-14-generic, default root (hd0,0)
kernel /boot/vmlinuz-2.6.22-14-generic root=/dev/md0 ro
initrd /boot/initrd.img-2.6.22-14-generic 


Let's say hd0,0 is really /dev/sda1. If this disk fails, the next drive in line becomes hd0,0, so you only need this single default entry.
GRUB sees PATA drives first, SATA drives second. Let's say you have two PATA disks and two SATA disks:

/dev/hda
/dev/hdb
/dev/sda
/dev/sdb


GRUB numbers them this way:

hd0
hd1
hd2
hd3

If you have one of each, /dev/hda=hd0, and /dev/sda=hd1. The safe way to test your boot setup is to power off your system and disconnect your drives one at a time.

 

Managing Linux RAID With mdadm

 

There are still a lot of howtos on the Web that teach the old md command and raidtab file. Don't use these. They still work, but the mdadm command does more and is easier.

 

Creating and Testing New Arrays

 

Use this command to create a new array:


# mdadm -v --create /dev/md1 --level=raid10 --raid-devices=2 /dev/hda2 /dev/sda2

You may want to have a hot spare. This is a partitioned, formatted hard disk that is connected but unused until an active drive fails, then mdadm (if it is running in daemon mode, see the Monitoring section) automatically replaces the failed drive with the hot spare. This example includes one hot spare:


# mdadm -v --create /dev/md1 --level=raid10 --raid-devices=2 /dev/hda2 /dev/sda2 --hot-spares=1 /dev/sdb2

 
You can test this by "failing" and removing a partition manually:


# mdadm /dev/md1 --fail /dev/sda2 --remove /dev/sda2

 
Then run some querying commands to see what happens.
When you have more than one array, they can share a hot spare. You should have some lines in /etc/mdadm.conf that list your arrays. All you do is create a share group by adding lines as shown in bold:
 

ARRAY /dev/md0 level=raid1 num-devices=2 UUID=004e8ffd:05c50a71:a20c924c:166190b6
shared-group=share1
ARRAY /dev/md1 level=raid10 num-devices=2 UUID=38480e56:71173beb:2e3a9d03:2fa3175d
shared-group=share1


View the status of all RAID arrays on the system:
 

$ cat /proc/mdstat
Personalities : 'linear' 'multipath' 'raid0' 'raid1' 'raid6' 'raid5' 'raid4' 'raid10'
md1 : active raid10 hda2'0' sda2'1'
6201024 blocks 2 near-copies '2/2' 'UU'

md0 : active raid1 hda1'0' sda1'1'
3076352 blocks '2/2' 'UU'

The "personalities" line tells you what RAID levels the kernel supports. In this example you see two separate arrays: md1 and md0, that are both active, their names and BIOS order, and the size and RAID type of each one. 2/2 means two of two devices are in use, and UU means two up devices.

You can get detailed information on individual arrays:


# mdadm --detail /dev/md0
Is this partition part of a RAID array? This displays the contents of the md superblock, which marks it as a member of a RAID array:

# mdadm --examine /dev/hda1
You can also use wildcards, like mdadm --examine /dev/hda*.

 

Monitoring

 

mdadm itself can run in daemon mode and send you email when an active disk fails, when a spare fails, or when it detects a degraded array. Degraded means a new array that has not yet been populated with all of its disks, or an array with a failed disk:
 
# mdadm --monitor --scan --mail=shiroy.p@hcl.in --delay=2400 /dev/md0

Your distribution may start the mdadm daemon automatically, so you won't need to run this command. Kubuntu controls it with /etc/init.d/mdadm, /etc/default/mdadm, and /etc/mdadm/mdadm.conf, so all you need to do is add your email address to /etc/mdadm/mdadm.conf.

 

Starting, Stopping, and Deleting RAID

 

Your Linux distribution should start your arrays automatically at boot, and mdadm starts them at creation. 
This command starts an array manually:

 # mdadm -A /dev/md0

This command stops it:

# mdadm --stop /dev/md0

You'll need to unmount all filesystems on the array before you can stop it.
To remove devices from an array, they must first be failed. You can fail a healthy device manually:

# mdadm /dev/md1 --fail /dev/sda2 --remove /dev/sda2

If you're removing a healthy device and want to use it for something else, or just want to wipe everything out and start over, you have to zero out the superblock on each device or it will continue to think it belongs to a RAID array:

# mdadm --zero-superblock /dev/sda2

Adding Devices

You can add disks to a live array with this command:

# mdadm /dev/md1 --add /dev/scd2

This will take some time to rebuild, just like when you create a new array.
That wraps up ourtour of RAID 10 and mdadm.

 

Resources

 

     
Visit my BLOG

andLinux, an opposite of WINE

andLinux is a complete Ubuntu Linux system running seamlessly in Windows 2000 based systems (2000, XP, 2003, Vista, 7; 32-bit versions only). This project was started for Dynamism for the GP2X community, but its userbase far exceeds its original design. andLinux is free and will remain so, but donations are greatly needed.
andLinux uses coLinux as its core which is confusing for many people. coLinux is a port of the Linux kernel to Windows. Although this technology is a bit like running Linux in a virtual machine, coLinux differs itself by being more of a merger of Windows and the Linux kernel and not an emulated PC, making it more efficient. Xming is used as X server and PulseAudio as sound server.
andLinux is not just for development and runs almost all Linux applications without modification.



To start Linux applications, you may either use the XFCE Panel:


Or, you may choose to use the andLinux Launcher, which ships with andLinux since Beta 1. It consists of:
  • quicklaunch icons (e.g. for the file manager or the terminal)
  • a start menu in the system tray (next to the clock) which can be adapted to your own needs
  • so-called Explorer shell extensions, i.e. context menu item, with which you can open a folder in the file manager / terminal or open a file with the text editor
  • file type associations at your choice (e.g. for KOffice files, .tex / .dvi / .ps / .pdf files)
  • andCmd.exe to run linux commands from Windows scripts 
Download:

andLinux Beta 2 (final)

KDE version, 537 MB:
  • SourceForge.net [http]
  • md5: 3bbe8a0ae67e189ef9ff787d6d184b64
  • sha1: 5f411810553d4472cf6f1c36f75bd732c90f84d7
minimal / XFCE version, 200 MB:
  • SourceForge.net [http]
  • md5: 4ec330df10af572274ec3b83d45d0ea7
  • sha1: ca21f1c917d44574ec13525da457bf6bf4d9405e
Note: You need to run the installer with administrator privileges.

Security warning: It is recommended to use andLinux only on single-user-PCs or in a trustworthy environment because the communication with the X-Server and the launcher is not secured, i.e., every user who can login to Windows can access andLinux.

Tuesday, March 30, 2010

How can I create a disk partition on a disk that is greater than 2TB in size?

  • The fdisk command only supports the legacy MBR partition table format (also known as msdos partition table)
    • MBR partition table do not support disks greater than 2.1TB, and therefore fdisk is also unable to create partition tables on these devices.
    • Note that some older versions of fdisk may permit a larger size to be created but the resulting partition table will be invalid.
  • The parted command can create disk labels using MBR (msdos), GUID Partition Table (GPT), SUN disk labels and many more types.
    • The GPT disk label overcomes many of the limitations of the DOS MBR including restrictions on the size of the disk, the size of any one partition and the overall number of partitions.
    • Note that booting from a GPT labelled volume requires firmware support and this is not commonly available on non-EFI platforms (including x86 and x86_64 architectures).

    Procedure:
  • Use the parted tool to access the partition table of the device:
    # parted /dev/sdj
    Using /dev/sdj
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted)
    
    
  • Once at the parted prompt, create a GPT label on the disk:
    (parted) mklabel
    Warning: The existing disk label on /dev/sdj will be destroyed and all data on this disk will be lost. Do you want to continue?
    Yes/No? Yes                                                                 
    New disk label type?  [gpt]? gpt                                          
    (parted)
    Note: This will remove any existing partition table and partitions on the device.
  • Use the print command to show the size of the disk as reported by parted.  We need this later:
    (parted) print                                                            
    
    Model: Linux device-mapper (dm)
    Disk /dev/sdj: 5662310.4MB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
    Number  Start  End  Size  File system  Name  Flags
    
    
  • Create a primary partition on the device.  In this example, the partition will encompass the entire disk (using size from the step above):
    (parted) mkpart primary 0 5662310.4MB
    
    
  • Unlike fdisk, you do not have to write out the partition table changes with parted.  Display your new partition and quit.
    (parted) print
    
    Model: Linux device-mapper (dm)
    Disk /dev/mapper/VolGroup00-gpttest: 5662310.4MB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
    Number  Start   End          Size         File system  Name     Flags
     1      17.4kB  5662310.4MB  5662310.4MB               primary       
    
    (parted) quit                                                             
    Information: Don't forget to update /etc/fstab, if necessary.
    
    
  • You can now create a filesystem on the device /dev/sdj1

Tuesday, March 9, 2010

View Config Files Without Comments

I've been using this grep invocation to trim comments out of config files.Comments are useful, but when you want to just get the active configuration entries alone from a long file ( may be of 1000 lines where the config entries will be around 50 lines only ), use the below technique.

$ grep ^[^#] /etc/httpd/conf/httpd.conf

The regex ^[^#] matches the first character of any line, as long as that character that is not a #. Because blank lines don't have a first character they're not matched either, resulting in a nice compact output of just the active configuration lines.

Monday, March 8, 2010

Setup Your Linux Server to Use a Serial Console

Do you have a linux server without a keyboard or monitor? Need to administer the server on-site but don't want to lug over a monitor and keyboard (or kvm)? Then setup the server to output the console to a serial port and use screen/minicom (Hyperterminal or putty in Windows) to console into the server over a serial cable.

To set this up, you need to edit /etc/inittab to tell it to start a terminal on the serial port for the console. If you want to see the kernel load and see all the services start then you also need to configure grub to use the serial port as well.

Edit /etc/inittab and add the line starting with "co" to the file (substitute the device name of your serial port for ttyS0 below):

co:2345:respawn:/sbin/agetty ttyS0 9600 vt100-nav # ADD THIS LINE
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6


To watch the kernel load (and all the services) you must configure grub to enable the console option in the kernel on boot. Edit /boot/grub.conf and add the "serial" and "terminal" lines below, and modify the "kernel" line to include the console specification:

serial --unit=0 --speed=9600
terminal --timeout=5 serial console
title CentOS (2.6.9-55.0.2.EL)
root (hd1,0)
kernel /vmlinuz-2.6.9-55.0.2.EL ro root=/dev/VolGroup00/LogVol00 console=ttyS0,9600n8
initrd /initrd-2.6.9-55.0.2.EL.img


To connect to the server just hook a serial cable from your laptop to the server. Set the speed to 9600, no parity and 8bits. Boot up the server, you should see kernel output, services load, and finally a login prompt. After you disconnect you can easily re-connect and log in: just fire up your terminal emulator, connect your serial cable, hit enter a few times and you should get a prompt to log in.