Skip to content

Instantly share code, notes, and snippets.

@schmich
Last active September 26, 2018 18:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmich/c3b3837a9692304b7fa2669826b58219 to your computer and use it in GitHub Desktop.
Save schmich/c3b3837a9692304b7fa2669826b58219 to your computer and use it in GitHub Desktop.
VirtualBox/CentOS setup

Setup host-only networking

This creates a dedicated network between the host and guest, allowing you to SSH and use other network services without the need of an external router.

  • In VirtualBox, edit VM settings and add a second host-only network adapter
  • Log into the guest VM
  • Run ifconfig, note the new adapter's interface name (like enp0s8)
  • Run nmtui
    • Edit a connection > Add > Ethernet
    • Profile name: Host-only Adapter
    • Device: enp0s8 (interface output from ifconfig)
    • IPv4 configuration:
      • Addresses: 192.168.56.100/24
    • Save new connection
    • Activate the new connection
    • Ensure no other connections appear under the Host-only Network adapter
  • Allow all external connections on the 192.168 subnet:
    • firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source address="192.168.0.0/16" accept'
  • VM should now be accessible from the host via 192.168.56.100

Setup shared folders

This allows you to edit and use files on the host from the guest.

  • Shutdown VM
  • Add shared folder to VM
    • VM > Settings... > Shared Folders
    • Add a new shared folder under `Machine Folders
    • Folder Path: Specify the host path to share
    • Folder Name: Choose a simple identifier, e.g. "project" or "shared"
    • Read-only: no
    • Auto-mount: no
    • Make Permanent: yes
    • Save changes
  • Add CD-ROM device to VM
    • VM > Settings... > Storage
    • Add IDE Controller if one doesn't already exist
    • Under the IDE controller, add an optical drive, choose Leave Empty
    • Save changes
  • Install kernel modules for shared folders
    • Boot VM
    • Once VM is booted, from the menu, choose Devices > Insert Guest Additions CD image...
    • mount /dev/cdrom /mnt/cdrom
    • /mnt/cdrom/VBoxLinuxAdditions.run
      • The installer might complain about not having kernel headers available
      • If so: yum install kernel-devel kernel-devel-3.10.0-693.2.2.el7.x86_64
      • Re-run installer
  • Add shared folder mount to /etc/fstab:
    • project /srv/www/project vboxsf rw,uid=0,gid=0,fmode=0777,dmode=0777 0 0
    • project is the simple identifier you used when adding a shared folder in VirtualBox settings
  • Reboot, shared folder should be available under /srv/www/project

Setup shared folder symlinking

This allows you to create symlinks in a shared folder on the guest. This must be done for each shared folder you have.

  • See this answer for details
  • Important: Shutdown VM and the VirtualBox GUI
  • On the host
    • VBoxManage setextradata VirtualMachineName VBoxInternal2/SharedFoldersEnableSymlinksCreate/project 1
    • VBoxManage getextradata VirtualMachineName enumerate
    • VirtualMachineName is the name of your virtual machine as seen in VirtualBox
    • project is the name of your shared folder in the VM's Shared Folders settings
  • Boot VM
  • On the guest, create a test symlink
    • cd /srv/www/project && ln -s . test
    • rm test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment