[PATCH] guestfs_file_arch command
This patch adds a new function, guestfs_file_arch, which is like guestfs_file but specifically intended to determine the architecture of binaries and libraries. Usage is: guestfs_file_arch (g, "/bin/ls") ==> "x86_64" (or whatever) What it can do: - ELF binaries - ELF shared libraries - Windows Win32 and Win64 binaries - Windows Win32 and Win64 DLLs - Linux kernel modules - Linux new-style initrd images - some non-x86 Linux vmlinuz kernels What it can't do: - static libraries (libfoo.a) - Linux old-style initrd as compressed ext2 filesystem (RHEL 3) - x86 Linux vmlinuz kernels - ancient stuff like a.out, COFF binaries It turns out that x86 vmlinuz (ie. bzImage) is virtually impossible to unpack. It consists of an amalgam of 16 bit code, 32 bit code (even on x86-64) and compressed kernel. The only way to unpack it would be to either uncompress the compressed kernel, or else reverse the (32 bit) CPU detection code. Neither is very realistic, but I left in some commented-out code to show you how far I got. An easy LKML patch for someone would be to add the required architecture into the setup header so we can just read it out directly, or maybe someone else can see something I've missed. Initrd unpacking is relatively simple. We unpack the initrd and look for some known binaries inside it. This seems to work OK on all the new-style initrds I tested it against. Finally, in order to run the tests we need binaries from lots of different architectures. Obviously building these is difficult, as it would require a cross-compiler. So instead I've proposed we just add them into the images/ directory. These come "without source", but the source is just: main(){} for the binaries, and (literally) the empty file for the libraries. Hope that doesn't annoy any purists. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
Why not use libmagic for this? This looks like a whole lot of voodoo we don't want to be maintaining. Matt -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team M: +44 (0)7977 267231 GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
On Tue, Jul 28, 2009 at 01:23:07PM +0100, Matthew Booth wrote:
Why not use libmagic for this? This looks like a whole lot of voodoo we don't want to be maintaining.
As I understand it (correct me if I'm wrong), libmagic is just a programmatic way to use file(1), which we already expose. The problems with file are: (a) Requires a lot of further parsing to decode what file means, eg: $ file /bin/ls /bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped ==> "x86-64" (b) Can't look inside anything, specifically initrd files. I think the serious alternative would be to do all of this logic on the host side, eg. in Lib.pm or in a 'virt-arch' utility: http://git.et.redhat.com/?p=libguestfs.git;a=blob;f=TODO;h=291d220ae03fc57cd... This would make it easier to extend in future, since writing parsing code in Perl is infinitely easier than writing it in C. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
On 28/07/09 14:07, Richard W.M. Jones wrote:
On Tue, Jul 28, 2009 at 01:23:07PM +0100, Matthew Booth wrote:
Why not use libmagic for this? This looks like a whole lot of voodoo we don't want to be maintaining.
As I understand it (correct me if I'm wrong), libmagic is just a programmatic way to use file(1), which we already expose.
The problems with file are:
(a) Requires a lot of further parsing to decode what file means, eg:
$ file /bin/ls /bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped ==> "x86-64"
I don't disagree that it's a very unpleasant api. However it does encapsulate a level of testing and coverage which we couldn't possibly hope to achieve. I would be inclined to work with it anyway. It might also be worth raising with upstream that access to the structured data parsed using the magic DB would be desirable. In the mean time, we might have to grep a list of possible strings from source.
(b) Can't look inside anything, specifically initrd files.
It will decompress a file before inspecting it. See file -z, or MAGIC_COMPRESS in libmagic. However, it won't allow you to inspect a single file within a cpio archive. In this case I would extract the file manually, then inspect it using libmagic.
I think the serious alternative would be to do all of this logic on the host side, eg. in Lib.pm or in a 'virt-arch' utility:
http://git.et.redhat.com/?p=libguestfs.git;a=blob;f=TODO;h=291d220ae03fc57cd...
I don't have a strong opinion on host vs appliance. Matt -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team M: +44 (0)7977 267231 GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
participants (2)
-
Matthew Booth -
Richard W.M. Jones