Rocky Linux 10 Tutorial / Identify a new disk, create GPT and format XFS

When connecting an additional disk to Rocky Linux 10, first compare the device's serial number, capacity, and usage status, then create a GPT partition table and partitions on that disk, and create a file system within the partition. Finally, mount it to an empty directory and perform actual file write and read operations to confirm whether it is ready for use. In this article, XFS is configured on a new practice disk separated from the existing system disk, without changing the automatic mount settings.

Preparation of the Practice Environment and New Disk

The disk created here is a separate virtual disk with no data, not the remaining space of the existing disk. Do not follow this procedure on an operational server or an external disk containing data. Creating a partition table and formatting can overwrite the existing structure and cannot be undone by unmounting.

The source lab environment was Rocky Linux 10.2 Minimal, kernel 6.12.0-211.74.1.el10_2.x86_64, VirtualBox 7.2.10. The system disk is 40 GiB, and the additional disk is a newly created 4 GiB VDI. The commands were executed in the Rocky Linux guest, not using GNU tools on Windows. The packages used are util-linux 2.40.2, parted 3.6, xfsprogs 6.16.0.

  1. Before adding the disk, save the following disk list from the existing VM. This serves as a reference for comparison with the list after connecting the new device.
lsblk -b -o NAME,PATH,TYPE,SIZE,MODEL,SERIAL,FSTYPE,MOUNTPOINTS
findmnt /
swapon --show
  1. Shut down the guest normally to sudo systemctl poweroff and verify that it is powered off in VirtualBox. Saved states or pauses are not considered as shutdowns.
  2. In the VM's settings → Storage , select the existing SATA controller and create a new VDI using the add hard disk feature. Set the virtual capacity to 4 GiB and leave the existing system VDI unchanged. Record the disk file path, virtual capacity, and connection ports, then boot. The role of this storage setting can be verified in VirtualBox 7.2 official user manual .
  3. Check whether console login and SSH are normal, and compare the before-and-after lists. This is not a procedure to reboot the installation ISO and initialize the disk.

Dynamically allocated VDIs may have different virtual capacity and file size on the host. Compare the capacity shown in the guest's lsblk -b with the virtual capacity in the VM settings. If you don't have the practice tools, first check the packages and install only the missing packages.

rpm -q util-linux parted xfsprogs
sudo dnf install util-linux parted xfsprogs

The source VM became available for login after a delay caused by the timeout of the encryption self-test during boot. This was not considered evidence of normal operation of the additional disk or passing the security self-test, and security features were not disabled. The verification scope in this text is disk identification after boot, GPT, XFS creation, mounting, and file reading. If a similar delay occurs, check the console and boot logs first, and do not try to resolve it by repeating format commands.

Distinguishing disks, partitions, file systems, and mounts

A disk is a device that provides storage space, and a partition table is a map that records how that space is divided. GPT stands for GUID Partition Table , a format that records the location and identification information of partitions. A file system manages file names, directories, data, and metadata within a partition. In this practice, the XFS file system is used.

Steps Target of this practice Results to check
Additional disk New 4 GiB device, in this VM /dev/sdb Serial number and capacity correspond to the new VDI, and no previous usage traces
GPT and partitions GPT on the disk, with one partition named data21 Partition exists, but FSTYPE is still empty
Create XFS On the first partition, not the whole disk TYPE=xfs, file system UUID and lfdata21 label
Mount Attach XFS to /mnt/lf-data21 The actual source at that path is the new partition, and file writing/reading is successful

parted mkpart ... xfs's xfs is the format specification of the command to create a partition, not the execution of the XFS format. You need to create the file system separately with mkfs.xfs. In addition, mklabel gpt is not a command to change only the disk name while preserving existing data. For the definition of commands and units, please refer to the command manual of the GNU Parted project .

Check the serial number and usage relationship rather than the device name

