LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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
 
LinkBack Search this Thread
Old 07-18-2009, 09:38 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,956
Blog Entries: 1

Rep: Reputation: 81
grub2: Skipping one partition from OS detection


I have this laptop where I have GNU/Linux, Windows and one recovery partition that I haven't removed.

When I run update-grub2, I get the instances of GNU/Linux, memtest, Windows and another for the recovery partition. Is there a way to make os-prober skip one partition?
 
Old 07-19-2009, 02:34 AM   #2
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
http://pwet.fr/man/linux/administrat...me/update_grub
You edit /boot/grub/menu.lst and remove the entry for that partition.
 
Old 07-19-2009, 10:26 AM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,956
Blog Entries: 1

Original Poster
Rep: Reputation: 81
yea, simon, but then if I run update-grub2 it'd be back, wouldn't it?
 
Old 07-20-2009, 01:10 AM   #4
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
Hmmm... looking closer: The old update-grub just added entries for each /boot/vmlinuz-* it saw and did nothing to probe partitions.

The main issue here is lack of documentation:
http://osdir.com/ml/debian-bugs-dist.../msg03754.html

Here is an attempt to rectify this:
http://ubuntuforums.org/showthread.php?t=1195275


You issue is that you want to skip the search for non-linux OSs
On a quick look -

* 10_linux searches for installed linux kernels.
* 30_os-prober searches for other Operating Systems.

So you don't want to run the prober.

However, grub2 uses different paradigms to grub and you should look through that link. eg. to remove an entry, change the permissions of the grub.d file ... I can see how you may create a bash alias which will remove the extraneous entry each time update-grub2 is run.


Is it possible that the bootable flag is set for more than one partition?
 
Old 12-15-2009, 03:24 PM   #5
johanfa
LQ Newbie
 
Registered: Feb 2006
Location: Catalonia
Distribution: Debian testing, Ubuntu
Posts: 2

Rep: Reputation: 1
Hello eantoranz,

If you want to skip one (or some) partition/s (not only recovery or memtest entries), this is a simple easy trick that worked for me.

SIMPLE EASY TRICK: EDIT 3 FILES TO PREVENT SOME PARTITIONS BEING AUTODETECTED BY GRUB2

STEP 1)

Add the variable
GRUB_DONT_ AUTODETECT_PART
to the file
/etc/default/grub

This variable must contain the name of the partitions you don't want to be autodetected.
It's the list of these space-separated names.
The partitions naming is the usual one in linux.
If you are not sure, run:
update-grub
as superuser (root),
i.e. if your distribution is, for example, Ubuntu, run:
sudo update-grub
and take a note of the names (without the /dev/)

Example:
This is my /etc/default/grub:

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.

GRUB_DEFAULT=0
GRUB_TIMEOUT=7
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="noresume quiet splash verbose vga=788"
GRUB_CMDLINE_LINUX=

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
GRUB_GFXMODE=800x600

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entrys
#GRUB_DISABLE_LINUX_RECOVERY="true"

# This variable has been added by me
# It prevents some partitions to be autodetected
GRUB_DONT_AUTODETECT_PART="hda1 hda5"

As you can see, in my case I don't want hda1 and hda5 to be autodetected.



STEP 2)

Apply a little patch to the file /usr/sbin/grub-mkconfig.
(This is the really executed program when you run update-grub)

After the second export command, add another one (more or less, in the line 229) export with this new created variable:
export GRUP_DONT_AUTODETECT_PART

Example:
This is my /usr/sbin/grub-mkconfig:

... ...
# These are optional, user-defined variables.
export GRUB_DEFAULT \
GRUB_HIDDEN_TIMEOUT \
GRUB_HIDDEN_TIMEOUT_QUIET \
GRUB_TIMEOUT \
GRUB_DISTRIBUTOR \
GRUB_CMDLINE_LINUX \
GRUB_CMDLINE_LINUX_DEFAULT \
GRUB_TERMINAL_INPUT \
GRUB_TERMINAL_OUTPUT \
GRUB_SERIAL_COMMAND \
GRUB_DISABLE_LINUX_UUID \
GRUB_DISABLE_LINUX_RECOVERY \
GRUB_GFXMODE \
GRUB_DISABLE_OS_PROBER

# This variable is intended to prevent some partitions to be detected
export GRUB_DONT_AUTODETECT_PART

