Tuesday, July 10, 2012

How to replace portions of a unix path with sed

Sometimes you need to replace part of a pathname with a substitution. For example, you might want to change /my/old/path to /this/new/path.

Doing this with the typical delimiter '/' can look pretty ugly due to escape characters:

$ echo /my/old/path | sed 's/\/my\/old\/path/\/this\/new\/path/g' 
/this/new/path 

However this looks much cleaner by changing delimiter, the char after 's':

$ echo /my/old/path | sed 's|/my/old/path|/this/new/path|g'
/this/new/path

Monday, July 9, 2012

How to access a physical hard disk from VirtualBox

VirtualBox is a "virtualization product" with allows you to run a guest OS in a virtual machine.  While you typically boot from a VirtualBox Virtual Disk Image (.vdi), it may be useful to boot off of physical media like a USB drive, or a partition of your hard drive.

Support for this feature is described in the manual (you did read the manual, right?) in section 9.8 Advanced Storage Configuration.

Simply run:

$ VBoxManage internalcommands createrawvmdk -filename \
/path/to/file.vmdk -rawdisk /dev/sda