Skip to content

Instantly share code, notes, and snippets.

@takase1121
Last active February 6, 2022 03:59
Show Gist options
  • Save takase1121/d0085193c43ed10df2adee8e12d7bd61 to your computer and use it in GitHub Desktop.
Save takase1121/d0085193c43ed10df2adee8e12d7bd61 to your computer and use it in GitHub Desktop.
My VirtualBox setup for Windows interop

Setup

  • Fedora XFCE (seamless mode only works on X11 currently)
  • Setup shared folder (for Guest->Host communication):
    • C:\ -> /mnt/c
    • %USERPROFILE%\Documents -> ~/winhome
  • Use NAT and a Host-Only Adapter (Or bridged on vmware. Trust me, it'll save a lot of time)
  • Setup sshfs-win for Host->Guest access (or see below for smb configuration)

Files

  1. sshfs.ps1 -> Listens on ~/winhome/vmstatus and mounts mapped drive automatically.
  2. suspendwatcher.sh -> Test if the VM is suspended / restarted / shut down and writes to ~/winhome/vmstatus

After 10 years I finally got samba to work.

smb.conf:

[global]
	workgroup = WORKGROUP
	security = user

	passdb backend = tdbsam
	lanman auth = no
	ntlm auth = yes
	client lanman auth = no

[homes]
	browseable = no
	writable = yes

Use this to allow samba to r/w to home directories:

setsebool -P samba_export_all_rw=1

Allow samba to use [homes]:

setsebool -P samba_enable_home_dirs=1

Do not use semanage fcontext to change the fcontext of home dir. It'll break everything.

$machines = @{
'fedora' = {
if (!(Test-Path Y:)) {
net use Y: \\sshfs\takase@192.168.56.1 /user:takase takabaka
}
}
}
$folder = "$env:USERPROFILE\Documents\vmstatus"
$filter = "*"
$watcher = New-Object IO.FileSystemWatcher
$watcher.Path = $folder
$watcher.Filter = $filter
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$global:fileChanged = $false
$global:fileChangedMap = @{}
$changeAction = {
$name = $Event.SourceEventArgs.Name
$global:fileChanged = $true
$global:fileChangedMap[$name] = $true
}
$event = Register-ObjectEvent $watcher -EventName "Changed" -Action $changeAction
try {
while ($true) {
Start-Sleep -Milliseconds 200
if ($global:fileChanged) {
$global:fileChangedMap.Keys | Where-Object { $machines[$_] }| foreach { Invoke-Command -ScriptBlock $machines[$_] }
$global:fileChangedMap.Clear()
$global:fileChanged = $false
}
}
} finally {
Unregister-Event -SubscriptionId $event.Id
}
#/bin/sh
DELTA_THRESHOLD=5
LAST_TIME_FILE="/tmp/last_time"
while true
do
LAST_TIME="$(cat $LAST_TIME_FILE 2>/dev/null)"
CURRENT_TIME=$(date +%s)
DELTA=$(( $CURRENT_TIME - "${LAST_TIME:-0}" ))
if [[ $DELTA -gt $DELTA_THRESHOLD ]]; then
echo "a" > "$HOME/winhome/vmstatus/fedora"
fi
date "+%s" > $LAST_TIME_FILE
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment