From 84b520dd580b7725de4c9e62b11ec490cb8d3f4f Mon Sep 17 00:00:00 2001
From: zsdc <taras@vyos.io>
Date: Wed, 13 Mar 2024 00:40:09 +0200
Subject: grub: T4548: Fixed configuration files order

To iterate files on ext* file systems GRUB reads their inodes one by one,
ignoring names. This breaks our configuration logic that relies on proper
loading order.

This commit adds a helper `sort_inodes()` that needs to be used whenever GRUB
configuration files are created. It recreates files, changing their inodes in a
way where inodes order matches alphabetical order.

(cherry picked from commit f74923202311e853b677e52cd83bae2be9605c26)
---
 src/system/grub_update.py | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'src/system')

diff --git a/src/system/grub_update.py b/src/system/grub_update.py
index 5a7d8eb72..5a0534195 100644
--- a/src/system/grub_update.py
+++ b/src/system/grub_update.py
@@ -105,4 +105,8 @@ if __name__ == '__main__':
     else:
         render(grub_cfg_main, grub.TMPL_GRUB_MAIN, {})
 
+    # sort inodes (to make GRUB read config files in alphabetical order)
+    grub.sort_inodes(f'{root_dir}/{grub.GRUB_DIR_VYOS}')
+    grub.sort_inodes(f'{root_dir}/{grub.GRUB_DIR_VYOS_VERS}')
+
     exit(0)
-- 
cgit v1.2.3