Using a visual hash to quickly recognize the system you’re logged on

When you work as a sysadmin you end up with many terminals open and connected to different systems. Problem is, most of these systems have nearly-identical Bash prompts and it might happen to run one command on the wrong system because of this.

I wanted to display in my bash prompts something that would let me to easily discern which system I was logged on. What I needed was a visual hash.

I ended up crafting a crude, but effective script that calculates an MD5 sum of the hostname, mac addresses and PCI devices of a system and outputs a color-coded string of unicode characters representing that sum.

It would make sense to run the script on boot and save the string somewhere, then include that string in your prompt with something like

VHASH=$(cat /etc/visual_hash)
PS1="${VHASH} \u\@\h \w $"

I’m quite happy with the results but I didn’t experiment too much with it, I’m quite sure you can get even better looking hashes with a little more effort.

visual_hash

The script is available on GitHub.

grub-install: The file /boot/grub/stage1 not read correctly.

I had to deal with this error while converting an old CentOS 4 install to a virtual machine.
I used a CentOS 6 disk in rescue mode to create a partition scheme similar to the one on the physical machine and then copied the files from the live system, but once chrooted in the newly created install, I couldn’t install grub. grub-install was failing with the message

The file /boot/grub/stage1 not read correctly.

and I had weird error messages about the partition format using the grub command line.

After a bit of poking around (usual stuff, check permissions, md5sum, I even restarted the system to make sure the partition table was read correctly and checked grub config and device.map files), I resorted to the Internet and thankfully I found out this knowledgebase that documents this exact issue: turns out, the mkfs.ext3 command from CentOS 6 created a partition with 256bit inodes and the old grub couldn’t deal with that. I formatted the filesystem again from inside the chroot, using CentOS 4 mkfs.ext3, copied the files again and the grub installation completed successfully.