tips

All posts tagged tips

Renaming/moving files with suffixes quickly:

This expands to:





cd ESC.

 

——————-

Tuning the %packages section

When using %packages to define the set of packages that should be installed there are a number of more or less documented options that can be set:

–resolvedeps
Dependencies between packages will be automatically resolved. This option has been deprecated in Centos 5, dependencies are resolved automatically every time now.
–excludedocs

Skips the installation of files that are marked as documentation (all files that are listed when you do rpm -qld )
–nobase
Skips installation of @Base. This won’t work unless you know what you’re doing as it might leave out packages required by post installation scripts
–ignoremissing
Ignore missing packages and groups instead of asking what to do. This option has been deprecated in Centos 5, dependencies are resolved automatically every time now.

Example of minimal package selection for CentOS 4:

%packages –resolvedeps –excludedocs –nobase
kudzu

please note that essential stuff will be missing. There will be no rpm, no yum, no vim, no dhcp-client and no keyboard layouts. Kudzu is required, because the installer fails if it is missing.

Example of minimal package selection for CentOS 5:

%packages –excludedocs –nobase
@Core

Again, this will leave you with a *very* basic system that will be missing almost every feature you might expect.

The –resolvedeps used with CentOS 4 is not required for CentOS 5 as the newer installer always resolves dependencies.

Partitioning

If you start out with a unpartitioned disk, or a virtual machine on a unpartitioned image, use the –initlabel parameter to clearpart to make sure that the disklabel is initialized, or Anaconda will ask you to confirm creation of a disklabel interactively. For instance, to clean all partitions on xvda, and initialize the disklabel if it does not exist yet, you could use:

clearpart –all –initlabel –drives=xvda

Running anaconda in real text-mode

You probably already know that you can make anaconda run with a ncurses interface instead of the X11 interface by adding the line “text” to your kickstart file. But there’s another option: install in real shell-like textmode. Replace the “text”-line with a “cmdline”-line in your kickstart file and anaconda will do the whole installation in textmode. Especially when you use %packages –nobase or run complex %post scripts this will probably save hours of debugging, because you can actually see the output of all scripts that run during the installation.

Enable/disable firstboot

You all know firstboot, the druid that helps you to set up the system after install. It can be enabled and disabled by adding either “firstboot –enable” or “firstboot –disable” to the command section of your kickstart file.

What the different terminals display

Alt-F1
The installation dialog when using text or cmdline
Alt-F2
A shell prompt
Alt-F3
The install log displaying messages from install program
Alt-F4
The system log displaying messages from kernel, etc.
Alt-F5
All other messages
Alt-F7
The installation dialog when using the graphical installer

Logging %pre and %post

When using a %pre or %post script you can simply log the output to a file by using –log=/path/to/file

%post –log=/root/my-post-log
echo ‘Hello, World!’

Another way of logging and displaying the results on the screen would be the following:

%post
exec < /dev/tty3 > /dev/tty3
chvt 3
echo
echo “################################”
echo “# Running Post Configuration #”
echo “################################”
(
echo ‘Hello, World!’
) 2>&1 | /usr/bin/tee /var/log/post_install.log
chvt 1

Trusted interfaces for firewall configuration

You can use the –trust option to the firewall option multiple times to trust multiple interfaces:

# Enable firewall, open port for ssh and make eth1 and eth2 trusted
firewall –enable –ssh –trust=eth1 –trust=eth2

Use a specific network interface for kickstart

When your system has more than one network interface anaconda asks you which one you’d like to use for the kickstart process. This decision can be made at boot time by adding the ksdevice paramter and setting it accordingly. To run kickstart via eth0 simply add ksdevice=eth0 to the kernel command line.

A second method is using ksdevice=link. In this case anaconda will use the first interface it finds that has a active link.

A third method works if you are doing PXE based installations. Then you add IPAPPEND 2 to the PXE configuration file and use ksdevice=bootif. In this case anaconda will use the interface that did the PXE boot (this does not necessarily needs to be the first one with a active link).

Within the kickstart config itself you need to define the network interfaces using the network statement. If you are using method 2 or 3 then you don’t know which device actually will be used. If you don’t specify a device for the network statement anaconda will configure the device used for the kickstart process and set it up according to your network statement.

