Author Topic: [ SOLVED ] Grub Question  (Read 1522 times)

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
[ SOLVED ] Grub Question
« on: July 20, 2010, 02:09:23 PM »
When Grub is run from command line, it has a list of commands available which are useful when dealing with some devices.

Is there a method where the output of some of those commands could be exported to a file in (for instance) /home/<user>/documents.

Forget about copy/paste or whatever.
I want to export the info from within a script.

Any information gratefully received.

Thanks.

regards.
« Last Edit: March 23, 2011, 07:43:41 AM by Just19 »

Offline kjpetrie

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 4004
Re: Grub Question
« Reply #1 on: July 21, 2010, 03:19:41 AM »
Do you mean you want to write a script to automate the loading of GRUB and capture all the output in a file so you have a log to inspect if something goes wrong? If so, you could launch GRUB as "grub > /home/<user>/documents/grub.log". However, then you won't get any prompt from GRUB as that will also go to the file.

If you still need the prompt so your script can also read the response you can either get it to tail the file or duplicate the output into the file. There are lots of options and the bash man page might be the place to read up on them.

Hope that helps.
-----------
KJP
-----------------------------------------------------------
PClos64 RC1 on Intel D945GCLF2 motherboard (Atom 330), 2GB DDR2 RAM, Maxtor STM325031, HL-DT-ST DVDRAM GSA-H42N, Amilo LSL 3220T monitor. Also Acer 5810TG (with custom kernel) and Asus eeePC 2G surf

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Grub Question
« Reply #2 on: July 21, 2010, 06:32:11 AM »
Thank you  .....  I was just coming back to say I had found a different means of doing what I needed.
It seems to be working OK, so I will leave this for now.

Next time I may try what you outlined above.
It should work for what I wanted .....  to capture the output from a couple of Grub commands in a file.

Thanks again.

regards.
« Last Edit: July 21, 2010, 06:34:01 AM by JohnBoy »

Offline barjac

  • New Friend
  • *
  • Posts: 1
Re: [RESOLVED] Grub Question
« Reply #3 on: August 10, 2010, 06:00:22 AM »
Code: [Select]
# grub | tee <path_to_log_file>Screen output is unaffected and you get your log. (The log does have a scattering of control codes in it but the plain text is OK)
HTH
« Last Edit: August 10, 2010, 06:03:44 AM by barjac »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: [Revisited] Grub Question
« Reply #4 on: March 13, 2011, 07:35:25 AM »
I would like to revisit this thread as I have an idea I would like to implement in a script file.

I wish to use Grub to locate some Grub files on all partitions in a system.
The advantage is that Grub will report the partition number that holds the specified file, whether that partition is presently mounted or not.

The idea is that rather than mounting each and every one of the partitions and then checking for the presence of the file, Grub could be used to do the search, not needing all the partitions to be mounted.

With Grub launched, passing the find command to it as below

Code: [Select]
grub> find /boot/grub/stage1
 (hd0,5)
 (hd2,0)
 (hd2,1)

grub>

returns the location of all the partitions with the specified path/file present. In the case above (hd2,n) are not mounted.

I then wish to be able to use those locations for other purposes in the script .....  so it would be great if the answer to the find command could be assigned to a variable.

None of the rest of the Grub output is of interest.

I have been playing about with different ideas but have no concrete results.

Any help appreciated.  Thanks.

I have used the idea posted by barjac to tee the output to a log file, successfully.
I would of course much prefer if only the required info was logged.
Also there appears to be something odd about the format of the file.
Below is what the file contains ......

Code: [Select]
[?1049h(B[?7h[?1h=GNU GRUB  version 0.97  (640K lower / 3072K upper memory)
 [ Minimal BASH-like line editing is supported.  For the first word, TABlists possible command completions.  Anywhere else TAB lists the possiblecompletions of a device/filename. ]
grub> find /boot/grub/stage1
 (hd0,5)
 (hd2,0)
 (hd2,1)
grub> quit[?1049l
[?1l>[?1049l
[?1l>
« Last Edit: March 13, 2011, 07:40:03 AM by Just19 »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: [Revisited] Grub Question
« Reply #5 on: March 23, 2011, 04:01:07 AM »
Regarding the format of the output file - as above - is there some method of changing the format?

The file does not appear to be searchable as created.


regards.

Offline AS

  • Hero Member
  • *****
  • Posts: 4111
  • Have a nice ... night!
Re: [Revisited] Grub Question
« Reply #6 on: March 23, 2011, 04:22:04 AM »
may be running grub --batch,
should avoid all the garbage (that really are escape sequence related to terminfo).

AS

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: [Revisited] Grub Question
« Reply #7 on: March 23, 2011, 05:23:26 AM »
may be running grub --batch,
should avoid all the garbage (that really are escape sequence related to terminfo).

AS

I will have a look at that again ....  I thought that using that option prevented all output, not just the 'garbage'.

Thanks.


EDIT
            Yes indeed it does what I require.

Thanks again for the push in the right direction  ;)
« Last Edit: March 23, 2011, 05:40:20 AM by Just19 »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: [Revisited] Grub Question
« Reply #8 on: March 23, 2011, 07:43:02 AM »
To finalise this thread ....

Code: [Select]
#!/bin/bash

#  Find and print the location of each Grub stage1 file

grub --batch << EOT | tee ~/grub.log
find /boot/grub/stage1
quit
EOT

Parts=$(cat ~/grub.log | grep "(hd")

echo "Partitions found with Grub" $Parts

exit 0
« Last Edit: March 23, 2011, 07:45:18 AM by Just19 »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: [ SOLVED ] Grub Question
« Reply #9 on: March 23, 2011, 08:32:42 AM »
Lastly, while on the subject of Grub finding files .......  it does not appear to find files that are on FAT32 partitions.

I found this odd so wanted to ask anyone reading if it behaves in a similar fashion on their PC.

regards.

Offline AS

  • Hero Member
  • *****
  • Posts: 4111
  • Have a nice ... night!
Re: [ SOLVED ] Grub Question
« Reply #10 on: March 23, 2011, 09:32:55 AM »
Lastly, while on the subject of Grub finding files .......  it does not appear to find files that are on FAT32 partitions.

I found this odd so wanted to ask anyone reading if it behaves in a similar fashion on their PC.

regards.

I have to confirm, tryed on a HD partition and on a USB flash.  ???  Oddly enough docs says FAT32 is supported. (FAT16 appear to work).  ???

AS

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: [ SOLVED ] Grub Question
« Reply #11 on: March 23, 2011, 09:46:11 AM »
Thanks AS ......  thought something was gone very weird here  ::)