if test "x${grub_cfg}" != "x"; then
... ...



STEP 3)

And lastly, you must apply 2 little patchs to the file
/etc/grub.d/30_os-prober
Note.- In my package the name begins by 30. It's not mandatory.
This number establishes the execution order (sequence) for all the files (executable files) in the directory.

a) Fisrt patch:

# My patch to prevent some partitions being autodetected
PARTITIONNAME="`echo ${DEVICE} | cut -c 6- 2> /dev/null`"
if [ "`echo ${GRUB_DONT_AUTODETECT_PART} | grep -e ${PARTITIONNAME} 2> /dev/null`" ] ; then
BOOT="banned"
fi
# End of first part of the patch

Example:
Here you can see where it must be placed (in the line 45, more or less):

for OS in ${OSPROBED} ; do
DEVICE="`echo ${OS} | cut -d ':' -f 1`"
LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
BOOT="`echo ${OS} | cut -d ':' -f 4`"

# My patch to prevent some partitions being autodetected
PARTITIONNAME="`echo ${DEVICE} | cut -c 6- 2> /dev/null`"
if [ "`echo ${GRUB_DONT_AUTODETECT_PART} | grep -e ${PARTITIONNAME} 2> /dev/null`" ] ; then
BOOT="banned"
fi
# End of first part of the patch

if [ -z "${LONGNAME}" ] ; then
LONGNAME="${LABEL}"
fi


b) Second patch:

# My patch to prevent some partitions being autodetected: 2n part
banned)
echo " ${DEVICE} has been prevented to be autodetected." >&2
;;
# End of the 2n part of my patch

Example:
Here you can see where it must be placed (in the line 159, more or less, nearly at the end of the file):

EOF
;;
# My patch to prevent some partitions being autodetected: 2n part
banned)
echo " ${DEVICE} has been prevented to be autodetected." >&2
;;
# End of the 2n part of my patch
hurd|*)
echo " ${LONGNAME} is not yet supported by grub-mkconfig." >&2
;;
esac
done



Et voilą!
At this moment you only must run:

update-grub

as superuser (root)


This trick has been applied to the files provided by the package
grub-common 1.97~beta3-1
and checked successfuly on
Debian squeeze (testing)

Regards,

Johan
 
1 members found this post helpful.
Old 12-15-2009, 05:34 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,799

Rep: Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923
Interesting. What about if the package gets updated ?.
 
Old 12-16-2009, 12:59 PM   #7
johanfa
LQ Newbie
 
Registered: Feb 2006
Location: Catalonia
Distribution: Debian testing, Ubuntu
Posts: 2

Rep: Reputation: 1
Hello syg00,

Unfortunately grub2 is under development yet and this trick is only a workaround.

Well, in short, if the package gets updated, you'll have to reedit the updated files if grub2 developers won’t have included this feature yet.

Anyway, reedit the files is not difficult at all (it's only a pain) and it may be worthwhile if:

a) you have installed a distribution that is not well recognized by grub2 (i.e. Mandriva): in this case the straightforward workaround is preventing its autodetection and booting the system by means of a customized entry in the file
/etc/grub.d/40_custom

Example:
This is my /etc/grub.d/40_custom:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "Mandriva Linux release 2010.0 (Official) for x86_64 (on /dev/hda5)" {
insmod ext2
set root=(hd0,5)
linux (hd0,5)/boot/vmlinuz-2.6.31.5-desktop-1mnb
initrd (hd0,5)/boot/initrd-2.6.31.5-desktop-1mnb.img
}

b) you have a partition you don't want to be accessed or booted by users (i.e. Vista recovery partition): in this case the partition only needs to be ignored.

Regards,

Johan
 
Old 12-16-2009, 04:02 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,799

Rep: Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923
The question was meant as a warning to others.
Have you submitted the change upstream ? - seems like a worthwhile addition.
 
Old 04-16-2012, 11:24 AM   #9
justin.perkins
LQ Newbie
 
Registered: Apr 2012
Location: Boston
Distribution: Ubuntu
Posts: 1

Rep: Reputation: Disabled
Quick update. works on natty 11.04

I used this method successfully with 11.04, thanks for this. Just wondered if it was still going to work and when I discovered it did, I figured I'd put a note up (which I looked for but didn't find initially)

*8^)
 
