Exporting and Importing Virtual Box Images

Problem

Needed to save a virtual box image to be shared with someone else

Solution

Using vboxmanage command line to export the image and then test importing the image.

Steps

  • First list the virtual box images available

imela@whiscardz$ vboxmanage list vms
"test_default_1549514247520_18667" {6e29d56a-6531-4274-9d91-c6719e9fdaf3}
  • Then export the image you want to a file

imela@whiscardz$ vboxmanage export test_default_1549514247520_18667 -o test_default_1549514247520_18667.ova

  • Then copy it to the machine that you want to import the image.
  • Finally import the image.

imela@whiscardz2$ vboxmanage import test_default_1549514247520_18667.ova
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Potential Issues

When I tried exporting to a file name other than the name of the image, it failed and threw the error below (it could be the extention):


imela@whiscardz2$ vboxmanage export test_default_1549514247520_18667 --output otherFileName.ovf
0%...
Progress state: VBOX_E_IPRT_ERROR
VBoxManage: error: Appliance write failed
VBoxManage: error: RTVfsFsStrmAdd failed for 'otherFileName.ovf' (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component ApplianceWrap, interface IAppliance
VBoxManage: error: Context: "RTEXITCODE handleExportAppliance(HandlerArg*)" at line 1263 of file VBoxManageAppliance.cpp

References

How to export and import VirtualBox VM images?

VBoxManage registervm/unregistervm

Export to OVF

VBoxManage export

VBoxManage import

virtualbox commandline options

Update 2019-01-15

Problem

Also needed to delete virtual box images that were not being used via the command line

Solution

  • First list the vms

$ VBoxManage list vms
"20180126" {00953737-12d0-49eb-a1d2-c749047ccacf}
"1519895285801_90671" {ac82a1dc-ef6b-40de-8a35-ce4dbee3e6e3}
"1522057779833_1088" {87021084-3202-4131-8f9c-5839774140a8}
  • Use the unregistervm flag along with the –delete option to delete the vm and it’s associated files.

$ vboxmanage unregistervm {ac82a1dc-ef6b-40de-8a35-ce4dbee3e6e3} --delete
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Problem

Needed a way to be able to start and stop GuestOS on virtualbox using the commandline.

Solution

  • First list the vms

$ VBoxManage list runningvms
"academy_default_1522238466753_84362" {3a36e205-e8e2-4a96-b9c3-9f76f2ad17e5}

Here are some more options that can be used with the list command. NB If your vm was started with a specific user then running list without switching to the user that started the vm causes the result to be blank:


~$ vboxmanage list
Usage:

VBoxManage list [--long|-l] [--sorted|-s] vms|runningvms|ostypes|hostdvds|hostfloppies|
intnets|bridgedifs|hostonlyifs|natnets|dhcpservers|
hostinfo|hostcpuids|hddbackends|hdds|dvds|floppies|
usbhost|usbfilters|systemproperties|extpacks|
groups|webcams|screenshotformats

  • Then shutdown the vms

~$ vboxmanage controlvm "academy_default_1522238466753_84362" poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
:~$ vboxmanage list runningvms
:~$

References

vboxmanage command line options

How to safely shutdown Guest OS in VirtualBox using command line

How to automatically start and shut down VirtualBox machines?

VBoxManage control and manage Virtualbox from command line

How to run VirtualBox virtual machines from the command line

VBoxManage registervm/unregistervm or delete vm

 

Pound Gateway Won’t Start on CentOS 7

Problem

I had Setup the pound gateway as per the steps here. The issue was that the gateway wasn’t starting. The following error was on the log:

Sep 7 15:09:49 localhost systemd: Starting Pound Reverse Proxy And Load-balancer...
Sep 7 15:09:49 localhost pound: starting...
Sep 7 15:09:50 localhost pound: get_host(192.168.56.101, res, 0)
Sep 7 15:09:50 localhost pound: getaddrinfo OK
Sep 7 15:09:50 localhost pound: ret OK
Sep 7 15:09:50 localhost pound: done
Sep 7 15:09:50 localhost pound: get_host(192.168.56.101, res, 0)
Sep 7 15:09:50 localhost pound: getaddrinfo OK
Sep 7 15:09:50 localhost pound: ret OK
Sep 7 15:09:50 localhost pound: done
Sep 7 15:09:50 localhost pound: get_host(192.168.56.102, res, 0)
Sep 7 15:09:50 localhost pound: getaddrinfo OK
Sep 7 15:09:50 localhost pound: ret OK
Sep 7 15:09:50 localhost pound: done
Sep 7 15:09:50 localhost pound: get_host(192.168.56.103, res, 0)
Sep 7 15:09:50 localhost pound: getaddrinfo OK
Sep 7 15:09:50 localhost pound: ret OK
Sep 7 15:09:50 localhost pound: done
Sep 7 15:09:50 localhost systemd: Failed to read PID from file /var/run/pound.pid: Invalid argument
Sep 7 15:11:19 localhost systemd: pound.service operation timed out. Terminating.
Sep 7 15:11:19 localhost systemd: Failed to start Pound Reverse Proxy And Load-balancer.
Sep 7 15:11:19 localhost systemd: Unit pound.service entered failed state.

Solution

According to this mailing list, the solution is to edit the file pound.service shown below and remove the line with something like PID.

After editing, the file should have the following:

[root@localhost ~]# cat /usr/lib/systemd/system/pound.service
[Unit]
Description=Pound Reverse Proxy And Load-balancer
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/usr/sbin/pound

[Install]
WantedBy=multi-user.target 

Resources

[Pound Mailing List] pound won’t start

When i try to logon to my WordPress Backend with pound in front it tells me this error “You do not have sufficient permissions to access this page.”

 

Load Balancing — Pound Gateway

Setup

Guest OS – CentOS 7

Configure Load Balancer

  • Enable the EPEL repository.
  • Install pound on the Load Balance Server. In my case this is on IP 192.168.56.101
[root@localhost ~]# yum install pound
  • Configure pound
[root@localhost ~]# vim /etc/pound.cfg
vim /etc/pound.cfg
pound config file

NB:// Remember to add the http service to the firewall as detailed below. Otherwise this will happen.

  • Add pound to chkconfig so it starts at bootup:
[root@localhost]# systemctl is-enabled pound
disabled
[root@localhost]# systemctl enable pound
ln -s '/usr/lib/systemd/system/pound.service' '/etc/systemd/system/multi-user.target.wants/pound.service'
[root@localhost]# systemctl is-enabled pound
enabled

Configure Back End Servers

  • Install apache and php
[root@localhost ~]# yum install --disablerepo="*" --enablerepo="LocalRepo" httpd

[root@localhost ~]# yum install --disablerepo="*" --enablerepo="LocalRepo" php
  • Edit apache config so webserver listens to traffic on static IP
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
vim /etc/httpd/conf/httpd.conf
Apache Config File
  • Create a sample web page on Backend server(s)
[root@localhost ~]# vim /var/www/html/index.html
sample_webpage
sample_webpage
  • change ownership of the index.html file:
[root@localhost ~]# chown apache:apache /var/www/html/index.html
  • Restart Apache
[root@localhost ~]# service httpd restart

Out of the box, enterprise Linux distributions such as CentOS or RHEL come with a powerful firewall built-in, and their default firewall rules are pretty restrictive. Thus if you install any custom services (e.g., web server, NFS, Samba), chances are their traffic will be blocked by the firewall rules. You need to open up necessary ports on the firewall to allow their traffic.

NB: We are adding the service to the public zone since its the active zone. Check active zones so you know which zone to add the service.  See this as well.

[root@localhost jeremy]# firewall-cmd --get-active-zones
public
 interfaces: enp0s3 enp0s8
[root@localhost jeremy]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@localhost jeremy]# firewall-cmd --reload
success
  • Then start pound:
