How Do I: A Linux Q&A

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 02:30, 13 September 2007 by Admin (Talk | contribs)

Jump to: navigation, search

HOW DO I?

Answers to common Linux configuration and end user modification

index: how do i...

[LOGIN SWITCHING]


Switch between boot to graphical xwindows login or standard text login

Edit the /etc/inittab file and look for "Default runlevel". Runlevel values differ from one distribution to another.

Set to TEXT Multiuser Boot Login (for Redhat):

id:3:initdefault:

Set to GRAPHIC X11 Boot Login (for Redhat):

id:5:initdefault:


[RESTRICT ROOT LOGIN LOCATIONS]


(see RootAccess.html for more information)

An empty /etc/securetty file prevents root login on any devices attached to the computer.

Edit the /etc/ssh/sshd_config file and set the PermitRootLogin parameter to no.


[PREVENT CONSOLE MONITOR BLANK]


This is like sleep mode, the monitor screen goes blank after a period of inactivity until a key press.

Modify the .bash_profile in your home directory.

echo "setterm -blank 0" >> .bash_profile


[MODIFY DEFAULT COMMAND KEYWORDS AND VALUES]


For example, you can stop nslookup from complaining about deprecation by using the -sil switch. To make it automatically assume the -sil switch simply modify your .bashrc file for your shell.

vi /home/username/.bashrc

add the following:

alias nslookup='nslookup -sil'


[MORE BASH COMMAND ALIASING]


Open the .bashrc file

vi .bashrc

Add the following (these are example aliases):

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias last='last -a'
alias nslookup='nslookup -sil'
alias ftp='ftp -i'


[CHANGE BASH CUSTOM PROMPT]


he appearance of the prompt is governed by the shell variable PS1. The default prompt is customized on many linux distributions. It is sometimes customized differently for root and regular users.

Redhat Linux default prompt:  PS1='[\u@\h \W]\$ '
Trustix Linux default prompt:  PS1='\u@\h \w\$ '

To see how the current prompt is set

echo $PS1

Set prompt style on login, edit .bash_profile (or equivalent) example:

PS1='root@\h \w\$ '
export PS1
 
  • PS1 - The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is \s-\v\$ .
  • PS2 - The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is >
  • PS3 - The value of this parameter is used as the prompt for the select command
  • PS4 - The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +



[CONFIGURE SYSLOG TO LOG TO A REMOTE HOST]


1.) Setting up a remote log server is not covered. To make syslog spool the logs to a remote host edit /etc/syslog.conf and add the following line at the bottom after everything else:

*.*				@10.10.1.1

Where 10.10.1.1 is the IP address of the remote log server.

2.) Setting up syslog on the remote log server. With the log server, (the machine accepting all of the remote logs), all you have to do is launch syslogd with the -r switch, specifying remote logging capabilities. Make sure that you remember to ADD: syslog 514/udp to the /etc/services file as well, on the server, or it will not listen to the specified port.

Now we have to configure our server to accept those connections on port 514, so we do that by editing /etc/rc2.d/S10syslogd and we change the SYSLOGD="" line to the following:

SYSLOGD="-rm 0"

In the above line, the r tell syslogd there will be clients connecting to it, and that it should accept them, the m 0 signifies we don't want to see - MARK - entries in the logs that our server records.


[GET DNS WORKING USING resolv.conf, hosts, and hosts.conf FILES]


Often your computer's hostname and/or host and domain name do not really exist on the Internet. Your linux workstation has to be able to determine its own host and domain name, real or not, for applications and services to run correctly.

To use both a local hosts file and an external name server, /etc/host.conf should read

order hosts, bind
multi on

That will cause the system to look in /etc/hosts first, and if it can't resolve the IP, then it checks /etc/resolv.conf for a nameserver address.

In resolv.conf, you only need the the following:

domain yourdomain.com
nameserver 192.168.1.1

Replace the IP with a valid DNS server IP address. An example hosts file needs only have the following:

127.0.0.1	myboxen		localhost.localdomain   localhost
24.208.79.172			myboxen.foo.com		myboxen

[TURN ON AND OFF PC SPEAKER BEEP IN CONSOLE AND X]


In Xfree you can turn the PC-speaker bell on and off with the xset commands option b, type:

xset b off

To turn off the pc speaker on console mode use setterm with the argument blength, type:

setterm -blength 0


[SUPRESS diskcheck WARNING MESSAGES FOR SPECIFIC PARTITIONS ONLY]


