You’ve added a disk to your server, a second drive on a dedicated server or an extra volume on a VPS, and it shows up empty in lsblk. Before you can store files on it, it needs a partition table, a partition and a filesystem. fdisk is the standard interactive tool for the partitioning step.
Warning: partitioning rewrites the start of a disk. Double-check the device name. Running this on the wrong disk destroys its data.
1. Identify the disk
lsblk -f
vda 80G disk
└─vda1 79G part ext4 /
vdb 500G disk ← new, empty
See lsblk and blkid. This guide uses /dev/vdb. Replace it with yours.
2. GPT or MBR?
| GPT | MBR (DOS) | |
|---|---|---|
| Max disk size | Practically unlimited | 2 TiB |
| Partitions | 128 by default | 4 primary (or extended/logical) |
| Redundancy | Backup header at the end of the disk | None |
Use GPT for new disks. MBR only matters for very old systems.
3. Create the partition
sudo fdisk /dev/vdb
fdisk is interactive. Nothing is written until you press w. Type:
| Key | Action |
|---|---|
g |
Create a new, empty GPT partition table |
n |
New partition. Accept the defaults (number 1, first sector, last sector) for one partition using the whole disk |
p |
Print the table to check |
w |
Write the changes and exit |
q |
Quit without saving |
A whole session looks like this:
Command (m for help): g
Created a new GPT disklabel (GUID: …).
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-1048575966, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (…, default …):
Created a new partition 1 of type 'Linux filesystem' and of size 500 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
For several partitions, give sizes at “Last sector”, such as +100G.
The default starting sector (2048) aligns the partition to 1 MiB, which is optimal for SSDs and RAID.
Partition types
The default type, “Linux filesystem”, fits ext4 and XFS. Change it with t if needed:
Type L in the t prompt to list all types.
4. Make sure the kernel sees it
lsblk /dev/vdb
You should see vdb1. If the disk was in use and the kernel kept the old table, run:
sudo partprobe /dev/vdb
5. Format and mount
sudo mkfs.ext4 -L data /dev/vdb1
sudo mkdir -p /mnt/data
sudo mount /dev/vdb1 /mnt/data
Then make it permanent with the UUID in /etc/fstab:
sudo blkid -s UUID -o value /dev/vdb1
# add: UUID=<uuid> /mnt/data ext4 defaults,noatime,nofail 0 2
sudo mount -a
Do you even need a partition?
You can format a whole disk without a partition table (mkfs.ext4 /dev/vdb), and it works. A partition table is still recommended. Tools and other admins expect it, it prevents another OS or tool from mistaking the disk for empty, and it makes alignment explicit. For LVM, you can use the whole disk directly as a physical volume (pvcreate /dev/vdb).
Non-interactive partitioning (scripts)
sfdisk takes a script:
echo 'label: gpt
,,L' | sudo sfdisk /dev/vdb
Or use parted in script mode:
sudo parted -s /dev/vdb mklabel gpt mkpart data ext4 1MiB 100%
See parted.
Other fdisk commands
sudo fdisk -l # list all disks and partition tables
sudo fdisk -l /dev/vdb # one disk
Inside fdisk: d deletes a partition, m shows help, and x gives expert mode.
Resizing the system disk
When your VPS disk is upgraded to a larger size, you don’t create a new partition. You grow the existing one. That’s a different procedure, using growpart and resize2fs or xfs_growfs. See resize a disk partition.
Common issues
“Device or resource busy” / “re-reading the partition table failed” — the disk or one of its partitions is mounted or in use. Unmount it, or run partprobe. A reboot also works.
Disk larger than 2 TiB shows only 2 TiB — it has an MBR table. Recreate it as GPT, which erases the partitions on it.
Wrong disk partitioned — stop immediately. Don’t write further. If you haven’t pressed w, quit with q. If you have, testdisk can sometimes recover the old partition table.
Quick reference
| Task | Command / key |
|---|---|
| List disks | sudo fdisk -l / lsblk |
| Start | sudo fdisk /dev/vdb |
| New GPT table | g |
| New partition | n |
| Change type | t |
p |
|
| Save / quit | w / q |
| Re-read table | sudo partprobe /dev/vdb |