help-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: check if file exist on ntfs partition to decide default boot order


From: Hans Gruber
Subject: Re: check if file exist on ntfs partition to decide default boot order
Date: Sat, 24 Apr 2021 02:17:38 +0000 (UTC)

 Hello Jarek,
It's possible to do with grub what you want to do.You will need to script a 
little using grub which use a shell like syntax.
All commands from bash are not available but you can create function, variable 
(no array), use if .. then, elif ... then, else, fi and for ..  in.. do .. 
done, while, until ... $#, $@, $* and so onit's very powerful.for example, if 
requires single [ ... ] not [[ ... ]], "or" "and" operators are not && || but 
"-o" "-a". 

See "6.3 Writing full configuration files directly" in Grub manual for more 
information.
https://www.gnu.org/software/grub/manual/grub/grub.htmlSome module as regexp, 
tr, ... can be loaded if you need additional command.

About ntfs you will need to load ntfs module (+reqs if needed)
You have a really interresting file inside /boot/grub/${arch}/moddep.lst which 
list all required dependencies for each module.
About searching a file you will need the search module which will return the 
root of drive if file is found. you can search file system uuid or file system 
label if you want.
eg: search --file [--set=root] /path/win.txtwill return the root of drive if 
absolute path /path/win.txt is found; else nothing([--set=root] if not 
specified, root variable is used but you can use another variable to get result 
and test if variable exists or not)
search --file --set=winroot "/path/win.txt"if [ -n "${winroot}" ]; then
    echo "root found"    set root="${winroot}"    set prefix=    ...
else    echo "oops no windows"fi
or this work too

if search --file --set=winroot "/path/win.txt"; then
    echo "windows root found"    set root="${winroot}"    set prefix=    ...
elif search --file --set=linroot "/boot/grub/grub.cfg"; then
    echo "oops no windows but linux"    set root="${linroot}"    set prefix=    
..
else    echo "oops nothing found :("
fi
Here is the manual with all command.
https://www.gnu.org/software/grub/manual/grub/grub.html#search
Hope this help.
RegardsHans



    Le samedi 24 avril 2021 à 02:50:07 UTC+2, Jarek <jarekvxm@jarek.vxm.pl> a 
écrit :  
 
 Hi!

I want to check if specific file (let's say win.txt) exist in root 
directory at ntfs WIndows partition and if does, then boot Windows (or 
better: make it default choice but still display menu and timeout), and 
if not boot Linux (or leave default menu with default Linux and 
timeout). I've seen command test -e file and insmod ntfs, but I don't 
know what next. Does "grub works" like shell scripts? Are entries from 
grub.cfg are just interpreted and executed from top to bottom or is it 
compiled on update?

Jarek



  

reply via email to

[Prev in Thread] Current Thread [Next in Thread]