A display can exist without a physical screen

How pixels move from memory to a screen on Linux, and how Xvfb and other tools let programs work without a physical screen.

On this page

A program can draw a window without a physical screen. Its pixels can stay in memory while a display server handles its window requests. Tools such as Xvfb provide this environment for many graphical applications running on Linux.

I needed this in a cloud worker. The application expected display services, but nobody needed to see its windows. Understanding which services it needed meant separating image storage, drawing and physical display output.

To understand that separation, it helps to follow an image through the system. We first need memory for its pixels and rules for reading them. Then we can look at how software draws the image, how hardware displays it, and which parts Linux and a virtual display provide.

An image needs memory before it needs a screen

A framebuffer stores an image's pixels. Its simplest form is an array of pixel values, described by a width, height and pixel format. That format tells us what the bits mean. Four bytes might hold red, green, blue and transparency, or leave the fourth byte unused.

This storage can live in different places. A separate graphics card usually has its own memory, called VRAM. A GPU built into the processor can use system RAM. Both can hold framebuffers, textures and other graphics data. The Linux graphics memory documentation covers both arrangements.

A renderer is the part of a program that draws an image. Textures are images it uses while drawing, such as photographs placed on 3D surfaces. A depth buffer stores depth values to decide which surface appears in front when surfaces overlap. These buffers, temporary images and several windows can use much more memory than the final screen image.

To calculate the space for one framebuffer, take an image that is 1920 pixels wide and 1080 pixels tall. Give each pixel four bytes and store the rows without gaps.

1920 × 1080 × 4 = 8,294,400 bytes
                   about 7.91 MiB

A program can reserve those bytes, change the pixels and save the image without a physical screen. But the byte count only tells us how much storage we need. To find a particular pixel, we also need the row layout.

The row layout tells us where a pixel is

In an image stored row by row, the byte distance between the starts of neighbouring rows is its stride, also called pitch. Our 1920 pixel row needs 7680 bytes at four bytes per pixel. Without gaps between rows, that is also its stride.

Using that stride, we can calculate a pixel's offset from the start of the image. Here, x and y count from zero.

offset = y × stride + x × bytes_per_pixel

pixel (100, 50)
offset = 50 × 7680 + 100 × 4
       = 384,400 bytes from the start

Rows can include padding, extra bytes that let the next row start at a required memory boundary. A row of 1919 pixels needs 7676 bytes for its pixels, but its stride could still be 7680. Moving by width × 4 would then leave us four bytes short of the next row and eight bytes short on the following row.

The Linux framebuffer API reports row length separately so programs can read and write pixels using the actual layout.

Our formula assumes a single image plane, one set of pixel rows stored line by line. GPU images can instead use tiles, compressed blocks or separate regions for colour components. Those layouts need different calculations. An address and a resolution alone do not describe them.

For the simple layout, we now know where a pixel starts. The next question is what its bytes mean.

The pixel format tells us what those bytes mean

A pixel can carry 24 bits of colour while occupying 32 bits, or four bytes, in memory. The remaining bits do not automatically represent transparency. Colour depth and storage size describe different properties.

Xlib, a library for talking to an X11 display server, keeps separate fields for depth, stored bits per pixel, bytes per row and byte order in its image structure.

Suppose a pixel's numeric layout is 0x00RRGGBB, where RR, GG and BB are its red, green and blue bytes. In little endian memory, the bytes appear as BB GG RR 00. Little endian stores the least significant byte first, starting at the right of this written number.

Red therefore appears in different positions in the number and a memory dump. Reading the right number of bytes in the wrong order can still produce the wrong colours. I check colour information, storage size and byte order separately.

With the row layout and pixel format, we can find and interpret the pixels. Drawing an image means producing those values. Showing it on a screen adds another job.

Display hardware reads the finished image

A software renderer calculates pixel values on the CPU and writes them into memory. A GPU renderer sends commands to the GPU to produce image buffers. Either way, the image exists before it appears on a screen.

