38
38
Works only if libguestfs tool guestfish is in the path.
39
39
40
40
See https://libguestfs.org/
41
-
42
- On Ubuntu, you may face this issue when running guestfish:
43
-
44
- - https://bugs.launchpad.net/ubuntu/+source/linux/+bug/759725
45
- - https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1813662
46
- - https://unix.stackexchange.com/a/642914/185837
47
41
"""
48
42
49
43
logger = logging .getLogger (__name__ )
59
53
'WARNING: guestfish executable is not installed. '
60
54
'Unable to extract virtual machine image: you need to install the '
61
55
'guestfish tool from libguestfs and extra FS drivers if needed. '
62
- 'See https://libguestfs.org/ for details.'
56
+ 'See the ExtractCode README.rst and https://libguestfs.org/ for details.'
63
57
)
64
58
59
+ GUESTFISH_KERNEL_NOT_READABLE = (
60
+ '''libguestfs requires the kernel executable to be readable.
61
+ This is the case by default on most Linux distributions except on Ubuntu.
62
+ Please follow the instructions in ExtractCode installation guide to make this happen.
63
+ See the ExtractCode README.rst for details.
64
+ ''' )
65
+
65
66
EXTRACTCODE_GUESTFISH_PATH_ENVVAR = 'EXTRACTCODE_GUESTFISH_PATH'
66
67
67
68
@@ -89,26 +90,15 @@ def check_linux_kernel_is_readable():
89
90
- https://bugzilla.redhat.com/show_bug.cgi?id=1670790
90
91
- https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1813662
91
92
"""
92
- error = (
93
- 'libguestfs requires the kernel executable to be readable. '
94
- 'This is the case on most Linux distribution except on Ubuntu.\n '
95
- 'Run this command as a temporary fix:\n '
96
- ' for k in /boot/vmlinuz-*\n '
97
- ' do sudo dpkg-statoverride --add --update root root 0644 /boot/vmlinuz-$(uname -r)\n '
98
- ' done\n '
99
- 'or:\n '
100
- ' sudo chmod +r /boot/vmlinuz-*\n \n ' ,
101
- 'For a permanent fix see: '
102
- 'https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1813662/comments/21'
103
- )
93
+
104
94
if on_linux :
105
95
kernels = list (pathlib .Path ('/boot' ).glob ('vmlinuz-*' ))
106
96
if not kernels :
107
- raise ExtractErrorFailedToExtract (error )
97
+ raise ExtractErrorFailedToExtract (GUESTFISH_KERNEL_NOT_READABLE )
108
98
for kern in kernels :
109
99
if not os .access (kern , os .R_OK ):
110
100
raise ExtractErrorFailedToExtract (
111
- f'Unable to read kernel at: { kern } .\n { error } ' )
101
+ f'Unable to read kernel at: { kern } .\n { GUESTFISH_KERNEL_NOT_READABLE } ' )
112
102
113
103
114
104
@attr .s
@@ -250,7 +240,7 @@ def run_guestfish(self, args, timeout=None):
250
240
return as_unicode (stdout )
251
241
252
242
253
- def extract (location , target_dir , as_tarballs = True ):
243
+ def extract (location , target_dir , as_tarballs = False ):
254
244
"""
255
245
Extract all files from a guestfish-supported VM image archive file at
256
246
location in the target_dir directory. Optionally only extract the
@@ -306,8 +296,7 @@ def extract(location, target_dir, as_tarballs=True):
306
296
# we can safely extract this to a root / dir as we have only one partition
307
297
partition , _parttype = partitions [0 ]
308
298
if not as_tarballs :
309
- intermediate_dir = fileutils .get_temp_dir (prefix = 'extractcode-vmimage' )
310
- tdir = intermediate_dir
299
+ tdir = fileutils .get_temp_dir (prefix = 'extractcode-vmimage' )
311
300
else :
312
301
tdir = target_dir
313
302
@@ -329,8 +318,7 @@ def extract(location, target_dir, as_tarballs=True):
329
318
base_name = partition .replace ('/' , '-' )
330
319
331
320
if not as_tarballs :
332
- intermediate_dir = fileutils .get_temp_dir (prefix = 'extractcode-vmimage' )
333
- tdir = intermediate_dir
321
+ tdir = fileutils .get_temp_dir (prefix = 'extractcode-vmimage' )
334
322
else :
335
323
tdir = target_dir
336
324
@@ -344,7 +332,7 @@ def extract(location, target_dir, as_tarballs=True):
344
332
fileutils .create_dir (partition_target_dir )
345
333
warns = extract_image_tarball (
346
334
tarball = target_tarball ,
347
- target_dir = target_dir ,
335
+ target_dir = partition_target_dir ,
348
336
skip_symlinks = False )
349
337
warnings .extend (warns )
350
338
0 commit comments