ARTICLE - Cloud Servers

Complete Steps to Mount a Disk (Under 4T) on CentOS

Disks under 4T can be partitioned with fdisk on CentOS, formatted with mkfs.ext4, and mounted to a target directory. This article covers the full flow from listing disks, formatting, partitioning, mounting, to writing fstab.

2023-04-03 cnblogs.com (CQZHUOMI)

Complete Steps to Mount a Disk (Under 4T) on CentOS

When you provision a cloud server, only the system disk is attached by default — the data disk is usually purchased separately and must be mounted by hand. You buy a 2TB data disk, log in, and df -h does not show it, because it has not been partitioned, formatted, and mounted yet. Do those three steps and the new capacity finally appears. If you bought the disk from a cloud provider's console, you usually need to "attach it to the instance" there first, or the OS never sees it; on a physical server, just insert the drive. The steps below start after login, assuming lsblk already shows an unpartitioned disk. Mounting is not a one-and-done task — full disks, expansion, and disk swaps all touch it again, so understanding the process beats blindly copying commands.

Warning: Mounting operations erase data. Make sure the disk to be mounted has no data or is unused.

Step 1: List all disks

ll /dev/disk/by-path

Or use lsblk for a clearer disk tree:

lsblk

In the output the system disk is usually sda (with partitions like sda1, sda2), while the data disk is typically a whole disk such as sdb or sdc. Vendor docs usually name the data disk, e.g. Alibaba Cloud uses /dev/vdb, Tencent Cloud uses /dev/vdb or /dev/sdb — local naming can differ, so trust the actual lsblk output. If you still cannot confirm, use the df command to verify the system disk name and avoid mounting the wrong disk.

Step 2: Partition the disk

fdisk /dev/sdb

Inside the fdisk interactive prompt, run the following in sequence:

  • Enter n to create a new partition;
  • Enter p to select a primary partition;
  • Press Enter to accept the default partition number;
  • Press Enter to accept the default start and end sectors (using the whole disk);
  • Enter w to save and exit.

After exiting, run lsblk again to confirm that sdb1 now exists.

Step 3: Create the filesystem

mkfs.ext4 /dev/sdb1

To increase the number of available inodes (useful for many small files), use:

mkfs.ext4 -i 2048 /dev/sdb1

-i 2048 allocates one inode per 2048 bytes, raising the file-count ceiling at the cost of a little more metadata space. The default is fine for typical workloads; adjust it only for huge numbers of small files (cache directories, attachment stores).

Step 4: Mount the partition

mkdir /data
mount /dev/sdb1 /data

The commands above mount the sdb1 partition to the /data directory. The mount point must be created first; pick a name to match your conventions (/data, /home, /www are all common).

Step 5: Write fstab for auto-mount at boot

echo "/dev/sdb1              /data                  ext4    defaults        0 0" >> /etc/fstab

After writing, verify the fstab configuration with mount -a to avoid boot failures caused by configuration errors. A more robust alternative is to reference the disk by UUID instead of device name — device names can change with reordering, UUIDs do not:

blkid /dev/sdb1   # get the UUID
echo "UUID=xxxx-xxxx  /data  ext4  defaults  0 0" >> /etc/fstab
mount -a && df -h

Verify the mount

df -h

You should see an entry similar to:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1       3.6T   77M  3.4T   1% /data

Bonus: unmounting and remounting

When expanding or swapping disks, first make sure no process is using the directory:

lsof +D /data        # check which processes are using it
umount /data         # unmount

Then re-partition, reformat, and remount, and keep the UUID in /etc/fstab in sync. Before swapping, confirm the new disk's capacity matches the partition table type; default sectors are fine for a whole disk, and only special array environments need extra handling. fdisk only handles disks under 4T; for larger disks use parted to create a GPT partition table — full steps in mounting a 4T disk on CentOS.

  • mount reports "already mounted": the partition is attached somewhere else; umount the old mount point first.
  • Not mounted after a reboot: most likely a bad fstab line; check the device name/UUID and always run mount -a before rebooting.
  • Switching to a larger disk: unmount the partition first, then re-partition, reformat and remount — back up first.
  • Permission problems: after mounting, the directory owner is root; chown it to the right user when a web app needs to write data.
  • XFS or ext4: CentOS 7 and above support XFS by default, which suits large files and high throughput; ext4 has the best compatibility and the widest use. Both satisfy normal workloads — pick one and stay consistent.
  • Still not visible in df -h: check the fstab line, whether mount -a succeeded, or whether it was mounted to a different path.
  • The mount point already holds data: mounting hides whatever was in the directory; move that data to a temp directory first, mount, then copy it back so nothing looks lost.
  • Read-only after a reboot: usually a filesystem issue or a bad fstab option; check dmesg, then decide whether to repair with fsck — back up before repairing.

Notes

  1. Disks larger than 4T cannot be partitioned with fdisk; use parted to create a GPT partition table instead, see mounting a 4T disk on CentOS;
  2. The mount point directory must be created first (mkdir /data);
  3. Back up /etc/fstab before modifying it and double-check the device name and mount point to prevent boot failure.

Disk mounting is a common server expansion operation. For more server configuration and operations tips, see the cloud servers category, such as server operations tips and server backup strategy.

Reference: CentOS's official documentation on storage partitioning is at https://docs.centos.org/en-US/centos/install-guide/Partitioning/; fdisk, mkfs.ext4, mount, and fstab all have man pages.
Original post: https://www.cnblogs.com/cqzhuomi/articles/17282793.html (cnblogs.com CQZHUOMI, repost)

Integration & Code Examples

