Why Is a Pi KVM Different?

Unlike VPN or remote access apps such as TeamViewer that require the OS to work, a KVM or Pi KVM (KVM running on Raspberry Pi) runs independently of the system’s operating system and allows you to remotely power on the system, access the BIOS, install an operating system, reboot, etc.

Things You’ll Need to Build a DIY Pi KVM

You’ll need the following hardware components to build your Raspberry Pi KVM:

A Raspberry Pi 3, 4, or Zero 2 W with a power supply. 16GB or larger microSD card. 2 x USB Type A male to Type A female cables. A USB Type C cable—if you are using a Raspberry Pi 4. A micro USB cable—if you are going to use a Raspberry Pi 3 or Zero 2 W.

If you can’t find the splitter cable, you can also build your own by splicing and connecting a pair of Type A male-to-female USB cables.

Also, the Pi KVM captures the snapshots from the HDMI output of your system and displays them in real time. There are two different ways to capture the video when you choose to build your own Pi KVM. You can choose either, based on the available Raspberry Pi board.

HDMI to CSI adapter: works with all Raspberry Pis, including Raspberry Pi Zero W and 2 W. It’s also much faster, with extra low latency (MJPEG and H. 264/WebRTC stream). HDMI to USB video capture card: works with Raspberry Pi 2, 3, 4. It’s comparatively slower than the CSI, with high latency, but works well.

Below, you will learn the steps to build a Pi KVM with a Raspberry 4 or Raspberry Pi Zero 2 W, using an HDMI to USB video capture card or CSI to HDMI adapter and a DIY USB splitter cable.

Flash Pi KVM Disk Image on the MicroSD Card

To get started, download the latest readymade Pi KVM image for your Raspberry Pi. There are a few different images available for the Raspberry Pi based on the model and the HDMI adapter (HDMI to CSI adapter or HDMI to USB dongle) you are going to use for this build.

Then follow these steps to flash the microSD card with the Pi KVM OS image.

Connect the microSD card to your system. Download and launch the Raspberry Pi Imager tool. Select Choose OS > Use Custom and then browse to the location where the downloaded Pi KVM image is stored. Click Open. Click Choose Storage and select your microSD card. Click Write. Click Yes to confirm. This will take a while to finish.

If you are going to use a Raspberry Pi Zero W or 2 W or Wi-Fi for network connection, you need to mount the PIBOOT (FAT32) partition and edit the pikvm.txt file. Open the file in Notepad and paste the following lines below the FIRST_BOOT=1 line and replace the Wi-Fi SSID and password.

Connect the Raspberry Pi to Power and HDMI Adapter

After the microSD card is flashed, connect the Raspberry Pi to the HDMI to USB or HDMI to CSI adapter.

Insert the microSD card into the Raspberry Pi. Take the USB splitter cable and insulate the +5V pin in one of the USB Type A male ports in the splitter cable using tape. This Type A port with non-insulated +5V pin is connected to the USB port of the computer/server that you want to manage remotely. If you don’t disable this pin, you may damage the USB port on the computer or server. If you are building a DIY splitter cable as we did, you can keep the red wire of one of the USB Type A male cables unconnected. Refer to the following wiring diagram for details. Take a USB Type A to Type C cable and connect it to the female Type A port in the splitter cable and the Type C port on the Raspberry Pi power input. If you are using the HDMI to the USB dongle, connect it to one of Raspberry Pi 4’s USB 2. 0 ports, as shown below. If you are going to use the HDMI to CSI bridge, connect the ribbon cable to the Camera port on the Raspberry Pi 4 or Raspberry Pi Zero 2 W. Connect the LAN cable to the Raspberry Pi 4 and router. Raspberry Pi Zero 2 W users need to enter the Wi-Fi details manually after flashing the microSD card with the Pi KVM OS image by mounting the PIBOOT partition. Lastly, connect the Type A port to the 5V/3A power supply to turn on and boot Raspberry Pi 4 or Zero 2 W.

Set Up the Pi KVM

The first boot process will take longer to complete. Once it is complete, open your router configuration and go to the DHCP settings. Find the IP address of the connected Raspberry Pi or Pi KVM. You may also use the Fing app on your smartphone to scan your network and find the IP address.

Once found, you can open the IP address in a web browser, such as Chrome or Safari. This will load the Pi KVM login page. Enter “admin” for both username and password, then click Login.

Click Terminal and then follow these steps to enable read/write permissions and update the Pi KVM.

Log in as a superuser (root user). The password is “root” by default.

Enable the read/write permissions:

Then enter the following command to check and update the Pi KVM:

This will check and install the updates. It can take several minutes to complete. After the updates, make the file system read-only by running the following command:

Next, go back to the homepage and click on the KVM option. This should immediately load the screen of your server or computer to which the HDMI to CSI or HDMI to USB capture card is connected. You can now access the PC or the server remotely.

There are also several other options available that you can use to adjust the streamed image quality, FPS, size, mount ISO, etc.

We are using a 32GB microSD card which provides us with more free space to host multiple OS images on the Pi. You can use a larger microSD card to store multiple OS images so that you can install a different OS on the server as and when required.

You can also hook up and enable ATX control to turn ON/OFF or reset the PC or server.

Expose the Pi KVM to the Internet for Remote Access

To enable remote access to your Raspberry Pi or Pi KVM, you can use the DuckDNS and Port Forwarding in your router. You may also set up a Cloudflare Tunnel to remotely access your Pi KVM and control your PC or server with a secure HTTPS connection.

Alternatively, you may also install and use the Tailscale VPN to access your Pi KVM from anywhere. TailScale is a free-to-use tool for private purposes that you can set up in Pi KVM and on your remote Windows, macOS, Linux, Android, or iOS device that you will be using to access the Pi KVM over the internet.

To install and set up Tailscale, run the following commands in the Terminal app.

This will install Tailscale and enable auto-start for it if the Pi KVM reboots.

This will display a URL. Copy the URL to the web browser and authorize. After authorization, enter the following command to restart the Pi KVM:

You can now access the server or computer connected to the Pi KVM from any system. You just need to install the Tailscale VPN on the device, visit the admin page to view the available VPN networks, and then use the displayed Tailscale URL of the Pi KVM to access and control your server or computer remotely. To learn more, you can visit the Pi KVM GitHub page.

Most Affordable KVM Over IP

This DIY Pi KVM is one of the most affordable KVM switch that you can use to have full control over your servers or machines remotely, even if they fail to boot, or crash, or encounter software or OS-related errors. You can quickly mount the operating system ISO, install it, and restore the backup to get the server and services back online.

You may also use a Raspberry Pi Zero 2 W to reduce the overall build cost and footprint. However, you should expect fewer frames and a bit more latency than the Raspberry Pi 4 we used in this tutorial.