[root@localhost ~]# service pound restart
  • Go to the Host OS browser and enter IP of the Load balancer server IP. You should see Server 1 and Server 2’s webpages being served.

Resources

Pound (networking)

POUND – REVERSE-PROXY AND LOAD-BALANCER

Pound : HTTP Load Balancing

Simple Apache Load Balancing – Pound RPM

Linux install and configure pound reverse proxy for Apache http / https web server

Pound Gateway & Config Directives Explained

Lighttpd & Config Directives Explained

A few ways to configure Linux firewalld

RHEL 7 / CentOS 7: How to get started with Firewalld

RHEL7: How to get started with Firewalld.

How to open a port in the firewall on CentOS or RHEL

Virtual Box Connect to HTTP Server on Guest OS

Problem

I have a Guest OS on Virtual Box, running on Ubuntu based Host OS. I can ping and ssh into my CentOS 7 Guest OS from the host after using the Host Only Networking option on Virtual Box.

The problem came in when I tried reaching the Guest OS’s IP on the Host OS web browser. I’d get this error:

Host OS Web Browser
Host OS Web Browser

Telnet from the host to the Guest IP gave the following error:

telnet 192.168.56.102 80 telnet: Unable to connect to remote host: No route to host
Telnet Result of Host-to-Guest

Troubleshooting

  • Check if port is Open and if firewall is running on Guest OS
check-port-firewall-on-guest-OS
check if-port is open-firewall-running-on-guest-OS
  • Tried to telnet port from Guest OS
telnet-from-guestOS
telnet-from-guestOS successful
  • Tried to ping Guest IP from the Host IP and this was successful:
ping-host-to-guest
ping-host-to-guest

Solution

After some doodling, found this pointer.

Starting with CentOS and RHEL 7, firewall rule settings are managed by firewalld service daemon. A command-line client called firewall-cmd can talk to this deamon to update firewall rules permanently.

service firewalld status
centos firewalld was running

So after stopping firewalld, I was able to telnet to port 80 and also get a response on the web browser:

service firewalld stop
stop-firewalld
telnet-host-to-guest successful
telnet-host-to-guest successful
host-web-browser
host-web-browser

