CentOS 7 Headless VirtualBox creation


Notes compiled to document the creation of a VirtualBox headless CentOS 7 VM.

Create VM

Using Virtualbox create new VM
Configure the Virtualbox VM properties to use
  • Redhat/Linux 64-bit
  • Use the CentOS Everything ISO image (find in CentOS-7-x86_64-Everything-1708.iso )
  • Select for a Dynamically allocated 128 GB VMDK (Virtual Machine Disk)
  • Select Manual Partitioning
    1. Select LVM partitioning scheme
    2. Give /home partition 10 GB
    3. Give / (root) partition 114.99 GB
  • Primary Network:
    • Use: Bridge Adapter
    • Use Network Card: Intel PRO/1000 MT Server (82545EM)
  • Add a second Network Adapter.
    1. Network:
      • Use: Host-only Adapter
      • Use Network Card: Intel PRO/1000 MT Server (82545EM)
During installation, refer to the following:
  • Software Selection
    • Base Environment: Infrastructure Server
    • Add-Ons for Selected Environment: Performance Tools
  • Network and Hostname:
    • Turn ON both network interfaces
    • Name the server
  • Security Policy
    • Select: Standard System Security Profile
  • Create User
    • Username: serenity
    • Check make this user administrator

Post creation

  1. Login to the VM and update to latest OS changes:
    sudo yum update -y
    sudo yum upgrade -y
    sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
  2. Give the serenity users ability to work w/o typing password:
    sudo echo "%serenity ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/serenity >/dev/null
  3. In an effort to create a VM that only requires a public key for logon the first question, before login is, what is the VM's IP address. The installation of VirtualBox Guest Addition CD allows for poking the VM instance for its public network interface address.
    1. Prepare for installation
      sudo yum update
      sudo yum install dkms gcc make kernel-devel bzip2 binutils patch libgomp glibc-headers glibc-devel make 
      
      sudo reboot
    2. Back from reboot, Install Guest Additions CD and:
      # install current version of kernel-devel
      # versions also available at /usr/src/kernel
      sudo yum install kernel-devel-`uname -a | awk  '{print $3}'`
      sudo mkdir -p /media/cdrom
      
      sudo mount /dev/scd0 /media/cdrom
      sudo sh /media/cdrom/VBoxLinuxAdditions.run
      More info at: https://unix.stackexchange.com/questions/18435/how-to-install-virtualbox-guest-additions-on-centos-via-command-line-only
  4. Shutdown the VM
  5. Create a "OS Installed" Snapshot for easy rollback, use the following description:
    1. OS Installed and upgraded
    2. serenity as sudoer
    3. Guest Additions CD installed
  6. Restart VM


The following sections are for reference only.

VM IP Address

To get the IP address from the "luna" VM from the Virtualbox host machine open the Windows or PowerShell command line and type the following:
cd C:\Program Files\Oracle\VirtualBox>
.\VBoxManage.exe guestproperty enumerate "luna" --pattens "/VirtualBox/GuestInfo/Net/*/V4/IP"
Name: /VirtualBox/GuestInfo/Net/0/V4/IP, value: xxx.xxx.xxx.xxx, timestamp: 1553000438603082200, flags:
Name: /VirtualBox/GuestInfo/Net/1/V4/IP, value: xxx.xxx.xxx.xxx, timestamp: 1553000438604059802, flags:

Addend Key to new server

Reference : https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/
cat .ssh/id_rsa.pub | ssh serenity@xxx.xxx.xxx.xxx 'mkdir -p .ssh && chmod 700 .ssh && cat >> .ssh/authorized_keys && chmod 644 .ssh/authorized_keys'

Change the hostname

  1. Change the hostname
    hostnamectl status
    sudo hostnamectl set-hostname new-name
  2. Update the hosts file:
    sudo vim /etc/hosts
    ...
    cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 new-name
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  3. References


Comments