Jump to content
Welcome to our new Citrix community!
  • 0

too many VDI/VHD per VM, how to get rid of unused ones


robert wild1709160729

Question

hi all,

 

i seem to have a LOT of unused VDI's for my VM's, im guessing its because i have made multiple copies of my VM's but its still kept the hard drive

 

how do i delete the unsused VDI's

 

im following this guide

 

http://deepix.github.io/2017/02/01/xsvdi.html

 

and when im running theses commands

 

[root@lon-p-xenserver01 ~]# xe vdi-list sr-uuid=0f956522-42d7-5328-a5ec-a7fd406ca0f3 params=uuid managed=true > /vdi_sr_list.txt
[root@lon-p-xenserver01 ~]# xe vbd-list vdi-uuid=cc47329b-f342-4c37-ab8f-e37df65845e4 params=vm-name-label
[root@lon-p-xenserver01 ~]# xe vbd-list vdi-uuid=d7d14ba2-eb82-4c5f-ac25-c352bf91cc7a params=vm-name-label
vm-name-label ( RO)    : Control domain on host: lon-p-xenserver01


[root@lon-p-xenserver01 ~]#


now obviously

 

cc47329b-f342-4c37-ab8f-e37df65845e4

 

is ok to delete as the vdi is not with a vbd

 

but what about d7d14ba2-eb82-4c5f-ac25-c352bf91cc7a ??

 

thanks,

rob

Link to comment

25 answers to this question

Recommended Posts

  • 0

That looks about right. I like to label my VDIs so there is no confusion about what is teh "real" one or ones. That way, you can always do a "xe vdi-list uuid=(UUID-of-VDI) params=name-label" to verify if it's one you want to keep.  Sorry, have been traveling and hence will be off and on a few days here.

 

-=Tobias

Link to comment
  • 0

Each VM may well have its own base copy, but not necessarily. That's why I suggest adding a name-label to each "real" VDI associated with a VM to make sure you don't get rid of something important! These might have come from cloning templates, for example, to create new VMs. This thread may be of some help: https://discussions.citrix.com/topic/324186-too-many-base-copy-when-xe-vdi-list/

 

-=Tobias

Link to comment
  • 0

it is already -

 

[root@lon-p-xenserver01 ~]# xe vm-disk-list vm=lon-p-alc02
Disk 0 VBD:
uuid ( RO)             : 55a7458d-f834-5a9b-2ecd-5410f0a59338
    vm-name-label ( RO): lon-p-alc02
       userdevice ( RW): 0


Disk 0 VDI:
uuid ( RO)             : 67de679b-c7bf-4797-bc03-3cdc880595d9
       name-label ( RW): lon-p-alc 0
    sr-name-label ( RO): Hardware HBA virtual disk storage
     virtual-size ( RO): 32212254720

Link to comment
  • 0

so some are labeled but others are called base


uuid ( RO)                : 888a0b7d-6c31-4e8d-b01f-84a8d39fa377
          name-label ( RW): lon-c-smtp10 0
    name-description ( RW): Created by template provisioner
             sr-uuid ( RO): 0f956522-42d7-5328-a5ec-a7fd406ca0f3
        virtual-size ( RO): 10737418240
            sharable ( RO): false
           read-only ( RO): false


uuid ( RO)                : 24d4e58d-9d92-4531-adff-2026c3f7161e
          name-label ( RW): lon-c-smtp10 0
    name-description ( RW): Created by template provisioner
             sr-uuid ( RO): 0f956522-42d7-5328-a5ec-a7fd406ca0f3
        virtual-size ( RO): 10737418240
            sharable ( RO): false
           read-only ( RO): false


uuid ( RO)                : ebb09d6f-52d3-411e-989d-d67e3945278d
          name-label ( RW): base copy
    name-description ( RW):
             sr-uuid ( RO): 0f956522-42d7-5328-a5ec-a7fd406ca0f3
        virtual-size ( RO): 53687091200
            sharable ( RO): false
           read-only ( RO): true


uuid ( RO)                : 1162a4de-d456-4209-ab10-ba4bd3a73545
          name-label ( RW): base copy
    name-description ( RW):
             sr-uuid ( RO): 0f956522-42d7-5328-a5ec-a7fd406ca0f3
        virtual-size ( RO): 64424509440
            sharable ( RO): false
           read-only ( RO): true

 