The display controller reads the selected buffer and sends its pixels towards the screen. This is scanout. It can read the buffer without the CPU sending each pixel, and keep reading an unchanged image while the application does no new drawing.

To understand its timing, picture two counters. The horizontal counter tracks position across a line. The vertical counter tracks the line within a frame. A pixel clock advances the horizontal timing. At the end of a line, the horizontal count starts again and the vertical count advances.

This timing includes visible pixels and gaps outside the image. The gap between one frame's last visible row and the next frame's first visible row is vertical blanking, or vblank. It is part of signal timing, not a visible black flash between frames.

A display mode therefore needs a pixel clock, synchronization signal lengths and blanking intervals as well as a resolution. The kernel's panel timing description defines these fields. The screen has further electronics to control its physical pixels.

Repeated scanout also means repeated image reads. We can estimate that data by reading our four byte per pixel image 60 times each second.

8,294,400 × 60 = 497,664,000 bytes per second
                 about 498 MB/s

This counts full image bytes, not a particular GPU's measured traffic or the required HDMI bandwidth. Display links add encoding and timing overhead. Drawing also moves data, while caching and compression can change actual memory traffic.

That describes repeatedly showing one image. A changing image introduces another problem. The application may be drawing while the controller is reading.

Drawing the next image needs coordination

If an application changes a buffer during scanout, the top of the displayed frame could show the old image and the bottom the new one. That is one way tearing happens.

Double buffering gives the application a back buffer for drawing the next image while the display reads the front buffer. Once drawing finishes, the display system can switch at the intended point in the refresh cycle. A page flip changes which buffer supplies the image without necessarily copying its pixels into the old buffer.

The drawing must finish before the display uses its result. A graphics fence signals when work has finished, including asynchronous GPU work that may complete after the CPU submits it. Coordinating the switch with vblank handles display timing. Extra buffers alone do not ensure either step. The kernel documents these signals and display events.

We now have the memory, drawing and timing parts of a physical display. Software still needs a way to control that hardware. On Linux, it does so through kernel drivers.

Linux manages the hardware through drivers

Desktop applications usually reach graphics drivers through libraries and display software running outside the kernel. The kernel provides graphics interfaces through its Direct Rendering Manager, or DRM. Its Kernel Mode Setting interface, KMS, lets display software configure outputs and choose their image buffers.

KMS names the parts we have been following. A framebuffer object describes the image's storage and pixel layout. A plane supplies image content. A CRTC controls scanout and timing. A connector represents an output such as HDMI or DisplayPort.

CRTC is an old name that remains in the API. These names appear in driver code, and the KMS overview shows their connections.

Programs access graphics devices through special files. Opening one returns a handle for sending driver requests.

  • /dev/dri/card0 provides a DRM device, including display configuration and other graphics operations when the program has the required permissions.
  • /dev/dri/renderD128 allows rendering work on a supporting driver, without control of display modes.
  • /dev/fb0 provides the older framebuffer device interface on systems that have one.

These paths are examples and need not exist on every machine. A render device can give a program GPU access without a desktop, but does not start an X11 or Wayland server. The render node documentation explains this separation.

Likewise, an application must understand /dev/fb0's interface to use it. That device does not provide a normal desktop display connection. Creating windows, receiving input events and asking about screens require windowing services above the driver.

Those windowing services are the next part a background application may be missing. Starting Linux in a microVM does not automatically start a desktop session.

Window requests go to a display server

Applications connect to a display server to create windows, ask about supported image formats and receive events such as mouse movement or a request to close a window.

Under X11, the application is a client of the X server. They can run on the same machine or connect across machines. The word server names its role, not a separate computer. This is part of the X Window System interface.

On a desktop, a window manager handles window placement and decorations such as borders and title bars. A compositor combines window images into the desktop we see. The same desktop component may do both jobs, which go beyond storing pixels.

Under Wayland, the compositor is also the display server. Applications draw into buffers, then tell it which buffers to display. The Wayland architecture documentation explains the drawing and communication.

Together, these parts form a common desktop display path.

