Portal:JeOS:Documentation:libguestfs-tools
JeOS : Customizing openSUSE Leap JeOS images with guestfs-virt-tools
What is guestfs?
guestfs project has a set of tools for manipulating virtual machine images of several formats
You can use a SUSE based machine and 'zypper in guestfs-tools'. The virt-\* series of commands use a minimal image created using supermin and runs it as a qemu "appliance" that will mount the target images and make modifications to the filesystem.
Notes:
guestfs on openSUSE had a bug (boo#1136878) that makes the network dysfunctional as a workaround you can:
sudo vim /usr/lib64/guestfs/supermin.d/packages
add "sysconfig-netconfig" to the package list
remove the old appliance (location is based in the user id number):
rm -rf /var/tmp/.guestfs-0/appliance.d
Running any command will rebuild the appliance.
To check you can run:
virt-rescue --network --scratch -v
This will bring a shell in the appliance where you can check proper DNS entries are added in /etc/resolv.conf
/etc/machine-id initialization
The commands of the virt-\* family initialize "/etc/machine-id", JeOS removes the machine-id at build time and try to reinitiliaze it during firstboot.
If control over the machine-id is desirable you will have to be sure to reset this file before starting the image, for that you can use:
virt-sysprep -a openSUSE-Leap-15.1-JeOS.x86\_64-15.1.0-kvm-and-xen-Snapshot9.124.qcow2 --operations machine-id
If you need more info from the command run you will need to add -v (--verbose) to the command line
You can do a dry-run by using -n (--dry-run), in this mode the changes are discarded after the commands finish
The original appliances run with 500Mb of RAM (the result of command 'guestfish get-memsize') if something more demanding is going to be run use --m MB --memsize MB to determine the amount of RAM necessary
How to customize jeos image:
Resize the virtual disk
JeOS OpenStack image has a virtual disk size of 1GB only, so it can be executed using the "tiny" flavor that by default has a disk size of 1GB.
So if you need more space in the image for offline manipulation you can use the following steps
First you need to create another qcow2 image to receive the expanded copy, this creates a 3Gb empty image:
qemu-img create -f qcow2 openSUSE-Leap-15.1-JeOS.x86\_64-15.1.0-OpenStack-Cloud-Current\_EXPANDED.qcow2 3G
Now we can expand the third partition that is the root of the filesystem:
virt-resize --expand /dev/sda3 openSUSE-Leap-15.1-JeOS.x86\_64-15.1.0-OpenStack-Cloud-Current.qcow2 openSUSE-Leap-15.1-JeOS.x86\_64-15.1.0-OpenStack-Cloud-Current\_EXPANDED.qcow2
Upload and install a single RPM:
virt-customize -v -a openSUSE-Leap-15.1-JeOS.x86\_64-15.1.0-OpenStack-Cloud-Current.qcow2 --upload ./RPM/cloud-init-18.5-5.8.1.x86\_64.rpm:/root/ --run-command="rpm -Uvh /root/cloud-init\*.rpm"
Install latest cloud-init on an image bsc#1119397:
virt-customize -v -a openSUSE-Leap-15.1-JeOS.x86\_64-15.1.0-OpenStack-Cloud-Current.qcow2 --run-command "zypper in -l -y cloud-init cloud-init-config-suse"
Update to latest versions of all packages:
virt-customize -v -a openSUSE-Leap-15.1-JeOS.x86\_64-15.1.0-OpenStack-Cloud-Current.qcow2 --update
Modifying a file in the image, i.e modifying cloud-init conf Example covers how to circumvent bsc#1120349
You can mount the image using 'guestmount':
mkdir mnt\_dir guestmount -i --rw -a openSUSE-Leap-15.1-JeOS.x86\_64-15.1.0-OpenStack-Cloud-Current.qcow2 mnt\_dir vim mnt\_dir/etc/cloud/cloud.cfg
add this, taking care of checking what sections are already there:
system_info: # This will affect which distro class gets used distro: sles # Default user name + that default users groups (if added/used) default_user: name: sles lock_passwd: True gecos: sles Cloud User groups: [cdrom, users] sudo: ["ALL=(ALL) NOPASSWD:ALL"] shell: /bin/bash
save any modifications then just unmount the image
guestunmount mnt\_dir