Friday, December 22, 2017

grub2 - Delete all traces of windows from Ubuntu



I used to have a dual boot in one of my hard disk drives - Ubuntu and Windows 7. Then, I added a SSD which is now my main hard disk drive, and I'm using it for Windows 7 completely, keeping Ubuntu in the old HD. I restored the Grub so everything works ok, except for one thing.




Everytime I update the grub, it detects two windows:



Found Windows 7 (loader) on /dev/sda1
Found Windows 7 (loader) on /dev/sdb1


Obviously, I don't want it to detect the Windows on sdb1. Because I no longer use it (I manually deleted the files). What can I do about that without wiping out completely the partition?



I'm not sure what it uses to detect the OS. I'd try a quick reformat of the partitions.




If nothing else works, here is a patch that can be made to /etc/grub.d/30_os-prober that will allow you to specify any partitions you want to skip:



/etc/grub.d/30_os-prober modification



These lines can be added to the file (just past the middle) to skip any partitions that you don't want to show up in the menu. Leaving the string empty will skip nothing.



Add the lines starting with



############## Patch to prevent some partitions being autodetected




through



############## End of patch:



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="sdb1"
# SKIP_THESE_DEVICES="sda1 sdb1 sdb2" example for multiple devices
# SKIP_THESE_DEVICES="" example for no devices

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


After changing this file, you will, of course, need to run sudo update-grub to regenerate the menu. You should be able to see the results from the terminal's output when it says "Found ..." for each entry; you can run it first before the mods, then compare the output to after the mods. You should not see the removed entries.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...