Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lBv2e-0007jn-AU for mharc-grub-devel@gnu.org; Tue, 16 Feb 2021 02:45:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBv2Y-0007hX-Fc for grub-devel@gnu.org; Tue, 16 Feb 2021 02:44:59 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:58834) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBv2R-0000Hi-6V for grub-devel@gnu.org; Tue, 16 Feb 2021 02:44:58 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4DftKV3Gy0z1qs3X; Tue, 16 Feb 2021 08:44:46 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4DftKV33C2z1qqkb; Tue, 16 Feb 2021 08:44:46 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id iyMrfkjHJvV3; Tue, 16 Feb 2021 08:44:45 +0100 (CET) X-Auth-Info: qvOjytYLQOZZckoiyJpsdfiGC1C/E9HuPO6OGj9NZwg= Received: from [10.88.0.186] (dslb-002-207-026-175.002.207.pools.vodafone-ip.de [2.207.26.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Tue, 16 Feb 2021 08:44:44 +0100 (CET) To: grub-devel@gnu.org Cc: Henning Schild From: Claudius Heine Subject: Atomic writing to environment file Organization: Denx Software Engineering Message-ID: Date: Tue, 16 Feb 2021 08:44:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: none client-ip=212.18.0.9; envelope-from=ch@denx.de; helo=mail-out.m-online.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2021 07:45:00 -0000 Hi, we were looking into using grub to implement an A/B system update mechanism [1] and came to the point where we need to change the grub environment from user space (grub-editenv) and from grub itself (save_env). We looked at the code [2] and [3], and it sort of looks like the environment file is written directly in both cases. We suspect that this might cause the environment file to become invalid/empty in a power-loss scenario. Other write schemes, like: `write file.tmp; mv file.tmp file` or using hard-links (if the fs supports it) might provide a better protection against a power-loss scenario. If this is an issue, then we would be willing to contribute some changes to grub for this. kind regards, Claudius Heine [1] https://sbabic.github.io/swupdate/overview.html#double-copy-with-fall-back [2] https://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/commands/loadenv.c#n380 [3] https://git.savannah.gnu.org/cgit/grub.git/tree/util/grub-editenv.c#n186