Tag Archives: lvm

What’s new for libguestfs

The libguestfs team have been busy adding features over the past few weeks. Here is a quick round-up.

  • Writing to Windows Registry files. We haven’t quite got this feature working yet, but we intend that you’ll be able to “shell into” a Windows Registry and change things:
     $ hivexsh SOFTWARE
      
      Welcome to hivexsh, the hivex interactive shell for examining
      Windows Registry binary hive files.
      
      Type: 'help' for help summary
            'quit' to quit the shell
      
      SOFTWARE\> ls
      ATI Technologies
      Classes
      Clients
      Intel
      Microsoft
      ODBC
      Policies
      RegisteredApplications
      Sonic
      Wow6432Node
      SOFTWARE\> cd \Microsoft\Windows\TabletPC\TabSetup
      SOFTWARE\Microsoft\Windows\TabletPC\TabSetup> ls
      SOFTWARE\Microsoft\Windows\TabletPC\TabSetup> lsval
      "TabletSetup"=dword:00000000"
      SOFTWARE\Microsoft\Windows\TabletPC\TabSetup> cd ..
      SOFTWARE\Microsoft\Windows\TabletPC> ls
      Snipping Tool
      TabSetup
    
  • Rename LVs and VGs. (Guymon’s incredibly convoluted description of how to do this when you don’t have libguestfs inspired me to add lvrename and vgrename commands).
  • C# bindings. This doesn’t mean you can use libguestfs on Windows, but it does mean you can use libguestfs from Mono/Linux.
  • Indian language support. We received Punjabi, Telegu and Oriya translations all at once from the Fedora L10N project so now you can display guestfish in elegant cursive script. “Run a command from the guest filesystem” is “ਗਿਸਟ ਫਾਇਲ-ਸਿਸਟਮ ਤੋਂ ਕਮਾਂਡ ਚਲਾਓ” in Punjabi – how beautiful. The L10N guys work hard doing a pretty thankless job and don’t seem to get much credit for what they do, so thanks guys (and gals).
Advertisements

1 Comment

Filed under Uncategorized

libguestfs 0.8, now with fewer bugs :-)

I released libguestfs 0.8 yesterday, the library for accessing virtual machines. This version fixes a large number of bugs, because I wrote a test suite which sends several hundred commands through the library and verifies the results. Took a couple of days to fix all the bugs this found …

Here are some interesting things you can do with guestfish.

1: Just find out what’s in a virtual machine:

$ guestfish -a RHEL52PV32.img run : list-devices
/dev/sda
$ guestfish -a RHEL52PV32.img run : list-partitions
/dev/sda1
/dev/sda2
$ guestfish -a RHEL52PV32.img run : lvs
/dev/VolGroup00/LogVol00
/dev/VolGroup00/LogVol01

2: Make virtual machine filesystems containing partitions, LVM, filesystems and whatever else you want:

$ guestfish
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.

Type: 'help' for help with commands
      'quit' to quit the shell

><fs> alloc /tmp/test 500M
><fs> run
><fs> pvcreate /dev/sda
><fs> vgcreate VG /dev/sda
><fs> vgs
VG
><fs> lvcreate LV VG 250
><fs> lvs
/dev/VG/LV
><fs> mkfs ext3 /dev/VG/LV
><fs> mount /dev/VG/LV /
><fs> touch /myfile
><fs> ll /
total 13
drwxr-xr-x  3 root root  1024 Apr 12 17:19 .
drwxr-xr-x 18 root root     0 Apr 12 17:15 ..
drwx------  2 root root 12288 Apr 12 17:19 lost+found
-rw-r--r--  1 root root     0 Apr 12 17:19 myfile
><fs> sync
><fs> quit
$ ll /tmp/test
-rw-rw-r--. 1 rjones rjones 524288000 2009-04-12 22:19 /tmp/test
$ file /tmp/test
/tmp/test: LVM2 (Linux Logical Volume Manager) , UUID: bhL0DP0rySspzviDKHN7TZABBcfTWuo

3: Use Augeas to edit configuration files:

$ guestfish -a RHEL52PV32.img -m /dev/VolGroup00/LogVol00
  
  Welcome to guestfish, the libguestfs filesystem interactive shell for
  editing virtual machine filesystems.
  
  Type: 'help' for help with commands
        'quit' to quit the shell
  