Old 05-24-2012, 01:48 PM   #10
WallyWorld
LQ Newbie
 
Registered: Jan 2011
Posts: 5

Rep: Reputation: 6
Quote:
Originally Posted by johanfa View Post
this is a simple easy trick that worked for me.
SIMPLE EASY TRICK: EDIT 3 FILES TO PREVENT SOME PARTITIONS BEING AUTODETECTED BY GRUB2
Thanks for this, I simplified it down to 5 lines.

So for anyone coming here from Google, as I did, all you need to do is modify your '30_os-prober' file
For me it is located at '/etc/grub.d/30_os-prober'

So open it with a text editor (I used nano)
then go to line 139, which should look like this

Code:
for OS in ${OSPROBED} ; do
  DEVICE="`echo ${OS} | cut -d ':' -f 1`"
  LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
  LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
  BOOT="`echo ${OS} | cut -d ':' -f 4`"
  #### ::: Line 139 ::: ####
  if [ -z "${LONGNAME}" ] ; then
    LONGNAME="${LABEL}"
  fi

then modify it to add the following lines, that are highlighted red.

Code:
for OS in ${OSPROBED} ; do
  DEVICE="`echo ${OS} | cut -d ':' -f 1`"
  LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
  LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
  BOOT="`echo ${OS} | cut -d ':' -f 4`"

  # Patch to prevent some partitions being autodetected
  SKIP_THESE_DEVICES="sda7 sda1"

  PARTITIONNAME="`echo ${DEVICE} | cut -c 6- 2> /dev/null`"
  if [ "`echo ${SKIP_THESE_DEVICES} | grep -e ${PARTITIONNAME} 2> /dev/null`" ] ; then
    continue
  fi
  # End of patch

  if [ -z "${LONGNAME}" ] ; then
    LONGNAME="${LABEL}"
  fi
You can move the line 'SKIP_THESE_DEVICES="sda7 sda1"' to the top of the '30_os-prober' file if you want so you can easily add or remove devices without scrolling down
 
1 members found this post helpful.
Old 05-24-2012, 06:06 PM   #11
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,799

Rep: Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923
Better to generate a patch. Looks like it should also fit on F16 which now also uses grub2.
I am responsible for a netbook that has been booted to Windows recovery twice - this automatically starts a rebuild. Might just apply this ...
 
Old 09-04-2012, 03:16 AM   #12
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I'm aware that the original post is very old Just an update to say thanks and update for Ubuntu 12.04

For Ubuntu 12.04, the line from WallyWorld's patch has changed to 158. Everybody thanks for posting the solutions.

Code:
    152 for OS in ${OSPROBED} ; do
    153   DEVICE="`echo ${OS} | cut -d ':' -f 1`"
    154   LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
    155   LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
    156   BOOT="`echo ${OS} | cut -d ':' -f 4`"
    157 
    158 # WimS
    159 # based on http://www.linuxquestions.org/questions/linux-software-2/grub2-skipping-one-partition-from-os-detection-741100/ post #10
    160 
    161   # Patch to prevent some partitions being autodetected
    162   SKIP_THESE_DEVICES="sdb7 sdb1"
    163 
    164   PARTITIONNAME="`echo ${DEVICE} | cut -c 6- 2> /dev/null`"
    165   if [ "`echo ${SKIP_THESE_DEVICES} | grep -e ${PARTITIONNAME} 2> /dev/null`" ] ; then
    166     continue
    167   fi
    168   # End of patch
    169 
    170 # WimS End
    171 
    172   if [ -z "${LONGNAME}" ] ; then
    173     LONGNAME="${LABEL}"
    174   fi
    175
 
  


Reply

Tags
configuration, grub2


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
altered partition table, Grub2 will not load, how-to chroot? kyrand0047 Linux - General 11 02-25-2011 04:57 PM
skipping dhcp broadcast/network detection xxNEEDHELPxx Linux - Software 1 05-06-2008 07:10 PM
Stuck at Grub2 prompt after deleting Linux partition of dual boot alcorta Linux - Software 3 07-08-2005 11:12 PM
FC2 test 3 mouse skipping a beat, movie skipping also jang Fedora 1 10-28-2004 07:42 PM
Skipping failing HD detection jeanluc_orsai Linux - Hardware 1 04-14-2004 04:02 PM


All times are GMT -5. The time now is 08:40 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration