Systems

Customized Bash Prompt

Posted in Systems on July 12th, 2010 by Angelo – Be the first to comment

The following sites inspired me to explore creating a customized prompt (for bash):

So here is mine:

PS1="\$(if [[ \$? != "0" ]]; then echo \[\e[31m\]; fi)\n\$(date)\n\\[\e[1m\\]\[\$(dirs)\]\n\\[\e[m\\]"
PS2=""

Features:

  • Color change on error return code
  • The current date
  • The current directory stack (I use pushd and popd)
  • Commands start on their own line

And that’s it!  I really don’t need the prompt to tell me what my username is or the hostname of the machine (duh!).

Rsync Speed-up

Posted in Systems on May 25th, 2010 by Angelo – Be the first to comment

Online docs say that rsync sends only the differences and “information about structure” but my experience seems to indicate otherwise. So I ran a little test too on a file where I just changed the timestamp without changing the file contents:

$ cp -a testfile-100M destfile

$ rsync -av testfile-100M destfile
sending incremental file list

sent 56 bytes received 12 bytes 8.00 bytes/sec
total size is 104857600 speedup is 1542023.53

$ touch testfile-100M

$ rsync -av testfile-100M destfile sending incremental file list
testfile-100M

sent 104870495 bytes received 31 bytes 113804.15 bytes/sec
total size is 104857600 speedup is 1.00

I didn’t time it, but the initial cp easily took 1/3rd the time the final rsync did–I would estimate more like 1/4th or 1/5th the time. I’ve always read “speedup is 1.00″ as “this is equivalent to having copied the whole file.” Meaning I gained no speedup over just transmitting the file regularly, as calculated by the algorithm.

I think what might be going on is that when rsync sees the timestamp has changed it transfers the file. But in doing so, it does a diff on the contents which is slower than just copying a file.

DOS Disk/Flash BIOS

Posted in Systems on April 12th, 2010 by Angelo – Be the first to comment

These are some notes on making a DOS disk using FreeDOS for those of us with Linux needing to do things like flash our BIOS.


wget -c http://fdos.org/bootdisks/autogen/FDOEM.144.gz
gunzip FDOEM.144.gz
mount -t vfat -o loop FDOEM.144 /mnt/floppy

Put the driver files on the floppy (stay within the space limit)

umount /mnt/floppy
mkisofs -o bootcd.iso -b FDOEM.144 FDOEM.144

For Windows Users Who Want to Try Linux

Posted in Systems on June 13th, 2009 by Angelo – 1 Comment

Using computers is not intuitive.  We may feel it is intuitive because we have used computers for a long time, or have become familiar with them.  However, computers are not intuitive—especially their interfaces.  Someone who is used to Windows may find the MacOS GUI frustrating.

Most people are familiar with Windows.  The Windows GUI environment has become so familiar to us, that some of us may find it difficult to operate in another environment.  Even down to the direction mouse pointer (arrow) is pointing—seeing a right-pointing arrow may make one a little uneasy about having to adjust their “aim” for the pointer to the right side of the pointer instead of the left side.

But there is one point I’d like to make:  Windows isn’t intuitive either.  I’ve seen people use Windows for the first time, and it’s a little bit awkward.  The most noticable thing that people have difficulty with is “double-clicking.”  Double-clicking is certainly not intuitive, and makes Windows difficult to use for first-timers.  But other than that Windows contains other non-intuitive items as well:  menu item names, descriptions of features, locations of files, etc. all contain counter-intuitive elements.

Therefore, if you know Windows, you had to learn Windows.  You probably learned it because “it was there” and you wanted to use the computer.  So, you should not become afraid of Linux when your first attempts prove frustrating.  Linux requires you to learn a different set of rules for operating the computer, and even though Linux has come a long way with its GUI, the operating system and applications may seem so unfamiliar that navigating them and trying to be productive may drive you back to Windows.  But there are ways to start to become more familiar with items of Linux and ease yourself into using the new system.

Probably the number one thing Windows users use their computers for are the Internet and word processing.  Luckily the free software that runs on Linux for these things is also available for free for Windows.  That means you can start to use software which will be familiar to you on both Windows and Linux, while at first retaining a lot of your familiar Windows features.  The following software installed on your Windows machine should help you if you find going cold turkey to Linux difficult.

  • Mozilla Firefox: a web browser for surfing the ‘net, similar to Internet Explorer
  • OpenOffice.org: an office suite containing a word processor, spreadsheet, HTML editor, presentor, etc.
  • Mozilla Thunderbird: an email client similar to Outlook (or Outlook Express)
  • GIMP: an image editing and manipulation tool
  • VideoLAN Player: a great media player that can play many file formats.
  • Wine: an emulator that can allow you to run many Windows programs on Linux (helps with games)
  • DOSBox: an emulator to allow you to run old DOS programs.

And the best part about the above software is not only is it free, but it’s super easy to install.  Most Linux, like Ubuntu, have an easy-to-use interface that will automatically download and install software packages for you.  Just search, choose, and apply the changes.

CD/DVD Filesystem Snapshot

Posted in Systems on August 21st, 2008 by Angelo – Be the first to comment

This will work with other filesystems, not just ext2, so you may want to choose a filesystem that is similar to what you currently run (if you care). The idea is that instead of creating an ISO image that is very flexible (can be read by Windows), you create a filesystem image and burn it to disc. The advantage of this is that you can preserve filesystem properties such as permissions, ownership, etc. The disadvantage is that the straightforward approach (everything on one disk) only gives you about 4.5 G of space to work with (depending on the media size).