i have actually found one i can delete

 

[root@lon-p-xenserver01 ~]# xe vm-disk-list vm=lon-c-smtp10_02
Disk 0 VBD:
uuid ( RO)             : 68479de5-4aa0-c20f-75a6-c0cd9a44f628
    vm-name-label ( RO): lon-c-smtp10_02
       userdevice ( RW): 0


Disk 0 VDI:
uuid ( RO)             : 24d4e58d-9d92-4531-adff-2026c3f7161e
       name-label ( RW): lon-c-smtp10 0
    sr-name-label ( RO): Hardware HBA virtual disk storage
     virtual-size ( RO): 10737418240

 

so i can delete vdi "888a0b7d-6c31-4e8d-b01f-84a8d39fa377"

 

 

Link to comment
  • 0

ok got the commands now making a script and variables to do it all -

 

xe vm-list power-state=running is-control-domain=false is-a-snapshot=false

 

xe vm-snapshot uuid=78cb1761-5b3e-4225-df4d-d7d54b9768c0 new-name-label=squid_snap

 

xe template-param-set is-a-template=false ha-always-run=false uuid=e13f0a98-dfb1-e6e6-6cbc-705d800ea836

 

xe vm-export vm=e13f0a98-dfb1-e6e6-6cbc-705d800ea836 filename=/backup/squid_back.xva

 

xe vm-uninstall uuid=e13f0a98-dfb1-e6e6-6cbc-705d800ea836 force=true

 

 

Link to comment
  • 0

just put together this -

 

#!/bin/bash
#
uuid="/scripts/uuid.txt"
date=date +"%d-%m-%Y"
path=/lon-pixit/pxl-pfs01/engineering/xen/backup
#
xe vm-list power-state=running is-control-domain=false is-a-snapshot=false | awk '/uuid/{print $5}' > "$uuid"
#
while IFS= read -r line
do
name=`xe vm-list uuid="$uuid" | awk '/name-label/{print $4}'`

snap=`xe vm-snapshot uuid="$uuid" new-name-label="snap_"$name"_$date"`

xe template-param-set is-a-template=false ha-always-run=false uuid=$snap

xe vm-export vm=$snap filename=$path/"$name"_$date".xva

xe vm-uninstall uuid=$snap force=true
done < "$input"

 

 

Link to comment
  • 0

smashed it!!!!!!!!!!!!!!!!

 

#!/bin/bash
#
uuid="/scripts/uuid.txt"
date="$(date +"%d-%m-%Y")"
path=/run/sr-mount/SMB/10.100.1.5/xen/backup/6a84f57c-541f-012a-84a5-7ce9416e9e30
#
#list UUIDS of all running VM's
xe vm-list power-state=running is-control-domain=false is-a-snapshot=false | awk '/uuid/{print $5}' > "$uuid"
#
while IFS= read -r line; do
#
name=`xe vm-list power-state=running is-control-domain=false is-a-snapshot=false | awk '/name-label/{print $4}'`
#
snap=`xe vm-snapshot uuid="$line" new-name-label="$name-$date-ss"`
#
xe template-param-set is-a-template=false ha-always-run=false uuid="$snap"
#
xe vm-export vm="$snap" filename="$path/$name-vm.xva"
#
xe vm-uninstall uuid="$snap" force=true
#
done < "$uuid"

 

Link to comment
  • 0

scrap that made once change on a line

 

tested the below and it works like a charm

 

https://i.postimg.cc/6Q0qrrmB/backup.png

 

#!/bin/bash

uuid="/scripts/uuid.txt"
date="$(date +"%d-%m-%Y")"
path=/run/sr-mount/SMB/10.100.1.5/xen/backup/6a84f57c-541f-012a-84a5-7ce9416e9e30

#list UUIDS of all running VM's
xe vm-list power-state=running is-control-domain=false is-a-snapshot=false | awk '/uuid/{print $5}' > "$uuid"

while IFS= read -r line; do

name=`xe vm-list uuid="$line" | awk '/name-label/{print $4}'`

snap=`xe vm-snapshot uuid="$line" new-name-label="$name-$date-ss"`

xe template-param-set is-a-template=false ha-always-run=false uuid="$snap"

xe vm-export vm="$snap" filename="$path/$name-vm.xva"

xe vm-uninstall uuid="$snap" force=true

done < "$uuid"

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...