3

For context, I'm creating a script to simplify the process of creating xen guests. The script uses xen-create-image and uses a bunch of flags to set as many useful settings as possible (distro, vg, root-disk size, IP, etc). This is all on a Debian 10.

I want to know if there's an other Xen tool or configuration I can use to (pre)install certain packages, and set certain settings/configuration files in the newly created guest.

I want to avoid using an image file with all the preinstalled packages and then dd into the new LV, and then have to change hostnames, IP, etc.

Is there such a command or setting?

EDIT: For clarification, I'm using open source Xen 4.11

EDIT 2: I have considered SSH, but apparently xen-create-image does not install and enable openssh-server.

5
  • 1
    Would an answer using Ansible or another similar orchestration toolset be acceptable or must the answer involve a solution provided directly by xenserver?
    – kemotep
    Nov 20, 2019 at 14:55
  • @kemotep I'd like to currently avoid orchestration toolsets as I'm currently creating an "infrastructure" from scratch. But if there's no better way, Puppet (Community edition) is the demanded tool to use. Best part is, I have no idea how to manage a Puppet server. Nov 20, 2019 at 15:01
  • Okay, just to confirm: Are you using the open source version of Xen or Citrix XenServer? Please let us know the version. If you are not aware of the differences: the open source version of Xen is overall nearly identical to Citrix's version. Citrix XenServer has new features and functions that is later added to open source Xen. And Xen lacks the enterprise support contracts of course. Not too different from how Red Hat Enterprise Linux and CentOS's relationship works.
    – kemotep
    Nov 20, 2019 at 15:14
  • @kemotep I'm using open source Xen 4.11. I've edited the question clarifying that. Nov 20, 2019 at 15:21
  • I've discovered the --roles option, which appears to be very close to what I want. Gonna play with that tomorrow. Nov 20, 2019 at 16:47

1 Answer 1

3

I figured it out.

xen-create-image has an option called --role; these roles are defined as sh scripts in /etc/xen-tools/role.d/, and you can create your own, as long as it is executable.

I made a really simple role, just for testing:

#!/bin/sh

prefix=$1

installDebianPackage ${prefix} openssh-server

chroot ${prefix} /bin/systemctl enable ssh
chroot ${prefix} /bin/echo 'PermitRootLogin yes' >> ${prefix}/etc/ssh/sshd_config

prefix=$1 is by default a folder in /tmp/ with a randomly generated name. In here xen-create-image builds the file system and installs packages before putting it in the logical volume or image (or so it seems).

common.sh is a script containing a bunch of functions that xen-create-image uses to build the VM. installDebianPackage is one of those functions, as far as I can read, and this installs packages specified into the VM.

Lines starting with chroot could be commands making sure certain settings are set, adding lines into configuration files and so on. This is a powerful feature of roles, as this makes it possible to run basically any command. systemctl start, systemctl stop, and systemctl restart of course don't work, but systemctl enable does.

In the case of enabling, sshd took about 5 minutes to start after starting the machine, including the boot time and my machine somehow saying "can't process the volume group" 50 times before actually booting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.