···11+layout: blog.njk
22+type: blog
33+index: true
44+is_note: true
55+year: 2024
+44
lume/src/notes/2024/delete-zfs-zvol-sometimes.md
···11+---
22+title: "How to delete a ZFS zvol when it claims to be busy but you're sure it isn't"
33+date: 2024-01-05
44+---
55+66+Sometimes when you delete ZFS datasets you get this error:
77+88+```
99+$ sudo zfs destroy -rf arsene/vms
1010+cannot destroy 'arsene/vms/oracle-linux-9': dataset is busy
1111+cannot destroy 'arsene/vms/rocky-linux-9': dataset is busy
1212+cannot destroy 'arsene/vms': dataset already exists
1313+```
1414+1515+The "dataset is busy" error is thrown when deleting a zvol if
1616+something has the file open. This can happen with zvols for linux
1717+systems when your kernel's LVM stack is autodetecting the LVM groups
1818+in the zvols. You can confirm this with the `lvdisplay` command:
1919+2020+```
2121+$ lvdisplay
2222+2323+--- Logical volume ---
2424+LV Path /dev/vg_main/lv_swap
2525+LV Name lv_swap
2626+VG Name vg_main
2727+LV UUID 0phfZx-OYpN-EHUe-11Gs-8fzl-iuwf-jgh9Nl
2828+LV Write Access read/write
2929+LV Creation host, time localhost.localdomain, 2023-05-22 05:50:13 -0400
3030+LV Status NOT available
3131+LV Size 4.00 GiB
3232+Current LE 1024
3333+Segments 1
3434+Allocation inherit
3535+Read ahead sectors auto
3636+```
3737+3838+You can disable them with the `dmsetup` command:
3939+4040+```
4141+$ sudo dmsetup remove -f /dev/vg_main/lv_swap
4242+```
4343+4444+This will let you delete the offending zvols.