How to Add a Disk in Linux
To how to add a disk in linux, you usually detect the new drive, create a partition if needed, format it with a filesystem such as ext4 or XFS, mount it, and then add it to /etc/fstab so it stays mounted after reboot. The most important step is identifying the correct block device before you format anything, because the wrong command can erase data permanently.
Quick answer
If Linux already sees the new disk, the basic workflow is:
- Find the device name with
lsblkorblkid. - Create a partition table and partition if the disk is blank.
- Format the partition with
mkfs.ext4ormkfs.xfs. - Create a mount point.
- Mount the partition.
- Add a UUID-based entry to
/etc/fstabfor persistent mounting. - Verify the mount with
df -handlsblk.
If you are using a cloud VM or virtual machine, the same process applies, but the disk may first need to be attached in the cloud console or hypervisor before Linux can detect it.
What you need before starting
- Root access or
sudoprivileges. - A new disk that is attached to the server, VM, or cloud instance.
- Enough free space on the system to create a mount point.
- A decision on the filesystem you want, usually ext4 or XFS.
Safety checklist before formatting:
- Confirm the disk size matches the new drive you added.
- Check the model name or serial number if available.
- Make sure you are not selecting the boot disk or an existing data disk.
- Double-check the device path, such as
/dev/sdbor/dev/nvme1n1.
Warning: Formatting the wrong disk will destroy data. Always verify the device name before running mkfs, fdisk, or parted.
Find the new disk
Start by listing block devices:
lsblkThis shows disks, partitions, sizes, and mount points. A new disk often appears as something like /dev/sdb, /dev/vdb, or, on NVMe systems, /dev/nvme1n1.
Example output might look like this:
NAME SIZE TYPE MOUNTPOINT
sda 100G disk
├─sda1 99G part /
sdb 500G diskIn this example, sdb is the new disk because it has no partition or mount point yet.
You can also use:
sudo blkidblkid is useful after formatting, because it shows filesystem type and UUID values.
How to identify the correct disk safely
If more than one drive is present, compare these details:
- Size, for example 500G or 1T.
- Model or serial number, if displayed by
lsblk -o NAME,SIZE,MODEL,SERIAL. - Whether it is mounted, especially if one disk already contains
/,/home, or database data.
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,MODEL,SERIALOn cloud systems, the attached volume may show up after a short delay, or only after rescan. On some virtual machines, the disk may appear under a different controller name than expected.
Partition the disk
If the disk is empty, you usually need a partition table first, then a partition. For most modern setups, a single partition using the whole disk is enough.
Use fdisk for MBR or simple GPT setups
fdisk is a good choice for standard disks and straightforward partitioning.
sudo fdisk /dev/sdbInside fdisk:
- Type
gto create a new GPT partition table, orofor MBR if you specifically need it. - Type
nto create a new partition. - Accept the default partition number and start sector.
- Accept the default end sector to use the full disk, or specify a size.
- Type
wto write changes and exit.
After that, the partition will usually appear as /dev/sdb1.
Use parted for larger or scripted setups
parted is often preferred for GPT disks, larger drives, or scripts.
sudo parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart primary ext4 0% 100%
(parted) quitIf you are adding a disk to a modern server, GPT is usually the better default. It handles large disks well and is widely supported.
Format the partition
Once the partition exists, format it with a filesystem. The two most common choices are ext4 and XFS.
ext4 vs XFS, which should you use?
| Filesystem | Best for | Notes |
|---|---|---|
| ext4 | General-purpose servers, broad compatibility | Safe default for most Linux systems |
| XFS | Large filesystems, high-throughput workloads | Common on enterprise Linux systems |
If you are unsure, ext4 is a reasonable default. If you expect very large files, heavy parallel I/O, or you are following an enterprise standard that uses XFS, choose XFS instead.
Format the partition with one of these commands:
sudo mkfs.ext4 /dev/sdb1
sudo mkfs.xfs /dev/sdb1After formatting, the device now has a filesystem and can be mounted.
Mount the disk
First, create a directory where the disk will be mounted.
sudo mkdir -p /mnt/dataThen mount the partition:
sudo mount /dev/sdb1 /mnt/dataCheck that it mounted correctly:
df -h /mnt/dataYou can also confirm with:
lsblkThe mount point should now appear next to the new partition.
Make the mount permanent
Mounting with mount lasts only until the next reboot unless you add the filesystem to /etc/fstab.
Get the UUID
Use blkid to find the UUID of the new filesystem:
sudo blkid /dev/sdb1Example output:
/dev/sdb1: UUID="1234-ABCD" TYPE="ext4"Add the entry to /etc/fstab
Edit the file carefully:
sudo nano /etc/fstabAdd a line like this:
UUID=1234-ABCD /mnt/data ext4 defaults 0 2If you used XFS, the entry would look similar, but the filesystem type would be xfs:
UUID=1234-ABCD /mnt/data xfs defaults 0 0Save the file, then test it before rebooting:
sudo mount -aIf there is no error, the fstab entry is likely correct.
Verify everything works
After mounting, check three things:
- The filesystem is mounted where you expect.
- The filesystem type is correct.
- Free space is reported correctly.
Useful commands:
df -h /mnt/data
lsblk -f
mount | grep /mnt/dataIf the disk survives a reboot and still mounts automatically, the setup is complete.
Cloud, SSD, NVMe, and virtual machine notes
The overall process is the same, but the device name can differ depending on the environment:
- SSD or SATA disk, often appears as
/dev/sdb,/dev/sdc, and so on. - NVMe disk, often appears as
/dev/nvme0n1or/dev/nvme1n1, with partitions like/dev/nvme1n1p1. - Cloud volume, may need to be attached in the provider console before Linux can see it.
- Virtual machine disk, may require a rescan or reboot if the hypervisor added it while the system was running.
For NVMe devices, pay attention to the partition name format. The first partition is usually named with a p, such as /dev/nvme1n1p1, not /dev/nvme1n11.
Common mistakes and fixes
- The disk does not show up in lsblk, check whether it was actually attached in the cloud console or VM settings. In some cases, rescan the bus or reboot the system.
- You formatted the wrong disk, stop immediately and assess the damage. If the wrong device was overwritten, recovery may be difficult or impossible.
- mount says the directory does not exist, create the mount point first with
mkdir -p. - mount -a returns an error, check the UUID, filesystem type, and spacing in
/etc/fstab. - The disk mounts manually but not after reboot, verify that the
/etc/fstabentry uses the correct UUID and mount path. - You used the wrong filesystem type, make sure the type in
/etc/fstabmatches what you created withmkfs.
What if you need the disk without partitioning?
Some administrators format the whole disk directly, but partitioning is usually safer and more standard. A partition table gives you a clearer layout and more flexibility later. If you are following a platform-specific guide that recommends formatting the whole disk, make sure you understand that layout before using it.
Practical example
Here is a minimal example for a new 500G disk on a Linux server:
- Confirm the disk with
lsblk. - Create a GPT partition table with
fdiskorparted. - Create one partition that uses the whole disk.
- Format it with
mkfs.ext4 /dev/sdb1. - Create a mount point such as
/mnt/data. - Mount it with
mount /dev/sdb1 /mnt/data. - Get the UUID with
blkid. - Add a UUID entry to
/etc/fstab. - Test with
mount -aand verify withdf -h.
Frequently Asked Questions About how to add a disk in linux
How do I add a new disk in Linux?
Detect the disk with lsblk, partition it if needed, format it with mkfs, mount it, and add a UUID-based entry to /etc/fstab so it mounts automatically after reboot.
How do I find the new disk name in Linux?
Use lsblk or lsblk -o NAME,SIZE,TYPE,MOUNTPOINT. Match the size and check whether the disk has no existing partitions or mount point.
How do I make a new disk mount permanently in Linux?
Use blkid to get the filesystem UUID, then add it to /etc/fstab with the mount point and filesystem type. Test the entry with sudo mount -a.
Should I use fdisk or parted for a new disk?
fdisk is simple and works well for many standard setups. parted is often better for GPT disks, larger drives, or scripted provisioning. Either can work if you are careful.
How do I format a disk in Linux without losing data?
You generally cannot format a disk without affecting data on that filesystem. If you need to preserve files, back them up first or attach a separate empty disk. Never run mkfs on a disk unless you are sure it is the correct target.
What is the safest filesystem choice for most Linux servers?
ext4 is the safest general-purpose default for many systems because it is widely supported and straightforward to manage. XFS is also a strong choice, especially for large filesystems or workloads that benefit from it.
Conclusion
The practical way to add a disk in Linux is to identify the correct device, create a partition, format it, mount it, and make the mount persistent with /etc/fstab. The most important habit is verifying the device name before formatting, especially on systems with multiple drives, NVMe storage, or cloud-attached volumes. Once the UUID-based mount is in place and tested, the disk should remain available after every reboot.
