Debian 13 Tutorial / Identify a New Disk, Create GPT and ext4, and Verify Mounts

When adding a new disk to Debian 13, do not initialize it by just looking at the device name; instead, check the capacity, serial number, partitions, and usage status before and after adding it. After confirming that it is a newly created empty disk, create a GPT partition table and an ext4 file system, then verify the actual storage results through mounting, writing, and remounting.

Confirm the New-disk Lab’s Scope

This lab adds one newly created 8 GiB VDI disk to a Debian 13 VM in VirtualBox 7.2. The existing 40 GiB system disk is preserved. GPT (GUID Partition Table) records a disk’s partition layout; ext4 is the filesystem that stores files and directories inside the partition. Creating the partition table and creating the filesystem are separate operations.

sfdisk and mkfs.ext4 can damage the existing storage structure and data of the selected target. The following operations apply only to a newly created dedicated disk. Do not assume an unknown disk, a disk with existing data, or a disk used by running services is an empty disk. Unmounting does not restore the data before formatting.

Check the tools you are using. In this environment, sfdisk 2.41.5 from the fdisk package and mke2fs 1.47.2 from e2fsprogs were installed. If the tools are not available, review the package change list and install the necessary packages.

command -v lsblk sfdisk mkfs.ext4 wipefs udevadm mount findmnt
dpkg-query -W fdisk e2fsprogs

Record Existing Storage, Then Attach a New Virtual Disk

First, record the existing disk and system mounts on the guest.

lsblk -b -o NAME,PATH,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL,SERIAL
findmnt -n -o SOURCE,FSTYPE /
cat /etc/fstab

In this practice, /dev/sda is a 42,949,672,960-byte system disk, sda1 is EFI, sda2 is root, and sda3 is swap. Do not generalize the name of this device as the system disk name for all computers. In NVMe, LVM, or multi-disk environments, the paths and relationships may vary.

  1. Shut down the VM normally with sudo systemctl poweroff and confirm in VirtualBox that the power is off.
  2. Go to the target VM's Settings → Storage → SATA Controller → Add Hard Disk , and create a new disk. Do not remove or replace the existing system disk entry.
  3. Select VDI, dynamically allocated, 8GiB, and record the location and size of the new file. Distinguish this from the option to reuse an existing disk file.
  4. Check that the new disk has been added to an empty SATA port and boot the VM normally.

Exact UI labels may vary depending on the version. VirtualBox virtual storage description distinguishes between disk images and controller connections. A dynamically allocated VDI initially shows a small host file size but displays the logical size set for the guest, consuming host space as it is used. Free space on the host is also required.

Identify the Disk by Capacity, Serial Number and Use

sudo udevadm settle
lsblk -b -o NAME,PATH,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL,SERIAL
ls -l /dev/disk/by-id/ata-VBOX_HARDDISK*
findmnt -n -o SOURCE,FSTYPE /

udevadm settle is a command that waits for device event processing to complete. It helps reduce situations where information is not yet ready immediately after a new device is added. lsblk manual guides scripts to specify output columns and check mount relationships.

Devices confirmed in practice Capacity Serial number Status
Existing /dev/sda 40GiB VBe2c98114-1df921f9 EFI, root and swap in use; preserve this disk
New /dev/sdb 8GiB, 8,589,934,592 bytes VB50a843e8-b263b0b5 No partitions, filesystem or mounts

This table shows the identification values for the actual exercise. In the reader's VM, the serial number and device name will differ. Do not judge a disk as new based solely on the name /dev/sdb. Compare the before-and-after inventory to confirm that the device is newly present and matches the disk created in VirtualBox. The by-id path is also a means to aid identification, but it does not guarantee that the serial numbers of all devices are absolutely unique.

The following commands are executed in the same Bash terminal. The variables below are the actual by-id paths for this exercise. Replace them with the full paths and serial numbers corresponding to your new disk and check the results. The partition path -part1 has not yet been created.

data_disk=/dev/disk/by-id/ata-VBOX_HARDDISK_VB50a843e8-b263b0b5
expected_serial=VB50a843e8-b263b0b5
readlink -f "$data_disk"
lsblk -b -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,SERIAL "$data_disk"
sudo wipefs --no-act "$data_disk"

If a signature of an existing partition table or file system appears in this wipefs check, stop and verify its source first. The wipefs manual --no-act refers to options that do not perform writing. Even if no signatures are visible, this does not prove the absence of raw data, so you should assess it along with the fact that it is a newly created VDI. Do not start by running wipefs -a merely because a signature was found.

Check the New Disk and Rehearse the GPT Layout

The following function checks the condition of a new 8GiB disk without partitions for this tutorial. Do not arbitrarily remove the check to fit devices of other sizes. You must complete the previous manual identification before performing the check.

check_new_data_disk() {
    test -b "$data_disk" || return 1
    test "$(lsblk -dnro TYPE "$data_disk")" = disk || return 1
    test "$(lsblk -dnro SERIAL "$data_disk")" = "$expected_serial" || return 1
    test "$(sudo blockdev --getsize64 "$data_disk")" = 8589934592 || return 1
    test "$(lsblk -nr -o NAME "$data_disk" | wc -l)" = 1 || return 1
    test -z "$(lsblk -nro FSTYPE,MOUNTPOINTS "$data_disk" | tr -d '[:space:]')" || return 1
    signature_types=$(sudo wipefs --no-act --noheadings --output TYPE "$data_disk") || return 1
    test -z "$signature_types" || return 1
}
check_new_data_disk && printf 'New data disk checks passed\n'

