Wednesday, February 27, 2013

Easy conversion from VMDK to Proxmox

I kind of stumbled on this accidentally, but it has worked in the one instance in which I have tried it so far.

Proxmox uses KVM/QEMU for virtualization and stores disk images in raw format. Converting from a VMDK to a raw format is simple:

$ qemu-img convert -f vmdk my-vmdk.vmdk -O raw my-raw-image.raw


You can check the format if you like:

$ qemu-img info my-raw-image.raw 
image: my-raw-image.raw
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 1.8G

However Proxmox as far as I can tell has no method for simply choosing a virtual drive to use for a VM. So you have to create a VM (not a VZ container) using the regular Proxmox web interface (choose "no media" for the installation step since we won't be installing anything), then replace the raw image created for the new VM with the one created in the step above.

$ scp my-raw-image.raw root@PROXMOX-IP:/var/lib/vz/data/images/VM_ID/vm-VM_ID-disk-1.raw

In my instance this would be basically:

$ scp my-raw-image.raw root@192.168.1.100:/var/lib/vz/data/images/104/vm-104-disk-1.raw


The particularities here can change, so its probably better to ssh to the Proxmox server yourself and make sure the file/folder names are what you expect.

Anyway after this process I booted my VM, and it came right up, although it did inform me that I needed to run fsck (disk checker).

Note: If your virtual machine image has multiple partitions, I have no idea what you need to do, but take a look here for ideas, though the actual steps didn't work for me.

Boot speed in Arch

I've noticed that my bootups seem to be getting faster and faster. I remembered installing something that was supposed to automatically adjust the boot process over time and reboots, but I couldn't remember what it was. 

* EDIT: I remembered what I did to speed things up, from the Arch wiki :
# systemctl enable systemd-readahead-collect systemd-readahead-replay


Anyway, I ran systemd-analyze and compared the results to a post from a couple weeks ago, and man I was definitely right, just the four top entries are below:

Two weeks ago:

$ systemd-analyze blame
 7977ms NetworkManager.service
 2796ms colord.service
 2788ms bluetooth.service
 2728ms systemd-logind.service

Today:

$ systemd-analyze blame
1923ms systemd-modules-load.service
 769ms systemd-binfmt.service
 589ms NetworkManager.service
 555ms systemd-udev-trigger.service 

So these four entries alone show a change from about 16 seconds to about 3.

Wednesday, February 20, 2013

Convert PS to PDF, A4 vs Letter

In the US here we use some paper size called "letter" and apparently elsewhere they use A4, and for some reason is very close, but not quite the same. Probably some sort of metric thing. Anyway, I got a PostScript file that was created for A4 size output and wanted to convert it to a PDF. Regular ol' ps2pdf would truncate parts of the border, same with printing to a pdf. So, even though its not in "my" man page for ps2pdf, there is an option for telling ps2pdf the type of paper to expect.
$ ps2pdf -sPAPERSIZE=a4 toconvert.ps converted.pdf
Edit:
I did a bit more messing around: this page at linuxjournal.com has a lot of additional information on these types of conversions. In Arch, the package you need to get psselect is "psutils". I ended up having to experiment a bit to get what I needed. I wanted to remove the first 3 pages which were cover pages.

The command below did what I needed, order of arguments is important.
$ psselect -p3-25 toconvert.ps | ps2pdf -sPAPERSIZE=a4 - converted.pdf
The first command select pages 3-25 of the input PS file, pipes that to ps2pdf which then uses a dash "-" in place of the input file name.

Bash Guide for Beginners

Though I wouldn't classify myself as a beginner, http://tldp.org/LDP/Bash-Beginners-Guide/html/ is a fantastic source of information for Bash programming. It has good examples and covers lots of topics that aren't covered in other guides.

Blogilo blogging client

Note: I am posting this from the web client because Blogilo, after successfully submitting one initial post of "test" and then deleting it, has not successfully posted again. It did crash, so there may be some residual problems that need rebooted away.

I noticed I had a blogging application called "Blogilo" installed (it must come default with KDE or something). But I'm not crazy about web based interfaces for things I do often, so I decided to give it a try. 

Configuration was tricky, many people would have given up after the very simple configuration dialog repeatedly failed, but I found this post which explained things. 

You have to manually figure out the blogid, and get part of the URL used when editing posts...
After getting that to work, I tried to upload a post with an image, that didn't work either. It just said "uploading" forever.
Trying to fix that, I saved two posts I was working on "locally" at which point the application crashed and no posts were saved. 

I have tried again to "save locally" as well as click the "save as draft" checkbox when submitting, but I have seen no way to retrieve these drafts.

I have since been unable to get it to post anything and am getting an error whose "details" are:
An error occurred in the last transaction.
Server (Atom) error: Could not regexp the id out of the result.
So, this sucker is buggy. I'll give it another shot, but its not looking good so far.

Tuesday, February 19, 2013

Sort folders by modification times of contents

This is a handy bash script that will take a folder or list of folders, and show you the date of the most recently modified file or folder that exists within it.

I use it to prune users from my server that are no longer active.

#!/bin/bash
# Take a list of folders, search each of 
# them for the most recently modified file
# output the top level folder name and date
while (( "$#" )); do
  FOLDER=$1
  shift

  NEWEST=`find $FOLDER -printf '%T@ %p\n' | 
   sort -k 1nr | sed 's/^[^ ]* //' | 
   head -n 1 `

  DATE=`stat -c %y "$NEWEST" | cut -f 1 -d " "`
  echo "$DATE:  $FOLDER"
done
# ~/scripts/find-inactive.sh `ls /home` | sort
2008-07-28:  lost+found
2012-01-06:  gshaughnessy
2012-01-19:  mwilliams
2012-01-21:  agreenfield
2012-01-22:  zsilva
2012-01-26:  lwomack
2012-01-26:  rmcknight
2012-01-27:  ckyzer
2012-01-29:  crowe
...

Thursday, February 14, 2013

Analyzing the boot process

Something I want to investigate further in the future, so I'm making a note of it here.
Arch uses systemd to initialize the OS, which has some cool features for analyzing the boot process and showing where the time is taken.

Show the hogs:
$ systemd-analyze blame
  7977ms NetworkManager.service
  2796ms colord.service
  2788ms bluetooth.service
  2728ms systemd-logind.service
  1558ms polkit.service
   516ms systemd-tmpfiles-setup.service
   488ms tmp.mount
   486ms systemd-binfmt.service
   484ms dev-mqueue.mount
  ...
Create a plot of processes:
$ systemd-analyze plot > ~/plot.svg
$ kde-open ~/plot.svg
There's also some way to create a "bootchart" but it may required a custom kernel or something, I don't remember.

Install Microsoft Office 2010 in 64 bit Arch Linux

This might actually help someone other than me... I am running 64 bit Arch Linux and last November or so I installed Office2010 using PlayOnLinux with no problems.
Unfortunately I had to re-install Arch about a week ago (Early February) and afterwards my Office applications would no longer start (my home is on a separate partition so I didn't have to reinstall Office). Nothing I tried could get Office 2010 to work properly. I deleted my .wine and .PlayOnLinux folders and tried to reinstall.
I either couldn't get it to install, or could get it to install, but activation over the Internet would not work. I didn't want to call Microsoft even though that would probably have been the easiest solution. I tried exporting WINEARCH="win32" but the installer then crashed.

What I finally had to do was uninstall wine and all its dependencies and then install bin32-wine-snapshot from the AUR. After that everything was just great.

# packer -S bin32-wine-snapshot     # or yaourt or whatever...
$ export WINEPREFIX="${HOME}/.msoffice2010"
$ export WINEARCH="win32"
$ wine my-installer.exe
Done, and it activated with no issue.

Thursday, February 7, 2013

Fixing slow SSH logins

I've noticed recently that logging in to my server over SSH has a delay of 5 to 10 seconds, which gets irritating. The problem has to do with SSHD trying to resolve IP addresses of incoming connections. Add "UseDNS no" to sshd's config file and it all goes away.

# echo "UseDNS no" >> /etc/ssh/sshd_config
Restart your DNS server and it should log in instantly.

Tuesday, February 5, 2013

Copying files or partitions using dd and netcat

Something I need to do every so often, but not enough to remember is copy files across a network when the destination computer has no obvious way to receive the files.

Using netcat on both ends makes it easy.

On recipient computer (whose IP is 192.168.1.5)

netcat -l -p 2000 | dd of=some.file
(-l is for listen, -p is the port number)

On sending computer:

dd if=some.file | netcat 192.168.1.5 2000
I actually used this to copy a partition (hence the dd command). I haven't tried this with a file as shown, but it should work with files just the same.