Home / Alt manpages / deallocvt(1)

  • deallocvt(1)
  • User command
  • linux

Free Idle Virtual Consoles with deallocvt

Nobody has touched /dev/tty3 in months, but the kernel is still holding memory for it, and deallocvt hands that memory back. The examples use kbd 2.6.4, installed here as package version 2.6.4-2ubuntu2, and take about ten minutes.

You need a shell on a Linux host with the kbd package installed. Inspecting the command is ordinary, read-only work. Running it changes kernel state, so treat it as an administrative operation and do not do it while someone may be using a text console.

1. Confirm the installed command

Check the binary, package and version. None of this deallocates anything, and it normally needs no elevated privileges:

$ command -v deallocvt
/usr/bin/deallocvt
$ deallocvt --version
deallocvt from kbd 2.6.4
$ dpkg-query -W -f='${Package} ${Version}\n' kbd
kbd 2.6.4-2ubuntu2

The command takes optional console numbers. Its installed synopsis is deallocvt [option...] [N ...]. The -h/--help and -V/--version options only report information.

Checkpoint

If command -v finds a different executable, stop and read that system's installed documentation. Do not assume another implementation behaves the same way.

2. Know what counts as unused

A console is not unused just because it is not on your monitor. The installed manual sets three conditions:

  • Not in the foreground. It must be away from the foreground console.
  • Nothing open. No process has it open for reading or writing.
  • No selection. No text is selected on its screen.

With no console numbers, deallocvt considers every console meeting those conditions. With one or more numbers, it considers only the matching devices, such as /dev/tty3 for the argument 3. It will not make a busy console unused for you.

This is a resource-reclamation command. It does not log users out or close arbitrary terminal sessions, and it has no option to force deallocation. Do not use it to shift an occupied console by guessing at a number.

3. Pick one target

If you know a particular console is unused, prefer a single numeric argument over a blanket scan. Replace CONSOLE_NUMBER with a real number from your host:

$ CONSOLE_NUMBER='3'
$ printf 'selected device: /dev/tty%s\n' "$CONSOLE_NUMBER"
selected device: /dev/tty3

The assignment and printf are harmless checks. They do not ask deallocvt to act. Keep the number as a separate shell argument, and quote the variable if you later build a scripted command.

There is no universal list of safe console numbers. The foreground console and the ones used by login managers, monitoring tools, installers or recovery sessions vary by host. A console that looks quiet may still be held open by a background process.

4. Check for users and open handles

Before changing state, inspect the chosen device with ordinary diagnostic tools. Substitute the device from the previous step:

$ CONSOLE_DEVICE='/dev/tty3'
$ ls -l "$CONSOLE_DEVICE"
$ fuser "$CONSOLE_DEVICE"
$ lsof "$CONSOLE_DEVICE"

Empty output from fuser or lsof is useful evidence, not a permanent guarantee, because a process can open the device after your check. Both tools may be missing on a minimal install, and their output is host-specific. Do not swap a missing tool for a guessed result.

Also check which console is in the foreground, if your host provides the usual virtual-console interfaces:

$ fgconsole
3

The number here is illustrative. If it matches your chosen console, do not deallocate it. If fgconsole is unavailable or errors, stop and investigate rather than treating that as proof the console is safe.

Warning

Do not run the command from a maintenance procedure that may be using the target console, and do not use a broad command while an operator is working in a text-mode session. The operation is small, but it acts on shared kernel resources.

5. Deallocate one verified console

Once the checks show the target is neither in the foreground nor in use, run the command with that number:

$ sudo deallocvt "$CONSOLE_NUMBER"

Use an elevated shell only when your host's permissions require it. If the command reports permission denied, record that exact error and check the device permissions and administrative policy before retrying. Adding sudo does not make a console safe to reclaim.

On success it normally prints nothing and returns status zero. Capture the status straight away:

$ status=$?
$ printf 'deallocvt exit status: %s\n' "$status"
deallocvt exit status: 0

A non-zero status means the operation did not complete as expected. Keep the diagnostic output, re-check the device and consult deallocvt --help or the local manual. Do not turn a failed targeted attempt into an unreviewed all-console run.

6. Verify without expecting a message

deallocvt has no documented per-console success report and no documented dry-run option. So verification means checking conditions and exit status, not waiting for a message saying a device was freed.

Repeat the non-destructive checks for the target:

$ fuser "$CONSOLE_DEVICE"
$ lsof "$CONSOLE_DEVICE"
$ fgconsole

Checkpoint

Empty process listings and a foreground console number different from the target are consistent with the intended result. They do not prove a race was impossible, and they do not tell you how many bytes were reclaimed. The installed manual promises neither measurement.

Recovery

There is no persistent configuration file to edit and no documented undo command. If the console is needed later, switch to it or start a login service using your distribution's normal tools. Do not try to recreate a console by inventing device nodes or writing directly under /dev.

7. Use the all-console form on purpose

After a maintenance window, you may choose to let the command inspect every unused console:

$ sudo deallocvt

This is broader than the numbered form. It still only deallocates consoles meeting the unused definition, but a changing host can have more eligible consoles than you meant. Prefer the targeted form for one known stale console, and keep the all-console form for a controlled cleanup where every eligible virtual console is in scope.

Warning

Do not put a shell wildcard after the command. Console numbers are arguments, not file names, and a wildcard can expand to unrelated directory entries. If you automate this, validate that each generated value is a decimal console number before passing it, and log the exact list.

Done means

  • Version confirmed. The installed command is kbd 2.6.4 and you read its local synopsis.
  • Device named. You identified a specific console device instead of guessing from a screen number.
  • Handles checked. You looked at the foreground console and for processes holding the target.
  • Scope chosen. You used a numbered invocation for narrow cleanup, or knowingly approved the all-console form.
  • Result recorded. You captured the exit status and repeated the non-destructive checks afterwards.
  • No undo remembered. There is no documented undo, so future use follows the same checks.