Mounting a New 4T Disk to /www on CentOS 7

The most common disk-growth path for a website: site data, backups, and logs slowly fill the system disk, then you add a large data disk. This guide uses a brand-new 4T disk (device name /dev/sdb) to demonstrate the full flow of partitioning, formatting, mounting, and enabling auto-mount at boot. The following steps are run as root.

Warning: Mounting and formatting operations erase disk data. Make sure the target disk contains no important data.

1. List the Disks

fdisk -l

Confirm the device name of the new disk. Naming generally follows attachment order: /dev/sda is the system disk, and the new data disk is usually /dev/sdb. If unsure which disk is new, compare sizes in the fdisk -l output.

2. Clean the Disk if Needed

If the disk previously had partitions or a filesystem, format the whole disk first:

mkfs -t ext4 /dev/sdb

This formats the entire disk. For a brand-new disk with no old data, this step can be skipped.

3. Create a GPT Partition with parted

Because fdisk only supports partitions up to 2T (the MBR partition table tops out around 2T), a disk larger than 2T must use parted with a GPT partition table:

parted /dev/sdb

Inside the parted interactive prompt, create the GPT partition table:

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on
this disk will be lost. Do you want to continue? Yes/No? yes

4. Handle Partition Alignment

When creating a partition, using the default values may produce a warning that the partition is not aligned for best performance:

(parted) mkpart primary 0 4001GB
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? cancel

Check the disk parameters first to calculate the correct starting sector:

cat /sys/block/sdb/queue/optimal_io_size
cat /sys/block/sdb/queue/minimum_io_size
cat /sys/block/sdb/alignment_offset
cat /sys/block/sdb/queue/physical_block_size

If optimal_io_size is not 0 and is, say, 1048576, add the alignment_offset value and divide by the physical_block_size value to get the starting sector:

(1048576 + 0) / 512 = 2048

If optimal_io_size is 0, use the default starting sector of 2048.

Why does alignment matter? Modern disks use 4096-byte (4K) physical sectors while exposing 512-byte logical sectors. If a partition starts at a non-4K boundary, a single I/O can straddle two physical sectors, cutting read/write performance — especially noticeable with many small files. The "start at sector 2048" convention isn't superstition; it aligns the partition to 4K physical blocks.

5. Create the Partition with the Aligned Start Sector

(parted) mkpart primary 2048s 100%
(parted) print
Model: ATA WDC WD40EFRX-68N (scsi)
Disk /dev/sdb: 4001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
1       1049kB  4001GB  4001GB               primary

(parted) align-check optimal 1
1 aligned
(parted) quit

align-check optimal 1 returning 1 aligned means the partition is correctly aligned. This is the easiest step to get wrong in the whole guide — always run the alignment check.

6. Check the Disk Status

fdisk -l

Confirm the partition was created successfully and that /dev/sdb1 exists.

7. Format the Disk

mkfs.ext4 -F /dev/sdb

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

mkfs.ext4 -F -i 2048 /dev/sdb

A note: if you prefer strict partition management, you can format just the partition device /dev/sdb1 and mount that instead of the whole disk. Both work; this guide follows the original post's whole-disk approach.

8. Mount the New Disk to /www

mkdir /www
mount /dev/sdb /www

Choose the mount point by purpose: mount at the site directory for site data, at a backup directory for backups. /www is an example — use whatever fits your directory plan.

9. Enable Auto-Mount at Boot

vim /etc/fstab

Append the following line:

/dev/sdb                /www                   ext4    defaults        1 2

Save and exit (:wq).

Prefer UUID over device name. After a reboot, device names can change (/dev/sdb becomes /dev/sdc), breaking the mount. The more robust approach is to use the partition's UUID:

blkid /dev/sdb

Then put the UUID="xxxx" from the output into fstab:

UUID=xxxx-xxxx-xxxx        /www                   ext4    defaults        1 2

10. Mount All Pending Entries

mount -a

mount -a mounts every not-yet-mounted entry in fstab in one go, which also validates your fstab config. If it errors, your fstab is wrong — fix it before rebooting.

11. Verify the Mount

df -h

After a successful mount you should see output similar to:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb        3.6T  140M  3.4T   1% /www

The /www directory now has about 3.4T of usable space. Consider a quick read/write speed test to confirm alignment took effect — see disk speed testing on CentOS.

Common Issues

Issue Cause Fix
/www is empty after reboot Wrong fstab entry or device name changed Mount by UUID; verify with mount -a first
No write permission on mount point Wrong directory owner chown -R www-data:www-data /www
parted reports unaligned Start sector not a 4K multiple Calculate the start sector per step 4
Data disk mistaken for system disk Misread device name Double-check with lsblk -f before mounting

Summary

The flow for mounting a disk larger than 2T on CentOS 7 is: create a GPT partition table with parted → calculate the aligned starting sector and partition → format with mkfs.ext4 → mount with mount → write to /etc/fstab (preferably by UUID) for auto-mount at boot. Alignment noticeably affects performance on large disks, so follow steps 4 and 5 carefully.

Disk mounting is a fundamental server operations task. For more server configuration and operations tips, see the cloud servers category, such as server operations tips and server backup strategy. For mounting smaller disks under 4T, refer to mounting a disk (under 4T) on CentOS. Before picking a disk, match capacity to your workload — see server storage selection.

Original post: https://www.cnblogs.com/cqzhuomi/articles/17284398.html (cnblogs.com CQZHUOMI, repost)