Skip to content

Commit 34dfeda

Browse files
shradhagupta6root
andauthored
Sync the grub cmdline changes before exiting (#24)
* Fix: exit on failures during defrag operation and add verbose logging * After updating GRUB configuration to enable hibernation, the tool does not ensure that these changes are fully committed to disk. On some filesystems, committing can take tens or even hundreds of seconds. If a hibernation request occurs before the commit completes, the subsequent resume fails because the resume and resume_offset parameters are missing from the kernel command line. To prevent this, the changes to the GRUB cmdline must be explicitly committed to disk. This requires: 1. sync() to flush data buffers, and 2. fsfreeze/unfreeze to flush filesystem metadata and ensure the journal is clean. --------- Co-authored-by: root <root@DESKTOP-UT47VEB>
1 parent 462c733 commit 34dfeda

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

hibernation-setup-tool.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,23 @@ static bool update_kernel_cmdline_params_for_grub(
12591259
}
12601260
}
12611261

1262+
if (is_exec_in_path("sync")) {
1263+
log_info("sync the grub cmdline changes to disk");
1264+
spawn_and_wait("sync", 0);
1265+
}
1266+
/*
1267+
* If the underlying filesystem is a journaling filesystem, and hibernation is triggered immediately
1268+
* after these updates are done, sometimes the initramfs during resume ends up reading the older grub
1269+
* cmdline(without the resume and resume_offset param). This is because the metadata for these files
1270+
* does not get updated immediately. We need to force this by flushing the fs journal after successfully
1271+
* making the grub cmdline changes
1272+
*/
1273+
if (is_exec_in_path("fsfreeze")) {
1274+
log_info("force fs journal flush by freezing/unfreezing filesystem using fsfreeze");
1275+
spawn_and_wait("fsfreeze", 2, "-f", "/boot");
1276+
spawn_and_wait("fsfreeze", 2, "-u", "/boot");
1277+
}
1278+
12621279
free(args);
12631280

12641281
return ret_value;

0 commit comments

Comments
 (0)