0 Голосов
Версия 1.1 от Сергей Коршунов на 2022/07/01 13:40

Последние авторы
1 = Fix Proxmox (PVE) “can’t lock file ‘/var/lock/qemu-server/lock-xxx.conf’ – got timeout” (Proxmox can’t shutdown/stop virtual machine) (Proxmox kill/force stop virtual machine) =
2
3
4 Last Updated on 8 October, 2021
5
6 == The Issue ==
7
8 When trying to “Stop” or “Shutdown” virtual machine from Proxmox (PVE) web gui, the “Cluster log” shows
9
10 end task UPID:pve:xxxxxxxx:xxxxxxxx:xxxxxxx:qmstop:xxx:root@pam: can’t lock file ‘/var/lock/qemu-server/lock-xxx.conf’ -got timeout
11
12 end task UPID:pve:xxxxxxxx:xxxxxxxx:xxxxxxx:qmreboot:xxx:root@pam: VM quit/powerdown failed
13
14 Error: can’t lock file ‘/var/lock/qemu-server/lock-202.conf’ – got timeout
15
16 == Related Question ==
17
18 * How to manually (Using terminal/console to) unlock a VM
19
20 == The Fix ==
21
22 === Manually ===
23
24 We can manually delete the lock from following path
25
26 {{{/run/lock/qemu-server
27 # The file will be
28 /run/lock/qemu-server/lock-100.conf
29 /run/lock/qemu-server/lock-102.conf
30 ...
31 # Make sure only delete the correct one
32 # Manually unlock again (100 is the VM id)
33 qm unlock 100}}}
34
35 === Automated via bash script ===
36
37 1 Open Proxmox web gui
38
39 2 Click on “>_ Shell” to launch Shell for Proxmox
40
41 3 Type following command to create a “killvm.sh” file
42
43 {{{nano killvm.sh}}}
44
45 4 Select which script you want to use, copy paste the script to nano editor (Here we use the Simple Script as example, you can use Interactive script or Loop script based on your needs)
46
47 [[~[~[image:https://dannyda.com/myupload/2020/05/image-28.png~|~|alt="Copy paste script to nano editor" height="290" width="445"~]~] >>url:https://dannyda.com/myupload/2020/05/image-28.png]]
48
49 Copy paste script to nano editor
50
51 5 Use Ctrl + X, Y, Enter key to Exit and Save the file
52
53 6 Allow the script executing as program
54
55 {{{chmod +x killvm.sh}}}
56
57 7 Now we can use the bash script to remove locks easily by using following command
58
59 {{{# ./killvm.sh VMID
60 #e.g.
61 ./killvm.sh 202}}}
62
63 [[~[~[image:https://dannyda.com/myupload/2020/05/image-30.png~|~|alt="Lock for VM ID 201 removed" height="325" width="468"~]~] >>url:https://dannyda.com/myupload/2020/05/image-30.png]]
64
65 Lock for VM ID 201 removed
66
67 8 If you would like to use other bash scripts or all of them, save each of them to separate .sh files e.g. killvm-select.sh killvm-loop.sh, the rest steps will be the same as above
68
69 Simple script is suitable to normal usage and can be used with other custom scripts
70
71 Interactive script is verbose
72
73 Copy one or all of following bash scripts to separate name.sh files to use them
74
75 ==== Simple script ====
76
77 {{{#!/bin/sh
78 echo
79 echo '-----AUTHOR: https://dannyda.com-----'
80 echo
81 echo '---Existing locks---'
82 qm unlock $1
83 ls -l /run/lock/qemu-server
84 rm -f /run/lock/qemu-server/lock-$1.conf
85 qm unlock $1
86 echo
87 echo '---Remaining locks---'
88 ls -l /run/lock/qemu-server}}}
89
90 Usage: Assume saved as “killvm.sh” in “/root” folder on PVE, 202 is the VM ID we want to delete
91
92 {{{./killvm.sh 202}}}
93
94 ==== Interactive script ====
95
96 {{{#!/bin/sh
97 echo
98 echo '-----AUTHOR: https://dannyda.com-----'
99 echo
100 echo 'Existing lock files'
101 ls -l /run/lock/qemu-server
102 read -p 'Enter the VM ID here to delete corresponding lock e.g. 101: ' vmid
103 qm unlock $vmid
104 rm -f /run/lock/qemu-server/lock-$vmid.conf
105 qm unlock $vmid
106 echo
107 echo '---Remaining locks---'
108 ls -l /run/lock/qemu-server}}}
109
110 Usage: Assume saved as “killvmi.sh” in “/root” folder on PVE, 203 is the VM ID we want to delete
111
112 {{{./killvmi.sh
113 Enter the VM ID here to delete corresponding lock e.g. 101: 203}}}
114
115 [[~[~[image:https://dannyda.com/myupload/2020/05/image-31.png~|~|alt="Interactive script to rm lock" height="408" width="570"~]~] >>url:https://dannyda.com/myupload/2020/05/image-31.png]]
116
117 Interactive script to rm lock
118
119 ==== Loop script for deleting multiple lock files with ease ====
120
121 (Double click on the following script to select all, then copy)
122
123 |(((
124 1
125
126 2
127
128 3
129
130 4
131
132 5
133
134 6
135
136 7
137
138 8
139
140 9
141
142 10
143
144 11
145
146 12
147
148 13
149
150 14
151
152 15
153
154 16
155
156 17
157
158 18
159
160 19
161
162 20
163
164 21
165
166 22
167
168 23
169
170 24
171
172 25
173 )))|(((
174 #!/bin/bash
175
176 echo
177
178 echo '~-~-~-~--AUTHOR: [[https:~~/~~/dannyda.com~~-~~-~~-~~-->>url:https://dannyda.com-----]]'
179
180 echo
181
182 echo 'Existing lock files'
183
184 ls -l /run/lock/qemu-server
185
186 while read -p 'Enter the VM ID here to delete corresponding lock, press Enter key to exit e.g. 101: ' vmid; do
187
188 echo
189
190 echo '~-~-~-~--AUTHOR: [[https:~~/~~/dannyda.com~~-~~-~~-~~-->>url:https://dannyda.com-----]]'
191
192 echo
193
194 echo 'Existing lock files'
195
196 ls -l /run/lock/qemu-server
197
198 if ~[~[ "$vmid" = "" ]] || ~[~[ "$vmid" = "q" ]] ;
199
200 then      
201
202 exit
203
204 elif ~[~[ "$vmid" -gt 0 ]] && ~[~[ "$vmid" -lt 1000000000 ]];
205
206 then
207
208 qm unlock $vmid
209
210 rm -f /run/lock/qemu-server/lock-$vmid.conf
211
212 qm unlock $vmid
213
214 ls -l /run/lock/qemu-server
215
216 else
217
218 echo 'Input error, please enter correct VM ID.'
219
220 fi
221
222 done
223 )))
224
225 Usage: Assume saved as “rmlock.sh” in “/root” folder on PVE, 201, 202 is the VM ID we want to delete
226
227 [[~[~[image:https://dannyda.com/myupload/2020/05/image-32.png~|~|height="966" width="798"~]~]>>url:https://dannyda.com/myupload/2020/05/image-32.png]]
228
229 {{{./rmlock.sh
230 # Enter the VM ID which we want to delete but locked, then hit Enter key to unlock it
231 # Note
232 # Press Enter key without entering anything to exit the script, or type q then press Enter key to exit.}}}
233
234 Last step
235
236 Now we can stop/shutdown or reboot the virtual machine from Proxmox web gui without problem!
237
238
239 == Bonus ==
240
241 === Simple script (Remove the lock and stop the VM) ===
242
243 {{{#!/bin/sh
244 echo
245 echo '-----AUTHOR: https://dannyda.com-----'
246 echo
247 echo '---Existing locks---'
248 qm unlock $1
249 ls -l /run/lock/qemu-server
250 rm -f /run/lock/qemu-server/lock-$1.conf
251 qm unlock $1
252 echo
253 echo '---Remaining locks---'
254 ls -l /run/lock/qemu-server
255 echo
256 qm stop $1 && qm status $1}}}
257
258 === Interactive script (Remove the lock and stop the VM) ===
259
260 {{{#!/bin/sh
261 echo
262 echo '-----AUTHOR: https://dannyda.com-----'
263 echo
264 echo 'Existing lock files'
265 ls -l /run/lock/qemu-server
266 read -p 'Enter the VM ID here to delete corresponding lock e.g. 101: ' vmid
267 qm unlock $vmid
268 rm -f /run/lock/qemu-server/lock-$vmid.conf
269 qm unlock $vmid
270 echo
271 echo '---Remaining locks---'
272 ls -l /run/lock/qemu-server
273 echo
274 qm stop $vmid && qm status $vmid}}}
275
276 === Loop script for deleting multiple lock files with ease (Remove the lock and stop the VM) ===
277
278 |(((
279 1
280
281 2
282
283 3
284
285 4
286
287 5
288
289 6
290
291 7
292
293 8
294
295 9
296
297 10
298
299 11
300
301 12
302
303 13
304
305 14
306
307 15
308
309 16
310
311 17
312
313 18
314
315 19
316
317 20
318
319 21
320
321 22
322
323 23
324
325 24
326
327 25
328
329 26
330 )))|(((
331 #!/bin/bash
332
333 echo
334
335 echo '~-~-~-~--AUTHOR: [[https:~~/~~/dannyda.com~~-~~-~~-~~-->>url:https://dannyda.com-----]]'
336
337 echo
338
339 echo 'Existing lock files'
340
341 ls -l /run/lock/qemu-server
342
343 while read -p 'Enter the VM ID here to delete corresponding lock, press Enter key to exit e.g. 101: ' vmid; do
344
345 echo
346
347 echo '~-~-~-~--AUTHOR: [[https:~~/~~/dannyda.com~~-~~-~~-~~-->>url:https://dannyda.com-----]]'
348
349 echo
350
351 echo 'Existing lock files'
352
353 ls -l /run/lock/qemu-server
354
355 if ~[~[ "$vmid" = "" ]] || ~[~[ "$vmid" = "q" ]] ;
356
357 then      
358
359 exit
360
361 elif ~[~[ "$vmid" -gt 0 ]] && ~[~[ "$vmid" -lt 1000000000 ]];
362
363 then
364
365 qm unlock $vmid
366
367 rm -f /run/lock/qemu-server/lock-$vmid.conf
368
369 qm unlock $vmid
370
371 ls -l /run/lock/qemu-server
372
373 qm stop $vmid && qm status $vmid
374
375 else
376
377 echo 'Input error, please enter correct VM ID.'
378
379 fi
380
381 done
382 )))
383
384 === Using command to unlock VM ===
385
386 {{{qm unlock <VMID>
387 # e.g.
388 qm unlock 100}}}