(1) Create a 2 GB image:
sudo dd if=/dev/zero of=snapshot.img bs=1024k count=2000 &
You can create a larger image size if you need it, and your burnable media can handle it.

(2) Format it using ext2
sudo mke2fs -m 0 -q -F -b 2048 snapshot.img 1>&2
Honestly, I can’t remember why I was redirecting output to stderr. Maybe I had a good reason for that. But suffice it to say, you simply want to use the file you created to make a file system. For example, instead of the above, you can use something like `mkfs -t xfs snapshot.img`

(3) Mount the image
sudo mount -t ext2 -o loop snapshot.img /mnt/snapshot
For the mount, you want to make sure to use whatever filesystem type you created the image with.

(4) Copy the data, preserving information
sudo rsync -avH --numeric-ids --progress --stats --delete --exclude /proc/ \
--exclude /sys/ --exclude /tmp/ --exclude /var/run/ --exclude /var/tmp/ \
--exclude /mnt/snapshot/ / /mnt/snapshot/

This is an example of copying the entire system (if it’s small enough to fit). In this example, you want to make sure you exclude the mount point for the snapshot, because otherwise you’ll have a recursive rsync that will go on forever. It’s definitely good to make sure you exclude /proc/ and /sys/ too. You could exclude /dev/ since today’s Linux just regenerates it on boot anyway. (If you were porting to other hardware you may want to do this to be “safe” but usually it’s safer to just keep a copy of it.) –progress and –stats are extraneous options, and if you’re a neat freak, you can use –delete-excluded too to make sure those directories are cleared out in case you accidentally copied things over.

(5) Unmount and burn using cdrecord
sudo umount /mnt/snapshot
sudo cdrecord -v -eject dev=/dev/cdrom snapshot.img

You can alternatively use any burning software to apply the image directly to burnable media.

Now keep in mind, that when you want to mount this CD/DVD you will need to mount it by hand, as root, using the filesystem type you burned it with. It’s a good idea to write the fs type on the CD along with whatever else you’re going to call it so you know how to mount it later.


rsync --verbose --progress --stats --compress -a --delete -H --numeric-ids --exclude "#*#" --exclude "*~" --exclude "/proc/*" --exclude "/dev/*" --exclude "/var/cache/*" --exclude "/tmp/*" --exclude "/var/tmp/*" descartes:/ /mnt/backup/rsync/descartes/

Windows Hosts File

Posted in Systems on August 10th, 2008 by Angelo – Be the first to comment

Did you know that Windows also has equivalent to /etc/hosts where you can set IP addresses for domain names? It’s a plain text file in the same format, and it’s typically found in one of these two places:

  • C:\winnt\system32\drivers\etc\hosts
  • C:\windows\system32\drivers\etc\hosts

Notice how they kept the etc/ directory? Hmmmmm ;)

Install OpenOffice.org for a Single User (without Root)

Posted in Systems on August 8th, 2008 by Angelo – Be the first to comment

OpenOffice.org distributes their binaries as rpms. That’s great for a majority of the people who can install them, but in a couple of situations I’ve found myself wanting to use the most updated version but didn’t have root access to do the install of the package properly.

Here is how I installed it for my own user. You will need the cpio utilities installed including ‘cpio’ and ‘rpm2cpio’ which are installed on many rpm based systems.

  1. Download the gzipped rpm files from OpenOffice.org
  2. Unpack:
    tar xzvf OOo_2.2.0_LinuxIntel_install_wJRE_en-US.tar.gz
  3. You should now have a directory similar to OOF680_m14_native_packed-1_en-US.9134/
    cd to the RPMs directory inside this new directory and unpack the RPM files locally:

    ls *.rpm | while read file; do rpm2cpio $file | cpio -idmv; done
  4. You should see the files from the RPMs created, e.g.
    ./etc
    ./etc/.java
    ./etc/.java/.systemPrefs
    ./etc/.java/.systemPrefs/.system.lock
    ./etc/.java/.systemPrefs/.systemRootModFile
    ./etc/init.d/jexec
    ...
    opt/openoffice.org2.2/share/xslt/export/xhtml/header.xsl
    opt/openoffice.org2.2/share/xslt/export/xhtml/master_chapter_numbering.xsl
    opt/openoffice.org2.2/share/xslt/export/xhtml/master_document.xsl
    opt/openoffice.org2.2/share/xslt/export/xhtml/master_refs_workaround.xsl
    opt/openoffice.org2.2/share/xslt/export/xhtml/master_usability_links.xsl
    opt/openoffice.org2.2/share/xslt/export/xhtml/ooo2xhtml.xsl
    opt/openoffice.org2.2/share/xslt/export/xhtml/table.xsl
  5. I like to keep all of my personal packages in a single directory. Usually I make a directory in my home called pkg/ which I will move openoffice to. So first, move the openoffice directory under opt/ that was created above to ~/pkg/:
    mv opt/openoffice.org2.2/ ~/pkg/
  6. I also like to use symlinks for my current most updated version of a software:
    cd ~/pkg/
    ln -s openoffice.org2.2/ openoffice.org
  7. Then I create some scripts in my ~/bin/ directory that I include in my path environment. The first one is openoffice.org itself. I create an executable file called ~/bin/openoffice.org that looks like this:
    #!/bin/bash
    exec ~/pkg/openoffice.org/program/soffice "$@"
  8. It’s also nice to create one for the openoffice.org printer administration gui. I create an executable script called ~/bin/openoffice.org-printeradmin that looks like this:
    #!/bin/bash
    exec ~/pkg/openoffice.org2.1/program/spadmin

Now, if you have ~/bin/ in your PATH environment you should be able to load files using openoffice.org <filename>