All posts in the Tips category

Power Down Headless Virtual Box VMs

Quick follow up post to yesterdays “Headless Virtualbox VMS With VBoxHeadless”.

Once you’ve started using VBoxHeadless to run VMs in the background you tend to start spinning up more and more at once. At this point it can become a hassle to log into each VM and issue poweroff when you need to free up resources, save battery life, etc.

VBoxManage is a huge command that covers pretty much everything that one would want to do with a VirtualBox VM from the CLI. Not surprisingly it can accomplish our task quite easily.

VBoxManage controlvm $VM_Name poweroff

Where $VM_Name is either the name that the VM would be displayed in the VirtualBox GUI manager or the UUID of the VM.

I plan on doing quite a long series exploring VirtualBox commands from beginner to advanced level. I hope you’ve enjoyed these quick introductory articles and will stick around as we go through some of the more exotic functions of the VirtualBox suite.

Headless VirtualBox VMs With VBoxHeadless

Recently I’ve found myself spending so much time in and out of VMs that a good way to spin them up in the background with my attention elsewhere was necessary.

Enter VBoxHeadless: it comes with a standard VirtualBox install on Linux to solve exactly this problem.

In a nutshell to start a VM in headless mode you would use:

VBoxHeadless –startvm $VM_Name

$VM_Name in this case being the name it would show up with in the VirtualBox GUI. You can also use the UUID of the VM but for me name is much easier to remember.

This one usage of the command is enough to accomplish 99% of what a normal user wants to do, but there are a few more parameters for things like VRDE and screen capturing as shown in the output of VBoxHeadless below:

[mm 21:51 0]$ VBoxHeadless -h
Oracle VM VirtualBox Headless Interface 4.1.4
(C) 2008-2011 Oracle Corporation
All rights reserved.

VBoxHeadless: error: –height: RTGetOpt: Command line option needs argument.
Usage:
-s, -startvm, –startvm Start given VM (required argument)
-v, -vrde, –vrde on|off|config Enable (default) or disable the VRDE
server or don’t change the setting
-e, -vrdeproperty, –vrdeproperty Set a VRDE property:
“TCP/Ports” – comma-separated list of ports
the VRDE server can bind to. Use a dash between
two port numbers to specify a range
“TCP/Address” – interface IP the VRDE server
will bind to
-c, -capture, –capture Record the VM screen output to a file
-w, –width Frame width when recording
-h, –height Frame height when recording
-r, –bitrate Recording bit rate when recording
-f, –filename File name when recording. The codec
used will be chosen based on the
file extension

That’s it for headless VMs on VirtualBox. Once you decide to leave the GUI in the dust I think you’ll find VirtualBox a much more flexible and easy to use virtualization platform.

ESX Host Randomly Restarts After Being (Re) Added to HA Cluster

I apologize ahead of time for the title. I could not think of a more elegant way to describe this problem that would actually allow those who needed the solution to find it. Still, long title is too long.

I got to work this morning and a box in my VMWare ESX cluster was disconnected. No big deal right? I power cycled the physical machine and then right click connected in vSphere. Everything looked great and it reconnected like normal. Then before I could start moving VMs back over it was disconnected again with a “host or network” error. I tried removing the machine from the HA Cluster and readding it after which it stayed on a little longer but the end result was the same.

The only discernible error I could see was “Cannot connect: already managed by 127.0.0.1″. After googling I found some fellow sysadmins having similarly strange problems and a VMWare KB article that was being passed around. It seems that the management IP of the host had gone FUBAR. I wish I could explain why this happened, the KB article mentions it being an issue after upgrading a host between ESX versions but mine had not been upgraded even remotely recently.

My solution:

- Log into the ESX box terminal directly.

- Open vpxa.cfg in a text editor:

nano /etc/opt/vmware/vpxa/vpxa.cfg

- Find the entry, if you’re having the same problem this will likely read 127.0.0.1.

- Change this to the IP of your vCenter server.

- Save the file, make sure to restart any vSphere/vCenter connections you have open and then reconnect the host.

After that the host came back online in the vSphere console correctly and stayed up. If you have the same error hopefully this will save you some frustration.

Alternate Source of Slackware Linux Packages: SalixOS

I was browsing around the Slackware forums over at slacklinux.darkbb.com this afternoon and I came across an interesting topic.

It seems there is a distro based on Slack that I’d never heard of before named SalixOS and they only build packages that are fully backwards compatible for mainstream Slackware.

You can check out their repo mirrors over here: http://www.salixos.org/wiki/index.php/Repository_mirrors

So if you’re in a pinch and just can’t wait for that compile, or can’t find what you need in Slackware extras or Slackbuilds then check out the SalixOS repositories. It’s awesome to see these guys taking the effort to make sure their packages are usable by a wider audience than just their own users. If the entire community could cooperate that well I wouldn’t have to know about 10 different package formats just to work on all the distros I come across.

