Category: Linux

Backups: Beep Beep Beep

This post isn’t technical. It’s mostly steam, technical steam. The message is meant mostly for end users. I’m decommissioning a server that is barely used. The only user left on the system, after being warned about the decommissioning informs me that the files are mostly corrupted on the system. The system is almost as old as I am and the files in question were changed roughly half a decade ago. Backups, even if they existed are long gone.

It appears that the former owner of the server converted the system to a virtual hypervisor around that time. Why the files are corrupted are beyond me. If files were across the board corrupted then the system would not be booting or giving other errors. Maybe /home was selectively corrupted? That would be very… odd.

Regardless, it’s important to not rely on saving your files on remote servers. Make certain you keep a backup. Verify your content!

QEMU VNC: Change Your Password And Daemonize Your Monitor

I had a lovely time figuring this out. For obvious reasons you don’t pass the vnc password to the qemu command as it can be seen with a ps. The only other approved unimplemented option is to have a password file. At least with a password file you can secure it with file system permissions. My box has no users so to me whatever works works. Anyway…

The problem: daemonize your qemu while still allowing vnc with security! To change the vnc password you have to issue a command ‘change vnc password XXXXX’ to the qemu monitor. The monitor can work with stdio but that defeats the point of daemonize…

My solution: set the monitor to use a tcp port bound to localhost. This way you can continue to control the qemu monitor from the tcp socket. Then use netcat’s nc command to issue it the change vnc password command. I ran in to yet another problem. The nc command didn’t automatically exit and my scripts are non interactive start up scripts.

qemu-kvm -vnc 192.168.0.1:0,password -monitor telnet:127.0.0.1:4444,server,nowait –daemonize
echo change vnc password XXXXX; echo | nc 127.0.0.1 4444

Solution to new problem: Tell nc to execute a command rather than use stdio. The command would simply echo command then echo a new line and exit. This also solved my problem of how to tell qemu to stop running without simply issuing it a kill command. My script took arg1 as the vnc password.

nc 127.0.0.1 4444 -e /change_vnc.sh XXXXX

The fact that I’m using busybox to do all of this may have complicated the nc command so I don’t know if actual netcat would have had that problem. Regardless it was very simple.

Remote OS Conversion: Doing It Remotely

Ok, this post is useful for more than its original scope… the problem is simple; your machine is hundreds of miles away and all you have is remote console. Your mission if you choose to accept (if you’re even given the choice) is to install Centos on the remote machine. Now, huge disclaimer… there may be a better way to do this.

As I saw it… I could have tried to set something up to run from the current distribution. My problem is that I also had to redo the partition tables and reformat. I can’t boot to a second medium as I can’t just pop in a CD or USB drive. This also excludes rsyncing a Centos install to the destination.

My first attempt was to chainboot an ISO using grub. Unfortunately I wasn’t running grub2 and I had to use an ISO which can’t be mapped because it isn’t a HD device. Of course grub2 apparently natively supports it. Also don’t be fooled by Google. Loads of people suggest using a knoppix kernel which supports the bootfrom kernel option. The caveat is that the booting kernel must match the kernel in the ISO.

Here was my plan and I totally have done this before. The first line of business was to grab the Centos net install ISO. Fortunately its totally not bloated and is roughly 10 mbs. Next you have to mount it to disect the CD.

mount -oloop Centos_netinstall.iso /mnt/cd-rom

Most, if not all, Linux bootable CDs use isolinux. All I needed to do was find the isolinux configuration, which reminds me a lot like the Lilo configuration file.

The configuration has a kernel and an initrd. The kernel in my case was called vmlinuz and the initrd was called initrd.img. I copied those over to /boot and modified my grub like the following.

title sin
root (hd0,0)
kernel vmlinuz
initrd initrd.img

Fire it up and you have yourself a Centos net install from grub on your remote system.

Let us talk about further thinking… This principal can be used to create a bootable USB Centos net install thumb drive. Simply install grub to the thumb drive and perform the previous commands.

Say you have a Android x86 bootable ISO and you want to load in your own kernel or turn the ISO into an bootable USB drive. Do the same to grab the kernel and the ram disks. Then boot it from the USB or what have you. Once booted you can grab the configuration for the kernel from /proc/config.gz and compile your own replacement kernel remembering to slip in your new modules in the Android appropriate location.

There’s probably more helpful things you can do after you split the ISO open and remove the precious brains.

Caio!