2005/12/28

Beautiful dirty trick: Embedded only-file bash filesystem

This is a beautiful trick. Tip includes: making an empty 10Mb file; creating a filesystem on it; creating basic tree; creating devices; copying bash and required libs; unmounting it; making it a boot file and adding a grub entry.

Put this on an executable-file-script and run it (tested on Fedora Core 4):

#!/bin/bash
#Script start ----------------------
#Bash only filesystem on a file - rodolfoap@hotmail.com

#Create an empty 10Mb file
dd if=/dev/zero of=/tmp/embed bs=1k count=10k

#Make an ext2fs
/sbin/mkfs.ext2 -q /tmp/embed

#Mount it as a loop
mkdir /mnt/embed
mount /tmp/embed /mnt/embed -o loop
cd /mnt/embed

#Create basic structure and fill it with needed files
mkdir bin dev lib
cp -a /dev/tty /dev/console /dev/ram dev/
cp /bin/bash bin/
#to found libs needed by bash, use # ldd /bin/bash
cp /lib/libtermcap.so.2 lib/
cp /lib/libdl.so.2 lib/
cp /lib/libc.so.6 lib/
cp /lib/ld-linux.so.2 lib/

#Create boot file
cd /tmp
umount /mnt/embed
gzip < embed > /boot/embed.gz
echo "
title Bash only filesystem
root (hd0,2)
kernel /boot/vmlinuz-2.6.14-1.1644_FC4 ro root=/dev/ram init=/bin/bash
initrd /boot/embed.gz" >> /etc/grub.conf
#Script end ------------------------

Reboot and choose the "Bash only filesystem" option.

2005/10/13

OS Tasting

A pic worths a thousand words. There are a lot of (linu)x-based distros, most of them oriented to specific user or application. This interesting page collects a lot of representative shots.

http://shots.osdir.com/

2005/10/10

Desktop GNUs

GNUs -mainly Linux- state of the arts for servers could be entitled as great. But that highlight not shows the same face for desktop usage. There are many issues to be confronted before we can see a really mature approach in migrating to linux environment. They can be organized in four main items, as we see on many posts of experienced admins, by the way, the most crystal approach: migration, stability, simplicity, comfort. Migration deals with the technical field: moving the user and his environment to this new gadget (thanks, wine; not wine for drinking, but the open application that is not an emulator; must include int this topic the learning curve fact). Stability, mainly with applications; if has been seen that the base OS handles tasks as a rock, is not the same with all applications. Comfort, with the maturity and easiness focus of task handling. The four issues lack off in some way. Not as a constant, but as everything, each case is to be handled with most care.

Years ago, we think man will live on the moon, by Y2k. Now we live another type of revolution: internet. We forgot the moon. Same way, on the desktop, we may probably not replace just the OS on final users' computers. Maybe the approach is based on powerful mainframes, generating desktops on dumb terminals. Simple, manageable, echologic. See the DiscoverStation solution as an example.

Anyway, there are new resources on the net, u r not alone. Check them out and you will find the named state of the arts has evolved. Here are a couple of them. You can google for more and be surprised.

www.desktoplinux.com/
www.desktoplinuxconsortium.org/
www.debian.org/devel/debian-desktop/
www.userful.com/products/library/

Estracted from http://www.swlink.net/~styma/LinuxForTheMasses.shtml:

* Linux/Fedora can supply the functionality that the end user needs once it is set up. It can do this more reliably than Windows.

* The application interface for the Linux end user tools (office, k3b, games, etc.) is similar enough to the windows interface to make the transition relatively painless.

* In it's current state, Fedora needs a technically savvy person to get it set up to a state that the end user can do things. Many of the issues revolve around licensing issues, such as the installs of xmms-mp3 and k3b-mp3. Some of the Firefox plugin issues fall into this category.

