this post was submitted on 23 Apr 2024
74 points (95.1% liked)

Linux

48332 readers
599 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I hate spending money on hardware when there's a software solution. like, I've got a subwoofer from a 2.1 system (without satellites) for free. instead of sourcing speakers for it, however cheap they might be, I'll just utilize the speakers from my monitor. pipewire to the rescue, it creates a combined sink that outputs sound to both DP and analog audio, et voila - a 2.1 sound system. people are like "your monitor sounds like that!?" and usually I play dumb: "yeah, yours doesn't? well that's linux for ya".

so, I have a desktop and a laptop and I'd like to share the same monitor, keyboard, and mouse. modern monitors have a KVM switch integrated, you connect your keyboard/mouse/etc. to it, one USB Type-C cable to the laptop, a couple to the desktop and you have a seamless switch; it even charges the laptop, how cool is that!

however, my monitor works just fine and I don't replace my hardware unless I really have to. USB KVMs with similar functions aren't cheap. also, the monitor already has multiple display inputs so I got to thinking, how do I re-create this with no money, or as little as possible, with DIY tech?

first, switching the display; this one took me no time at all. I have a USB Type-C to DP cable (with DP-Alt) and with the power of udev (detect a connection then trigger stuff) and ddcutil (sends commands to the monitor) I got it working as seamless as possible - I connect the laptop and it automagically switches the monitor over. when I disconnect it, the monitor falls back to an active connection, which is the desktop. awesome!

now how about switching the keyboard and mouse over? I'd like to do it in software, like barrier/inputleap does it but without having to move the cursor to the adjacent monitor. also, both machines are on wayland which isn't supported. eventual input lag to the laptop is unimportant, I game on the desktop. no idea if that can be accomplished or if that's even a thing...

that is a thing - it's called USB/IP, i.e. sharing your USB device over TCP/IP; it's a kernel module included by default for a long time now and that thing rocks! not only does the USB keyboard work without any perceivable lag on the laptop, it get's "disconnected" from the host, so your keypresses aren't disturbing the host. since it's a kernel module, no need to convince wayland to play ball! this also works for webcams, scanners, readers, etc., the client system thinks this is a local device and it just works.

so all we have to do is expand the shell script to bring over the keyboard and mouse along with switching over the monitor once the USB-C connection is detected annnd... success!

well, sorta. my wireless mouse is second-hand and I haven't got the USB receiver for it, so it connects over bluetooth. tried sharing with usbip and it works, but the radio connection gets interrupted or something and the mouse doesn't work there. maybe there's a workaround but I don't want to dig further.

also, how do I switch back to the desktop to shoot some peggies? I don't want to disconnect the laptop manually so I could come up with a slew of shell scripts and udev triggers and I'd also need a ssh tunnel, I don't want my keyboard input to travel over the LAN in cleartext, etc... kinda cumbersome. also, once the novelty wears off, the automagicallity gets tired, I'd prefer manually switching between devices with a keyboard combo.

enter rkvm. it's written in rust and as everybody knows that's super awesome. unlike usbip, comms are encrypted, so no sniffing possible, and hotkey switching is a default function, and it also handles the mouse!

now, rkvm currently doesn't support triggers, like "do X when hotkey combo pressed", but Plasma can handle running the monitor switch script on each device separately by listening to the same hotkey combo.

both solutions have their advantages and disadvantages, usbip requires more legwork but is more powerful whereas rkvm is simpler and easier to set up.

the final step, powering the laptop over the same cable. sadly, can't handle that in software, but there are power delivery injectors out there, some as cheap as $7. also, there's this cool project, looks easy enough to source and implement. not sure if I'm going that way or just go with a used dock station, as those can be had for a song for popular business ex-flagships, like the Thinkpad T-series, HP Elitebooks, Dell Latitudes, etc..

are there downsides? sure there are. numero uno, the host (desktop, in my case) has to be on all the time. not a big deal for me, it gets woken in the morning and suspended late at night. there are edge cases when rkvm geeks out, but for a thing that's in its 0.x version, this is more than usable.

so, I've been using this setup for the past week or so and haven't yet found it to break or have any negative side-effects. gaming on the desktop is as snappy (or shitty) as ever and using my mech keyboard and giant screen on the laptop allows me to easily compartmentalize my business and private stuff.

thanks for reading!

edit: edited title to clarify I'm talking about a Keyboard-Video-Mouse switch, not a Kernel-Virtual-Machine.

top 7 comments
sorted by: hot top controversial new old
[–] waldek@lemmy.86thumbs.net 7 points 7 months ago

This is pretty cool! Might test it out at some point. Thanks for the write up.

[–] Rikj000@discuss.tchncs.de 7 points 7 months ago (1 children)

I'm using Looking-Glass to share my mouse/keyboard/audio between host and client:
https://looking-glass.io/

And USB-Libvirt-Hotplug to pass through USB devices to the KVM on the fly:
https://github.com/olavmrk/usb-libvirt-hotplug

Hope these will prove useful to you :)

[–] dingdongitsabear@lemmy.ml 5 points 7 months ago* (last edited 7 months ago) (1 children)

just watched a video where the dev explains LG; this is for a Windows VM that allows GPU pass-through, or am I missing something? when you say "host" and "client", you're referring to two physical devices or how does that work in your case?

I have two physical machines (both running linux, Fedora 40 on the desktop and Debian 12 on the laptop) connected to the same monitor, keyboard and mouse and I need to alternate between them.

edit: aha, the LG site refers to KVM as kernel-virtual-machine, whereas I'm talking about KVM as in keyboard-video-mouse; completely different things, maybe I should amend the post's title.

[–] Rikj000@discuss.tchncs.de 1 points 7 months ago

Ah sorry that wasn't clear to me,
thought you where talking about KVMs as in Kernel Virtual Machines :)

[–] redcalcium@lemmy.institute 7 points 7 months ago

Wow, I never thought of using usbip to work around wayland issue with kvm apps. Sounds useful as a last resort to get kvm working.

[–] possiblylinux127@lemmy.zip 3 points 7 months ago (1 children)

I would use remote access tools

[–] variants@possumpat.io 1 points 7 months ago

Yeah I have a physical kvm on my home desk I use to switch between my desktop and virtual machine but when I have both on I just remote in so that I have access to both without waiting for that 2 second lag of the keyboard and monitor switching over each time