Reclaim Unused Linux Virtual Consoles with deallocvt
You will finish with a controlled way to release kernel memory and data structures belonging to unused Linux virtual consoles. The examples use deallocvt from kbd 2.6.4, installed here as package version 2.6.4-2ubuntu2.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow 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 avoid doing it while someone may be using a text console.
1. Confirm the installed command
Start by checking the binary, package and version. These commands do not deallocate anything and normally need 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 accepts 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 before continuing. Do not assume another implementation has the same behaviour.
2. Understand what counts as unused
A virtual console is not merely unused because it is not visible on your monitor. According to the installed manual, it must be away from the foreground console, have no process open for reading or writing, and have no text selected on its screen.
With no console numbers, deallocvt considers every console meeting those conditions. With one or more numbers, it considers only the corresponding devices, such as /dev/tty3 for the argument 3. The command will not make a busy console unused for you.
This is a resource-reclamation command, not a way to log users out or close arbitrary terminal sessions. It does not provide an option to force deallocation. Do not use it to solve an occupied console by guessing at a number.
3. Choose a narrow first target
If you already know that 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 use quotes around a variable if you later build a scripted command.
There is no universal list of safe console numbers. The foreground console and the consoles used by login managers, monitoring tools, installers or recovery sessions vary by host. A console that looks quiet may still be open by a background process.
4. Check for users and open handles
Before changing state, inspect the selected device with ordinary diagnostic tools. Substitute the device you identified in 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, but it is not a permanent guarantee. A process can open the device after your check. These tools may be absent on a minimal installation, and their output is host-specific. Do not replace a missing tool with a guessed result.
Also check which console is in the foreground if your host provides the usual virtual-console interfaces:
$ fgconsole
3
The number in this example is illustrative. If it matches your selected console, do not deallocate it. If fgconsole is unavailable or gives an error, stop and investigate rather than treating that as proof that 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 its effect is on shared kernel resources.
5. Deallocate one verified unused console
Once the checks show that the target is not the foreground console and is not being used, 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. Do not assume that adding sudo makes a console safe to reclaim.
On success, this command normally prints nothing and returns status zero. Capture the status immediately:
$ 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 command's 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 assuming a visible result
deallocvt has no documented success report for each console and no documented dry-run option. Verification is therefore about the conditions and exit status, not a fabricated message saying that a device was freed.
Repeat the non-destructive checks for the target:
$ fuser "$CONSOLE_DEVICE"
$ lsof "$CONSOLE_DEVICE"
$ fgconsole
Empty process listings and a foreground console number different from the target are consistent with the intended result. They do not prove that a race was impossible, nor do they tell you the exact number of bytes reclaimed. The installed manual does not promise either measurement.
There is no persistent configuration file to edit and no undo command documented for deallocvt. If the console is needed later, switch to it or start a login service using the normal tools for your distribution. Do not attempt to recreate a console by inventing device nodes or writing directly under /dev.
7. Use the all-console form only deliberately
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 that meet the unused definition, but a changing host can have more eligible consoles than you intended. Prefer the targeted form when you are reclaiming one known stale console. Reserve the all-console form for a controlled cleanup where every eligible virtual console is in scope.
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 need automation, validate that each generated value is a decimal console number before passing it as an argument, and log the exact list.
Done means
- You confirmed that the installed command is kbd 2.6.4 and read its local synopsis.
- You identified a specific console device instead of guessing from a screen number.
- You checked the foreground console and looked for processes holding the target device.
- You used a numbered invocation for a narrow cleanup, or consciously approved the all-console form.
- You recorded the exit status and repeated non-destructive checks afterwards.
- You know there is no documented undo operation, so future use will follow the same maintenance-window checks.