How to attach an extra disk
Separating application data from the system disk makes backups, migrations and resizing easier. This guide explains how to add a data disk to a VM from the console, then format and mount it in the operating system.
Prerequisites
- A Hikube account and a project with available Storage quota
- An existing VM instance
- SSH access to the VM
Steps
1. Open the VM for editing
- Open Infrastructure > VM Instances and click the VM name.
- Click Edit.
2. Add the disk
In the Storage section, click Add a disk. A Storage Volume #1 block appears. Two options:
New disk (New tab):
- Volume Name: keep the suggested name or enter your own (lowercase letters, digits and hyphens).
- Size (GB): 20 GB minimum, for example
50. - Replication Type: Asynchronous Replication (Recommended) or Synchronous Replication.
- Disk Encryption: enable it to encrypt data at rest.
Existing disk (Existing tab): under Select an existing volume, choose a data disk of the project that is not attached to any VM. Disks can also be created independently in the Disks menu (see Disks).
To remove a volume added by mistake before saving, click Remove disk (bin icon): nothing has been created yet.
The disks the VM already has are shown read-only: the New / Existing choice only exists on added volumes.
3. Save
Check the quota summary at the top of the page, then click Save.
The console shows Restart required: the new disk is only taken into account on the next VM restart. Click Restart in the Actions section of the detail page, then wait for the VM to return to Running status. The disk appears in the Storage & Disks section of the detail page.
You can also add disks directly when creating the VM, with Add a disk at the Storage step of the wizard. They are then named after the VM with a suffix (ma-vm-2, ma-vm-3…).
4. Format and mount the disk in the VM
Connect to the VM with the command from the SSH Connection block:
ssh -i ~/.ssh/hikube-vm ubuntu@<public-ip>
Identify the new disk:
lsblk
Expected result:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 19.9G 0 part /
└─vda15 252:15 0 106M 0 part /boot/efi
vdb 252:16 0 50G 0 disk
The new disk appears as vdb, with no partition and no mount point.
Format it as ext4:
sudo mkfs.ext4 /dev/vdb
Mount it:
sudo mkdir -p /mnt/data
sudo mount /dev/vdb /mnt/data
Make the mount persistent using the file system UUID, which is more stable than the device name:
UUID=$(sudo blkid -s UUID -o value /dev/vdb)
echo "UUID=$UUID /mnt/data ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
Verification
df -h /mnt/data
Expected result:
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 49G 24K 47G 1% /mnt/data
Test writing:
sudo touch /mnt/data/test.txt && echo "OK"
Detach a disk
Unmount the disk in the OS first and remove its line from /etc/fstab. Then, in Edit > Storage, click Detach disk on the volume, confirm with Detach in the Detach <name>? dialog, and click Save.
The disk is not deleted: its data is kept and it stays available in the Disks menu, where you can attach it to another VM. The detachment only takes effect on the next VM restart: until then, the disk remains visible to the system. The console shows Restart required; click Restart to apply it. The system disk cannot be detached: it has no action in Edit.
To delete the detached disk afterwards, restart the VM first: as long as the VM still uses it, the console refuses the deletion ("This disk was detached, but its VM still uses it until its next restart. Restart the VM, then try again.").