<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.define-technology.com/mediawiki-1.35.0/index.php?action=history&amp;feed=atom&amp;title=Containerised_guestfish</id>
	<title>Containerised guestfish - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.define-technology.com/mediawiki-1.35.0/index.php?action=history&amp;feed=atom&amp;title=Containerised_guestfish"/>
	<link rel="alternate" type="text/html" href="http://wiki.define-technology.com/mediawiki-1.35.0/index.php?title=Containerised_guestfish&amp;action=history"/>
	<updated>2026-05-04T20:19:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.0</generator>
	<entry>
		<id>http://wiki.define-technology.com/mediawiki-1.35.0/index.php?title=Containerised_guestfish&amp;diff=29664&amp;oldid=prev</id>
		<title>Mariusz: Add basic usage description and how to use containerised guestfish for editing instance disks</title>
		<link rel="alternate" type="text/html" href="http://wiki.define-technology.com/mediawiki-1.35.0/index.php?title=Containerised_guestfish&amp;diff=29664&amp;oldid=prev"/>
		<updated>2020-01-09T10:47:36Z</updated>

		<summary type="html">&lt;p&gt;Add basic usage description and how to use containerised guestfish for editing instance disks&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Basic usage ==&lt;br /&gt;
&lt;br /&gt;
The basic command for &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
docker run --rm -it --entrypoint /bin/bash -v &amp;lt;your-image&amp;gt;:/image:rw registry.vscaler.com:5000/docker-guestfish:latest&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Then, when inside the container, run:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
guestfish --rw -a /image&lt;br /&gt;
run&lt;br /&gt;
list-filesystems&lt;br /&gt;
... (mount the filesystem as /, view and edit files, etc.)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Replace &amp;lt;code&amp;gt;rw&amp;lt;/code&amp;gt; in the below commands with &amp;lt;code&amp;gt;ro&amp;lt;/code&amp;gt; if you only want to view the content of the image without editing files inside.&lt;br /&gt;
&lt;br /&gt;
Aside from guestfish, this Docker image contains &amp;lt;code&amp;gt;qemu-img&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;virt-customize&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;virt-v2v&amp;lt;/code&amp;gt; (for converting VMware images to QCOW, see: http://docs.vscaler.com/vscaler-docs/user-guide/_build/html/useful-tips/import-vmdk-from-vmware.html).&lt;br /&gt;
&lt;br /&gt;
== Editing instance disks ==&lt;br /&gt;
Containerised guestfish may come in handy when you want to edit files inside an instance but don&amp;#039;t have SSH access to the instance (so, for example, when you need to edit &amp;lt;code&amp;gt;/etc/shadow&amp;lt;/code&amp;gt; to set/change the root password).&lt;br /&gt;
&lt;br /&gt;
Find out on which hypervisor your instance lives (&amp;lt;code&amp;gt;openstack server show &amp;lt;instance-name-or-uuid&amp;gt; | grep hyper&amp;lt;/code&amp;gt;) and locate its disk file. For example &amp;lt;code&amp;gt;/var/lib/docker/volumes/nova_compute/_data/instances/5893ad03-42d5-43fb-b9a1-349f97d49e2b/disk&amp;lt;/code&amp;gt; is the disk file of instance with UUID &amp;lt;code&amp;gt;5893ad03-42d5-43fb-b9a1-349f97d49e2b&amp;lt;/code&amp;gt; (Glance is using the file backend here).&lt;br /&gt;
TODO: Describe how to retrieve disk files from Ceph RBD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red; font-weight:bold&amp;quot;&amp;gt;BEFORE PROCEEDING SHUT DOWN YOUR INSTANCE AND CREATE A BACKUP OF ITS DISK FILE!&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First, mount the disk file as described in the &amp;quot;Basic usage&amp;quot; section and run &amp;lt;code&amp;gt;qemu-img info /image&amp;lt;/code&amp;gt;. Here is an example of the output:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
# qemu-img info /image&lt;br /&gt;
image: /image&lt;br /&gt;
file format: qcow2&lt;br /&gt;
virtual size: 80G (85899345920 bytes)&lt;br /&gt;
disk size: 30G&lt;br /&gt;
cluster_size: 65536&lt;br /&gt;
backing file: /var/lib/nova/instances/_base/3c09392e65a56cc2c6ba5db1bd91601ae5a355c1&lt;br /&gt;
Format specific information:&lt;br /&gt;
    compat: 1.1&lt;br /&gt;
    lazy refcounts: false&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
As your image also has the &amp;quot;backing file&amp;quot; property, you&amp;#039;ll need to locate it in &amp;lt;code&amp;gt;/var/lib/docker/volumes/nova_compute/_data/instances/_base/&amp;lt;/code&amp;gt; and then mount it in the container in the location specified by the property (Feel free to also backup the backing file, just in case). Here are commands for mounting this sample image in a (temporary) guestfish container:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
export IMAGE=/var/lib/docker/volumes/nova_compute/_data/instances/5893ad03-42d5-43fb-b9a1-349f97d49e2b/disk&lt;br /&gt;
export IMAGE_BASE=/var/lib/docker/volumes/nova_compute/_data/instances/_base/3c09392e65a56cc2c6ba5db1bd91601ae5a355c1&lt;br /&gt;
export IMAGE_LOC=/var/lib/nova/instances/_base/3c09392e65a56cc2c6ba5db1bd91601ae5a355c1&lt;br /&gt;
docker run --rm -it --entrypoint /bin/bash -v ${IMAGE}:/image:rw -v ${IMAGE_BASE}:${IMAGE_LOC}:ro registry.vscaler.com:5000/docker-guestfish:latest&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again, &amp;lt;span style=&amp;quot;color:red; font-weight:bold&amp;quot;&amp;gt;BACKUP THE DISK FILE (cp -a, rsync -avz, etc.) BEFORE DOING ANYTHING WITH IT.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When inside, run &amp;lt;code&amp;gt;guestfish --rw -a /image&amp;lt;/code&amp;gt;, then &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt;, mount the filesystem, view and edit files, etc.&lt;br /&gt;
&lt;br /&gt;
=== Merging images ===&lt;br /&gt;
Alternatively, you can merge your backing file with the main image to create a snapshot of the disk file.&lt;br /&gt;
&lt;br /&gt;
First of all, copy your main disk file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red; font-weight:bold&amp;quot;&amp;gt;MERGING IS A DESTRUCTIVE OPERATION, SO DON&amp;#039;T DO IT DIRECTLY ON THE ORIGINAL DISK FILE!&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then mount this copy and the backing file in a container:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
export IMAGE=&amp;lt;copy-of-your-main-disk-file&amp;gt;&lt;br /&gt;
export IMAGE_BASE=&amp;lt;backing-file-of-the-main-disk-file&amp;gt;&lt;br /&gt;
export IMAGE_LOC=&amp;lt;backing-image-location-from-the-backing-image-property&amp;gt;&lt;br /&gt;
docker run --rm -it --entrypoint /bin/bash -v ${IMAGE}:/image:rw -v ${IMAGE_BASE}:${IMAGE_LOC}:ro -e IMAGE_LOC=${IMAGE_LOC} registry.vscaler.com:5000/docker-guestfish:latest&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Inside the container run the following commands to merge the images (this will take a while):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
qemu-img rebase -b ${IMAGE_LOC} /image&lt;br /&gt;
qemu-img commit /image&lt;br /&gt;
qemu-img info /image&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the container, add the resulting image to Glance and launch an instance off of this snapshot.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
# http://libguestfs.org/guestfish.1.html&lt;br /&gt;
# http://openstack.10931.n7.nabble.com/Migrating-KVM-VM-to-Openstack-td8004.html&lt;br /&gt;
# https://stackoverflow.com/questions/22913384/transforming-qcows2-snapshot-plus-backing-file-into-standalone-image-file&lt;/div&gt;</summary>
		<author><name>Mariusz</name></author>
	</entry>
</feed>