How to create a CentOS7 Virtual Machine (box) using packer

Hi, It's my first time trying to build a CentOS7 box using packer but I'm not having much success.  As can be seen from the following the VM will not start.  Anyone able to guide me to where the problem may be?

packer build centos-7.0-x86_64.json
centos-7.0-x86_64 output will be in this color.
==> centos-7.0-x86_64: Downloading or copying Guest additions
    centos-7.0-x86_64: Downloading or copying: file:///usr/share/virtualbox/VBoxGuestAdditions.iso
==> centos-7.0-x86_64: Downloading or copying ISO
    centos-7.0-x86_64: Downloading or copying: http://10.10.10.10/iso/CentOS-7-x86_64-DVD-1503-01.iso
==> centos-7.0-x86_64: Starting HTTP server on port 8695
==> centos-7.0-x86_64: Creating virtual machine...
==> centos-7.0-x86_64: Creating hard drive...
==> centos-7.0-x86_64: Creating forwarded port mapping for SSH (host port 2554)
==> centos-7.0-x86_64: Executing custom VBoxManage commands...
    centos-7.0-x86_64: Executing: modifyvm centos-7.0-x86_64 --memory 512
    centos-7.0-x86_64: Executing: modifyvm centos-7.0-x86_64 --cpus 1
==> centos-7.0-x86_64: Starting the virtual machine...
==> centos-7.0-x86_64: Error starting VM: VBoxManage error:
==> centos-7.0-x86_64: Unregistering and deleting virtual machine...
==> centos-7.0-x86_64: Deleting output directory...
Build 'centos-7.0-x86_64' errored: Error starting VM: VBoxManage error:
==> Some builds didn't complete successfully and had errors:
--> centos-7.0-x86_64: Error starting VM: VBoxManage error:
==> Builds finished but no artifacts were created.


cat centos-7.0-x86_64.json
{
    "builders": [{
        "name": "centos-7.0-x86_64",
        "vm_name": "centos-7.0-x86_64",
        "type": "virtualbox-iso",
        "virtualbox_version_file": ".vbox_version",
        "headless": "false",
        "guest_os_type": "RedHat_64",
        "disk_size": 40960,
        "iso_url": "http://10.10.10.10/iso/CentOS-7-x86_64-DVD-1503-01.iso",
        "iso_checksum": "99e450fb1b22d2e528757653fcbf5fdc",
        "iso_checksum_type": "md5",
        "http_directory": "/client_files/vagrant/template",
        "boot_command": [
          "<enter>",
          "<wait>",
          "<wait>",
          "text ks=http://{{.HTTPIP}}:{{.HTTPPort}}/client_files/vagrant/template/template.cfg",
          "<enter>"
        ],
        "boot_wait": "10s",
        "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
        "ssh_username": "vagrant",
        "ssh_password": "vagrant",
        "ssh_port": 22,
        "ssh_wait_timeout": "10000s",
        "vboxmanage": [
            ["modifyvm", "{{.Name}}", "--memory", "512"],
            ["modifyvm", "{{.Name}}", "--cpus", "1"]
        ],
        "shutdown_command": "echo 'vagrant'|sudo -S /sbin/halt -h -p"
    }],
    "post-processors": [{
        "output": "build/centos-7.0-x86_64.box",
        "type": "vagrant"
    }],
    "provisioners": [{
        "type": "shell",
        "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
        "scripts": [
            "/home/vagrant/vagrant.sh",
            "/home/vagrant/vboxguest.sh",
            "/home/vagrant/compact.sh"
        ]
    }]
}


cat /opt/kickstart/client_files/vagrant/template/template.cfg
#Do not install X system
skipx

#System  language
lang en_IE.UTF-8

#System keyboard
keyboard uk

#Sytem timezone
timezone --utc Europe/Dublin --isUtc

#Root password (password)
rootpw --iscrypted $6$EuNkX8.qySOfn4XH$N9ZKBMtQJHMMtgytbtIX7/sUEZRIvtNaU9WRRwzrKuS7ioj5YXS01wq4543h5E24vCQYvcooP58ZK30YhOmLS1

#Reboot after installation
reboot

#Install OS instead of upgrade
install

#System bootloader configuration
bootloader --location mbr --append "rhgb quiet"

#Clear the Master Boot Record
zerombr

#Partition clearing information
clearpart --all --initlabel
#Partioning information
part /boot      --fstype ext2   --size=200
part swap                       --size=2000
part pv.01      --fstype ext4   --size=1 --grow
#LVM information
volgroup sysvg pv.01
logvol /        --vgname=sysvg --size=1  --grow --name=lv_root

