LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-05-2020, 01:34 PM   #1
DapperDeer
LQ Newbie
 
Registered: Apr 2020
Distribution: Fedora 31
Posts: 5

Rep: Reputation: Disabled
Adding GRUB Env Variable for Integrity Checks


I’m currently developing a secure boot chain for my work. I’d like to utilize GRUB to boot into Linux where integrity checks will be performed, then if the filesystem is verified, change a custom GRUB environment variable flag which will allow the user to continue our boot into Windows.

My initial idea was led a bit astray as the emedded configuration doc is wrong, but I’ve been trying to persevere nonetheless. I found this StackOverflow thread suggesting a workaround is to embed a cfg file that uses `configfile` to call the “actual” file which contains the scripting and whatever else that I need.

This is my process:
1. Create a grub image:
Code:
$GRUBDIR/grub-mkimage               \
            -O i386-pc -d $CORE -v       \
            -p $CORE                      \
            -m $HOME/memdisk/memdisk.tar  \ # Memdisk has multiple cfgs dedicated 
            -c $HOME/memdisk/embedded.cfg \ # to each boot entry (Windows and Linux)
            -o $CORE/core.img             \
part_gpt biosdisk ext2 memdisk ntfs tar echo sleep configfile search_fs_uuid loadenv search normal
2. Install using that image:
Code:
$GRUBDIR/grub-install $DRIVE                    \
            --boot-directory=$MNTDIR/boot/      \
            -d $CORE
3. Using Dracut, create the initramfs

Embedded.cfg:
Code:
configfile (memdisk)/grub.cfg
Grub.cfg:
Code:
load_env

if [ $Clean == "false" ]; then 
                                configfile /boot/grub/windows.cfg
else
                                configfile /boot/grub/linux.cfg
fi
I looked through the GRUB documentation and it doesn't mention anything about singular brackets yet every grub.cfg I can find uses single brackets. GRUB has given me errors for using double brackets. I've tried "$Clean", $Clean, [[ "$Clean" == "false" ]].

Grubenv:
Code:
# GRUB Environment Block
Clean=false
###########...
On boot, I get this initial return:

Code:
Booting from Hard Disk...
GRUB loading.....
Welcome to GRUB!

error: can't find command `false'.
and I have absolutely no idea why it keeps thinking that "false" is a command rather than a string. I've tried a ton of different iterations, with and without quotes, I've tried making it a zero or one, I've tried caps/no-caps/mixed-caps, I've tried using "set Clean=false save_env" and yet nothing I do works.

To try and be ultimately clear:
I want to create a GRUB environment variable named Clean. If Clean is true, I want to use /boot/grub/windows.cfg. If Clean is false, I want to use /boot/grub/linux.cfg. Clean will be initially set to false, forcing the user to boot into our Linux kernel that will then verify the integrity of the filesystem. If the filesystem is verified, I want Clean to be set to true (on next boot only) to allow the user to boot into Windows. If/once the system shuts down past this point, whether graceful or ungraceful, Clean should be false to force the user to verify the filesystem once more.

I thoroughly feel like I’m missing one small detail for everything to fall into place, so if anyone has any advice, it would be greatly appreciated.

Thanks so much

Last edited by DapperDeer; 06-05-2020 at 01:38 PM.
 
Old 06-06-2020, 11:53 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
1. Yes, I know, this is contrary to what GRUB documentation says, but all examples of grub.cfg I've seen use just = instead of ==, i.e.
Code:
if [ $Clean = "false" ]; then
2. What happens if you put $Clean in double quotes?
Code:
if [ "$Clean" = "false" ]; then
3. Did you check grub.cfg with grub-script-check*?

4. I suspect that Clean doesn't get set by load_env and is empty. Did you use grub-editenv* to change grubenv?

____
* On a Fedora/RHEL based system, the names of grub-* utilities would start with grub2- instead.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Using a Checksum for File Integrity Checks on Linux LXer Syndicated Linux News 0 07-18-2019 05:24 AM
Who checks the integrity of Linux distros? Altiris Linux - Newbie 17 01-21-2014 11:23 AM
Infinite Grub Loop: GRUB GRUB GRUB GRUB GRUB GRUB GRUB GRUB GRUB GRUB... beeblequix MEPIS 2 11-02-2013 10:56 PM
Data Integrity Checks itnaa Linux - Software 7 12-22-2006 01:28 PM
Integrity checks on RH 6.1 munyard Linux - Security 1 12-11-2002 07:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration