This page permanently redirects to gemini://shit.cx/tech/devenv/2020-11-04-a-macos-linux-hybrid-part-3/.

shit.cx

A Macos Linux/hybrid Laptop - Part 3

2020-11-04T21:05

This is the third and final piece for the series describing my macOS/Linux laptop environment. If you missed the other parts, you can find links at the end.

Part three describes some of the difficulties I had and how they were overcome. I've been using this setup daily for seven months now and it's become pretty polished.

SSH Agent

The first problem I had was with the SSH agent. I couldn't reconnect to Tmux session without loosing my SSH agent. This broke clipboard and file syncing, crippling the seamless integration I worked so hard for.

This is because the SSH_AUTH_SOCK environment variable which holds a reference to the running SSH agent is replaced for each SSH connection. The environment variable lasts for as duration of the tmux process. After reconnect to an existing tmux, the SSH_AUTH_SOCK is pointing to the old socket that existed at the time the Tmux process was started rather than the current one.

To work-around this problem, I hold a symlink in SSH_AUTH_SOCK which points to the correct value at all times. If it's clobbered with something else, then that's a sign that the symlink file needs to be updated with the new value. This is done in .bashrc.

if [[ "${SSH_AUTH_SOCK}" != "/tmp/ssh-auth-sock" ]]; then
  ln -sf ${SSH_AUTH_SOCK} "/tmp/ssh-auth-sock"
  export SSH_AUTH_SOCK="/tmp/ssh-auth-sock"
fi

It's a fairly brutal solution and probably wont support multiple Tmux sessions — but that isn't how I use Tmux, so it works fine for me.

Clock Sync

Another issue is that the clock falls out of sync with the host. This usually occurred after the host has been sleeping.

To solve this, I needed to configure a few properties on the VM.

#!/usr/bin/env bash
VBoxManage guestproperty set devbox "/VirtualBox/GuestAdd/VBoxService/--timesync-interval" 10000
VBoxManage guestproperty set devbox "/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust" 100
VBoxManage guestproperty set devbox "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore" 1
VBoxManage guestproperty set devbox "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 1000
VBoxManage startvm devbox --type headless

Audio

I keep my headphones connected to a headphone jack on my USB-C hub. From the point of view of my computer, the Hub is affectively an external audio device. When I disconnect from the hub, the device disappears and audio is sent to the build-in audio device. When I plug back into the hub it switches back.

The problem is that VirtualBox can't cope at all with the audio interface getting flipped around beneath it. For a long time, all I knew was Cmus (my music player) stalled at 1 second into a song and that rebooting it was the only way I knew to recover. Restarting daemons didn't help. Eventually I looked harder at the problem and received a helpful error message from Mplayer.

[AO_ALSA] alsa-lib: pcm_hw.c:1711:(snd_pcm_hw_open) open '/dev/snd/pcmC0D0p' failed (-77): File descriptor in bad state

With that, I worked out that I could recover audio by reloading the kernel module.

This is a script to do that.

#!/usr/bin/env bash
alsactl kill quit
modprobe -r snd_intel8x0
modprobe snd_intel8x0
/etc/init.d/alsa-utils restart

I only use audio when I'm playing music with Cmus, so I reload the kernel module within a wrapper to start cmus. Now I don't need to think about it anymore.

Summary

Having used this setup for seven months now, I can happily say that it does everything I hoped it would. If you like macOS but you would prefer Linux on the command line, I believe this is about as close as you can get.

The apps I use on the host are pretty minimal:

For that, I honestly don't need a Mac. If I had the choice, I would use Linux — it's specifically Fluxbox that I like, for me most window managers are no better than macOS — but unless I supply my own laptop (or change jobs), it isn't an option.

=> More Posts Like This | Return to Homepage

The content for this site is CC-BY-SA-4.0.

Proxy Information
Original URL
gemini://shit.cx/tech/devenv/2020-11-04-a-macos-linux-hybrid-part-3
Status Code
Success (20)
Meta
text/gemini;
Capsule Response Time
3029.015734 milliseconds
Gemini-to-HTML Time
1.002544 milliseconds

This content has been proxied by September (3851b).