#Network information
#network --device link --bootproto dhcp --hostname centos7.0-template

#Firewall configuration
firewall --disabled

#SELinux configuration
selinux --permissive

#Package install information
%packages --ignoremissing
@Base
@Core
@Development Tools
kernel-devel
%end

%post
#!/bin/sh

## Allow root ssh
sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config

## Misc
wget -O/etc/pki/tls/certs/ca-bundle.crt http://curl.haxx.se/ca/cacert.pem
groupadd vagrant -g 999
useradd vagrant -g vagrant -G wheel -u 900
echo "vagrant" | passwd --stdin vagrant
echo "vagrant        ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers

%end
micktAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Zephyr ICTCloud ArchitectCommented:
Are you able to create a VM manually in Virtualbox and run it without issues?
Did you enable the VT-x settings in the BIOS of the host?
You can run packer with the "-debug" switch, you'll get asked questions at the end and might see a more specific error in Virtualbox this way... So it can help in pinpointing the issue.
0
micktAuthor Commented:
vboxmanage list runningvms
"kolla-ol_default_1435243979149_85470" {7a69ebb5-1796-43f3-89e0-ea1475e539e7}
"o3l_default_1435309497200_60836" {685d1207-a70e-442a-9807-8a16a05d8af3}


I didn't know to use debug.  Did so but have to say, it doesn't help too much.

packer build -debug centos-7.0-x86_64.json
Debug mode enabled. Builds will not be parallelized.
centos-7.0-x86_64 output will be in this color.

==> centos-7.0-x86_64: Downloading or copying Guest additions
    centos-7.0-x86_64: Downloading or copying: file:///usr/share/virtualbox/VBoxGuestAdditions.iso
==> centos-7.0-x86_64: Pausing after run of step 'StepDownloadGuestAdditions'. Press enter to continue.
==> centos-7.0-x86_64: Downloading or copying ISO
    centos-7.0-x86_64: Downloading or copying: http://10.169.107.0/iso/CentOS-7-x86_64-DVD-1503-01.iso
==> centos-7.0-x86_64: Pausing after run of step 'StepDownload'. Press enter to continue.
==> centos-7.0-x86_64: Pausing after run of step 'StepOutputDir'. Press enter to continue.
==> centos-7.0-x86_64: Pausing after run of step 'StepCreateFloppy'. Press enter to continue.
==> centos-7.0-x86_64: Starting HTTP server on port 8663
==> centos-7.0-x86_64: Pausing after run of step 'StepHTTPServer'. Press enter to continue.
==> centos-7.0-x86_64: Pausing after run of step 'StepSuppressMessages'. Press enter to continue.
==> centos-7.0-x86_64: Creating virtual machine...
==> centos-7.0-x86_64: Pausing after run of step 'stepCreateVM'. Press enter to continue.
==> centos-7.0-x86_64: Creating hard drive...
==> centos-7.0-x86_64: Pausing after run of step 'stepCreateDisk'. Press enter to continue.
==> centos-7.0-x86_64: Pausing after run of step 'stepAttachISO'. Press enter to continue.
==> centos-7.0-x86_64: Pausing after run of step 'StepAttachGuestAdditions'. Press enter to continue.
==> centos-7.0-x86_64: Pausing after run of step 'StepAttachFloppy'. Press enter to continue.
==> centos-7.0-x86_64: Creating forwarded port mapping for SSH (host port 4269)
==> centos-7.0-x86_64: Pausing after run of step 'StepForwardSSH'. Press enter to continue.
==> centos-7.0-x86_64: Executing custom VBoxManage commands...
    centos-7.0-x86_64: Executing: modifyvm centos-7.0-x86_64 --memory 512
    centos-7.0-x86_64: Executing: modifyvm centos-7.0-x86_64 --cpus 1
==> centos-7.0-x86_64: Pausing after run of step 'StepVBoxManage'. Press enter to continue.
==> centos-7.0-x86_64: Starting the virtual machine...
==> centos-7.0-x86_64: Error starting VM: VBoxManage error:
==> centos-7.0-x86_64: Pausing before cleanup of step 'StepVBoxManage'. Press enter to continue. ^C
==> centos-7.0-x86_64: Unregistering and deleting virtual machine...
==> centos-7.0-x86_64: Deleting output directory...
0
Zephyr ICTCloud ArchitectCommented:
I assume you had Virtualbox open when you ran the packer with debug? Is there a log for the vm by any chance? (usually somewhere in $HOME/.VirtualBox/Machines/<vm name>/Logs)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