* A tool, similar in concept to the wine-tools, would be useful in the distribution. It would have options like "use MP3 format files", and if selected would add the livna repo's and check if k3b, xmms, and others with -mp3 versions were installed. If so, it would yum down the mp3 versions of these RPM's. The same would be true for enabling Java in the browser. Nothing I did could not be done by an automated tool.

* Non-technical users need a support structure to use their Linux machines effectively. I suspect this is mostly true if one is migrating the users away from Windows. If they know how to do something in windows, it is easier to switch back than to go through the learning curve on Linux. The question remains, what do the non-technical Windows users do when they get stuck? I suspect they either thrash around till they get something to work or just give up. I do not have good data on this and don't see how to get it. As Dr. Heisenberg discovered, measuring things affects the object being measured.

* It is possible that some of the procedures used could have been done better. "How do I" requests I got were often things I don't do often so I researched the issue to supply an answer.




2005/10/01

VNC tools mainframe-like terminals

What about buying a 50 bugs Pentium-I used computers(32 Mb RAM, 1Gb HD), and using the last Fedora Core 4 release, or Sarge? You can do that with linux VNCServer. VNC, on linux has the ability of creating desktop environments for each client. Here is an example with FC4.

1. Install vncserver on linux server. Install vncviewer from RealVNC on clients. You need 128Mb RAM on server for each client.
2. Create client entries like the line examples on /etc/sysconfig/vncserver

VNCSERVERS="1:rodolfoap"
VNCSERVERARGS[1]="-geometry 800x600"

3. su as each user. Run vncserver. It will create the ~/.vnc structure.
4. Edit ~/.vnc/xstartup:

unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
exec gnome-session &

5. Check your firewall rules! Start service. Connect from clients to SERVER_IP:5901 (each client is enumerated from 5901).

This method allows you to have a lot of clients working on his own homes. Startup scripts, allowable programs, quotas. But thats a KDE or GNOME issue.

2005/09/09

Documentation-time logic

Document! But do not take this task as an addition to developing. Here is an example of an integrated way of developing and socumenting at the same time.

The example shows a script which includes its own documentation. With simple tools, we generate man documentation from its output.

First of all, you need this formatted output: --version and --help. This example applies the "fortunes" script written in a previous post.

[rodolfoap] /home/rodolfoap > fortunes --version
GNU fortunes v0.1

Copyright (C) 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Written by Rodolfo Alcazar <rodolfoap@hotmail.com>
[rodolfoap] /home/rodolfoap > fortunes --help
GNU fortunes is a personal fortunes engine organizer, written in bash.

Usage: fortunes [OPTION]

Options:
-e edit fortunes file
-l enters learning mode
-m enters multiline-learning mode
--help shows this help
--version shows version

Examples:

fortunes --help shows this help
fortunes -e edits fortunes file
fortunes generates a random fortune
fortunes -l starts learning mode

Report bugs to rodolfoap@hotmail.com

Start documentation process:

[rodolfoap] /home/rodolfoap > help2man fortunes|gzip -f>fortunes.1.gz

User just access the man page. In this case, the man page is not stored in its proper location.

[rodolfoap] /home/rodolfoap > man ./fortunes.1.gz

2005/08/07

Linux power tools and classic formats

This is an interesting one. I had a 200-pages book, and need a 50-page book, with 4 little pages on each page. So I based this script on psdim, one of a thousand linux power tools:
#bin/bash
IMAGES=4
echo Must have installed psdim!
echo Converting...
gs -dBATCH -dNOPAUSE -sDEVICE=pswrite -sOutputFile=$1.tmp.ps $1
echo PSDIM output --------------------
psdim -$IMAGES $1.tmp.ps
echo PSDIM output end ----------------
pstops $(psdim -$IMAGES $1.tmp.ps) $1.tmp.ps $1.tm2.ps
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=$1.tiled.pdf $1.tm2.ps
rm $1.tmp.ps $1.tm2.ps
rename .pdf.tiled.pdf .tiled.pdf $1.tiled.pdf
echo Done!

