help-grub
[Top][All Lists]
Advanced

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

Re: Probing for the existence of a device.


From: Jordan Uggla
Subject: Re: Probing for the existence of a device.
Date: Sun, 23 Jun 2013 11:54:33 -0700

On Sat, Jun 22, 2013 at 2:44 PM, João Ricardo Sares Teles de Matos
<address@hidden> wrote:
> I couldn't find a reliable way to do something like this:
>
> if drive_exists_p (hd1); then
>   menuentry_to_chainload_drive (hd1)
> fi
>
> Where the missing piece is the pseudo-command "drive_exists_p", which has a 
> zero return when the device exists.

insmod regexp

function drive_exists_p {

  for drive in *; do
    if [ "$drive" = "$1" ]; then
      return 0;
    fi
  done

  return 1
}

That said, I dislike testing for a hard coded static device name when,
as shown above, we can iterate through all available drives, or as
shown by
Andrey Borzenkov we can search for a device by UUID (of a filesystem
within a partition or other abstraction), either of which will allow
for the possibility that the BIOS will enumerate drives differently at
different times.

>
> The "probe --driver" command sort of does the job, but it prints error 
> messages and causes a "Press any key to continue..." prompt when the device 
> doesn't exist.
>
> The idea is having automatically (dis)appearing menu entries to chainload 
> devices that may be (un)plugged, which is useful in an environment where USB 
> thumb drives are frequently used as boot devices.

Are you looking for a specific drive, or are you wanting entries for
any drive that happens to be plugged in? If the former, I'd recommend
searching by UUID. If the latter, I'd recommend
http://askubuntu.com/questions/141381/ubuntu-in-usb-boot-from-fixed-hdd
.

>
> The test command with -e or -d doesn't work unless the device contains a 
> filesystem that GRUB can read.
>
> Am I missing something, or is this something that can't be done without 
> extending GRUB?
>
> By the way, is this sort of message appropriate for this mailing list?
> I'd hate to be spamming the list with offtopic queries.

This question is definitely appropriate for this mailing list.

-- 
Jordan Uggla (Jordan_U on irc.freenode.net)



reply via email to

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