A common path from application pixels to a physical display ApplicationDraws a window Window buffers CompositorCombines visible windows Output framebuffer Display controllerScans out pixels Display linkPhysical panel
A common path from application pixels to a physical display

Hardware planes can also combine images, while direct scanout lets the display read an application buffer without first drawing a combined desktop image.

An application saving a file may need the windowing connection even though it never needs physical display output. We can keep the services it talks to and leave out the final connection to a screen.

Xvfb keeps that connection without physical output

Xvfb stands for X virtual framebuffer. It runs an X11 server without physical display hardware or input devices. Applications can ask about screens and create windows whose pixels stay in a virtual framebuffer in memory.

By default, Xvfb gets that memory with malloc. Its -fbdir option uses memory mapped files, while -shmem uses System V shared memory, an operating system interface for sharing memory between processes. The Xvfb manual describes these options.

Xvfb runs in userspace, outside the kernel, using memory managed by Linux. It adds no graphics card to the VM and needs neither a physical screen nor /dev/fb0.

An application can use a virtual display while producing a separate file Application XvfbX11 Screenpixels Outputfile
An application can use a virtual display while producing a separate file

The application still runs its existing code. It can draw windows and wait for input. Xvfb supplies the X11 environment without turning the application into a command line program. To use it for a job, we need the server to stay alive until that job finishes.

Running a command inside the virtual display

On Debian or Ubuntu, these packages install Xvfb, its access credential utility and tools for checking the display connection.

sudo apt-get update
sudo apt-get install -y xvfb xauth x11-utils

xvfb-run manages the server for one command. It starts Xvfb, creates an access credential called an authority cookie, and supplies the command's connection settings. When the command finishes, it shuts down the temporary server and cleans up. The wrapper manual describes this lifecycle.

We can check it with xdpyinfo, which connects and prints the server's screen information and supported image formats.

xvfb-run -a -s "-screen 0 1920x1080x24" xdpyinfo

-a finds an available display number. The screen option creates screen 0 at 1920 pixels wide, 1080 pixels tall and a colour depth of 24. As before, depth is separate from storage size. That 24 does not promise three bytes per pixel. The virtual screen's size also does not set an exported image's resolution.

Replace xdpyinfo with the application command. Keep it in the foreground so the wrapper waits for it. If a wrapped shell starts the application in the background and exits, cleanup can remove the display while the application still needs it.

The wrapper also tells the application which server it started. Those connection settings matter when several jobs run on the same machine.

DISPLAY identifies the server a command uses

The X11 name :99.0 means local display number 99, screen 0. Leaving off the suffix gives :99, which normally selects screen 0. Linux commonly uses a Unix socket such as /tmp/.X11-unix/X99 for this connection. A Unix socket lets processes on the same machine communicate.

Setting the name only tells an application where to connect.

export DISPLAY=:99

It starts no server. A server must already be listening, and the application's credentials must be accepted. xvfb-run supplies DISPLAY and XAUTHORITY, which points to the file holding those credentials.

If the wrapper selects :100 but the application resets DISPLAY to :99, it looks for a different server. The connection or authentication may fail. Let the application inherit the wrapper's settings.

Native Wayland applications instead use WAYLAND_DISPLAY, with a socket in XDG_RUNTIME_DIR. Xvfb cannot accept Wayland connections just because DISPLAY is set. The toolkit needs a matching backend, the part that knows how to communicate with X11 or Wayland.

That protocol choice is one reason Xvfb is not the answer to every missing display. Other tools provide different parts of the system.

Other tools replace other parts of the system

The choice depends on the interface an application needs and whether a person needs to view or control it.

  • Xvfb provides an X11 display in memory for background applications.
  • Weston's headless backend provides Wayland without physical output, for running applications or testing a compositor.
  • Xvnc provides X11 with remote viewing and control through VNC.
  • VKMS provides a virtual Linux display driver for testing DRM/KMS software without physical display hardware.

Weston supports several renderers, including Pixman for CPU drawing. It needs a suitable runtime directory for its Wayland socket. This supplies a Wayland connection, rather than X11, even when neither uses a physical screen.