You just need to start exploring GNU power tools now!

2005/07/13

Scripted Server Setup

As a tasks-overloaded systems administrator, I really experienced the information is, by far, the most important asset of a company motto. Enough to risk your job or your career if you lose some. So, years ago, I focused on two highlights on servers management: keeping safe data and automatizing administrative processes. I will focus on this article on the automatizing administrative processes issue.

With Turbolinux, I wrote once a script, which allows me, runt before a fresh install, to complete a mailserver setup. Install tooks 10 minutes. Script execution (install additional rpms, copying mailboxes from other server, replacing configuration files, configure services and reboot), 5 minutes. With bash.

The only problem was that next year we, the company, found ourselves working with SuSE. A couple of years, with Fedora. We expect the script will just need a little review with each scenario changing. False. The script needed a rewrite every time. So, as a part of writing automatization processes scripts, we include the "source code" of our needs.

This is an excerpt of a class I dictated. Useful for a mailserver setting up.

Linux Fedora Core 4 Server
==========================

- Install Fedora Core 4

- Do Not install SELINUX.

- Custom Type installation - no packages

- Hostname=www.example.org.bo

Firewalling config with IP Tables
=================================

Add this rules to /etc/sysconfig/iptables:
-A RH-Firewall-1-INPUT -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp --dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp --dport 110 -j ACCEPT

# service iptables restart

Create yum repository
=====================

Install createrepo with rpm:
# yum -y install createrepo

Create basedir:
# mkdir -p /rpm/Fedora/RPMS
# cd /rpm/Fedora/RPMS

Put each disc on cdrom and
# mount /media/cdrom; cp -v /media/cdrom/Fedora/RPMS/*.rpm . ; eject

On /etc/yum.repos.d/fedora.repo comment baseurl=, mirrorlist, gpg...,
and add
baseurl=file:///rpm/

Create repository:
# createrepo /rpm

Config Apache web server
========================

# yum -y install httpd
# service httpd start
# chkconfig httpd on

Config Pop3 server with Dovecot
===============================

# yum -y install dovecot
# service dovecot start
# chkconfig dovecot on

Config SMTP server with Sendmail
================================

# yum install sendmail-cf
# cd /etc/mail/

# vi sendmail.mc