diskcheck is a cron script in /etc/cron.daily on Redhat. Although it is merely a shell script, it has a configuration file /etc/diskcheck.conf Modify the 'exclude' line to prevent diskcheck from looking at specific mounted file system partitions. (redhat lists the following parameters):

  • defaultCutoff - disk drives reach this percent capacity, it

will be reported. For example, if defaultCutoff = 90, an email will be sent when the monitored disk drives reach 90% capacity.

  • cutoff[/dev/partition] - Override the defaultCutoff for the

partition. For example, if cutoff['/dev/hda3'] = 50 is specified, diskcheck will alert the system administrator when the partition /dev/hda3 reaches 50% capacity.

  • cutoff[/mountpoint] - Override the defaultCutoff for the mount

point. For example, if cutoff['/home'] = 50 is specified, diskcheck will alert the system administrator when the mount point /home reaches 50% capacity.

  • exclude - Specify one or more partitions for diskcheck to ignore.

For example, if exclude = "/dev/sda2 /dev/sda4" is specified, diskcheck will not alert the system administrator if /dev/sda2 or /dev/sda4 reaches the specified cutoff percentage.

  • ignore - Specify one or more file system types to ignore in the

format -x filesystem-type. For example, if ignore = "-x nfs -x iso9660" is specified, the system administrator will not be alerted about nfs or iso9660 file systems reaching capacity.

  • mailTo - Email address of the system administrator to alert when

partitions and mount points reach the specified capacity. For example, if mailTo = "webmaster@example.com" is specified, webmaster@example.com will be emailed alerts.

  • mailFrom - Specify the identity of the email sender. This is useful

if the system administrator wants to filter the mail from diskcheck. For example, if mailFrom = "Disk Usage Monitor" is specified, email will be sent to the system administrator with the sender Disk Usage Monitor.

  • mailProg - Specify the mail program to use to send email alerts. For

example, if mailProg = "/usr/sbin/sendmail" is specified, Sendmail will be used as the mail program.


[DISABLE ANNOYING KDE Autorun WHEN CDROM IS IN DRIVE WHEN KDE STARTS]


Auto-run support is controlled in KDE by the Autorun.desktop module, which is automatically started when you start KDE by virtue of its being in the ~/.kde/Autostart folder.

