On Fri, Mar 14, 2014 at 12:47:08PM +0500, Shumaila Naeem wrote:> Also i can't use the newest version of libguestfs as im on a production > system and i could not use the newest version due to some limitations.You can use the new version without installing it. However you would need to be able to install a compiler and other dependencies, which may not be possible on a production system.> Also the new version is not available in repo. > > > > Im getting antother problem : > > while running these commands im getting error : > guestfish -- add /dev/null : config -set > drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : run : > inspect-os > /dev/ubuntu-1204-vg/root > [root@EQkvm0101 ~]# guestfish -- add /dev/null : config -set > drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : > inspect-get-distro /dev/ubuntu-1204-vg/root > libguestfs: error: no inspection data: call guestfs_inspect_os firstYou have to call inspect-os, and pass the returned value back to inspect-get-distro. This is (to say the least) awkward in guestfish, but much easier if you use a real programming language (libguestfs has many language bindings, see http://libguestfs.org). Also you are missing a call to 'run'. Here's how you could do it in Perl: ------------------------------------------------------------ #!/usr/bin/perl -w use strict; use Sys::Guestfs; my $g = Sys::Guestfs->new (); $g->add_drive_opts ("/dev/null", readonly => 1); # RHEL 6 hack for adding Ceph drives: $g->config ("-set", "drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img"); $g->launch (); my @roots = $g->inspect_os (); if (@roots == 0) { die "no operating systems found"; } my $root = $roots[0]; my $distro = $g->inspect_get_distro ($root); print "distro = $distro\n"; ------------------------------------------------------------ Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
i want to do it remotely through command : although if i use python language the thing works for me you can see the python code>>> import guestfs >>> g = guestfs.GuestFS (python_return_dict=True) >>> g.add_drive_opts ("/dev/null", readonly=1) >>> g.config('-set',"drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img")>>> >>> g.launch() >>> g.inspect_os()['/dev/ubuntu-1204-vg/root']>>> g.inspect_get_distro('/dev/ubuntu-1204-vg/root')'ubuntu' but when i try to do the same from command line it failed: firstly i run command guestfish -- add /dev/null : config -set drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : run : inspect-os this is returning me : /dev/ubuntu-1204-vg/root when i pass this output to get-distro , it failed guestfish -- add /dev/null : config -set drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : run : inspect-get-distro /dev/ubuntu-1204-vg/root libguestfs: error: no inspection data: call guestfs_inspect_os first this time i have called run Regards Shumaila Naeem On Fri, Mar 14, 2014 at 12:59 PM, Richard W.M. Jones <rjones@redhat.com>wrote:> On Fri, Mar 14, 2014 at 12:47:08PM +0500, Shumaila Naeem wrote: > > Also i can't use the newest version of libguestfs as im on a production > > system and i could not use the newest version due to some limitations. > > You can use the new version without installing it. However you would > need to be able to install a compiler and other dependencies, which > may not be possible on a production system. > > > Also the new version is not available in repo. > > > > > > > > Im getting antother problem : > > > > while running these commands im getting error : > > guestfish -- add /dev/null : config -set > > drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : run : > > inspect-os > > /dev/ubuntu-1204-vg/root > > [root@EQkvm0101 ~]# guestfish -- add /dev/null : config -set > > drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : > > inspect-get-distro /dev/ubuntu-1204-vg/root > > libguestfs: error: no inspection data: call guestfs_inspect_os first > > You have to call inspect-os, and pass the returned value back to > inspect-get-distro. This is (to say the least) awkward in guestfish, > but much easier if you use a real programming language (libguestfs has > many language bindings, see http://libguestfs.org). Also you are > missing a call to 'run'. > > Here's how you could do it in Perl: > > ------------------------------------------------------------ > #!/usr/bin/perl -w > > use strict; > use Sys::Guestfs; > > my $g = Sys::Guestfs->new (); > $g->add_drive_opts ("/dev/null", readonly => 1); > # RHEL 6 hack for adding Ceph drives: > $g->config ("-set", > > "drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img"); > $g->launch (); > > my @roots = $g->inspect_os (); > if (@roots == 0) { > die "no operating systems found"; > } > my $root = $roots[0]; > my $distro = $g->inspect_get_distro ($root); > print "distro = $distro\n"; > ------------------------------------------------------------ > > Rich. > > -- > Richard Jones, Virtualization Group, Red Hat > http://people.redhat.com/~rjones > Read my programming blog: http://rwmj.wordpress.com > Fedora now supports 80 OCaml packages (the OPEN alternative to F#) >
On Fri, Mar 14, 2014 at 02:14:48PM +0500, Shumaila Naeem wrote:> but when i try to do the same from command line it failed: > > firstly i run command > > guestfish -- add /dev/null : config -set > drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : run : > inspect-os > > this is returning me : > /dev/ubuntu-1204-vg/root > > when i pass this output to get-distro , it failed > > guestfish -- add /dev/null : config -set > drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : run : > inspect-get-distro /dev/ubuntu-1204-vg/root > libguestfs: error: no inspection data: call guestfs_inspect_os first > > this time i have called runYou're starting a new guestfish process. This creates a completely new handle. Any state in the old handle and old process is lost, so the fact you called inspect-os previously is not relevant. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
See also: http://libguestfs.org/guestfs.3.html#inspection "The call "guestfs_inspect_os" performs inspection and caches the results in the guest handle. Subsequent calls to guestfs_inspect_get_* return this cached information, but do not re-read the disks. If you change the content of the guest disks, you can redo inspection by calling "guestfs_inspect_os" again." Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.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://people.redhat.com/~rjones/virt-df/
On Fri, Mar 14, 2014 at 04:09:23PM +0500, Shumaila Naeem wrote:> is there any way i can run both inspect-os and get-distro in one line > > something like this > guestfish -- add /dev/null : config -set > drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : run : > inspect-get-distro inspect-osNot like this. This is why I said before this is "awkward in guestfish". TBH you're best off continuing with the Python program. If you absolutely must use guestfish (which I don't recommend for this case) then: ---------------------------------------------------------------------- #!/bin/bash - guestfish <<'EOF' add /dev/null readonly:true # RHEL 6 hack for adding Ceph drives: config -set drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img run inspect-os | head -1 > /tmp/root <! echo inspect-get-distro `cat /tmp/root` EOF ---------------------------------------------------------------------- Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.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 KVM guests. http://libguestfs.org/virt-v2v
yes you are right .. i will use python APi's then Thankyou so much for your time and help Regards Shumaila Naeem On Fri, Mar 14, 2014 at 4:38 PM, Richard W.M. Jones <rjones@redhat.com>wrote:> On Fri, Mar 14, 2014 at 04:09:23PM +0500, Shumaila Naeem wrote: > > is there any way i can run both inspect-os and get-distro in one line > > > > something like this > > guestfish -- add /dev/null : config -set > > drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img : run : > > inspect-get-distro inspect-os > > Not like this. This is why I said before this is "awkward in > guestfish". TBH you're best off continuing with the Python program. > If you absolutely must use guestfish (which I don't recommend for this > case) then: > > ---------------------------------------------------------------------- > #!/bin/bash - > > guestfish <<'EOF' > > add /dev/null readonly:true > # RHEL 6 hack for adding Ceph drives: > config -set drive.hd0.file=rbd:ssd-clonetest-rule5/ubuntu-12.04--1.raw.img > > run > > inspect-os | head -1 > /tmp/root > <! echo inspect-get-distro `cat /tmp/root` > > EOF > ---------------------------------------------------------------------- > > Rich. > > -- > Richard Jones, Virtualization Group, Red Hat > http://people.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 KVM guests. > http://libguestfs.org/virt-v2v >