lost and found ( for me ? )

How to install libguestfs on Ubuntu 11.04 64bit ver.

[ What’s libguestfs ? ]

libguestfs enables you to modify/edit/view files form VM disk images.
There are many useful commands such as , guestfish , virt-cat , virt-copy-in , vrit-win-reg etc.
What an interesting tool xD

[ How to install libguestfs on Ubuntu11.04 ]

RHEL6 ( CentOS6 , SL6 , Fedora15 ) provides you with libguestfs rpm packages , so you can install libguestfs easily through yum command. On Ubuntu , however , you can’t install it via apt-get. Here’s an explanation of how to install libguestfs on Ubuntu 11.04 64bit ver.
# tail -2 /etc/lsb-release
DISTRIB_CODENAME=natty
DISTRIB_DESCRIPTION="Ubuntu 11.04"

# uname -r
2.6.38-8-server


1.
add the following URLs to /etc/apt/sources.list and install packages which are needed for libguestfs.
# tail -3 /etc/apt/sources.list
# Add for libguestfs
deb http://gb.archive.ubuntu.com/ubuntu/ natty main
deb http://gb.archive.ubuntu.com/ubuntu/ natty universe

# apt-get install libhivex0 btrfs-tools cryptsetup diff libaugeas0 reiserfsprogs zfs-fuse jfsutils lvm2 scrub xfsprogs zerofree

2.
# wget http://libguestfs.org/download/binaries/ubuntu-packages/insmod.static
# cp insmod.static /sbin
# chmod +x /sbin/insmod.static


3.
# ls
febootstrap_3.6-1_amd64.deb        libguestfs-perl_1.11.8-1_amd64.deb
guestfish_1.11.8-1_amd64.deb       libguestfs-tools_1.11.8-1_amd64.deb
guestmount_1.11.8-1_amd64.deb      libguestfs0-dbg_1.11.8-1_amd64.deb
libguestfs-dev_1.11.8-1_amd64.deb  libguestfs0_1.11.8-1_amd64.deb
libguestfs-doc_1.11.8-1_all.deb    python-guestfs_1.11.8-1_amd64.deb


install all deb pakages
# dpkg -i *.deb


get things done :)
# guestfish --version
guestfish 1.11.8

# guestfish

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

Type: 'help' for help on commands
     'man' to read the manual
     'quit' to quit the shell

><fs>


[ How to use ]

- guestfish

mount VM disk image and view/edit files.
mount SL6-vm1’s virtual disk which is off-line VM.
# LANG=C virsh list --all
Id Name                 State
----------------------------------
 - BT5                  shut off
 - SL6-vm1              shut off
 - SL6-vm2              shut off

# guestfish -i -d SL6-vm1

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

Type: 'help' for help on commands
     'man' to read the manual
     'quit' to quit the shell

Operating system: Scientific Linux release 6.0 (Carbon)
/dev/vda1 mounted on /

><fs>


You can check/edit all files in SL6-vm1’s virtual disk
><fs> cat /etc/sysconfig/network
><fs> edit /etc/sysconfig/network
><fs> exit

#


- virt-cat

see a file (/var/log/messages) form a VM which is off-line
# LANG=C virsh list --all
Id Name                 State
----------------------------------
 - BT5                  shut off
 - SL6-vm1              shut off
 - SL6-vm2              shut off

# virt-cat -d SL6-vm1 /var/log/messages | tail -1
Jul  7 17:06:31 SL6-vm1 rsyslogd: [origin software="rsyslogd" swVersion="4.6.2" x-pid="1030" x-info="http://www.rsyslog.com"] exiting on signal 15.


- virt-ls

list /root directory
# virt-ls -d ubuntu-vm1 /root
.bash_history
.bashrc
.cache
.lesshst
.profile
.rnd
.selected_editor
.ssh
bind-9.8.0-P2.tar.gz


[ clone a Linux VM and change hostname and IP addresses before fly clone VM ]

make a clone VM ( original : SL6-vm1 , clone VM : SL6-vm3 )
# virt-clone --original SL6-vm1 --name SL6-vm3 --file /var/disk1/SL6-vm3.img
'SL6-vm3.img' を確保中                               | 9.8 GB     01:46

Clone 'SL6-vm3' created successfully.


change hostname and IPaddress setting of SL6-vm3 with guestfish

mount
# guestfish -i -d SL6-vm3

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

Type: 'help' for help on commands
     'man' to read the manual
     'quit' to quit the shell

Operating system: Scientific Linux release 6.0 (Carbon)
/dev/vda1 mounted on /


change hostname
><fs> edit /etc/sysconfig/network

><fs> cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=SL6-vm3.localdomain


change MAC address from SL6-vm1’s (original VM )to SL6-vm3’s ( clone VM ).

You can check SL6-vm3’s MAC ( clone VM ) through vrish command
# virsh dumpxml SL6-vm3 | egrep "mac address"
     <mac address='00:16:36:13:56:28'/>


SL6-vm1’s MAC ( original VM )
# virsh dumpxml SL6-vm1 | egrep "mac address"
     <mac address='52:54:00:11:18:f1'/>


change red line (52:54:00:11:18:f1 -> 00:16:36:13:56:28 )
><fs> cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="00:16:36:13:56:28"  
NM_CONTROLLED="yes"
ONBOOT="yes"
BOOTPROTO="dhcp"

><fs> cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# net device () (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:13:56:28", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
><fs> quit


fly SL6-vm3
hostname and MAC address were changed.
# virsh start SL6-vm3 –console
Scientific Linux release 6.0 (Carbon)
Kernel 2.6.32-131.2.1.el6.x86_64 on an x86_64

SL6-vm3.localdomain login: root
Password:
Last login: Thu Jul  7 17:03:13 on ttyS0
[root@SL6-vm3 ~]# hostname
SL6-vm3.localdomain

# ifconfig eth0 | head -1
eth0      Link encap:Ethernet  HWaddr 00:16:36:13:56:28

1 comment:

  1. I had to install these packages as well: libsys-virt-perl ntfsprogs ocaml-findlib.
    Using libguestfs0-1.14

    ReplyDelete

Note: Only a member of this blog may post a comment.