share keyboard and mouse from pc to odroid htpc-from initram

Moderators: mdrjr, odroid, meveric

share keyboard and mouse from pc to odroid htpc-from initram

Unread postby sputnik » Fri Jun 15, 2018 12:03 pm

I've been hesitant to post this, don't know why because I think many would benefit from it. For example, I think with a little modification it could be used on the popular loboris triple-boot, to allow keyboard selection of boot OS. It is a bit involved if you wish to understand it thoroughly, but I think it's pretty cut and paste friendly too if you don't want to bother. I use this setup on a C1+, but it should be applicable to any remote computer you are using.
There's a great but little known tool available from netevent. By running it on both pc's you have the ability to share your input devices over your network. Sure, there's others available like synergy and x2x, but this tool is far superior. Virtually all of the others require you to move your mouse to the edge of the screen to switch to another computer, this is extremely annoying after a while. Netevent instead is switched with a hotkey, much more convenient. I also have it controlling my scroll lock led on the keyboard for a visual indicator as to which device is active, another nifty feature I don't think you'll find elsewhere. And more than that, netevent works even without X, meaning you can work on your remote computer tty console screens too. Once again, no other programs do that. I actually initiate it in my initramrd now, so I can switch to the odroid long before it's even booted. Handy if you also build a custom fsck option into your initramrd too. I've always kept a $1 thrift store keyboard connected to the odroid just for things like that, no longer needed.
I run Funtoo on both pc's. If you don't care about the ability to instantly switch input devices on bootup, I have written a guide that accomplishes this after your desktop is up and I have used it that way for a long time - on blub's wiki: https://github.com/Blub/netevent/wiki/S ... ted-bootup. Just sit back, when the desktop comes up, hit the hotkey and you're switching away.
I do want to point out though that I tried that on the "official" Hardkernel Ubuntu and had problems, specifically with /dev/uinput permissions. I never solved it because I went back to Funtoo.
1st you must clone the netevent github site, note that he has a master branch and a stable-1 branch (older).
Code: Select all
git clone https://github.com/Blub/netevent.git
git checkout stable-1 # or
git checkout master

I use the stable-1 branch because I couldn't figure out how to get the scroll lock led indicator with the much newer branch, but otherwise both work the same, although they are quite different. Incidentally the newer master branch no longer depends on /dev/uinput, so it may be easier to incorporate into a distro that is _funny about uinput ( :roll: Ubuntu). Follow the instructions and compile the executable (netevent). Put it somewhere (mine is in $HOME/netevent) and I'll use that for this example.
If you choose to use the master version you will have to get creative with all of the scripts, as it's commands differ quite a bit from the old version. You are warned.
You'll also need netcat installed from your distro package manager, note that there are several versions out there and they have slightly different syntax, so you may need to adjust my scripts from blub's wiki slightly (or the dracut netevent_slave_setup module). Whether you use it from full desktop startup or initramrd, you'll still need the main pc script.
You must build your own initramrd if you want the early input device switching, for that I use dracut, you can install that from your distro package manager. I have another post explaining in more detail how to build your initramrd with dracut here: Dracut instructions for the C1. I won't repeat that here, if you want to do this follow that post (but don't actually build it yet) and come back to this point.
As noted in that post, you can add your own modules to dracut. In fact, as a bare minimum on the Odroid C1 you must add the c1-init script from mdrjr, also the additions to /etc/dracut.conf.
Here is the info for my 98netevent_slave_setup module:
Code: Select all
# ls /usr/lib/dracut/modules.d/98netevent_slave_setup
module-setup.sh  netevent_slave_setup.sh

Code: Select all
# cat /usr/lib/dracut/modules.d/98netevent_slave_setup/module-setup.sh
#!/bin/bash
check() {
return 0
}

depends() {
return 0
}

install() {
inst_hook pre-pivot 98 "$moddir/netevent_slave_setup.sh"
}

Code: Select all
# cat /usr/lib/dracut/modules.d/98netevent_slave_setup/netevent_slave_setup.sh
#!/bin/bash