So  make sure to check them out at salixos.org and if you use their packages on your Slack box I’m sure they wouldn’t mind a nice thank you in their forums or IRC!

Set a Wallpaper That Survives Reboots in Slackware Linux

If you’re using KDE, GNOME, XFCE or any other full desktop environment you probably have a right-click “set as background” option that handles this for you. However if you’re on Fluxbox,  DWM, AwesomeWM, TWM or another lightweight window manager this tip might be helpful for you.

The command we’ll use is the fluxbox wallpaper command fbsetbg, it should work across almost all other window managers however.

Usage is simple:

fbsetbg mywallpapername.jpg

However that wallpaper won’t survive a reboot and you’ll be back with a blank screen the next time you need to power down. To make it permanent we can use fbsetbg -l (which automatically sets the last wallpaper set with the command) in our ~/.xinitrc.

So for example a minimal .xinitrc to launch fluxbox with our wallpaper could look like:

exec fbsetbg -l &

exec fluxbox

It’s simple but elegant. Since the last wallpaper set will always be restored on the start of X you’re free to change it as much as you want without updating anything.

There are several other cool things you can do with fbsetbg covered in it’s help output and man pages. Go forth and experiment!

How Strong is your tcpdump Fu?

Tonight I just wanted to point out a great little article that ran on Linux Journal a few days ago by author Henry Van Styn titled tcpdump fu.

It goes into a few of the more useful things you can do with the tcpdump command and does a good job of it. If you’re looking for a good five minute primer on using tcpdump for packet analysis I’d recommend checking it out.

Seeing it pop up in my feed reminded me I need to actually read the copy of Network Flow Analysis by Micheal Lucas that I bought a few months ago. Look for an in depth series on packet an flow analysis in the future.

Find Your Public IP from the Linux Command Line

Here’s another short ass-kicking tip.

Whenever you’re wondering what the public IP of the box your working on is, whether it’s to perform a scan, correctly point DNS, forward ports or any of the other many reasons one needs to find a public IP try this:

curl icanhazip.com

That’s it. If you go to http://www.icanhazip.com in a browser you’ll see it just spits out your IP in plaintext.

It’s no beautiful 10000 character one liner but it’s amazingly helpful to remember when you need it ( and you will, trust me ).

Completely Kick a User on Linux

This is so quick it probably doesn’t even warrant a post. However it’s Sunday, i’m lazy, and I don’t intend on breaking my perfect one post per day streak.

The killall command is really useful in several different circumstances but for our purposes right now we’re interested in the -u switch. This tells killall to kill every process running as a user, that covers ssh sessions, screen, any GUI, everything. If you need someone off of your system immediately for whatever reason just use:

killall -u someusername

There you have it, nothing fancy but it does the job fast. Use it to strike fear into the hearts of your mere user enemies.

Allow MySQL Users to Create Databases Safely

If you’ve used a shared hosting platform before and wondered why your databases were always $username_database or even a random string of characters, it’s a pretty simple concept. When you have multiple users sharing the same RDBMS ( in this case MySQL ) you can’t have them all trying to create databases with the same name, you need some way of keeping every DB name unique.

This handy little trick for MySQL allows a user to create any database he wants as long as it starts with $username_. So I could create masen_wordpress but not wordpress, and so on and so forth.

GRANT ALL PRIVILEGES on `monty\_%` .  * TO ‘monty’@'localhost’;

Obviously this can be tweaked to shave down the permissions given and any arbitrary string can be used in place of monty, the basic concept remains the same however. After entering this in the mysql command line our user monty can create databases to his hearts content.

Quickly Find Thinkpad CPU Temp Linux

This one is a little specific but I needed it this morning so I made a quick one liner for it that I thought I would share.

tc=`tc=`cat /proc/acpi/ibm/thermal | awk ‘{ print $2 }’`;tf=$(echo “scale=2;((9/5) * $tc) + 32″ |bc) echo “CPU TEMP => $tf F”

Pretty simple but I’ll break it out for you anyway.

cat /proc/acpi/ibm/thermal

This proc file contains quick readings for each thermal sensor, you can check out the listings for them over on thinkwiki: http://www.thinkwiki.org/wiki/Thermal_Sensors. A reading of -128 means a disconnected sensor.

awk ‘{ print $2 }’`

Print the second collumn, I happen to know this is the CPU Temp colloum.

tf=$(echo “scale=2;((9/5) * $tc) + 32″ |bc) echo “CPU TEMP => $tf F”

Use bc to convert the C reading to F which makes more sense to me, then output a pretty reading.

As you can see it’s a pretty simple little one liner. This is obviously specific to a Thinpad T400 but it would work the same with any other machine, just sub the correct /proc file for your model.