You should not judge that it is a new disk just by the name /dev/sdb. The name can change depending on the device order, and multiple virtual disks may all have the same model as VBOX HARDDISK. Specify the columns explicitly, as recommended by the lsblk manual, and compare the differences before and after adding a new device along with VM storage information.

lsblk -b -o NAME,PATH,TYPE,SIZE,MODEL,SERIAL,FSTYPE,MOUNTPOINTS
ls -l /dev/disk/by-id/
findmnt /
lsblk -snpr -o NAME "$(findmnt -nro SOURCE /)"
swapon --show
sudo pvs -o pv_name,vg_name,pv_size

The actual identification result of this VM is as follows. The serial number is not an item to memorize using example values; it is a value to check in your own environment.

Category Actual size and serial number Previous use
System /dev/sda 42,949,672,960 bytes / VBfcb8de61-24efa6f6 In use by EFI boot partition, LVM, root, and swap
Additional /dev/sdb 4,294,967,296 bytes / VB36d9d5af-5d5369e3 No sub-partitions, file systems, or mount points immediately after addition

lsblk -snpr outputs the device backing the root file system in reverse. In this environment, it continued to /dev/mapper/rlm-root → /dev/sda3 → /dev/sda. Since LVM is a layer that manages multiple storage spaces as logical volumes, an empty mount point in the disk row does not mean it is unused. The dependencies with sub-partitions, swap, LVM physical volumes, and other devices must also be checked.

Once the new device is confirmed, use the /dev/disk/by-id/ path that includes the serial number. The values below are the values from this exercise, and on other VMs, replace them with the paths you actually confirmed. The results of readlink, along with its serial number and byte capacity, must match exactly.

DISK=/dev/disk/by-id/ata-VBOX_HARDDISK_VB36d9d5af-5d5369e3
readlink -f -- "$DISK"
lsblk -bdn -o NAME,TYPE,SIZE,SERIAL "$DISK"
sudo wipefs --no-act "$DISK"

wipefs --no-act is used to check for identifiable signatures without performing any writing. If signatures such as GPT, file systems, or RAID appear, reconfirm the assumption that it is a new empty disk. The absence of any signature does not necessarily mean that there is no data. The history of creating a new VDI and the results of other inspections should match. In this exercise, wipefs -a, which erases signatures, is not used. The wipefs manual also distinguishes between deleting the signature and deleting the data itself.

Create GPT only on confirmed new empty disks.

The following script is an example intended to be run only once on the new practice disk. Save it as a ~/lf-disk21-create.sh file. The reason for bundling the commands is to prevent accidentally executing the next write command after a failed inspection. It is not a script that only performs inspection; if it passes, GPT and partitions are created immediately.

#!/usr/bin/env bash
set -euo pipefail
export LC_ALL=C
DISK=${1:?Supply the confirmed /dev/disk/by-id path}
SERIAL=${2:?Supply the independently confirmed serial}
BYTES=${3:?Supply the confirmed disk size in bytes}
case "$DISK" in /dev/disk/by-id/*) ;; *) echo 'Use a verified by-id path' >&2; exit 1;; esac
REAL=$(readlink -f -- "$DISK")
test -b "$REAL"
test "$(lsblk -dn -o TYPE "$REAL")" = disk
test "$(lsblk -bdn -o SIZE "$REAL" | xargs)" = "$BYTES"
test "$(lsblk -dn -o SERIAL "$REAL" | xargs)" = "$SERIAL"
test "$(lsblk -nr -o NAME "$REAL" | wc -l)" -eq 1
MOUNTS=$(lsblk -dn -o MOUNTPOINTS "$REAL")
test -z "$MOUNTS"
HOLDERS=$(find "/sys/class/block/${REAL##*/}/holders" -mindepth 1 -maxdepth 1 -print -quit)
test -z "$HOLDERS"
ROOT_SOURCE=$(findmnt -nro SOURCE /)
ROOT_DEVICES=$(lsblk -snpr -o NAME "$ROOT_SOURCE")
if printf '%s\n' "$ROOT_DEVICES" | grep -Fxq -- "$REAL"; then
    echo 'Refusing the root disk' >&2
    exit 1
