Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorchestwood96 <adi.joachim12@gmail.com>2023-03-10 15:07:36 +0100
committerGitHub <noreply@github.com>2023-03-10 15:07:36 +0100
commit6884cd52cbbceccf1fc240854a1433918bb66e3d (patch)
tree81da0cb9aaae3e4b801a0ea4860d6aa65e7b4d6f /archinstall/lib
parente4f3198505c736e8825a6fd056b71f9a7336c1d3 (diff)
Initial swapfile prototype (#1558)
* Initial swapfile prototype * add_swapfile different exception handling * Added error handling to add_swapfile prototype --------- Co-authored-by: Anton Hvornum <anton.feeds+github@gmail.com>
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/installer.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index 2b0830d3..55bf5570 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -132,6 +132,7 @@ class Installer:
# if HSM is not used to encrypt the root volume. Check mkinitcpio() function for that override.
self.HOOKS = ["base", "systemd", "autodetect", "keyboard", "sd-vconsole", "modconf", "block", "filesystems", "fsck"]
self.KERNEL_PARAMS = []
+ self.FSTAB_ENTRIES = []
self._zram_enabled = False
@@ -318,6 +319,26 @@ class Installer:
partition.mount(f'{self.target}{mountpoint}', options=options)
+ def add_swapfile(self, size = '4G', enable_resume = True, file='/swapfile'):
+ if file[:1] != '/':
+ file = f"/{file}"
+ if len(file.strip()) <= 0 or file == '/':
+ raise ValueError(f"The filename for the swap file has to be a valid path, not: {self.target}{file}")
+
+ SysCommand(f'dd if=/dev/zero of={self.target}{file} bs={size} count=1')
+ SysCommand(f'chmod 0600 {self.target}{file}')
+ SysCommand(f'mkswap {self.target}{file}')
+
+ self.FSTAB_ENTRIES.append(f'{file} none swap defaults 0 0')
+
+ if enable_resume:
+ resume_uuid = SysCommand(f'findmnt -no UUID -T {self.target}{file}').decode('UTF-8').strip()
+ resume_offset = SysCommand(f'/usr/bin/filefrag -v {self.target}{file}').decode('UTF-8').split('0:', 1)[1].split(":", 1)[1].split("..", 1)[0].strip()
+
+ self.HOOKS.append('resume')
+ self.KERNEL_PARAMS.append(f'resume=UUID={resume_uuid}')
+ self.KERNEL_PARAMS.append(f'resume_offset={resume_offset}')
+
def post_install_check(self, *args :str, **kwargs :str) -> List[str]:
return [step for step, flag in self.helper_flags.items() if flag is False]
@@ -431,6 +452,11 @@ class Installer:
if hasattr(plugin, 'on_genfstab'):
if plugin.on_genfstab(self) is True:
break
+
+ with open(f"{self.target}/etc/fstab", 'a') as fstab_fh:
+ for entry in self.FSTAB_ENTRIES:
+ fstab_fh.write(f'{entry}\n')
+
return True