вторник, 24 мая 2011 г.

Base64 and Pipes

Today I needed to copy an rpm file to Xen virtual machine having xm console as the only access to VM (xm console opens console to virtualized OS).

The first idea that comes is to open editor in the VM and copy-paste the contents of rpm there. 
Unfortunatelly it's not going to work because virtual console will interpret non-ASCII symbols of binary file stream as escape codes which makes copying in this way impossible.

The UNIX utility which can help us is base64. It converts binary file to text representation which can be copied safely.
The whole process can be simplified to following:

from host side:
base64 file.rpm | xm console vm

from VM side:
base64 -d < /dev/tty > file.rpm

Where
"< /dev/tty"
- standart input (from console),
"> file.rpm" - standart output (to file)

Комментариев нет:

Отправить комментарий