1. How do you take a single line of input from the user in a shell script?
2. Write a script to convert all DOS style backslashes to UNIX style slashes in a list of files.
3. Write a regular expression (or sed script) to replace all occurrences of the letter ‘f’, followed by any number of characters, followed by the letter ‘a’, followed by one or more numeric characters, followed by the letter ‘n’, and replace what’s found with the string “UNIX”.
4. Write a script to list all the differences between two directories.
5. Write a program in any language you choose, to reverse a file.
6. What are the fields of the password file?
7. What does a plus at the beginning of a line in the password file signify?
8. Using the man pages, find the correct ioctl to send console output to an arbitrary pty.
9. What is an MX record?
10. What is the prom command on a Sun that shows the SCSI devices?
11. What is the factory default SCSI target for /dev/sd0?
12. Where is that value controlled?
13. What happens to a child process that dies and has no parent process to wait for it and what’s bad about this?
14. What’s wrong with sendmail? What would you fix?
15. What command do you run to check file system consistency?
16. What’s wrong with running shutdown on a network?
17. What can be wrong with setuid scripts?
18. What value does spawn return?
19. Write a script to send mail from three other machines on the network to root at the machine you’re on. Use a ‘here doc’, but include in the mail message the name of the machine the mail is sent from and the disk utilization statistics on each machine?
20. Why can’t root just cd to someone’s home directory and run a program called a.out sitting there by typing “a.out”, and why is this good?
21. What is the difference between UDP and TCP?
22. What is DNS?
23. What does nslookup do?
24. How do you create a swapfile?
25. How would you check the route table on a workstation/server?
26. How do you find which ypmaster you are bound to?
27. How do you fix a problem where a printer will cutoff anything over 1MB?
28. What is the largest file system size in solaris? SunOS?
29. What are the different RAID levels?
30. Advantages/disadvantages of script vs compiled program.
31. Name a replacement for PHP/Perl/MySQL/Linux/Apache and show main differences.
32. Why have you choosen such a combination of products?
33. Differences between two last MySQL versions. Which one would you choose and when/why?
34. Main differences between Apache 1.x and 2.x. Why is 2.x not so popular? Which one would you choose and when/why?
35. Which Linux distros do you have experience with?
36. Which distro you prefer? Why?
37. Which tool would you use to update Debian / Slackware / RedHat / Mandrake / SuSE ?
38. You’re asked to write an Apache module. What would you do?
39. Which tool do you prefer for Apache log reports?
40. Your portfolio. (even a PHP guest book may work well)
41. What does ‘route’ command do?
42. Differences between ipchains and iptables.
43. What’s eth0, ppp0, wlan0, ttyS0, etc.
44. What are different directories in / for?
45. Partitioning scheme for new webserver. Why?
Unix/Linux administration interview questions
What is LILO?
LILO stands for Linux boot loader. It will load the MBR, master boot record, into the memory, and tell the system which partition and hard drive to boot from.
What is the main advantage of creating links to a file instead of copies of the file?
A: The main advantage is not really that it saves disk space (though it does that too) but, rather, that a change of permissions on the file is applied to all the link access points. The link will show permissions of lrwxrwxrwx but that is for the link itself and not the access to the file to which the link points. Thus if you want to change the permissions for a command, such as su, you only have to do it on the original. With copies you have to find all of the copies and change permission on each of the copies.
Write a command to find all of the files which have been accessed within the last 30 days.
find / -type f -atime -30 > December.files
This command will find all the files under root, which is ‘/’, with file type is file. ‘-atime -30′ will give all the files accessed less than 30 days ago. And the output will put into a file call December.files.
What is the most graceful way to get to run level single user mode?
A: The most graceful way is to use the command init s.
If you want to shut everything down before going to single user mode then do init 0 first and from the ok prompt do a boot -s.
What does the following command line produce? Explain each aspect of this line.
$ (date ; ps -ef | awk ‘{print $1}’ | sort | uniq | wc -l ) >> Activity.log
A: First let’s dissect the line: The date gives the date and time as the first command of the line, this is followed by the a list of all running processes in long form with UIDs listed first, this is the ps -ef. These are fed into the awk which filters out all but the UIDs; these UIDs are piped into sort for no discernible reason and then onto uniq (now we see the reason for the sort - uniq only works on sorted data - if the list is A, B, A, then A, B, A will be the output of uniq, but if it’s A, A, B then A, B is the output) which produces only one copy of each UID.
These UIDs are fed into wc -l which counts the lines - in this case the number of distinct UIDs running processes on the system. Finally the results of these two commands, the date and the wc -l, are appended to the file “Activity.log”. Now to answer the question as to what this command line produces. This writes the date and time into the file Activity.log together with the number of distinct users who have processes running on the system at that time. If the file already exists, then these items are appended to the file, otherwise the file is created.
Sunday, September 13, 2009
Linux admin interview questions
Monday, September 7, 2009
Mounting a Windows XP NTFS partition in Linux
How to access a Windows XP or Vista NTFS partition from Linux. The following tutorial explains how to gain access to a Windows NTFS partition using Linux. Reading or accessing NTFS partitions in Linux is important for many reasons. Some users repair Windows Operating environments using Linux, while others use a dual boot operating environment and would like to have access to their Windows File system.
The good news is that this is not a complicated task to accomplish. As a matter of fact, for those using a Linux version derived from Debian, (I.E. Ubuntu, Knoppix, etc…) the process can be accomplished in a matter of seconds.
How to Mount a Windows NTFS file system partition in Linux:
NOTE: In step four of the following tutorial, replace hdx1 with your actual partition found in step two. For example hda1, hdb2, sda1, etc.
- Open a terminal and type sudo su
- Type fdisk -l (note which partition contains the NTFS file system)
- Type mkdir /media/windows (This directory is where we will access the partition)
- Type mount /dev/hdx1 /media/windows/ -t ntfs -o nls=utf8,umask=0222
- Type cd /media/windows (Moves us to the windows directory)
- Type ls to list the files on the NTFS partition
Notes: Alternately, you can navigate to the media/windows directory outside of terminal to view the files.
To unmount the Windows NTFS partiton, from the terminal simply type umount /media/windows/
Wednesday, September 2, 2009
Small course Loadable Kernel Modules in linux Kernel 2.6
Loadable Kernel Modules in linux Kernel 2.6
Learning Objectives
- Discuss History of Loadable Kernel Modules (LKM).
- Describe advantages of Using LKMs
- Describe what LKMs can do.
- Discuss LKM Utilities
- Installing and removing
- Loadable Kernel Modules in Kernel 2.6
Reference
- Module-HOWTO
- /usr/share/doc/howto/en/html/Module-HOWTO
History of Loadable Module
- Loadable Kernel Modules did not exist in Linux in the beginning.
- Loadable Kernel Modules have been around at least since Linux1.2 (1995).
- Device drivers were always quite modular, and only small amount of work was needed to make them Loadable Kernel Module.
- Since about 2000 everything that make sense as an LKM had the option of being LKM.
Advantages of using LKMs
- Don’t have to rebuild Kernel Often
- Helps you diagnose system problem
- Saves Memory because only required modules will be loaded in the memory.
- Faster to maintain and debug.
- Gives same performance as Kernel built-in code.
What LKMs can Do
- Device drivers
- File System Drivers
- System Calls
- Network Drivers
- TTY line disciplines
- Executable interpreters
Building Kernel Modules
- Loadable Kernel Modules are also know as Kernel Modules.
- After building the Kernel image issue following commands: make modules Above command compiles the source code and creates module object files
- Then issue the following commandsmake modules_installAbove command will copy all modules over to the conventional locations
Loadable kernel Module Utilities
- insmod Insert an LKM into the kernel.
- rmmod Remove an LKM from the kernel.
- depmod Determine interdependencies between LKMs.
- lsmod List currently loaded LKMs.
- modinfo Display contents of .modinfo section in an LKM object file.
- modprobe Insert or remove an LKM or set of LKMs intelligently. For example, if load A before loading B, Modprobe will automatically load A when you tell it to load B.
Inserting kernel Modules
- Basic program for inserting LKMs is insmod.
- Try to load the modules “msdos” and “ntfs”.
- Try following commands to load the modules msdos, the path for module may change depending on your Kernel Version:
# cd /lib/modules/2.6.18-53el5/kernel/fs
# insmod msdos/msdos.ko
Listing the loaded modules
- Loaded modules may be listed by using the “lsmod” command.
- You may also get information about modules from “/proc/modules”cat /proc/modules
- You may also get information about “devices” and “interrupts” from “/proc/devices” and “/proc/interrupts”
Removing Modules
- Modules may be removed by using “rmmod” command.
- All these commands must be executed by superuser.
Using modprobe
- Using modprobe is a better way of loading modules. Modprobe checks dependencies and also loads the modules needed to support the module being loaded.
- Many modules such as some CDROM Drivers and Networks Drivers require certain parameters to be passed with the modules.
- The files “/etc/modprobe.conf”, “/etc/modprobe.conf.local” and the directory “/etc/modprobe.d” contains parameters for modules that directly access the hardware. As modprobe can use information from these files it is a better method to load modules.
- There are no standard module parameters, drivers may have their own set of parameters. To find out parameters of a driver read the documentation for that module in the directory “/usr/src/linux/documentation”.
Kmod – The Kernel Module Loader
- Kmod automates the process of loading Kernel Module.
- Kmod keeps on running in the background and automatically loads a kernel Module using “modprobe” whenever a desired feature is needed in the Kernel.
- Kmod does not unload the modules if not required in feature but with Amount of RAM available this is not a big issue.
Modules in Linux kernel 2.6
- The Linux 2.6 kernel introduces a new, unified framework for device drivers, which requires changes to custom device drivers developed to run under earlier versions of the Linux kernel.
- The new driver model provides a framework for full and complete support for
- device Plug and Play
- power management
- Defines the interfaces that these subsystems can use when communicating with individual drivers.
- The new driver framework provides a much cleaner separation of responsibilities between buses and drivers.
- The 2.6 Linux kernel also introduces the sysfs filesystem to provide a hierarchical view of each system's device tree (and to prevent further overloading of the proc filesystem).
- A new naming convention for loadable kernel modules, using the .ko extension (kernel object) rather than the standard .o (object) extension used in all previous stable releases of the Linux kernel.
Summary
- Kernel loadable module reduce the size of Kernel.
- It is easier to debug your system when using Kernel Modules.
- New drivers can be added to system without recompiling the Kernel.
- A set of utilities is available to manage Kernel Modules.