fi
SIGNATURES=$(wipefs --no-act --noheadings --output TYPE "$REAL")
test -z "$SIGNATURES"
printf 'Confirmed blank target: %s (%s bytes, serial %s)\n' "$REAL" "$BYTES" "$SERIAL"
parted --script --align optimal "$DISK" mklabel gpt
parted --script --align optimal "$DISK" mkpart data21 xfs 1MiB 100%
partprobe "$DISK"
udevadm settle
parted --script "$DISK" align-check optimal 1
parted "$DISK" unit MiB print
lsblk -o NAME,TYPE,SIZE,FSTYPE,PARTLABEL,MOUNTPOINTS "$REAL"

The first argument is the disk path, the second is the separately verified serial number, and the third is the byte capacity. Checks excluding the root disk assume general block devices and LVM-based roots. It is not a universal initialization tool to apply as-is in complex RAID, multi-path storage devices, or container environments. If the serial number is missing or the relationship cannot be interpreted, stop and do not run without performing inspections.

bash -n ~/lf-disk21-create.sh
sudo bash ~/lf-disk21-create.sh \
  /dev/disk/by-id/ata-VBOX_HARDDISK_VB36d9d5af-5d5369e3 \
  VB36d9d5af-5d5369e3 4294967296

1MiB is the partition start location, and 100% specifies the area to be used up to the end of the disk. The alignment is chosen based on the information provided by the device and checked with align-check optimal 1. On this 4 GiB disk, a partition was created starting at 1 MiB, ending at approximately 4095 MiB, with a size of about 4094 MiB. Due to the GPT's own metadata space, not all bytes of the disk become partition data areas.

Partition Table: gpt
Number  Start    End      Size     File system  Name
 1      1.00MiB  4095MiB  4094MiB               data21

At this point, the Parted File system column and the lsblk FSTYPE column can still be empty. If an error occurs in the middle, the GPT may already have been created, or the partition may have been created as well. Do not run it again from the beginning; instead, check the current status with parted "$DISK" print and lsblk. In the source lab checks, attempts with incorrect serial numbers or on a disk with an existing partition were stopped with exit code 1, and the partition table did not change.

Create XFS on the first partition and check the identification information

Now, the format target is not the entire disk but the first partition you just created. In this by-id path, -part1 is attached. The general device name of an NVMe device can be different like /dev/nvme0n1p1, so do not automatically append only the number 1 after DISK.

PART=${DISK}-part1
readlink -f -- "$PART"
lsblk -o NAME,TYPE,SIZE,FSTYPE,PARTLABEL,MOUNTPOINTS "$DISK"
sudo wipefs --no-act "$PART"

This is the first expected partition, PARTLABEL=data21, and you should recheck whether it has a file system, mount point, or signature. If the results differ, do not execute the format command below. Only execute it when it is confirmed to be a new partition.

sudo mkfs.xfs -L lfdata21 "$PART"
sudo blkid "$PART"
lsblk -o NAME,SIZE,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,MOUNTPOINTS "$DISK"

-L lfdata21 specifies the file system label. Do not use -f, which forcibly overwrites an existing format. If an error stating an existing file system occurs, instead of using the force option, re-verify the target. The meaning of formatting and its options is explained in and the mkfs.xfs manual of the XFS project .

This time, the results are TYPE=xfs, LABEL=lfdata21, and the file system UUID 278b7913-3bf0-433e-a8f1-6de4d3027b76. PARTLABEL=data21 and PARTUUID=451fa504-d71d-4e9f-9373-3e395d2e9b90 contain information about the GPT partition. The file system UUID and label, and the partition UUID and name, are values from different layers, and UUIDs will be generated differently on the reader's disk.

Mount to an empty directory and write as a regular user.

Mounting is the process of connecting the contents of a disk to the directory tree. If you mount over a directory that already contains files, those files will be hidden, so use a new and empty path. If the error below, mkdir, indicates that the path already exists, do not reuse the existing path and check the cause.

