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

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/