TigerVNC's Xvnc combines an X server for applications with a VNC server for remote viewers. Xvfb has no viewer service of its own. Inspecting its screen needs a screenshot or an additional remote access tool.

VKMS works inside the kernel and models display resources for KMS software. It requires kernel support and access to that interface. A program needing an X11 connection does not automatically need this virtual driver just because the machine has no screen.

Each tool supplies a particular interface. The software that draws the pixels is another part to check, especially for applications using OpenGL.

OpenGL rendering is a separate requirement

OpenGL is an interface for drawing graphics. A program needs an implementation and a suitable rendering context, which keeps its drawing state. An X server connection alone does not provide everything OpenGL needs.

Mesa's LLVMpipe driver draws on the CPU, letting some applications render without a GPU. Its supported features and CPU cost still matter. Xvfb provides the display environment, while LLVMpipe provides a renderer.

With a compatible Mesa installation, LIBGL_ALWAYS_SOFTWARE=true requests software rendering. Mesa documents the setting. It does not install a driver or guarantee support for the application's graphics features.

Some applications have their own headless or offscreen mode, producing output without a normal windowing session. If it supports the required operation, a display server may be unnecessary. An existing application path may still expect one, as mine did.

One worker that needed these parts

At PCB Cupid, I needed KiCad to process a board in a cloud microVM. The worker loaded the board, filled its copper zones and saved it. Copper zones are board areas filled with copper according to the board's rules. The result I needed was a board file.

That script also initialized wxPython, the toolkit used by this code path for its graphical interface. On the worker, initialization needed X11. These excerpts shorten the file path and leave out surrounding checks.

import wx
wx.App(False)

import pcbnew
board = pcbnew.LoadBoard("/tmp/board.kicad_pcb")
zones = list(board.Zones())
filler = pcbnew.ZONE_FILLER(board)
filler.Fill(zones)
board.Save("/tmp/board.kicad_pcb")

pcbnew lets Python call the editor's internal code. wx.App initializes the toolkit. Its False argument controls redirection of standard output and standard error, not the display requirement. The wxPython documentation explains this. In a standalone script, I would keep the application object reference with app = wx.App(False).

The worker runs these scripts through Xvfb.

await executeCommand(
  sandbox,
  "xvfb-run -a python3 /tmp/fill_zones_verify.py",
  60000,
);

This gave the toolkit a display connection so the board operation could finish. Nobody needed an editor window or a desktop to operate.

The snippets use the older Python bindings generated by SWIG, known as pcbnew, which KiCad deprecated in version 9. The bindings documentation explains their status. KiCad also has command line operations and a newer IPC interface for communication from another process. Its headless support depends on the version. This display dependency belonged to the worker's path, not every KiCad operation.

The same separation that explained this worker also gives us a way to investigate failures. We can check the display connection before bringing the whole application into the problem.

Checking the parts when a job fails

I would start with xdpyinfo. If it cannot connect, check server startup, the display name and credentials.

If it connects but the toolkit cannot initialize, check the installed libraries and selected X11 or Wayland backend. If the toolkit starts but the rendering context fails, check the graphics implementation. A missing window can come from any of these failures.

A working connection still does not run the application's event loop. The application runs that loop itself to receive events and pass them to windows. A short synchronous task, waiting for each call to finish before continuing, may not need it. Interactive work or work completed through later events may depend on it.

An application may also pause at a modal dialog until a person responds, even on a virtual display. A screenshot can reveal that wait. With Debian or Ubuntu's x11-apps package installed, this captures the root window, the screen's base window, without a mouse click.

xwd -root -silent -out /tmp/display.xwd

Use the application's display while it is still connected. A fresh xvfb-run starts another server and cannot capture the previous job's windows. The output is an X Window Dump file, not PNG. The xwd manual describes the format and capture options.

A working connection only proves that the application can reach the display server. Its intended output still needs checking.

I now follow the same path when a job asks for a display. Find where its pixels live, what draws them and which display interface its code expects. That tells me what must run, even when no physical screen is attached.