# ref:
# https://github.com/Blub/netevent/wiki/Share-devices-over-the-net
/sbin/modprobe uinput
/usr/bin/nc -l -p 1955 | /home/<user>/netevent/netevent -write &
/usr/bin/nc -l -p 1956 | /home/<user>/netevent/netevent -write &

Then add this to your /etc/dracut.conf:
Code: Select all
add_dracutmodules+="c1_init " # you already have that from my dracut post, right?
add_dracutmodules+="netevent_slave_setup "

Do note the extra space at the end of those lines, it is needed, well, not on the last line, but otherwise dracut will contecate them together like "c1_initnetevent_slave_setup" when it runs.

More /etc/dracut.conf additions:
Code: Select all
install_items+="/usr/bin/fbset /bin/date /bin/echo " # basic odroid startup stuff
install_items+="/bin/su /usr/bin/nc /home/<user>/netevent/netevent " # netevent slave setup from initramfs
add_drivers+="uinput"

Still the extra space at the end ;) Oh, you won't need /bin/su really, although it won't hurt. One disappointment is I'm now running the root setup on uinput, not good, but working on it. Turns out in the initramrd filesystem it doesn't know about my unprivileged user, gotta solve that.
And that's it! Just build your initramfs and convert it to initramrd as described in Dracut instructions for the C1. Your pc mouse and keyboard can access your odroid before the OS even boots.

BONUS
If you add this module to dracut, you can have it check your rootfs partition before it even gets mounted by simply adding a file to the rootfs ROOT directory. In this case I do this:
Code: Select all
# touch /force_fsck

And upon reboot, it checks the partition. I do this also on other computers here, for example with XFS partitions, by simply changing the command appropriately it works.

Actually it does mount briefly to search the / directory for force_fsck, if it finds it, it umounts it and runs fsck, then remounts it, deletes force_fsck and continues booting.
In other words, you won't have to ever remove the sd card and put it in another computer to check it.
Code: Select all
# ls /usr/lib/dracut/modules.d/99force_fsck
force_fsck.sh  module-setup.sh

Code: Select all
# cat cat /usr/lib/dracut/modules.d/99force_fsck/module-setup.sh
#!/bin/bash
check() {
return 0
}

depends() {
return 0
}

install() {
inst_hook pre-pivot 99 "$moddir/force_fsck.sh"
}

Code: Select all
# cat /usr/lib/dracut/modules.d/99force_fsck/force_fsck.sh
#!/bin/bash

if [[ -e /sysroot/force_fsck ]]; then
   echo "force_fsck file found in root directory - now force checking /dev/sda1..."
   umount /dev/mmcblk0p2
   /sbin/fsck -f /dev/mmcblk0p2
   mount /dev/mmcblk0p2 /sysroot
   rm /sysroot/force_fsck
fi

You'll have to change /dev/mmcblk0p2 to whatever partition your rootfs is on of course.
then add this to /etc/dracut.conf:
Code: Select all
add_dracutmodules+="force_fsck "

One final note. Dracut puts fsck automatically in the initrd, as well as mount, umount, but if you have something more exotic to be checked, you may have to add it. For example, my Big Boy pc runs XFS filesystem, so it has this in /etc/dracut.conf:
Code: Select all
fscks="/usr/sbin/xfs_growfs /sbin/xfs_repair"

I absolutely love this setup, been using it for many months. I hope you do too.
Last edited by sputnik on Fri Jun 15, 2018 8:07 pm, edited 1 time in total.
sputnik
 
Posts: 68
Joined: Tue Aug 11, 2015 9:39 am
languages_spoken: english, some spanish
ODROIDs: C1+

Re: share keyboard and mouse from pc to odroid htpc-from ini

Unread postby mad_ady » Fri Jun 15, 2018 5:36 pm

Thanks for sharing, it's really interesting. You could submit the idea for an article.
User avatar
mad_ady
 
Posts: 4262
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1


Return to Ubuntu (All Linux'es)

Who is online

Users browsing this forum: No registered users and 2 guests