If there is no success message or an error occurs in any command, stop. This check is a supplementary procedure to filter out devices that already have mounted devices/partitions or known signatures. It is not an approval that an unknown disk can be initialized.

Create a layout file in the general user's home directory. If the same file already exists, do not overwrite it.

test ! -e "$HOME/lf-data21-layout.sfdisk" &&
cat <<'EOF' > "$HOME/lf-data21-layout.sfdisk"
label: gpt
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, name="lf-data21"
EOF
check_new_data_disk &&
sudo sfdisk --no-act --lock "$data_disk" < "$HOME/lf-data21-layout.sfdisk"

The type value is the GPT Linux filesystem partition-type identifier. Omitting start and size uses default alignment and proposes one partition in the available space. The name field is the GPT partition name, separate from the ext4 LABEL set later. This example uses the named-field input and locking options documented in the sfdisk manual.

Even in the simulation output, expected results indicating that a new GPT or partition was created may appear, but it is not written to the device when --no-act is used. Check again with lsblk and wipefs to ensure there are no partitions or signatures. In this exercise, the initial input format was rejected in the simulation check and corrected before actual writing, and proceeded only after the above named-field format passed.

Write the GPT and Create ext4 on Its Partition

Check again that the capacity and device for target identification, inspection, and simulated output are all correct. The following is the actual recording step and not a command to be executed repeatedly.

check_new_data_disk &&
sudo sfdisk --lock "$data_disk" < "$HOME/lf-data21-layout.sfdisk"
sudo udevadm settle
data_part="${data_disk}-part1"
lsblk -o NAME,SIZE,TYPE,FSTYPE,PARTLABEL,MOUNTPOINTS "$data_disk"
readlink -f "$data_part"

Confirm whether one Linux filesystem partition under the disk and the partition named lf-data21 appear. In this exercise, the by-id partition path is linked to /dev/sdb1. If the partition is not yet visible or there was an error, do not proceed to formatting but check the device events and output first.

sudo mkfs.ext4 -L lf-data21 "$data_part"
sudo blkid "$data_part"

Run mkfs.ext4 on the newly created partition, not the whole disk. Do not use -F to force past filesystem checks. If an unexpected existing file system warning appears, do not force it and check the target again. The normal result will show TYPE=ext4, LABEL=lf-data21, and a new file system UUID. The UUID will differ each time. For creation options, refer to mkfs.ext4 documentation.

Mount the Filesystem and Test Ordinary-user Writes

Mounting is the process of connecting the file system to the directory tree. Make sure the new mount point is empty before proceeding. If the path below already exists, first check the internal files and the current mount.

sudo test ! -e /mnt/lf-data21 &&
sudo install -d -m 755 /mnt/lf-data21
sudo mount "$data_part" /mnt/lf-data21
findmnt --mountpoint /mnt/lf-data21
df -hT /mnt/lf-data21
sudo install -d -m 750 -o lfstudent -g lfstudent /mnt/lf-data21/work

In findmnt, check if the actual source is a new partition and whether it is ext4 with read-write access, then create a work folder for the user. If the mount fails but you create a folder underneath, you can write files to an empty mount point on the system disk, so the order of checking first is important. There is no need to open the entire filesystem root with chmod 777.

In a regular-user terminal logged in as lfstudent, write a file and check its contents. If you selected another user, also set the owner of the work folder to that user.

printf 'data-disk21\n' > /mnt/lf-data21/work/probe.txt
cat /mnt/lf-data21/work/probe.txt
sha256sum /mnt/lf-data21/work/probe.txt

The content is a single line of data-disk21. The SHA-256 for the exact bytes of this example is 8f70d7ab45f8620653f5326352310929cb0157c7c63ca5c6586e4bd95314690b. The comparison includes line breaks, and this value is not a signature guaranteeing the source or safety of the file. The df capacity may be displayed differently from the original disk size due to file system metadata, reserved space, etc.

Unmount, Remount and Verify the Data

Move the current directory of the related terminal outside of the mount point and make sure there are no tasks using the files. If it fails because the files are in use, first check the cause and do not move on to forced or lazy unmount.

cd /
sudo umount /mnt/lf-data21
findmnt --mountpoint /mnt/lf-data21
sudo mount "$data_part" /mnt/lf-data21
cat /mnt/lf-data21/work/probe.txt
sha256sum /mnt/lf-data21/work/probe.txt

It is expected that findmnt cannot find the mount immediately after unmounting. When reconnected, the contents and hash should be the same. The original directory contents under the mount point may be hidden while mounted, and unmounting is the action that disconnects that link. You can check the meaning of connecting and disconnecting in the mount manual.

After finishing the exercise, unmount again and remove only the empty mount point.

cd /
sudo umount /mnt/lf-data21
sudo rmdir -- /mnt/lf-data21
lsblk -o NAME,SIZE,FSTYPE,LABEL,UUID,MOUNTPOINTS
findmnt -n -o SOURCE,FSTYPE /
cat /etc/fstab

The new partition's ext4, LABEL, UUID, and data remain, and only the mount is removed. Since the current exercise did not register automatic mounting in fstab, existing system entries are also retained. During exercise verification, the existing system partition table and fstab were compared before and after, confirming that the root UUID remained unchanged. To ensure the new disk is no longer connected, shut down the guest normally and then remove only the added data disk connection in VirtualBox. The decision to delete the VDI file and its contents is separate.