When you add a new hard disk or SSD to a Linux server or desktop, you can’t store files on it straight away. First you create one or more partitions (sections of the disk), then format each partition with a filesystem such as ext4 or XFS, and finally mount it on a folder so it is usable, including after a reboot.
This guide walks through the whole process from the command line with lsblk, fdisk, parted, mkfs and /etc/fstab. We tested every command on Ubuntu 26.04 (util-linux 2.41, parted 3.6, e2fsprogs 1.47, xfsprogs 6.18). They work the same on Ubuntu 24.04, Debian, RHEL, Rocky Linux, AlmaLinux and Fedora.
Warning: creating a new partition table erases everything on that disk. Make sure you pick the new, empty disk in Step 1, not the disk your system runs from.
Quick Answer
To turn a new disk /dev/sdb into one ext4 partition mounted on /data:
sudo parted -s /dev/sdb mklabel gpt mkpart data ext4 1MiB 100%sudo mkfs.ext4 -L data /dev/sdb1sudo mkdir -p /datasudo mount /dev/sdb1 /data
Then add it to /etc/fstab as shown in Step 6 so it mounts at boot.
Before You Start: GPT or MBR?
Every disk needs a partition table that records where each partition starts and ends. There are two types:
| GPT | MBR (msdos/DOS) | |
|---|---|---|
| Maximum disk size | Practically unlimited (9.4 ZB) | 2 TiB |
| Number of partitions | 128 by default | 4 primary (more with an extended partition) |
| Backup copy of the table | Yes, at the end of the disk | No |
| Use it for | Every new data disk, and all UEFI systems | Old BIOS-only systems, small USB sticks |
Use GPT unless you have a specific reason not to. This guide uses GPT. Partitioning a USB stick? See how to format a USB drive in Linux instead.
Step 1 of 6Find the New Disk
List all disks and partitions:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
NAME SIZE TYPE FSTYPE MOUNTPOINTS
sda 40G disk
├─sda1 1M part
├─sda2 2G part ext4 /boot
└─sda3 38G part ext4 /
sdb 50G disk
The new disk is /dev/sdb: it has the expected size (50G) and no partitions, filesystem or mount point. Your system disk (here sda) has partitions mounted on / and /boot; never touch that one.
Disk names depend on the hardware:
- SATA, SAS, USB and most VMs:
/dev/sdb,/dev/sdc… with partitions/dev/sdb1,/dev/sdb2. - NVMe SSDs:
/dev/nvme1n1with partitions/dev/nvme1n1p1,/dev/nvme1n1p2(note the p). - KVM/Xen virtual disks:
/dev/vdb,/dev/xvdb.
sudo fdisk -l /dev/sdb shows the disk’s exact size and confirms it has no partition table yet (“Disklabel type” is missing).
Step 2 of 6Create Partitions with fdisk (Interactive)
fdisk is installed on every Linux system and asks you questions step by step. Nothing is written to the disk until you type w, so you can quit with q at any time without changes. Open the new disk:
sudo fdisk /dev/sdb
In this example we create three partitions on a 50 GB disk: 20 GB for data, 4 GB for swap and the rest for backups. Type the commands shown after each prompt; press Enter to accept a default.
- g: create a new, empty GPT partition table.
- n: new partition. Accept the default number (1) and first sector, then enter +20G as the last sector to set the size.
- n again for partition 2, with +4G.
- t: change the type of partition 2 to swap (only needed for a swap partition).
- n for partition 3, pressing Enter at every question to use all remaining space.
- p: print the table to check it.
- w: write the changes to disk and exit.
The full session looks like this:
Command (m for help): g
Created a new GPT disklabel (GUID: A170A28A-3915-4FF8-B072-2E22DF1DCCDC).
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-104857566, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-104857566, default 104855551): +20G
Created a new partition 1 of type 'Linux filesystem' and of size 20 GiB.
Command (m for help): n
Partition number (2-128, default 2):
First sector (41945088-104857566, default 41945088):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (41945088-104857566, default 104855551): +4G
Created a new partition 2 of type 'Linux filesystem' and of size 4 GiB.
Command (m for help): t
Partition number (1,2, default 2): 2
Partition type or alias (type L to list all): swap
Changed type of partition 'Linux filesystem' to 'Linux swap'.
Command (m for help): n
Partition number (3-128, default 3):
First sector (50333696-104857566, default 50333696):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (50333696-104857566, default 104855551):
Created a new partition 3 of type 'Linux filesystem' and of size 26 GiB.
Command (m for help): p
Disklabel type: gpt
Device Start End Sectors Size Type
/dev/sdb1 2048 41945087 41943040 20G Linux filesystem
/dev/sdb2 41945088 50333695 8388608 4G Linux swap
/dev/sdb3 50333696 104855551 54521856 26G Linux filesystem
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
fdisk starts the first partition at sector 2048 (1 MiB) automatically, which keeps partitions aligned for good SSD and RAID performance. For an MBR table, use o instead of g; fdisk then also asks whether each partition is primary or extended.
Step 2 of 6Alternative: Create Partitions with parted (One Command)
parted can do the same without questions, which is handy in scripts, cloud-init and Ansible. This creates a GPT table with a 20 GiB data partition and a backup partition that uses the rest of the disk:
sudo parted -s /dev/sdb mklabel gptsudo parted -s /dev/sdb mkpart data ext4 1MiB 20GiBsudo parted -s /dev/sdb mkpart backup xfs 20GiB 100%sudo parted /dev/sdb print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 21.5GB 21.5GB data
2 21.5GB 53.7GB 32.2GB backup
Notes on parted:
- -s (script mode) applies changes immediately, without asking for confirmation. Double-check the device name.
- The ext4/xfs words in
mkpartare only hints; they don’t format anything. You still need Step 4. - Start the first partition at 1MiB and use 100% for “until the end of the disk” to keep partitions aligned.
- parted shows sizes in GB (109 bytes); use
parted /dev/sdb unit GiB printto see GiB.
Step 3 of 6Check the New Partitions
The rest of this guide uses the three partitions from the fdisk example: /dev/sdb1 (data), /dev/sdb2 (swap) and /dev/sdb3 (backup).
Confirm the kernel sees the new partitions:
lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 50G 0 disk
├─sdb1 8:17 0 20G 0 part
├─sdb2 8:18 0 4G 0 part
└─sdb3 8:19 0 26G 0 part
If the partitions don’t appear (this can happen when the disk was in use), ask the kernel to re-read the partition table with sudo partprobe /dev/sdb.
Step 4 of 6Format the Partitions
A partition needs a filesystem before it can store files. Choose one:
| Filesystem | Command | Best for |
|---|---|---|
| ext4 | mkfs.ext4 | The safe default on Ubuntu and Debian; can be shrunk later |
| XFS | mkfs.xfs | Large files and big volumes; the default on RHEL, Rocky and AlmaLinux. Can grow but not shrink |
| Btrfs | mkfs.btrfs | Snapshots, compression and checksums; default on Fedora desktops and openSUSE |
| swap | mkswap | Swap space (extra virtual memory) |
| vfat / exFAT | mkfs.vfat, mkfs.exfat | EFI system partitions, disks shared with Windows or macOS |
Format the three example partitions. The -L option sets a label, which makes the partition easy to recognise later:
sudo mkfs.ext4 -L data /dev/sdb1sudo mkswap -L swap /dev/sdb2sudo mkfs.xfs -L backup /dev/sdb3
Example output from mkfs.ext4:
mke2fs 1.47.2 (1-Jan-2025)
Discarding device blocks: done
Creating filesystem with 5242880 4k blocks and 1310720 inodes
Filesystem UUID: b2cba04a-83e8-4e7a-ab08-45522368bfc2
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
If mkfs.xfs is not found on Ubuntu or Debian, install it with sudo apt install xfsprogs. For Btrfs, install btrfs-progs. mkfs -t ext4 /dev/sdb1 is an older way to write mkfs.ext4 /dev/sdb1; both do the same thing.
Step 5 of 6Mount the Partitions
A mount point is an empty folder where the partition’s files appear. Create the folders and mount the partitions:
sudo mkdir -p /data /backupsudo mount /dev/sdb1 /datasudo mount /dev/sdb3 /backupsudo swapon /dev/sdb2
Check that they are mounted, with their filesystem type and free space:
df -hT /data /backupswapon --show
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdb1 ext4 20G 2.1M 19G 1% /data
/dev/sdb3 xfs 26G 541M 26G 3% /backup
A new filesystem belongs to root. To let a normal user write to it, change the owner of the mount point, for example sudo chown $USER:$USER /data.
Step 6 of 6Mount Partitions Automatically at Boot (/etc/fstab)
Mounts made with the mount command are lost after a reboot. To make them permanent, add them to /etc/fstab. Use each partition’s UUID rather than a name like /dev/sdb1, because device names can change when disks are added or removed. Get the UUIDs:
sudo blkid /dev/sdb1 /dev/sdb2 /dev/sdb3
/dev/sdb1: LABEL="data" UUID="b2cba04a-83e8-4e7a-ab08-45522368bfc2" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="08502e05-9887-4b04-8a4f-3c9254ccc703"
/dev/sdb2: LABEL="swap" UUID="9926a25f-a593-4c79-8b3f-d5842360bfb7" TYPE="swap" PARTUUID="a991686d-9d02-4eae-89ca-8560615bd0d7"
/dev/sdb3: LABEL="backup" UUID="416875eb-3342-4ca6-8607-9c5767de0cb0" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="02e40053-0913-4582-9fee-db1a8b7abb47"
Back up the file, then open it in an editor:
sudo cp /etc/fstab /etc/fstab.baksudo nano /etc/fstab
Add one line per partition at the end, using your own UUIDs:
UUID=b2cba04a-83e8-4e7a-ab08-45522368bfc2 /data ext4 defaults,nofail 0 2
UUID=416875eb-3342-4ca6-8607-9c5767de0cb0 /backup xfs defaults,nofail 0 2
UUID=9926a25f-a593-4c79-8b3f-d5842360bfb7 none swap sw,nofail 0 0
The six fields are: device, mount point, filesystem type, mount options, dump (always 0) and fsck order (2 for data disks, 0 for swap; XFS ignores this field). The nofail option lets the system boot normally even if the disk is missing or broken, instead of stopping at an emergency shell.
Test the file before you reboot. A mistake in fstab can stop the server from booting:
sudo findmnt --verifysudo systemctl daemon-reloadsudo umount /data /backupsudo mount -adf -hT /data /backup
findmnt --verify should report Success, no errors or warnings detected, and mount -a should mount both partitions again without errors. Then they will also be mounted after every reboot.
Delete a Partition
Unmount the partition (and remove its line from /etc/fstab), then delete it with fdisk:
sudo umount /dev/sdb3sudo fdisk /dev/sdb
Type d, enter the partition number, and then w to save. With parted, the same is sudo parted /dev/sdb rm 3. All data on the deleted partition is lost.
To wipe a whole disk and start over, remove every partition table and filesystem signature with sudo wipefs -a /dev/sdb after unmounting all its partitions.
Use a GUI Instead: GParted and GNOME Disks
On a desktop, GParted shows the disk layout graphically and can create, delete, move and resize partitions:
sudo apt install gparted
Select the new disk in the drop-down at the top right, choose Device → Create Partition Table (GPT), then right-click the unallocated space and choose New. Changes are queued; click the green check mark to apply them. Ubuntu’s built-in Disks app can do the same with the + button under the empty space.
Troubleshooting
Re-reading the partition table failed: Device or resource busy
The disk, or one of its partitions, is in use. Unmount its partitions (and turn off swap with sudo swapoff /dev/sdb2), then run sudo partprobe /dev/sdb. If it still fails, reboot.
The new partitions don’t show up in lsblk
Run sudo partprobe /dev/sdb. On a virtual machine where you just added or resized the disk, you may need to rescan the bus or reboot first.
fdisk only lets me create 4 partitions
The disk has an MBR (DOS) partition table. Use GPT instead (g in fdisk, or mklabel gpt in parted), which allows 128 partitions. This erases the existing partitions.
I can only use 2 TB of a larger disk
Same cause: MBR can’t address more than 2 TiB. Create a GPT partition table.
The system boots into emergency mode after editing fstab
A line in /etc/fstab is wrong or the disk is missing. Log in at the emergency prompt with the root password, run mount -o remount,rw /, fix or comment out the bad line (or restore /etc/fstab.bak) and reboot. On Ubuntu, where root has no password by default, choose Advanced options → recovery mode → root from the GRUB menu, or use the cloud provider’s rescue console. Using nofail and testing with findmnt --verify prevents this.
mount: wrong fs type, bad option, bad superblock
The partition is not formatted yet, or the type in the mount command or fstab doesn’t match. Check the real type with lsblk -f /dev/sdb and format the partition if the FSTYPE column is empty.
Frequently Asked Questions
Should I use fdisk or parted?
Both create the same GPT partitions. fdisk is easier to use by hand because it asks for each value and only writes when you type w. parted is better for scripts because it takes all values on one command line.
Do I have to partition a disk before formatting it?
No. You can run mkfs.ext4 /dev/sdb on the whole disk, and Linux will use it. But a partition table makes the disk’s contents clear to other tools and operating systems (otherwise some show the disk as empty and offer to initialize it), so creating one partition is recommended.
How do I format an existing partition without deleting it?
Unmount it and run mkfs on it again, for example sudo mkfs.ext4 /dev/sdb1. The partition stays the same size but all files on it are erased. Update its UUID in /etc/fstab afterwards, because formatting creates a new UUID.
How many partitions should a data disk have?
Usually one. Separate partitions only make sense when you need different filesystems (for example swap and data) or want to keep one area from filling up another. For flexible sizes, use LVM (Logical Volume Manager) on top of a single partition instead.
Conclusion
To add a new disk in Linux: find it with lsblk, create a GPT partition table and partitions with fdisk or parted, format them with mkfs.ext4, mkfs.xfs or mkswap, mount them, and add them to /etc/fstab by UUID with the nofail option. Always test fstab with findmnt --verify and mount -a before rebooting.
Related guides:
- Mount and unmount disks in Linux
- A beginner’s guide to formatting ext4 partitions
- How to format a USB drive in Linux
- Swapfile vs swap partition
- Back up and clone disk partitions
- lsblk and mount command cheat sheets
How did it make you feel?

Just press Enter and it will set to default value
what is sector and what to select for first and for last sector.???