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.
Four common mount failures, their causes and fixes:
| 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)
Integration & Code Examples
Example 1: Create a GPT partition non-interactively and verify alignment
# 1) Identify the new disk and read the alignment parameters
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT
cat /sys/block/sdb/queue/optimal_io_size
cat /sys/block/sdb/queue/physical_block_size
# 2) Script a GPT label and start the partition at 2048s
parted -s /dev/sdb mklabel gpt
parted -s /dev/sdb mkpart primary 2048s 100%
# 3) Alignment check should report "1 aligned" before you continue
parted -s /dev/sdb align-check optimal 1
parted -s /dev/sdb unit GB print
# 4) Make the kernel re-read the partition table
partprobe /dev/sdb
lsblk /dev/sdb
2048s means 2048 sectors of 512 bytes (exactly 1MiB), aligned with 4K physical sectors and common RAID stripes; continue only when align-check optimal passes.
Example 2: Format as ext4 and pin it in fstab by UUID
# 1) Format and label the filesystem (-F forces; confirm the disk is empty)
mkfs.ext4 -F -L data4t /dev/sdb1
# 2) Read the UUID and mount it
UUID=$(blkid -s UUID -o value /dev/sdb1)
mkdir -p /www
mount UUID=$UUID /www
df -hT /www
# 3) Back up fstab, then add a UUID-based entry
cp /etc/fstab /etc/fstab.bak
echo "UUID=$UUID /www ext4 defaults,noatime 0 2" >> /etc/fstab
# 4) Validate syntax and the mount, then rebuild initramfs
mount -a
findmnt --verify
dracut -f
The job is done when mount -a is silent and df -h shows the new capacity; noatime drops metadata writes on reads, which pays off on read-heavy document roots.
Five Checks on a 4T Disk: Name, Table, Alignment, Filesystem, Capacity
| Check | Command | Value in this example | Pass condition |
|---|---|---|---|
| Device name and size | fdisk -l, lsblk |
/dev/sdb, 4001GB |
Size and model match the new disk |
| Partition table | parted -s /dev/sdb print |
Partition Table: gpt, partition 1 starts at 1049kB |
gpt with a single primary partition |
| Start-sector alignment | parted align-check optimal 1 |
Started at 2048s | Returns 1 aligned |
| Filesystem and mount point | df -h, blkid |
ext4, 3.6T available | Mounted at /www with capacity visible |
| Usable capacity | df -h |
3.6T available, 140M used (1%) | 4001GB decimal ≈ 3.6TiB; the gap is base-1024 |
The first check is the one people get wrong under time pressure. Device letters follow attach order, so /dev/sda is the system disk and a new data disk usually shows up as /dev/sdb; compare capacity and model rather than trusting the letter.
The third check is the only real verdict on alignment. When align-check optimal 1 does not return 1 aligned, stop before mkfs — formatting an unaligned partition bakes the problem in, and it only shows up later as slow small-file I/O.
The last two rows are a unit mismatch, not a fault: 4001GB is decimal, df -h reports binary units, so 3.6T available is what a 4T disk should show.
How Start-Sector Alignment Is Computed: Two sysfs Values
The calculation needs only three numbers from /sys/block/sdb/queue/: optimal_io_size, alignment_offset, and physical_block_size. With an optimal_io_size of 1048576 and an offset of 0, (1048576 + 0) / 512 = 2048 sectors, which is the start position to pass to mkpart.
When optimal_io_size reads 0 there is no reference stride to respect, and the default start sector 2048 applies directly.
The underlying reason is 4096B physical sectors behind 512B logical ones. A start position that is not a multiple of 4K makes a single I/O span two physical sectors, which hurts most on many-small-files workloads. parted print reporting a start of 1049kB is the same thing as 2048 × 512B.
Limitations
- This article reflects public information as of 2023-04-03; terms, prices and quotas follow the provider's current published terms.
- Third-party capability and limit statements follow their official documentation; no further commitment is implied here.
- Licensing, filing and data-residency decisions must be verified against the regulations of your operating region.
FAQ
Can fdisk handle a 4T disk?
No — fdisk uses an MBR table capped near 2T, so a 4T disk needs parted and GPT. Anything past 2T cannot be expressed in MBR, and fdisk leaves you with a partition that never uses the whole disk; after parted writes the GPT, run align-check optimal 1 to confirm alignment.
What prerequisites come before formatting a disk?
Confirm the device name first. mkfs -t ext4 /dev/sdb wipes the entire disk, so match capacity and model with fdisk -l and read mount points and filesystems with lsblk -f, or the system disk /dev/sda gets mistaken for the new one. Back up existing partitions before formatting, and do not reverse that order.
Which is better: format the whole disk or a partition?
Both work, so pick by team habit. Formatting the whole disk (/dev/sdb) is simpler, while formatting a partition (/dev/sdb1) makes later splitting and growth easier. This walkthrough uses the whole-disk form with mkfs.ext4 -F /dev/sdb; teams already managing partitions should format and mount /dev/sdb1 consistently.
Why is /www empty after a reboot?
Check fstab first — switching to UUID fixes device renaming for good. After a reboot the disk can move from /dev/sdb to /dev/sdc, and an entry written with the device name silently fails to mount; rewrite that line with the UUID from blkid, then verify with mount -a. Confirm /www shows 3.6T via df -h before the next restart.
Related Providers
- Alibaba Cloud ECS: Use it when the cloud disk must be attached in the console before any block device appears.
- Tencent Cloud CVM: Use it when verifying that a mounted cloud disk survives an fstab reboot.
- Huawei Cloud ECS: Use it when data disk naming differs by vendor and /dev/sdb must be matched against /dev/vdb.
Community & Resources
Official docs and communities
- parted(8) manual — authoritative notes on
mklabel,mkpart,align-check - ext4 filesystem docs — kernel-side design and mount option reference
- Stack Overflow: parted — Q&A on large-disk partitioning and alignment
- Stack Overflow: centos7 — hands-on CentOS 7 operations questions
Learning resources and tools
- Arch Wiki: Parted — a clear walkthrough of GPT partitioning and its traps
- mke2fs(8) manual — ext4 formatting options and what
-Land-Fdo - fstab(5) manual — the six fields and the full mount option list
Original source: cnblogs.com (CQZHUOMI) ↗