3

I'm reading the TurnKey Linux 14 documentation and it states that in order to preseed values for an appliance, you have to write them to the file system before the machine boots for the first time.

The most obvious way to do this that I can think of, is to boot the VM to a Live CD and mount the file system in question in order to write the file.

Does VirtualBox contain another way of doing this? For instance using a bash utility of some sort to write an external file to the existing file system?

I believe there was a way to accomplish this on VMWare using vSphere, which is why I am asking.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
leeand00
  • 4,443
  • 10
  • 51
  • 78
  • You can change the virtual hard drive file without the VM being booted (if thats what you want...). What do you want to do exactly? – Wilf Nov 14 '15 at 22:48
  • I'm trying to add `/etc/inithooks.conf` to the vdmk file that I have, so it will skip the interactive prompts asking the user for the values. – leeand00 Nov 14 '15 at 23:07

2 Answers2

3

You can use libguestfs tools to access filesystems in a virtual machine image.

mkdir ~/mnt
guestmount -a /path/to/vm-image.vdi -m /dev/sda1 ~/mnt
… edit files …
fusermount -u ~/mnt

Libguestfs uses QEMU, which may use KVM. KVM and VirtualBox cannot be used at the same time. If you have VirtualBox running, either close it and make sure that the kvm kernel module is loaded, or arrange to run QEMU without KVM. You can make QEMU avoid KVM (slower, but not in a way that matters to just mount the filesystem and edit a few files) by setting LIBGUESTFS_BACKEND_SETTINGS=force_tcg in the environment.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • Didn't know about this +1 - I think my previous method for mucking around with VM disks was to convert them to imgs or something :) – Wilf Nov 19 '15 at 19:51
1

If you are doing this so you can create a customised TurnKey VM that you can redistribute with pre-seeded values, then there is another option that is probably a little less involved (for some).

Boot your VM, run through the first boot scripts manually, create the pre-seeds file as you want it. Then reset the RUN_FIRSTBOOT flag (in /etc/default/inithooks) so that it will re-run the firstboot scripts on next boot (firstboot of your extracted virtual appliance).

Jeremy Davis
  • 777
  • 8
  • 19