Debian 13 Tutorial / Record a Server Baseline and Prepare an Independent VM Clone

Record a Debian server’s operating system, kernel, packages, services, network and mounts to compare its state before and after changes. When cloning a virtual machine, review both its hardware identity—the universally unique identifier (UUID) and network adapter’s Media Access Control (MAC) address—and its guest hostname, machine-id and SSH host keys. An inventory supports recovery decisions; it does not contain everything needed to restore the server.

Choose What to Include in the Baseline

Use the dedicated VM after completing initial setup and SSH key authentication checks. Recording a known working state helps you identify changes after package installation, updates or service configuration. Define what you are comparing and when each record was collected rather than relying on memory of a screen.

Record What the Record Tells You Contents not included
OS and kernel What distribution and running kernel are being used? The list of all installed kernels and the running kernel are different.
Packages and manual-install marks Which version and installation status have been recorded? These are not the actual .deb files or application data.
Services What are the boot settings and the current running status? The fact that it is running does not guarantee the normal response of the service.
Addresses, routes and mounts How are the communication and storage device connections currently set up? It does not collect all permanent configuration files and firewall policies.

Backups of configuration files, data, and secrets are managed by separate policies. The same server cannot be automatically reproduced with only the package list. This is because previous versions may disappear from the repository, and source installers, containers, and application settings do not all appear in the dpkg list.

Run the Complete Baseline Collection Script

Run this in Debian as a regular user. In a dedicated working directory, paste the complete block to create collect-baseline.sh and run it; if that filename already exists, inspect it and choose a fresh name rather than overwriting it. The script uses umask 077 to restrict newly created records to their owner. It reads system state and creates a new directory in your home without changing system settings.

