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