NB:// Another alternative to stopping the firewall, is open up the http service/port on the firewall. This can be achieved as explained here.

Resources

Virtualbox: How to access web server on guest OS from the host OS?

A few ways to configure Linux firewalld

RHEL 7 / CentOS 7: How to get started with Firewalld

RHEL7: How to get started with Firewalld.

How to open a port in the firewall on CentOS or RHEL

Networking in Virtual Box

Problem

I needed to install packages from the Internet as well as from the Local Repository. I had only 1 Interface i.e. Host Only Interface on my Guest OS which is CentOS.

Solution

From the Host OS (In my case an ubuntu distro):

  • Open the Virtual Box Manager and select the Guest OS, e.g in my case Guest OS 1, then click on Settings, then Network.
Settings on Virtual Box Manager
Virtual Box Manager
Click on Adapter 2 and select attached to Host Only
Host Only Adapter 2
  • Click on ok and boot up your Guest OS and you should be able to connect to the internet as well as reach the Guest OS’s static IP.

Notes

Bridged Networking: Bridged Networking is used when you want your vm to be a full network citizen, i.e. to be an equal to your host machine on the network.

Internal Networking: When you configure one or more vm’s to sit on an Internal network, VirtualBox ensures that all traffic on that network stays within the host and is only visible to vm’s on that virtual network.

Port-Forwarding with NAT Networking

Resources

Host-Only Networking With VirtualBox

Networking in VirtualBox

VirtualBox: Configuring Static IPs for VMs

Virtual networking

 

 

Using Local YUM repository on CentOS 7

Problem

I have the CentOS 7 complete DVD ISO and need to install packages from this ISO instead of via the internet.

Solutions

Only allow installations via DVD Rom:

  • Mount the DVD ROM as described here.
  • Create a Local Repository File called local.repo as below:
# vi /etc/yum.repos.d/local.repo

Add the following lines to the file:

Local Repository File Details
Local Repo File Details

NB:// gpgcheck is optional but you are advised to use it. To use it set value to 1 and add as shown below:

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Also baseurl depends on where your cd/dvd is mounted in my case its as above.

  • Remove (# rm *.repo) the other .repo file(s) (all except local.repo) in the location /etc/yum.repos.d/
  • Then clear the repository cache and update using:
#yum clean all
#yum update
  • Test installing a package:
yum install screen
Testing Local Repository Installation

Disabling Other Repos and Only Using LocalRepo

    • Add the local.repo file to /etc/yum.repos.d/ with the details described above or as below:
Local Repository File
Local Repository File
    • Then clear the repository cache and then update using
#yum clean all
#yum update
#yum install --disablerepo="*" --enablerepo="LocalRepo" vim

NB:// The Name LocalRepo is case sensitive so it should be the same name as the name in the header [] tag in your local.repo file in /etc/yum.repos.d

yum install --disablerepo=
Installing Package from Local Repository

Resources

Setup Local Yum Repository On CentOS 7

Create Local YUM repository on CentOS 7 / RHEL 7 using DVD

Creating a Local Yum Repository Using an ISO Image

How To Enable EPEL Repository in RHEL/CentOS 7/6/5?

Installing Guest Additions on Linux Host

Setup

  • Download the Guest Additions ISO from here. You will need to select the Version you want from the list as suggested here.
  • On the Linux host, in my case an ubuntu based distro:
On Host OS install dkms
Virtual Box Host OS
  • On Guest OS, in my case CentOS 7 minimal install. You will need to install bzip2, gcc, kernel-devel:
# yum update
# yum install bzip2
# yum install gcc
# yum install kernel-devel
cd to /media/cdrom --> sh ./VBoxLinuxAdditions.run
Installing Guest Additions
Guest Additions Installation Progress
Guest Additions Installation Progress

Resources

Guest Additions for Linux

VirtualBox Guest Additions ISO Download?

Index of /virtualbox

Installing the VirtualBox Guest Additions on Windows Host

Switching Between Virtual Box ISO on Linux Host

Problem

Needed to switch between mounting 2 ISOs on a Centos Guest in Virtual Box without having to restart.

Solution

  • Umount drive from guest OS:
    #umount /media/cdrom
    
    
  • From the booted CentOS guest select “Devices” then:

Devices->CD/DVD Devices -> Remove Disk From Virtual Drives

  • Incase of Error Below, force unmount:
Click Force Umount Button
Umount Virtual Drive
  • Double Check that Drive has been unmounted:
Confirm Virtual Drive Umounted
Unmounted Virtual Drive
  • Mount New Image, From the Guest OS, select Devices, then:
Devices-->CD/DVD Devices-->
Mounting New Virtual Drive
  • From the terminal window on the guest OS, mount the New ISO in this case Guest Additions as described here and also shown below:
mount cd/dvd drive on guest OS
Run the above on Guest OS

Resources

How to Mount and Unmount an ISO Image in RHEL/CentOS/Fedora and Ubuntu

How to Mount CDROM Media on CentOS 5/CentOS 6/CentOS 7