micktAuthor Commented:
What do you mean by "Virtualbox open"? I have no GUI on my server; use vboxmange etc.

 I can't find a log.
0
Zephyr ICTCloud ArchitectCommented:
Shouldn't this option be said to 'true' then? Otherwise it will try to start a console by default.

"headless": "false",
0
micktAuthor Commented:
Yes, I it probably should.

==> centos-7.0-x86_64: Starting the virtual machine...
    centos-7.0-x86_64: WARNING: The VM will be started in headless mode, as configured.
    centos-7.0-x86_64: In headless mode, errors during the boot sequence or OS setup
    centos-7.0-x86_64: won't be easily visible. Use at your own discretion.
==> centos-7.0-x86_64: Waiting 10s for boot...
==> centos-7.0-x86_64: Typing the boot command...
==> centos-7.0-x86_64: Waiting for SSH to become available...

Waiting .........
0
micktAuthor Commented:
I found the log.  It wasn't quite created when I checked earlier.  Hopefully I'll find something useful in it that will assist.  Cheers.  I'll get back to you later.
0
Zephyr ICTCloud ArchitectCommented:
OK, good luck!
0
micktAuthor Commented:
It is failing here.

==> centos-7.0-x86_64: Waiting for SSH to become available...
==> centos-7.0-x86_64: Timeout waiting for SSH.

I don't see anything in the log that is helping me.  is there something useful to grep for?  It's a large file so can't paste it here.
0
Zephyr ICTCloud ArchitectCommented:
You could look for "TCP connection to SSH" or just "ssh" ...

While it is waiting for the ssh connection, did you test if the machine was reachable manually? Ping, SSH ??? From another Terminal window maybe...

Another thing to try is to remove "ssh_port": 22,

-- You could zip the log and post it here, if that is a possibility...
0
micktAuthor Commented:
I looked for ssh in the log but there is no reference anywhere, which is strange.

I didn't think to do so; just tried now.

From vboxmanage showvminfo centos-7.0-x86_64:

NIC 1:           MAC: 080027F12459, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot pcy: deny, Bandwidth group: none
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0):   name = packerssh, protocol = tcp, host ip = 127.0.0.1, host port = 4025, guest ip = , guest port = 22

I presume that I should see a Guest IP address?
0
Zephyr ICTCloud ArchitectCommented:
Hmmm ... The thing is, if you use ssh on the packer machine,  it should automatically forward the SSH agent to the remote host ...

So, try to create the machine again, when it's waiting for the ssh connection try it manually with something like this:

ssh -p 2554 vagrant@127.0.0.1 -vvvv

Open in new window


That might shed some light on what is happening. Do check the port, I've taken it from your first post but might have changed.
0
micktAuthor Commented:
ssh -p 3689 vagrant@127.0.0.1 -vvvv
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 3689.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug3: Incorrect RSA1 identifier
debug3: Could not load "/root/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
ssh_exchange_identification: read: Connection reset by peer
0
Zephyr ICTCloud ArchitectCommented:
Is the ISO specific or is it a general ISO? It's looking for logging in using SSH keys... It's also looking at the ssh_config so maybe it's getting it there ...
0
micktAuthor Commented:
I've been looking into the failure here.  Should it not be using /root/.ssh/id_rsa.pub?
0
Zephyr ICTCloud ArchitectCommented:
You're actually giving a user/password with the config, so it shouldn't use a key at all ...
0
micktAuthor Commented:
I wonder why it is referenced.
0
Zephyr ICTCloud ArchitectCommented:
Good question, I will look into it ... Haven't seen this before either.
0
micktAuthor Commented:
I only have the two files, the json and kickstart, both are above. I couldn't find much but I'm kind of looking a t a few things at the moment.

I'm not 100% sure, is this a VM conf issue or host issue?
0
Zephyr ICTCloud ArchitectCommented:
You can check your ssh_config on the host ... and you could test ssh with the "-o" option, force it using password authentication ...

Something like this perhaps: "ssh -o PasswordAuthentication -p 2254 vagrant@127.0.0.1 -vvvv"
0
micktAuthor Commented:
.
0
Zephyr ICTCloud ArchitectCommented:
Your comment seems to be empty, was there anything you'd like to ask?
0
micktAuthor Commented:
Not at this time.  I've not had time to get back to this yet.
0
Zephyr ICTCloud ArchitectCommented:
Ok, no problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
micktAuthor Commented:
I didn't get back to this but your assistance was helpful.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.