Next: , Previous: , Up: Testing and Developing Trip   [Contents][Index]


8.3 Using QEMU for Development and Testing

QEMU can be used directly instead of using Vagrant for creating development and test environments, by setting up the QEMU image similarly to how the Vagrant setup scripts expect the environment to be configured.

  1. Download and startup the QEMU qcow2 image. Ideally download a version that corresponds with the Vagrant box version referenced within the Vagrantfile in the Trip Server source distribution tarball being used.

    Example command to create and start a Fedora server QEMU instance on macOS:

    1. Create the qcow2 image. This example creates the image based on the downloaded qcow2 image as a backing file. (Note that specifying a size is optional. The Fedora base was 6G and the system install completed with 1.5G to spare):
      $ qemu-img create -b Fedora-Server-KVM-38-1.6.x86_64.qcow2 \
      -F qcow2 -f qcow2 fedora-38.qcow2 6G
      
    2. Start the image...

      Fedora example on a Linux host:

      $ sudo qemu-system-x86_64 -name Fedora_38 -M accel=kvm \
      -cpu host -m 2G \
      -drive file=fedora-38.qcow2,if=none,id=hd -device \
      virtio-blk-pci,drive=hd \
      -nic user,hostfwd=tcp::2222-:22,hostfwd=tcp::8080-8080 \
      -nographic
      

      The above example uses the -nographic option which runs the server headless. It also forwards port 2222 on the host to port 22 on the guest, allowing you to SSH into the guest, e.g.:

      $ ssh -p 2222 vagrant@localhost
      

      Fedora example on a macOS host:

      $ sudo qemu-system-x86_64 \
      -name Fedora_38 -M accel=hvf -cpu host -smp cpus=2 -m 2G \
      -drive file=fedora-38.qcow2,if=none,id=hd \
      -vga virtio \
      -device virtio-blk-pci,drive=hd \
      -usb -device usb-tablet -device usb-audio \
      -display cocoa,show-cursor=on \
      -nic vmnet-bridged,ifname=en1
      

      The last line creates a bridged network for the Wi-Fi device named en1. This setting requires the command to be run as root to create the network bridge on the host.

    3. The version of Fedora in the above example uses LVM to manage logical partitions. If you created the image with a larger size than the original backing file, we now need to resize the LVM partition in the container, then resize the file system on the /dev/mapper/sysvg-root partition. Resizing is only required if you specified a size when creating the image and need the additional space.

      If you want to increase the image size subsequently, shutdown the instance and resize it with e.g. qemu-img resize fedora-38.qcow2 +5G to increase the image size by 5G. Then follow these instructions to resize the underlying file system.

      Run sudo parted /dev/vda interactively. The interactive command help provides help on the available commands. Use print free to see the available space. Resize the lvm partition, e.g. resizepart 3 10GB with the third END parameter being whatever then End column shows for the end of the free space. Exit parted with quit. Alternatively, use sudo cfdisk /dev/sda for another interactive command line tool to resize the partition.

      Resize the LVM physical volume with sudo pvresize /dev/vda3. Then resize the volume with sudo lvresize -l100%VG sysvg /dev/vda3. Finally, resize the root file system with sudo xfs_growfs /.

  2. Create a vagrant user in the QEMU instance. On most systems, this will be by using the adduser command.

    On Debian:

    $ sudo adduser vagrant
    

    On FreeBSD, install the bash package with pkg install bash then run adduser interactively with.

  3. Create the vagrant folder that would normally be mapped to the Trip Server source folder.
    # mkdir /vagrant
    # chown vagrant:vagrant /vagrant
    
  4. Upload the trip-server source distribution tarball to the QEMU instance.
  5. Extract the source to the /vagrant folder, e.g.:
    # cd /vagrant
    # su - vagrant -c 'tar -C /vagrant --strip-components=1 \
      -xf /home/vagrant/trip-2.2.2.tar.gz'
    
  6. Execute the Vagrant scripts:
    # bash -x /vagrant/provisioning/bootstrap.sh
    # bash -x /vagrant/provisioning/bootconfig.sh
    

    If all has gone well, trip-server will have been built in the /home/vagrant/build folder and installed at /usr/local/bin/trip-server.

  7. To test the server, open the firewall in the Fedora guest with:
    $ sudo firewall-cmd --add-port=8080/tcp
    $ sudo firewall-cmd --list-ports
    

    You can make the firewall change survive reboots with sudo firewall-cmd --runtime-to-permanent.

    Run trip-server and navigate to the host’s IP address and port 8080 using a browser and the login page should be shown.


Next: , Previous: , Up: Testing and Developing Trip   [Contents][Index]