Operations grimoire/How to attach a new virtual disk: Difference between revisions

From Nasqueron Agora
 
Line 43: Line 43:
# Format it: <code>mkfs -t xfs /dev/<volume group>/<name>code>
# Format it: <code>mkfs -t xfs /dev/<volume group>/<name>code>
# Mount it: <code>echo "/dev/mapper/centos_dwellers-wharf /wharf xfs defaults 1 2" >> /etc/fstab</code>
# Mount it: <code>echo "/dev/mapper/centos_dwellers-wharf /wharf xfs defaults 1 2" >> /etc/fstab</code>
If you need to extend a logical volume:
# Follow the same steps for fdisk, vgcreate, vgextend
# Extend the logical volume: <code>lvm extend <volume name></code>
# Extend the partition: <code>xfs_grow /dev/mapper/<partition></code>

Latest revision as of 17:40, 25 January 2026

This procedure can is intended to provision storage for a Docker engine, or to add extra space disk to a server.

On the hypervisor

VMWare ESXi

Disks are created on the VMFS datastore. They are generally stored in the server folder.

  1. Go to the relevant datastore folder:
    1. cd /vmfs/volumes/datastore1
    2. cd some-server
  2. Create the disk: vmkfstools -c 200G some-disk-name.vmdk
  3. Seek the server ID with vim-cmd vmsvc/getallvms | grep some-server (the server ID is the first column value)
  4. Attach the disk with vim-cmd vmsvc/device.diskaddexisting <server ID> /vmfs/volumes/53b61491-b0561938-eec8-0cc47a055d1e/Dwellers/Mastodon.vmdk 0 1, using absolute path to the disk

If all works, you should see the disk detected as new hardware in the guest journal.

For example, for a CentOS host:

Sep 17 21:49:43 equatower.nasqueron.org kernel: vmw_pvscsi: msg type: 0x0 - MSG RING: 1/0 (5) 
Sep 17 21:49:43 equatower.nasqueron.org kernel: vmw_pvscsi: msg: device added at scsi0:1:0
Sep 17 21:49:43 equatower.nasqueron.org kernel: scsi 0:0:1:0: Direct-Access     VMware   Virtual disk     2.0  PQ: 0 ANSI: 6
Sep 17 21:49:43 equatower.nasqueron.org kernel: sd 0:0:1:0: [sdb] 1677721600 512-byte logical blocks: (858 GB/800 GiB)
Sep 17 21:49:43 equatower.nasqueron.org kernel: sd 0:0:1:0: [sdb] Write Protect is off
Sep 17 21:49:43 equatower.nasqueron.org kernel: sd 0:0:1:0: [sdb] Mode Sense: 61 00 00 00
Sep 17 21:49:43 equatower.nasqueron.org kernel: sd 0:0:1:0: Attached scsi generic sg2 type 0
Sep 17 21:49:43 equatower.nasqueron.org kernel: sd 0:0:1:0: [sdb] Cache data unavailable
Sep 17 21:49:43 equatower.nasqueron.org kernel: sd 0:0:1:0: [sdb] Assuming drive cache: write through
Sep 17 21:49:43 equatower.nasqueron.org kernel: sd 0:0:1:0: [sdb] Attached SCSI disk

On the guest

CentOS / LVM

You need to create a new partition in the attached disk with fdisk. Afterwards, you can decalre this partition as a physical volume and add it to an existing logical group, or create a new group with this volume. Finally, you add mounting point to fstab.

That means:

  1. fdisk /dev/sdb
  2. Check the journal contains an entry for your new partition, like Sep 17 21:54:42 equatower.nasqueron.org kernel: sdb: sdb1
  3. Now, you need a volume group:
    1. If it's a new volume group, vgcreate <volume group name> /dev/sdb1
    2. If the volume group exists, vgextend <volume group name> /dev/sdb1
  4. Create a logical volume: lvcreate -l 50%FREE -n <name> <volume group name>
  5. Format it: mkfs -t xfs /dev/<volume group>/<name>code>
  6. Mount it: echo "/dev/mapper/centos_dwellers-wharf /wharf xfs defaults 1 2" >> /etc/fstab

If you need to extend a logical volume:

  1. Follow the same steps for fdisk, vgcreate, vgextend
  2. Extend the logical volume: lvm extend <volume name>
  3. Extend the partition: xfs_grow /dev/mapper/<partition>