I am having Ubuntu 12.04 minimal installed on my USB pen-drive; which I use on several systems as portable OS.
I was thinking to edit the boot parameters
so that before the main Ubuntu OS is loaded, it shows an option to Boot from Hard Drive
for 5 seconds, and then boots to Ubuntu.
This way i'll be able to have an option to boot to the OS installed on the Hard-Drive, without removing or unplugging my ubuntu USB stick.
How do I edit the boot parameters to achieve this?
This is actually a much more complicated scenario than it would seem at first, due to the annoying tendency that almost all BIOSs have of reordering how they present drives such that the drive you booted from is always the "first" drive, and that is also what some bootloaders (like the Microsoft's) expect (i.e. things won't work correctly if you try to chainload into Windows if it appears that the drive containing Windows is not the "first" as listed by the BIOS). You don't get this problem when booting from CD because CDs are treated separately from hard drives and don't change the order. There is also the fact that there may be more than one internal drive to choose from, so you should be able to select which of them you want to boot from in that case.
To add to this Ubuntu has a change to grub-mkconfig such that the GRUB_TIMEOUT setting in /etc/default/grub is ignored unless another OS is detected (with the idea being that if you don't have another OS, your computer should boot faster by not waiting on the grub menu unless you hold the shift key). The below solution handles all of these problems and I hope has enough comments that it's clear what's being done.
Run
gksudo gedit /boot/grub/custom.cfg
and copy and paste the following into it :Then just save the file and you're done.
When you boot, if there are other drives available to be chainloaded into you will see menu entries for them (and if there aren't, you won't). The default menu entry will remain unchanged, which means that Ubuntu should boot by default and you will have a 5 second timeout before that happens. Since you're editing /boot/grub/custom.cfg rather than /etc/grub.d/40_custom you don't even need to run update-grub.
1.
boot into ubuntu from USB. Open terminal.
2.1 Add entry to boot Hard drive
gksudo gedit /etc/grub.d/40_custom
append below entry. Do not remove any line.
2.2 Change default entry to boot
change
GRUB_DEFAULT=0
toGRUB_DEFAULT=X
hereX
is number of entry to boot minus one. If you want to boot 3rd entry in bootloader thenX
should be2
(grub counts entry fromzero
).Save it.
2.3 Change timeout to boot into default os
change
GRUB_TIMEOUT=30
toGRUB_TIMEOUT=X
hereX
is number of seconds to wait before boot into default os. (I have set it 3 seconds)3.
sudo update-grub
4.
restart and select
Boot From Hard disk