Connecting and Disconnecting a Disk in Linux¶
In this article
Note
For VPS servers use the upgrade plan option. Below is the instruction only for dedicated Linux servers.
Connecting a Disk¶
After attaching the disk, you need to prepare it within the OS. The process consists of four stages:
- Create a partition;
- Format (create a filesystem);
- Mount;
- Add to
/etc/fstabfor autostart.
Before preparing the disk, you need to identify the disk names present in the system.
You can list disks with the following command:
Example output:NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 15G 0 disk
└─sda1 8:1 0 15G 0 part /
sdb 8:16 0 10G 0 disk # new disk (no partitions)
vda 252:0 0 1M 1 disk
In this example, the new disk is /dev/sdb. All commands below use it as an example. Replace sdb with the actual name in your system.
1. Creating a Partition (fdisk)¶
Start the interactive mode for the disk:
Sequence of actions:
- Press
n> create a new partition; - Choose
p> primary; - Press
Enterthree times (keep default values: whole disk, first sector, etc.); - Press
w> write changes and exit.
Note
The MBR partition table (the fdisk default for an empty disk) does not support disks larger than 2 TB. For such disks, press g before creating the partition - a GPT partition table will be created (you will not need to choose p in this case).
Check the result:
A new partition should now appear, e.g., /dev/sdb1.

2. Creating a Filesystem¶
For example, use ext4 — a reliable and widely supported filesystem:
Note
Alternatives: xfs, btrfs, ntfs (via mkfs.ntfs) — depending on your needs.
3. Mounting the Disk¶
Create a mount point (directory):
Mount the partition:
Verify:

The disk is now ready for use: all files in /mnt/disk2 will be stored on the new disk.
4. Automatic Mounting at Boot (/etc/fstab)¶
Using the UUID (instead of /dev/sdb1) ensures stability when disk order changes.
Retrieve the partition's UUID:
Example output:
NAME UUID
sda
└─sda1 073e596c-0101-4b87-8f4e-40f96b90baa9
sdb
└─sdb1 1a138d62-46e2-4c2c-9d41-f488d6e340a4
Open /etc/fstab:
Add the following line (replace the UUID and path as needed):
Note
defaults — standard mount options (rw, suid, dev, exec, auto, nouser, async); 0 — not included in dumps; 2 — filesystem check at boot (after root).
Check the entry without rebooting - the command mounts everything listed in /etc/fstab and reports errors:
Attention
An error in /etc/fstab can prevent the server from booting. Do not reboot the server until mount -a completes without errors. For disks that may be absent at boot, add the nofail option (for example, defaults,nofail).
Disconnecting the Disk¶
A local disk cannot be removed if the server has a recovery point. First delete it in the control panel.
Steps:¶
-
Edit
/etc/fstaband comment out or remove the line with the disk: -
Unmount the disk:
Note
If you get the
target is busyerror, find out which processes are using the disk withsudo lsof +f -- /mnt/disk2orsudo fuser -vm /mnt/disk2and stop them. The-l(lazy,umount -l) flag only hides the mount point, and the actual unmounting happens after all files are closed - use it only as a last resort. -
Remove the mount point (optional):