cat > collect-baseline.sh <<'EOF'
set -eu
umask 077
record_dir="$HOME/server-baseline-$(date -u +%Y%m%dT%H%M%SZ)"
mkdir "$record_dir"
cat /etc/os-release > "$record_dir/os-release.txt"
uname -r > "$record_dir/kernel.txt"
dpkg-query -W -f='${binary:Package}\t${Version}\t${db:Status-Status}\n' > "$record_dir/packages.tsv"
apt-mark showmanual > "$record_dir/manual-packages.txt"
systemctl list-unit-files --type=service --no-pager > "$record_dir/service-files.txt"
systemctl list-units --type=service --state=running --no-pager > "$record_dir/running-services.txt"
ip -br address > "$record_dir/ip-address.txt"
ip route > "$record_dir/routes.txt"
findmnt --real > "$record_dir/mounts.txt"
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINTS > "$record_dir/disks.txt"
printf '%s\n' "$record_dir"
wc -l "$record_dir"/*
test -s "$record_dir/packages.tsv"
test -s "$record_dir/mounts.txt"
EOF
bash collect-baseline.sh

The first output line is the generated directory path, followed by line counts for each file. In the Debian 13.7 minimum-server lab, packages.tsv contained 334 records and the manual-install list contained 200. These are observations from that VM, not Debian’s required package counts. Read the status column: a package record can describe a removed package with configuration files remaining, so not every row means an installed package.

The dpkg-query manual documents -W and the output format to separate package, version, and status with tabs. Single quotes prevent expressions like ${Version} from being interpreted by the shell first. apt-mark showmanual shows packages that APT has marked as manually installed. This does not necessarily mean that a person installed them individually; they may also be marked by the installer or image configuration.

If re-executed in the same second and the directory already exists, mkdir will fail and stop. Do not delete or overwrite existing data; try again after a short while. set -e stops to prevent partially recorded data from being misinterpreted as a complete result after a failure, but pre-error files may remain, so check that the last two checks also succeeded.

Inspect Records and Compare Changes

Receive the output path and check its contents. Since the script was run with a separate bash, do not assume that the record_dir variable inside it remains in the current shell.

read -r -p 'Generated baseline directory: ' baseline_dir
ls -ld "$baseline_dir"
head -n 5 "$baseline_dir/packages.tsv"
cat "$baseline_dir/kernel.txt"
cat "$baseline_dir/mounts.txt"

In ls -ld, check whether you are the owner of the record directory and that the mode does not allow access to other users. Network addresses and service lists also reveal server structure, so do not upload the original directory to public boards as is. The script does not collect SSH private keys, password files, or the raw machine-id.

After making changes, run the collection script again and enter the two paths that are actually generated. For example, you can check the differences in package version changes and manual installation indicators, respectively.

read -r -p 'Baseline directory before the change: ' before_dir
read -r -p 'Baseline directory after the change: ' after_dir
diff -u "$before_dir/packages.tsv" "$after_dir/packages.tsv"
diff -u "$before_dir/manual-packages.txt" "$after_dir/manual-packages.txt"

No diff output means the compared files match. Changed lines appear with - for the earlier file and + for the later one. An exit status of 1 means differences were found; an unreadable file is a different error. Running-service records can also change because transient services start or stop, or output order varies. Do not infer a failure from one changed line alone. Copy records you need to keep to separate access-controlled storage that survives loss of the VM disk.

Understand Which Identities a Clone Copies

When you clone a virtual disk, the internal files of the operating system are also copied. Even if VirtualBox creates a new MAC for the new VM, you should not assume that the SSH host keys inside will also be automatically regenerated.

Information Management layer Checks Before Using the Clone as a New Server
VM UUID and MAC VirtualBox virtual hardware Use a new UUID and new MAC, and check before connecting to the network.
Hostname, IP address and DNS Guest and network settings Choose a name appropriate for the role and an address that is not duplicated.
machine-id Identify the guest operating system If it is a new server, verify that the value is unique.
SSH host key SSH server identity Generate a key for the new server and provide the verified fingerprint to clients.
User authentication keys and application secrets Account and application Separately review whether the copied access rights and tokens can be reused.

Disk and filesystem UUIDs and machine-id are different values. A replicated disk with the same file system UUID may exist within an independent VM, but if the original and the replicated disk are connected to a single guest at the same time, UUID-based mount selection may become ambiguous. Simply changing the disk UUID arbitrarily affects fstab and boot settings as well, so this practice does not do that.

Distinguish a replacement taking over a failed server’s role from an additional server that will run alongside the original. If the original is still serving traffic, do not connect a clone with duplicate addresses, names and authentication data to the same network.

Prepare an Independent Clone Offline

The practice targets only a minimal VM without business services. Properly shut down the original, then select the original in VirtualBox → execute the clone. Set a different name and storage path, choose full clone, current machine state, and generate new MAC addresses for all network adapters. Do not select the option to maintain the same hardware UUID. Linked clones depend on the original disk and snapshots, so they are not the same as independent backup.

The Oracle VirtualBox cloning documentation explains the available choices; check the options in your installed version. In the VirtualBox 7.2.10 lab, the full clone received a VM UUID and MAC address different from the original.

  1. In the settings of the clone, disable all network adapters. Also, check if the inherited NAT port forwarding matches the new server and remove any duplicate rules.
  2. The names and storage paths of the original and the copy are recorded separately. Only open the copy console to boot and log in.
  3. If operational apps, scheduled tasks, mail sending, external APIs, or backup tasks have been copied, stop and clean them up before connecting to the network. The minimal server in this article does not have such business services.

The reason the original host name appears inside the initial clone is that the setting was copied to the disk. First, check on this screen to make sure you haven't mistakenly selected the original VM itself. You can reduce the chance of error by turning off the original and keeping only the clone open.

Prepare the Clone’s Guest Identity and Shut Down

Apply this procedure only inside the intentionally disconnected new clone that will become a separate server. Do not run it on the original or on a production server. Run the first backup-directory command separately, and stop if it fails. If the path already exists, inspect it and choose a fresh name consistently before continuing. Store the comparison files in the clone’s restricted directory.

sudo test ! -e /var/backups/clone-identity-before && sudo install -d -m 700 /var/backups/clone-identity-before
sudo cp -a /etc/machine-id /etc/hostname /etc/ssh/ssh_host_ed25519_key.pub /var/backups/clone-identity-before/
sudo hostnamectl set-hostname debian13-clone01
sudo nano /etc/hosts

Only the lines in /etc/hosts with the previous name are updated to the new name. For host name settings and local name resolution methods, apply the procedures of hostname, time zone and locale exercise. Remove the existing SSH host keys of the replica and generate new keys using the following command. The contents of the private key are not displayed on the screen.

sudo rm -f /etc/ssh/ssh_host_*_key /etc/ssh/ssh_host_*_key.pub
sudo ssh-keygen -A
sudo /usr/sbin/sshd -t
sudo ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub

Since this task creates the identity of the new server, it is not directly applicable to recovery operations that retain the SSH identity of an existing server. Servers with separate configurations such as host certificates or hardware keys also do not use the general minimal installation example as is.

Services use machine-id as a stable identifier. Do not change it and then continue normal operation with services using mixed old and new identity state. For this isolated minimal clone, prepare the files below and immediately perform a normal shutdown so that a new ID is generated at the next boot. Automated generic-image deployment is better handled through a deliberate offline image-preparation process.

ls -l /var/lib/dbus/machine-id
sudo truncate -s 0 /etc/machine-id
sudo ln -sfn /etc/machine-id /var/lib/dbus/machine-id
sudo systemctl poweroff

This example targets a minimal Debian configuration where /var/lib/dbus/machine-id is a regular file or a link to /etc/machine-id. If the directory or mount differs from expectations, stop and verify. According to the systemd machine-id manual, an image with an empty machine-id generates an ID at boot. If a separate D-Bus ID is left as is, the previous value may be reused, so both paths are addressed together. Emptying the value and removing the file have differences in first-boot determination, so they are not used interchangeably.

Verify the Clone After Reboot

Restart only the clone, with networking still disabled, and log in through its console. Compare machine-id with the saved value without displaying either ID. The conditional reports unchanged identity, different identity or a comparison error; a difference is meaningful only after the files and format have also been verified.

hostnamectl --static
if sudo cmp -s /etc/machine-id /var/backups/clone-identity-before/machine-id; then
  printf 'machine-id is unchanged. Investigate before enabling the network.\n'
else
  case "$?" in
    1) printf 'machine-id differs from the previous value.\n' ;;
    *) printf 'Comparison failed. Check file existence and permissions.\n' ;;
  esac
fi
sudo wc -c /etc/machine-id
sudo grep -Eq '^[0-9a-f]{32}$' /etc/machine-id && printf 'machine-id format check passed\n'
sudo cmp /etc/machine-id /var/lib/dbus/machine-id
sudo ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
sudo /usr/sbin/sshd -t

For cmp, exit status 1 means different content; other error statuses indicate problems such as missing or unreadable files. A machine-id contains 32 lowercase hexadecimal characters followed by a newline, normally 33 bytes, and must not be all zeros. Check the format message as well as the size. The D-Bus path should match /etc/machine-id without a cmp error. Compare the new SSH fingerprint with the fingerprint of the saved public host key; it should differ for this new-server clone.

In the dedicated cloning practice, we confirmed the new host name, machine-id and SSH public host key differing from the original, D-Bus ID consistency, and SSH syntax check. We also restarted the original to separately compare that the original name, machine-id, and SSH key were preserved. A failed clone is shut down without connecting to the network to prepare it again, and we do not reset the original identification information to fix the clone.

Before connecting the new server to a working network, review addresses, DNS, user authentication keys, service tokens and scheduled tasks, and enable only what it needs. Distinct VM identity values do not prove that all copied credentials and external integrations have been dealt with.