sudo mkdir -m 755 /mnt/lf-data21
sudo mount -t xfs "$PART" /mnt/lf-data21
findmnt --mountpoint /mnt/lf-data21 -o TARGET,SOURCE,FSTYPE,OPTIONS
df -hT /mnt/lf-data21

findmnt checks whether SOURCE is a new partition and FSTYPE is xfs. The free space of df may be smaller than the raw partition size due to space used by file system metadata and logs. This time, it showed about 110M used out of 4.0G, with 3.9G free. The numbers vary depending on the version and creation options.

Just because it is mounted does not automatically allow general users to write. lfstudent is a practice account, so change it to your own account and group, check the mount source, and create only the subdirectories you will use inside. There is no need to apply chmod 777 to the entire disk.

sudo install -d -o lfstudent -g lfstudent -m 750 /mnt/lf-data21/work
printf 'disk21-ok\n' > /mnt/lf-data21/work/probe.txt
cat /mnt/lf-data21/work/probe.txt
sha256sum /mnt/lf-data21/work/probe.txt

The above file writing is performed in the shell logged in as lfstudent. The expected content is disk21-ok, followed by a single newline. The SHA-256 of this file was d6d494b0eaf4b2f36b92e4b855581ec6158195e180a4592bcd3b59482daed896. If a write error occurs, first check the user and directory permissions and whether the mount is read-only, and do not solve the issue by recreating the new file system.

mount manual explains the behavior where existing content at the mount point is hidden and the reason for using UUIDs instead of device names. In this text, manual mount specifying both arguments is used, and /etc/fstab is not modified.

Criteria for Unmount/Remount Verification and Stopping on Error

In addition to reading a file immediately after creating it, unmount it, remount it, and check the same file. Move out of the mount path in all shells, and close any programs that are using the file.

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

findmnt --mountpoint immediately after unmounting should not output anything and should have a non-zero exit status. After remounting, the original content and hash must match. The source lab recorded the matching content and hash after remounting. The fact that you returned from the mount point to a normal directory is entirely different from claiming that the disk's data has been erased.

Situation Verification and Response
The new disk is not in the list Check the VM's actual connection path and port, and whether it boots normally. Do not assume an existing disk is a new disk.
Signature, Subpartition, LVM Purpose Found Since the assumption of an empty disk may be incorrect, stop writing and check data, backup, and device identity.
Partition has been created but the device is still not visible partprobe "$DISK", udevadm settle check again afterwards. If notifying the kernel of changes fails, do not format; check usage relationships and errors.
File system format error during mount. Check the actual format of the target partition with blkid. Determine whether only mkpart was executed or if the wrong device was selected.
umount: target is busy Check the current path on other terminals and whether editors and services are in use, then retry after normal termination. Do not immediately remove devices in use with forced or lazy unmounting.
GPT or format executed on the wrong disk. Stop additional writing and reformatting, and determine recovery procedures. Do not assume that creating a new partition table automatically restores data.

To finish the practice, unmount as shown below and remove only the empty mount directory. The disk's GPT, XFS, and work/probe.txt remain. When detaching the disk from a VM, finish using it first, then shut down the guest properly, and remove only the newly connected VDI that you recorded. Distinguish between deleting the original VDI file and merely disconnecting it.

cd /
sudo umount /mnt/lf-data21
findmnt --mountpoint /mnt/lf-data21
sudo rmdir /mnt/lf-data21
lsblk -o NAME,TYPE,SIZE,FSTYPE,LABEL,MOUNTPOINTS

In the completed state, the new partition retains the XFS and label, the mount point is empty, and the existing root, boot, and swap devices along with /etc/fstab remain unchanged. The source lab also compared the partition table of the system disk, existing identification information, and fstab to confirm they were the same as before this operation. If a file system has already been created, you can check and use the existing partition with the saved identification information without repeating the entire creation script.