Uncomment (wipe dnl):
dnl define(`confAUTH_OPTIONS', `A p')dnl
dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5
LOGIN PLAIN')dnl

Comment (put dnl):
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

Generate sendmail cf file:
# m4 sendmail.mc > sendmail.cf

Add domains served by server:
# echo example.org.bo >> local-host-names

Add the networks this server accepts mail from:
# echo 10.0.0 RELAY >> access

Regenerate hash tables by restarting service
# make
or
# service sendmail restart

Install a webmail server with SquirrelMail
=============================================

# yum install squirrelmail

Fill organizational data with
# /usr/share/squirrelmail/config/conf.pl
Must complete numbers 1 (general data), 7 (Motd) and 10 (languaje, here
we use es_ES)

Install Mailman mailing lists server
====================================

Install mailman:
# yum install mailman

Config mailman:
# cd /usr/lib/mailman/bin
# ./mmsitepass

Maybe this is not necessary, but we must know where it is:
# vi /etc/mailman/mm_cfg.py # put fqdn='www.example.org.bo'

Create lists
# ./newlist # create "mailman" list and copy generated aliases
to /etc/aliases
# ./newlist # create "mylist" list and copy generated aliases
to /etc/aliases
# ./mailmanctl start
# service sendmail restart
# service httpd restart
# service mailman start
# chkconfig mailman on

(on redhat, mailman require MAILMAN_USER and GROUP = 'root' on
Defaults.py)

You can see how easy is to "compile" this to bash, with kickfiles, sed, yum or apt.

Additional tip: whilst including this lines as comments on the script, include instructions if you are gonna execute interactive commands...

2005/04/15

Increasing productivity

Wanna load a bunch of users/passwords to your system? Wanna auto-generate mailman lists? Wanna concentrate all your weekly backups on a single server directory? Wanna batch? Got it! But only on text-based systems (read x-based OSs). If you manage IT facilities, YOU WILL NEED:

* cron, at, batch

* man man

* perl, bash

And some specific tools examples:

* chpasswd, sed, awk, rsync, scp

* mailman: all in /bin dir. sync_members will save you days if you schedule it with your /etc/passwd or adduser changes!

* sendmail: m4, makemap

* apache: mod_auth_pam, if you wanna simplify managing and have a LDAPping-Krb alternative

* Windows admins: Have you tried bash tools on your cmd.exe line?

X-based servers are in a highly mature state. They had evolved to satisfy most common administrative requests. Just search.

A quote from "A quarter Century of Unix" by P Salus" states, quoted from Simone Demblon :)

* write programs that do one thing and do it well.
* write programs that work together
* write programs that handle text streams, because that is a universal interface

Cheers!

2005/03/03

Detailed Linux Boot Process

Linux boot process is based, among others, on the System-V filed structure. Can read more on this article.

http://www.ccoss.org/tutorials/lfs/Linux_from_Scratch_A_Tour.htm

Fedora boot process, in more detail:

http://openskills.info/infobox.php?ID=228

2005/02/16

High leveling common tools

Tools like bash worths a "man bash" reading. You can even make recursive scripts! Lets play...
#!/bin/bash

function generalista ()
{
if [ $1 == "0" ] || [ $1 == "1" ]
then
echo 1
else
VARF=$(($1-1))
echo $VARF
generalista $VARF
fi
}

if [ "$#" == "1" ]
then
if [ $1 -ge 0 ]
then
time LISTA=$(generalista $1)
echo El factorial es el producto de los factores de esta lista : $LISTA
FACTORIAL=1;
for FACTOR in $LISTA
do
TEMP=$(($FACTORIAL*$FACTOR))
FACTORIAL=$TEMP
done
echo Entonces, el factorial de $1 es $FACTORIAL, aunque eso no es correcto...
else
echo Error: integer MUST be positive
fi
else
echo Usage: $0 positive_integer
fi

2005/01/07

Bash humor quotes database aids

#!/bin/bash

FORTFILE=/home/rodolfoap/bin/fortunes.mine
EDITOR=vi

HLPTXT=$(cat <<EOT
GNU fortunes is a personal fortunes engine organizer, written in bash.

Usage: fortunes [OPTION]

Options:
-e edit fortunes file
-l enters learning mode
-m enters multiline-learning mode
--help shows this help
--version shows version

Examples:

fortunes --help shows this help
fortunes -e edits fortunes file
fortunes generates a random fortune
fortunes -l starts learning mode

Report bugs to rodolfoap@hotmail.com
EOT)

VERTXT=$(cat <<EOT
GNU fortunes v0.1

Copyright (C) 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Written by Rodolfo Alcazar
EOT)

case "$1" in
"")
fortune $FORTFILE
;;
"-e")
$EDITOR $FORTFILE
/usr/sbin/strfile $FORTFILE
echo
;;
"-l")
echo "Entering learning mode."
echo
read -p "> " QUE
echo -e "$QUE\n%" >> $FORTFILE
echo
/usr/sbin/strfile $FORTFILE
;;
"-m")
echo "Entering multiline learning mode. End questions and answers with ^D."
echo
echo -n "> "
QUE=$(cat)
echo -e "$QUE\n%" >> $FORTFILE
echo
/usr/sbin/strfile $FORTFILE
;;
"-h"|"--help")
echo "$HLPTXT"
;;
"-v"|"--version")
echo "$VERTXT"
;;
esac



Fun, hah? With this basics I've wrote a flashcards studying tool. Drop me a line if you want it. Even better, you can write your own!