Parallels / vagrant-parallels

Vagrant Parallels Provider
https://parallels.github.io/vagrant-parallels
MIT License
995 stars 88 forks source link

Failed to install Parallels Guest Tools on Alpine Linux #374

Open jicjoy opened 3 years ago

jicjoy commented 3 years ago

vagrant version: Vagrant 2.2.14 configure

config.vm.box = "generic/alpine38" config.vm.provider "parallels" do |prl| prl.name = "docker" prl.check_guest_tools = true prl.update_guest_tools = true

end

error:

The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed!

mount -o loop /tmp/prl-tools-lin.iso /media/prl-tools-lin_25557/

Stdout from the command:

Stderr from the command:

legal90 commented 3 years ago

Hi @worftan, I can confirm that the feature update_guest_tools doesn't work properly on VMs with Alpine Linux.

Due to the Alpine specifics, the mount command syntax is different and we should use -o iso9660 instead of -o loop. However, the installer of guest tools doesn't work there anyway:

# mount -t iso9660 /tmp/prl-tools-lin.iso /media/cdrom/

# /media/cdrom/install --install-unattended
Started installation of Parallels Guest Tools version '16.1.1.49141'
Error: none of supported package managers found in system.
Error: failed to install or upgrade Parallels Guest Tools!

# /media/cdrom/install --install-unattended-with-deps
Started installation of Parallels Guest Tools version '16.1.1.49141'
Error: none of supported package managers found in system.
Error: failed to install or upgrade Parallels Guest Tools!

Also, as we can see, in the box generic/alpine38 doesn't have Parallels Guest Tools preinstalled. Since commands don't work, they are commented, so the script is just a no-op doing nothing: https://github.com/lavabit/robox/blob/e3dd63cab909e065c684eb533ab90582deef4b1b/scripts/alpine38/parallels.sh#L41-L45 It's still the same on latest versions of generic/alpine.

Unfortunately, in order for it to work, the support of Alpine Linux should be first implemented on the Parallels Guest Tools side. That's out of the scope of vagrant-parallels provider.

legal90 commented 3 years ago

So, you can still run generic/alpine38 as Parallels Desktop VM, without guest tools support it will work:

# Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "generic/alpine38"
end

But shared folders won't work there.

meermanr commented 1 year ago

Here are some manual steps for installing Parallel Tools on Alpine which worked for me:

Based heavily on the work of m-emelchenkov / vagrant-alpine / commit / b133defd7e76 — Bitbucket

# Create and enter VM
vagrant init generic/alpine316
vagrant up
vagrant ssh

# First, bring system up to date. Otherwise kernel headers won't match the running kernel
sudo apk upgrade

# If kernel was updated, reboot to bring it into use, and re-enter VM

sudo apk add gcompat         # Adds glibc compatibility layer, needed by prl-tools user-space
sudo apk add alpine-sdk      # Equivalent of debian's build-essential: gcc, automake, etc
sudo apk add linux-virt-dev  # Linux headers for generic/alpine316's kernel (cf. `-virt` in output from uname -r)

# Check headers installed in /usr/src/linux-headers-* matches 
# running kernel version and type `uname -r`

# Tools needed by parallels installer
wget "https://bytebucket.org/m-emelchenkov/vagrant-alpine/raw/b133defd7e76a9e776932aa61b8d06ffe7b54cb4/Packages/packages/3rd-party/x86_64/dkms-2.5-r0.apk"
sudo apk add --allow-untrusted ./dkms-2.5-r0.apk
sudo apk install perl elfutils-dev

# Use Parallels GUI to open the VM, then use the Actions -> Install Parallel tools to insert a CD-ROM 
# into the VM, which will appear at /dev/sr0
sudo mount -t iso9660 -o exec /dev/sr0 /mnt
sudo /mnt/install

# There's a complaint about an error at this point, check the log file mentioned in the error
tail -n50 /var/log/parallels-tools-install.log

End of log file:

alpine316:/$ tail -n50 /var/log/parallels-tools-install.log
  The kernel was built by: gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219
  You are using:           cc (Alpine 11.2.1_git20220219) 11.2.1 20220219
warning: the comp  CC [M]  /usr/lib/parallels-tools/kmods/prl_fs_freeze/Snapshot/Guest/Linux/prl_freeze/prl_fs_freeze.o
  MODPOST /usr/lib/parallels-tools/kmods/prl_fs_freeze/Snapshot/Guest/Linux/prl_freeze/Module.symvers
  CC [M]  /usr/lib/parallels-tools/kmods/prl_fs_freeze/Snapshot/Guest/Linux/prl_freeze/prl_fs_freeze.mod.o
  LD [M]  /usr/lib/parallels-tools/kmods/prl_fs_freeze/Snapshot/Guest/Linux/prl_freeze/prl_fs_freeze.ko
