vmware / photon

Minimal Linux container host
https://vmware.github.io/photon
Other
3.03k stars 698 forks source link

Photon OS 3 doesn't work with Vagrant/VirtualBoxAdditions #892

Open jandrews65 opened 5 years ago

jandrews65 commented 5 years ago

Background: Unlike vmware/photon on vagrantcloud.com I did manage to get a full vagrantized version of Photon (version 1.0) to work including shared folders. Pull silverhighway/photon and take a look.

However I have not been able to do with same with version 2.0 or version 3.0

The installer VBoxLinuxAdditions.run does not detect the Linux headers for the subsequent versions even though they are installed (via tdnf install build-essential or just tdnf install linux-api-headers)

Here is the output

root@photon [ /mnt/cdrom ]# ./VBoxLinuxAdditions.run Verifying archive integrity... All good. Uncompressing VirtualBox 6.0.5 Guest Additions for Linux........ VirtualBox Guest Additions installer Removing installed version 6.0.5 of VirtualBox Guest Additions... Copying additional installer modules ... Installing additional modules ... VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Kernel headers not found for target kernel 4.19.29-1.ph3. Please install them and execute /sbin/rcvboxadd setup modprobe vboxguest failed The log file /var/log/vboxadd-setup.log may contain further information. root@photon [ /mnt/cdrom ]# uname -r 4.19.29-1.ph3 root@photon [ /mnt/cdrom ]#

Any ideas? Has anyone managed to get this to work?

jandrews65 commented 5 years ago

Found the problem. In addition to build essentials you need to install linux-devel

I'll post a link to the blog post and my vagrantized version of Photon 3.0 shortly.

jandrews65 commented 5 years ago

New build of Photon version 3.0 now available on virtualbox for download via vagrantcloud.com

vagrant init virtualmountain/photon3

And the explanation of how the build was done at How to setup Photon OS 3 for Vagrant with VirtualBox

dotcarls commented 5 years ago

@jandrews65 I was able to get VirtualBox + Vagrant working with 3.0 via Packer. My provisioners ended up looking something like this:

    "provisioners": [
        {
            "type": "shell",
            "inline": [ "tdnf --assumeyes distro-sync" ]
        },
        {
            "type": "shell",
            "only": [ "vagrant-virtualbox-iso" ],
            "script": "scripts/dependencies/virtualbox/install-virtualbox-packages.sh"
        },
        {
            "type": "shell",
            "inline": [ "reboot 0" ],
            "expect_disconnect": true
        },
        {
            "type": "shell",
            "only": [ "vagrant-virtualbox-iso" ],
            "scripts": [
                "scripts/dependencies/virtualbox/install-virtualbox-guest-additions.sh",
                "scripts/dependencies/virtualbox/clean-virtualbox-packages.sh"
            ]    
        },
    ...
    ]

install-virtualbox-packages.sh

#!/usr/bin/env bash

tdnf --assumeyes install \
    gawk \
    gcc \
    tar \
    linux-devel \
    binutils \
    linux-api-headers \
    lvm2 \
    dhcp-client \
    make \
    bc

install-virtualbox-guest-additions.sh (note: shamelessly stolen from this script, updated to hardcode the guest editions version I was targeting)

#!/usr/bin/env bash

# Faking a sysV-based system
if [ ! -d /etc/init.d ]; then mkdir /etc/init.d; fi

mkdir /tmp/virtualbox
mount -o loop /root/VBoxGuestAdditions_6.0.6.iso /tmp/virtualbox

sh /tmp/virtualbox/VBoxLinuxAdditions.run
umount /tmp/virtualbox
rmdir /tmp/virtualbox
rm /root/VBoxGuestAdditions_6.0.6.iso

echo "Compacting disk space"
FileSystem=`grep ext /etc/mtab| awk -F" " '{ print $2 }'`

for i in $FileSystem
do
        echo $i
        number=`df -B 512 $i | awk -F" " '{print $3}' | grep -v Used`
        echo $number
        percent=$(echo "scale=0; $number * 98 / 100" | bc )
        echo $percent
        dd count=`echo $percent` if=/dev/zero of=`echo $i`/zf
        /bin/sync
        sleep 15
        rm -f $i/zf
done

# Removing VBox startup files and removing init.d entirely if empty
find /etc/init.d -type f -name "vbox*" -exec rm {} \;
if [ ! "$(ls -A /etc/init.d)" ]; then rmdir /etc/init.d; fi

# Prevent vmhgfs module from loading on virtualbox platforms
if [ -f /etc/modules-load.d/vmhgfs.conf ]; then rm -f /etc/modules-load.d/vmhgfs.conf; fi

The reboot was required in my case so that guest additions would recognize the correct kernel header versions during compilation.

jandrews65 commented 5 years ago

This looks very cool and a lot simpler than my method.

I'd love to learn Packer. Any suggestions?

dotcarls commented 5 years ago

Hey @jandrews65 -- I found some time to create a fork of vmware/photon-packer-templates that can be used to create Photon 3.0 Vagrant boxes. You can grab it from here: dotcarls/photon-packer-templates

This is a sanitized version of some private work and so far I've only had time to do a quick test of the Virtualbox builder / provider. That said, I'm able to successfully build / publish the box to dotcarls/photon3 on Vagrant Cloud via the publish-vagrant-virtualbox-iso make target (see the README in the fork for more details).

There's an example Vagrantfile in the examples/virtualbox directory of the forked repo that you can also check out to see it in action. Feel free to message me with any questions!

NickMRamirez commented 3 years ago

@dotcarls Thanks for your work on this. I spun your Vagrant box up and was able to log in. I tried the virtualmountain/photon3 box, but the SSH authentication seems to be broken on that one. I could not log into it, so I was happy to find yours.

jandrews65 commented 3 years ago

Apologies to @NickMRamirez in particular. I have fixed the problem with my vagrant box with a new, updated, COVID-19 compliant version which works correctly and has the correct social distancing. Apparently some idiot forgot to make sure that the vagrant account didn't expire after 1 year.

So vagrant init virtualmountain/photon3 now or Joe Biden won't take office in January and tell all your friends!

No pressure...