><fs> aug-init / 0
><fs> aug-match /augeas/*
/augeas/root
/augeas/save
/augeas/files
><fs> aug-match /files//error
><fs> aug-match /augeas//error
><fs> aug-match /augeas/root/*
><fs> aug-match /files/etc/*
/files/etc/ldap.conf
/files/etc/aliases
/files/etc/yum.repos.d
/files/etc/yum.conf
/files/etc/sysconfig
[etc]
><fs> aug-match /files/etc/hosts/*
/files/etc/hosts/comment[1]
/files/etc/hosts/comment[2]
/files/etc/hosts/1
/files/etc/hosts/2
><fs> cat /etc/hosts               
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1      	       localhost.localdomain localhost
::1		               localhost6.localdomain6 localhost6
><fs> aug-get /files/etc/hosts/comment[1]
Do not remove the following line, or various programs
><fs> help aug-insert
aug-insert - insert a sibling Augeas node
       aug-insert   
  
      Create a new sibling "label" for "path", inserting it into the tree
      before or after "path" (depending on the boolean flag "before").
  
      "path" must match exactly one existing node in the tree, and "label"
      must be a label, ie. not contain "/", "*" or end with a bracketed index
      "[N]".
  
><fs> aug-insert /files/etc/hosts/comment[2] comment false
><fs> aug-match /files/etc/hosts/*
/files/etc/hosts/comment[1]
/files/etc/hosts/comment[2]
/files/etc/hosts/comment[3]
/files/etc/hosts/1
/files/etc/hosts/2
><fs> aug-set /files/etc/hosts/comment[3] HELLO
><fs> aug-save
><fs> cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
# HELLO
127.0.0.1		localhost.localdomain localhost
::1			localhost6.localdomain6 localhost6

There are C, C++, shell, Perl and OCaml bindings for all of these calls, and you don’t need to be root to do any of it.

Leave a comment

Filed under Uncategorized

libguestfs perl bindings

You can now use Perl to examine and modify virtual machine disk images through libguestfs, as in this example:

#!/usr/bin/perl -w
use strict;
use Sys::Guestfs;

# Look for LVM LVs, VGs and PVs in a guest image.

die "Usage: lvs.pl guest.img\n" if @ARGV != 1 || ! -f $ARGV[0];

my $h = Sys::Guestfs->new ();
$h->add_drive ($ARGV[0]);

print "Launching, this can take a few seconds\n";
$h->launch ();
$h->wait_ready ();

print "Looking for PVs on the disk image\n";
my @pvs = $h->pvs ();
print "PVs found: (", join (", ", @pvs), ")\n";

print "Looking for VGs on the disk image\n";
my @vgs = $h->vgs ();
print "VGs found: (", join (", ", @vgs), ")\n";

print "Looking for LVs on the disk image\n";
my @lvs = $h->lvs ();
print "LVs found: (", join (", ", @lvs), ")\n";

Which produces this output:

$ ./lvs.pl RHEL52PV32.img
Creating the libguestfs handle
Launching, this can take a few seconds
Looking for PVs on the disk image
PVs found: (/dev/sda2)
Looking for VGs on the disk image
VGs found: (VolGroup00)
Looking for LVs on the disk image
LVs found: (/dev/VolGroup00/LogVol00, /dev/VolGroup00/LogVol01)

1 Comment

Filed under Uncategorized

libguestfs: LVM support

libguestfs is the library I’m writing that lets you examine and modify any virtual machine disk image, offline or online.

I spent about 18 hours finding a bug in the LVM parsing code, but that bug has now been squashed and as of version 0.4 on the website you can examine PVs, VGs and LVs, as well as listing devices and partitions.

Next up: language bindings for Perl, OCaml and Python.
(C and C++ and shell scripting access already exist).

$ guestfish 

Welcome to guestfish, the libguestfs
filesystem interactive shell for
editing virtual machine filesystems.

Type: 'help' for help with commands
      'quit' to quit the shell

><fs> add /mnt/share/tmp/RHEL52PV32.img
><fs> run
><fs> pvs
/dev/sda2
><fs> lvs
/dev/VolGroup00/LogVol00
/dev/VolGroup00/LogVol01
><fs> mount /dev/VolGroup00/LogVol00 /
><fs> ls /
bin
boot
dev
etc
home
[...]

Leave a comment

Filed under Uncategorized