Skip to content

Connecting and Disconnecting a Disk in Linux

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:

  1. Create a partition;
  2. Format (create a filesystem);
  3. Mount;
  4. Add to /etc/fstab for autostart.

Before preparing the disk, you need to identify the disk names present in the system.

You can list disks with the following command:

lsblk
Example output:

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0   15G  0 disk
└─sda1   8:1    0   15G  0 part /
sdb1      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/sdb1. 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:

sudo fdisk /dev/sdb1

Sequence of actions:

  • Press n → create a new partition;
  • Choose p → primary;
  • Press Enter three times (keep default values: whole disk, first sector, etc.);
  • Press w → write changes and exit.

Check the result:

lsblk

A new partition should now appear, e.g., /dev/sdb1.

2. Creating a Filesystem

For example, use ext4 — a reliable and widely supported filesystem:

sudo mkfs.ext4 /dev/sdb1

Note

Alternatives: xfs, btrfs, ntfs (via mkfs.ntfs) — depending on your needs.


3. Mounting the Disk

Create a mount point (directory):

sudo mkdir -p /mnt/disk2

Mount the partition:

sudo mount -o barrier=0 /dev/sdb1 /mnt/disk2

Verify:

df -Th

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:

lsblk -o NAME,UUID

Example output:

NAME   UUID
sda
└─sda1 073e596c-0101-4b87-8f4e-40f96b90baa9
sdb
└─sdb1 1a138d62-46e2-4c2c-9d41-f488d6e340a4

Open /etc/fstab:

sudo nano /etc/fstab

Add the following line (replace the UUID and path as needed):

UUID=1a138d62-46e2-4c2c-9d41-f488d6e340a4  /mnt/disk2  ext4  defaults  0  2

Note

defaults — standard mount options (rw, suid, dev, exec, auto, nouser, async); 0 — not included in dumps; 2 — filesystem check at boot (after root).

Disconnecting the Disk

A local disk cannot be removed if the server has a recovery point. First delete it in the control panel.

Steps:

  1. Edit /etc/fstab and comment out or remove the line with the disk:

    sudo nano /etc/fstab
    # UUID=... /mnt/disk2 ext4 defaults 0 2
    
  2. Unmount the disk:

    sudo umount -l /mnt/disk2
    

    Note

    The -l (lazy) flag is useful if the disk is busy (e.g., a session is open inside the mount point).

  3. Remove the mount point (optional):

    sudo rmdir /mnt/disk2
    
question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×