Forcing kickstart to ask for network configuration

Starting at CentOS 5, there a undocumented option that enable a prompt asking for network configuration during the installation. At the network statement, put the query keyword at the –bootproto= networking configuration, as we see below:

network –device=eth0 –bootproto=query

And a dialog box will appear asking for IP addressing, as well the hostname configuration.

To copy fields 3 and 7 from input to output (3 string, 7 float):
awk ‘{printf”%s\t%10.4f\n”, $3, $7}’ < input > output
———-
To add a column of numbers:
awk ‘{sum=sum+$1;printf(“sum: %d\n”, sum)}’ < input | tail -1
———-
To calc the average of numbers in a file:
egrep “^:2″ *out | egrep total | cut -c44- | \
awk ‘{sum += $1;total += 1;printf”avg = %.4f\n”, sum/total}’ | \
tail -1
———-
To find ‘word’ in files owned by ‘username’ from location ‘.’:
find . -user username -print -exec \grep word ‘{}’ \; > output &
———-
To find all files that do not end in ‘pdb’ in location ‘.’:
find . \( ! -name \*pdb \) -print
———-
To find all files that do not end in ‘pdb’ in location ‘.’ and execute a
command on each file found:
find . \( ! -name \*pdb \) -exec \anneal2pdb ‘{}’ \;
———-
To remove all files ‘garb’:
find ~ -name garb -print -exec \rm ‘{}’ \;
———-
To report the file size of all files bigger than 2 meg and older than 30
days.
find . -type f -size +4096 -atime +30 -exec \du -sk ‘{}’ \;
———-
To search with a wildcard:
find . -name goob\* -print
———-
To manually nudge NFS:
umount /iris1/a (or whatever)
mount -a -t nfs
exportfs -a -v
———-
To encrypt the file ‘input’ to a file ‘output’:
crypt < input > output
enter key: (enter a password)
To decrypt the file ‘output’ to a file ‘done’:
crypt < output > done
enter key: (enter the password used to encrypt ‘output’)
———-
To convert tabs to spaces:
expand -tabstop filename.in > filename.out
eg
expand -3 garb > garb.out
will convert tabs to three spaces

To convert spaces to tabs:
unexpand filename
———-
To check the print que:
lpq
To remove a print job:
lprm <job # from lpq>
To check the printer:
lpc
———-
To remove duplicate lines from a file:
uniq filename > out
———-
To mail to compuserve:
If the username is ‘70000,200’, mail to:
mail 70000.200@compuserve.com
note the period instead of the comma.
To mail from compuserve:
>INTERNET Loopy@cup.portal.com
———-
To create a text file from a manual page:
man command | expand > file
vi file
:1,$s/.^V^H//g
😡
———-
To compare two files:
Flags 1, 2, or 3 suppress printing of the corresponding column. Thus
comm -12 prints only the lines common to the two files; comm -23 prints
only lines in the first file but not in the second; comm -123 prints
nothing.
———-
To run a string of commands over and over:
csh> sh
$ while :
> do
> command
> command
> done
When done, ^C to quit. ^D to return to csh.
———-
To get a list of ‘fsu.edu’ machines:
UNIX> nslookup
> ls fsu.edu > file
> exit
———-
To get a machine name from an IP address:
UNIX> nslookup
> set type=ptr
> 34.12.186.128.in-addr.arpa
Server: magnet.fsu.edu
Address: 146.201.250.2

34.12.186.128.in-addr.arpa name = weirdscience.chem.fsu.edu
———-
To add line numbers to the beggining of a file:
grep -n . input > output
or
paste x y > z
———-
To move (or copy) a directory heirarchy:
cd fromdir
tar cf – . | (cd todir; tar xfBp -)
———-
To copy a directory heirarchy exactly:
cd fromdir; tar cBf – . | (cd todir; tar xpBf -)
———-
To restart the sendmail process:
kill the original process
/usr/lib/sendmail -bd -q1h
———-
To alias rm so that it lists the files to be removed and asks for
confirmation:
alias rm \
‘/bin/ls -AsF \!* && echo -n “Remove? ” && if ($< == y) /bin/rm -rf \!*’
———-
To remove blank lines from a file:
sed -e ‘/^$/d’ file.in > file.out
———-