Attach a disk from another VM - ZFS

Bobbbb

Well-Known Member
Jul 13, 2018
78
1
48
29
Hi, can someone please assist me with the commands to attach an unused disk to another VM?
 
that is something that we are currently working on to make it nicer. For the time being, you will have to do it manually. Can you show the output of zfs list and indicate which disk should be attached to which VMID?
 
NAME USED AVAIL REFER MOUNTPOINT
rpool 384G 538G 96K /rpool
rpool/ROOT 1.49G 538G 96K /rpool/ROOT
rpool/ROOT/pve-1 1.49G 538G 1.49G /
rpool/data 383G 538G 96K /rpool/data
rpool/data/vm-100-disk-0 93.3G 538G 93.3G -
rpool/data/vm-100-disk-1 76K 538G 76K -
rpool/data/vm-101-disk-0 88K 538G 88K -
rpool/data/vm-101-disk-1 3.95G 538G 3.95G -
rpool/data/vm-103-disk-0 68.8G 538G 68.8G -
rpool/data/vm-105-disk-0 217G 538G 217G -


i would like to attach 105 to 100
 
A hint for the future, if you post console output, it is best to do it inside [code][/code] tags so that all the formatting stays intact :)

Okay, generally you will have to rename the dataset. Looking at the list, we can see that disk 0 and 1 for VM 100 are already in use. So the next free one would be 2.

Code:
zfs rename rpool/data/vm-105-disk-0 /rpool/data/vm-110-disk-2
should work.

Does VM 105 still exist? Then you will need to manually edit its configuration file to remove that disk.
The file is located at /etc/pve/qemu-server/105.conf. Look for the line referencing local-zfs:vm-105-disk-0 and remove that line.

Now for the disk to show up for VM 110, run qm rescan --vmid 110. The disk image should show up as unused disk in the VMs hardware panel. From there you can edit it to attach it.
 
  • Like
Reactions: ValkraS
Just wanted to quickly chime in to say that I was in a similar situation and this guide worked perfectly for me. My situation was I was moving my PBS server to another Proxmox host, which was stored on a USB external hard drive. These are my notes:

  1. Discover the list of ZFS pools
    1. zfs list
      1. You should get something like below:

EqnQKLTXQZxN5BcUGCtN2OAhmpvgdfe1FAitxZ8nMa4ZAuSU92bFBvqoJ49e6iUiQqi2bZN_WuFQC27Kraq959qMoRrUM5D4p0scECTLJd_zGX-xdODo8AncWY3Snat9mqDEYCN_hqiDRC1aqYSHtA0


  1. From the list of ZFS pools, identify the pool that you wish to import. Your desired pool will most likely not have a mountpoint. In this example we can import with the following command (replace the identifier with your own ZFS pool)
    1. zfs import ZFS-01
      1. If you have difficulty importing, you may need to add an -f after “import” to force it to import.
  2. From here, if you can create a VM with the same ID as the existing virtual disks (eg. 412) then you should be able to create this and run the following for the virtual disk to appear automatically:
    1. qm rescan
  3. If the disk is different from the VM ID that you intend to use, then you will have to rename the virtual subvolume. To rename this so the old 412 disk can be attached to the 416 VM, you can use the following command:
    1. zfs rename ZFS-01/vm-412-disk-0 ZFS-01/vm-416-disk-1 && qm rescan
  4. Your VM disk should now be renamed, and it should appear as an unreferenced volume to your VM. You should now be able to go back to your Proxmox WebUI and attach the unreferenced volume to your VM via the UI and you are done!
 
  • Like
Reactions: ValkraS
Hi guys,
On Oct. 1, 2021 you said:
that is something that we are currently working on to make it nicer. For the time being, you will have to do it manually.

my use-case for this is, when I have to restore a vm to a previous state, to restore some files.
The best way so far was to restore the vm in question, add a small transfer-disk - say 1GB to recover the file(s) needed, detach the disk, rename it to match the current productive vm and manually edit the matching .conf file under /etc/pve/qemu-server or on clusters under /etc/pve/nodes/..../qemu-server.
After recovery, I mostly delete the transfer-disk.
It would be nice, if there was an option from either within the vm hardware-config tab, in case a disk is unused, there could be an option "transfer disk to vm...." or there could be a section from within the storage "unused disks" and from there on the option "transfer disk to vm..."

regards,
Félix
 
  • Like
Reactions: ValkraS
Hi guys,
On Oct. 1, 2021 you said:


my use-case for this is, when I have to restore a vm to a previous state, to restore some files.
The best way so far was to restore the vm in question, add a small transfer-disk - say 1GB to recover the file(s) needed, detach the disk, rename it to match the current productive vm and manually edit the matching .conf file under /etc/pve/qemu-server or on clusters under /etc/pve/nodes/..../qemu-server.
After recovery, I mostly delete the transfer-disk.
It would be nice, if there was an option from either within the vm hardware-config tab, in case a disk is unused, there could be an option "transfer disk to vm...." or there could be a section from within the storage "unused disks" and from there on the option "transfer disk to vm..."

regards,
Félix
Same here.
It would be great for such an option - to make a virtual "storage" that can be created, mounted and unmounted from guest VMs.
Like an virtual USB Stoage you can configure from webGUI.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!