make[2]: Leaving directory '/usr/src/linux-headers-5.15.74-0-virt'
make[1]: Leaving directory '/usr/lib/parallels-tools/kmods/prl_fs_freeze/Snapshot/Guest/Linux/prl_freeze'
make: Leaving directory '/usr/lib/parallels-tools/kmods'
Start installation of prl_tg kernel module
Start installation of prl_fs kernel module
Start installation of prl_fs_freeze kernel module
Start installation of prl_eth kernel module

Creating symlink /var/lib/dkms/parallels-tools/17.1.4.51567/source ->
                 /usr/src/parallels-tools-17.1.4.51567

DKMS: add completed.
DKMS modules were added successfully
DKMS modules for kernel 5.15.74-0-virt were built successfully
DKMS modules for kernel 5.15.74-0-virt were installed successfully
Illegal option -p
Warning: libGL.so.1 has not found in the system
'/usr/lib/parallels-tools/tools/tools64/bin/prltimesync' -> '/usr/bin/prltimesync'
'/usr/lib/parallels-tools/tools/tools64/bin/prltoolsd' -> '/usr/bin/prltoolsd'
'/mnt/installer/prltoolsd_sysv.sh' -> '/etc/init.d/prltoolsd'
 * service prltoolsd added to runlevel default
Installation of prltoolsd service was finished successfully
cp: can't stat '/mnt/installer/prltools-reconfig_sysv.sh': No such file or directory
 * rc-update: service `prltools-reconfig' does not exist
Error: failed to install prltools-reconfig service
Error: failed to install Parallels Guest Tools!
2022-10-18T09:34:13+0000: iler differs from the one used to build the kernel
  The kernel was built by: gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219
  You are using:           cc (Alpine 11.2.1_git20220219) 11.2.1 20220219
Start installation of prl_tg kernel module
Start installation of prl_fs kernel module
Start installation of prl_fs_freeze kernel module
Start installation of prl_eth kernel module
DKMS modules were added successfully
DKMS modules for kernel 5.15.74-0-virt were built successfully
DKMS modules for kernel 5.15.74-0-virt were installed successfully
Illegal option -p
cp: can't stat '/mnt/installer/prltools-reconfig_sysv.sh': No such file or directory
 * rc-update: service `prltools-reconfig' does not exist
Error: failed to install prltools-reconfig service
Error: failed to install Parallels Guest Tools!
2022-10-18T09:34:13+0000: execCmd: ./install --install [1]
2022-10-18T09:34:13+0000: Error: An error occurred when installing Parallels Tools. Please go to /var/log/parallels-tools-install.log for more information.
2022-10-18T09:34:54+0000: Exiting with code 1
alpine316:/$

# Add a boot-time launcher for prltoolsd
echo -e '#!/bin/sh\n\n/etc/init.d/prltoolsd start\n' | sudo tee /etc/local.d/prltoolsd.start
sudo chmod 0755 /etc/local.d/prltoolsd.start
sudo rc-update add local

# Launch it manually now
sudo /etc/local.d/prltoolsd.start

# Use the GUI to create a shared folder called `vagrant`
sudo mkdir -p /vagrant
sudo mount -t prl_fs -o nodev,share vagrant /vagrant

# Make this mount on boot by adding the following line to fstab
echo -e '\nvagrant /vagrant prl_fs nodev,share 0 0\n' | sudo tee -a /etc/fstab
sudo mount -va # test mounting all entries in /etc/fstab

If you want to free some disk space, you can now delete all the packages except gcompat:

sudo apk del alpine-sdk linux-virt-dev perl elfutils-dev
rm ./dkms-2.5-r0.apk

To actually shrink the disk of the VM, you need to modify the virtual harddisks connection type from IDE to SCSI (which supports the TRIM command).

  1. Shutdown the VM
  2. Using the Parallels GUI, configure the VM -> Hardware -> Hard disk -> Advanced -> Location: set to SCSI 0:0 and ensure "Enable TRIM" is ticked.
  3. Boot the VM

Run the following on the VM to force the emission of TRIM commands (a.k.a. DISCARD) which inform the underlying storage system (Parallels in this case) which blocks are no longer needed by the VM. Note that this is not done automatically when you delete files, because on physical disks it has a significant performance penalty.

alpine316:~$ sudo fstrim -v /
/: 33025118208 bytes trimmed

To enable automatic TRIM when you delete a file, add discard to the mount options of your root folder.

# One off (resets on next boot)
sudo mount -oremount,discard /

To make this permanent I would expect to add discard to the mount options in /etc/fstab as below, but for some reason it seems to be ignored on boot?:

# Modify first line of /etc/fstab
# Sample before:
UUID=5a942e11-4646-496f-8e59-7e3f0f98c1d1       /       ext4    rw,relatime 0 1
# After:
UUID=5a942e11-4646-496f-8e59-7e3f0f98c1d1       /       ext4    rw,relatime,discard 0 1