summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-10-02 12:13:25 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-10-02 14:25:04 +0200
commitcc70274079a0de78497011e2c665838522b6e1f5 (patch)
tree5ce60b1203f392d0dacee9b593284b343eaf0991 /src
parenta2baad8c0b62c1d0f4bc2a01c0f442899bd7475c (diff)
src: check if the system is hibernated before /image/create
Mount the system partition in readonly mode and check for the hiberfil.sys file if the target system is a Windows. Fail the image creation process if the target system is hibernated.
Diffstat (limited to 'src')
-rw-r--r--src/live/ogOperations.py10
-rw-r--r--src/utils/fs.py11
-rw-r--r--src/utils/probe.py7
3 files changed, 24 insertions, 4 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 74e4c09..83242d2 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -648,6 +648,16 @@ class OgLiveOperations:
if not fstype:
raise OgError(f'No filesystem detected in {padev}. Aborting image creation')
+ ro_mountpoint = padev.replace('dev', 'mnt')
+ if not mount_mkdir(padev, ro_mountpoint, readonly=True):
+ raise OgError(f'Cannot mount {ro_mountpoint} as readonly')
+
+ try:
+ if is_hibernation_enabled(ro_mountpoint):
+ raise OgError(f'Target system in {padev} has hibernation enabled')
+ finally:
+ umount(ro_mountpoint)
+
if change_access(user=self._smb_user, pwd=self._smb_pass) == -1:
raise OgError('remount of /opt/opengnsys/images has failed')
diff --git a/src/utils/fs.py b/src/utils/fs.py
index 381f65b..d6cf36a 100644
--- a/src/utils/fs.py
+++ b/src/utils/fs.py
@@ -29,7 +29,7 @@ def find_mountpoint(path):
return path
-def mount_mkdir(source, target):
+def mount_mkdir(source, target, readonly=False):
"""
Mounts and creates the mountpoint directory if it's not present.
@@ -43,18 +43,21 @@ def mount_mkdir(source, target):
return False
if not os.path.ismount(target):
- return mount(source, target)
+ return mount(source, target, readonly)
return True
-def mount(source, target):
+def mount(source, target, readonly):
"""
Mounts source into target directoru using mount(8).
Return true if exit code is 0. False otherwise.
"""
- cmd = f'mount {source} {target}'
+ if readonly:
+ cmd = f'mount -o ro {source} {target}'
+ else:
+ cmd = f'mount {source} {target}'
proc = subprocess.run(cmd.split(), stderr=DEVNULL)
return not proc.returncode
diff --git a/src/utils/probe.py b/src/utils/probe.py
index 2ed029b..e53f08f 100644
--- a/src/utils/probe.py
+++ b/src/utils/probe.py
@@ -178,3 +178,10 @@ def os_probe(mountpoint):
return getwindowsversion(winreghives)
else:
return 'unknown'
+
+def is_hibernation_enabled(mountpoint):
+ if get_os_family(mountpoint) != OSFamily.WINDOWS:
+ return False
+
+ hiberfile_path = f'{mountpoint}/hiberfil.sys'
+ return os.path.exists(hiberfile_path)