Example 1: Identify a new disk, partition and format it

# 1) A whole disk with no MOUNTPOINT is usually the new data disk
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT

# 2) Cloud disks often appear as /dev/vdb or /dev/sdb - adjust as needed
fdisk -l /dev/vdb

# 3) Interactive partitioning: n new -> p primary -> Enter defaults -> w write
fdisk /dev/vdb
partprobe /dev/vdb

# 4) Format and mount
mkfs.ext4 /dev/vdb1
mkdir -p /data
mount /dev/vdb1 /data
df -hT /data

Confirm in lsblk that the disk holds no business data before partitioning; fdisk handles MBR up to 2T, so anything larger needs parted with GPT.

Example 2: Pin the mount by UUID and handle resizing

# 1) Record the UUID - more stable than a device name
blkid /dev/vdb1
UUID=$(blkid -s UUID -o value /dev/vdb1)

# 2) Back up fstab before appending
cp /etc/fstab /etc/fstab.$(date +%F)
printf 'UUID=%s  /data  ext4  defaults,noatime  0 2\n' "$UUID" >> /etc/fstab

# 3) Verify syntax, then mount for real
findmnt --verify
umount /data
mount -a && df -hT /data

# 4) After an online disk resize: grow the partition, then the filesystem
yum install -y cloud-utils-growpart
growpart /dev/vdb 1
resize2fs /dev/vdb1
df -hT /data

The order matters: growpart enlarges the partition first so resize2fs can extend the filesystem into the new space.

Mount Options and Filesystem Flags: What Each One Changes

Mount options change write behaviour, not capacity, which is why they belong to the deployment decision rather than to troubleshooting.

Option Effect Where it appears here Suited to
defaults Read-write, async, standard flags The base fstab line General workloads
noatime Skips access-time updates on reads defaults,noatime in the fstab example Read-heavy site directories
-i 2048 One inode per 2048 bytes at mkfs time Small-file scenario Caches and attachment libraries with many files
0 2 / 0 0 Dump flag and fsck order Tail of the fstab entry Data disks usually 0 2; 0 0 disables checks
growpart + resize2fs Enlarges partition, then filesystem Online volume expansion Volumes grown in the provider console

Inode count is fixed at mkfs time and cannot be raised later. -i 2048 buys headroom for many-small-files directories at the cost of extra metadata space, so it is a decision to make before the first mount, not after the disk fills up.

noatime is the only option in the table that reduces writes with no functional loss for a web document root: access timestamps are not needed to serve static files.

The last row is a two-step operation rather than a flag, covered separately below; the flags in fstab are written comma-separated right after ext4, and a typo there keeps the entry from mounting at boot.

Online Volume Expansion in Two Moves: growpart, Then resize2fs

A partition table and a filesystem are two separate boundaries, so growing a cloud volume needs both commands. growpart /dev/vdb 1 rewrites the partition entry to the new size, and resize2fs /dev/vdb1 then extends the filesystem into that space.

The order cannot be reversed. Running resize2fs first finds no additional partition space and reports success without growing anything, which looks like a silent failure.

Check the result with df -hT /data rather than the console: the provider shows the volume size, while df shows what the filesystem is actually using. On an XFS filesystem the second step is xfs_growfs instead of resize2fs, and cloud-utils-growpart provides the first.

Limitations

  • You buy a 2TB data disk, log in, and df -h does not show it, because it has not been partitioned, formatted, and mounted yet.
  • If you still cannot confirm, use the df command to verify the system disk name and avoid mounting the wrong disk.
  • The mount point must be created first; pick a name to match your conventions (/data, /home, /www are all common).
  • Disks larger than 4T cannot be partitioned with fdisk; use parted to create a GPT partition table instead, see mounting a 4T disk on CentOS; 2.
  • The mount point directory must be created first (mkdir /data); 3.

FAQ

What prerequisites does mounting a disk have?

Three things first. Where the disk is, whether it holds data, and whether the cloud volume is attached to the instance — a 2TB volume that never appears in df -h simply has not been partitioned, formatted and mounted. lsblk shows an unmounted whole disk, and vendor docs name the device (Alibaba Cloud /dev/vdb, Tencent Cloud /dev/vdb or /dev/sdb). A volume bought in the console must be attached there first, or the OS never sees it.

Why does the mount vanish after a reboot?

Check /etc/fstab first. A wrong device or UUID, mount point, filesystem type, options or the trailing 0 0 fields leaves it unmounted after reboot, so run mount -a before restarting. An already mounted error means the partition sits elsewhere — unmount that first; if df -h still hides it, confirm the real mount path.

At format time, ext4 or XFS — which one?

Pick by workload. CentOS 7 and later support XFS by default, which suits large files and high throughput; ext4 has the widest compatibility and the most usage. Both handle ordinary workloads, so the real rule is picking one and staying consistent per machine. For directories full of small files, mkfs.ext4 -i 2048 raises the inode count.

When should fdisk be avoided?

Avoid fdisk past 4T. parted must build a GPT table there, and the same applies beyond 2T under MBR. Unmount first, confirm nothing holds the directory with lsof +D /data, then partition and format, and update the UUID in fstab. Back up before touching it.

Related Providers

  • Alibaba Cloud ECS: when the data disk is attached in the console and the device stays /dev/vdb across reboots.
  • Tencent Cloud: when instances mix /dev/vdb and /dev/sdb naming and the fstab entry must survive a reboot.
  • Hetzner: when a dedicated box carries several physical disks that you partition and mount yourself.

Community & Resources

Official docs and communities

Learning resources and tools

Original source: cnblogs.com (CQZHUOMI) ↗