If you want to disable autorun (but not automount; there's a difference), then just remove this item from the folder (you can copy it to another folder, like your Desktop or something in case you ever want to re-enable it). Just keep in mind that this will most likely disable autorun of data CDs as well.

If you want to CHANGE the default cd player, then right-click on the item, and pick Properies. Select the Execute tab, and look for the "--cdplayer=/usr/bin/kscd" part.

It is also possible to edit the line:

Exec=/usr/bin/autorun -l --interval=1000 --cdplayer=/usr/bin/kscd


[DISPLAY VOLUME LABEL ON MOUNTED CDROM DISC]


There is a small utility called volname included with recent versions of the eject program. Alternatively you can run this shell command:

dd if=/dev/cdrom bs=1 skip=32808 count=32 

assuming /dev/cdrom is the device file name for your drive.


[FORMAT FLOPPY]


Insert the floppy and do not mount it. If mounted, type

umount /dev/fd0

-> Format Floppy (Redhat):

bash$ fdformat /dev/fd0

-> Format Floppy (other):

floppy --format /dev/fd0


[FORMAT PARTITION TO FAT32]


Format the first partition of drive c to be FAT 32, example:

mkfs.vfat -F 32 /dev/hdc1


[DOWNLOAD TO CONSOLE WITHOUT A BROWSER]


  • all the major distributions include the wget downloading tool.
 bash$ wget http://place.your.url/here
  • recursively mirror entire web-site directory trees
 bash$ wget -m http://target.web.site/subdirectory
  • follow only relative links and skip GIF images
 bash$ wget -m -L --reject=gif http://target.web.site/subdirectory
  • resume interrupted downloads if supported by the server.
 bash$ wget -c http://the.url.of/incomplete/file
  • retry the URL several times
 bash$ wget -t 5 http://place.your.url/here
  • schedule a download to take place later in the day using 'at'
   at 2300
   warning: commands will be executed using /bin/sh
   at> wget http://place.your.url/here
   at> press Ctrl-D 


[ENABLE IP FORWARDING]


To enable IP (IPv4) Forwarding in RedHat linux you need to activate it in the kernel. You can configure this to happen automatically or you can activate it on the fly.

To enable IP forwarding instantly:

 echo 1 > /proc/sys/net/ipv4/ip_forward

Placing that in the rc.local file will cause it to be executed during boot. Or you can set this up in the sysconfig network script. Edit /etc/sysconfig/network and change or add the following line:

 FORWARD_IPV4 = YES


[RESIZE WINXP NTFS PARTITION TO MAKE ROOM FOR LINUX]


  1. Download the SystemRescueCD ISO image (100 MB very useful softwares).
  2. Burn the ISO image to a CD.
  3. Boot from the CD.
  4. Enter run_qtparted when you get a command prompt.
  5. Select your disk on the graphical screen.
  6. Select your NTFS partition to be resized.
  7. Right click with the mouse and choose Resize.
  8. Set the new partition size.
  9. Commit your changes in the File -> Commit menu.

If your keyboard and mouse stop responding during resizing then please just be patient.

Reference: http://mlf.linux.rulez.org/mlf/ezaz/ntfsresize.html for more details.


[RESIZE LINUX PARTITION]


QTPARTED is a utility like Partition Magic. QPARTED is supposed to resize existing ext3 partitions. It wouldn't when I tried. Partition Magic versions seven and above or QPARTED may have problems with ext3. The solution, convert the partition file system type to ext2, resize it, then convert it back. for your ext3 journalling file system: You can use 'tune2fs' on linux to turn journaling off and make it basically ext2.

technical comments: Using a Linux bootable disk or cd the utilities are be sure to boot from a rescuse disk. Do not do it to a mounted drive (unless it is mounted read-only but that is still crazy)

WARNING! PARTED and QTPARTED are limited. Testing had determined that attempting to resize an ext2 or ext3 logical drive within an extended partition, or the extended partition itself cannot be accomplished with Partition Magic 7, or parted/qtparted (always or most of the time).

In theory if the partition is a primary in ext2, either parted or partition magic should be able to perform the resize operation.

  • ..convert to ext2:
 tune2fs -O ^has_journal /dev/hdaX
  • ..check the drive:
 fsck -f /dev/hdaX
  • ..resize the partition(s)
 run_qtparted (or reboot to your Partition Magic 7 or 8 disc)
  • ..convert back to ext3:
 tune2fs -j /dev/hdaX

troubleshooting: qtparted gives an error and refuses to resize the ext2 partition. (developing workaround) resize2fs doesn't resize a partition, just file system sitting on top. Fdisk can be used in a hazardous workaround along with resize2fs.

note: sources say qtparted doesn't support ext3, however, the qtparted supplied with "SystemRescueCD" (a great emergency boot disc) claims to support ext3.

Unfortunately, this documentation is sketchy on performing all types of partition resizing because it is not always possible to resize a partition, and as better tools are developed what is not possible today could be possible tomorrow. What is covered here experience provides.


[DETACH PROCESS FROM SHELL AND LEAVE RUNNNING AFTER SHELL CLOSED]


To keep a program running while not logged on, you need to use the prefix your command with the word nohup. You will need to run this command in the background.

for example:

 nohup grep 'director' emp.lst & | nohup sort &


[EMERGENCY BOOT RECOVER ROOT PASSWORD OR FIX MOUNTING ISSUE]


In an emergency you may have to recover from problems such as a lost root password, messed up fstab configuration, harddrive corruption, device driver or kernel error; all of which may prevent normal booting.

If you lost your root password, you may gain access to the system by booting into 'single user mode' from the system console (not remote).

For Lilo: at boot screen press 'tab' and type: 'linux single'. This will pass the parameter to the kernel booting linux into single user mode.

For Grub:

Your system might be messed up to the point it will not boot into single user mode. You may need to repair your fstab file, remove a kernel module, or some other boot parameter or perhaps you need to repair file system damage. To do this you may boot linux into emergency mode.

For Lilo:

For Grub:

Another way to boot lilo into an emergency mode

For Lilo: at boot screen press 'tab' and type: 'linux init=/bin/sh'

Now that you are booted into emergency mode you will note that your file system is mounted read-only. To get into a file such as /etc/fstab you will need write access. Remount the file system read-write.

Bash: type 'mount -n -oremount,rw /'

Notice root is / and the option is 'remount' or

mount -n -oremount,rw /

Now you have full read-write access to the filesystem. You may need to mount other partitions into /mnt or perform copy or restore operations. You can also chroot.

If your bootloader is messed up, you should boot from a boot floppy or cdrom. Suggested here is SystemRescueCd, a utility made with Gentoo, any Tiny Linux on floppy, or a Knoppix CD. Determine your root partition so you can rebuild your boot loader. Use 'fdisk -l'. You can make a /mnt/rootpart then to mount your root partition too and 'chroot /mnt/rootpart'