LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   Changing Grub Defaults until VMWare (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/changing-grub-defaults-until-vmware-879293/)

kdmorse 05-06-2011 11:51 PM

Changing Grub Defaults until VMWare
 
This is gonna be a strange questions, but here it goes....

Is there any way for Grub to sense if it is running under VMWare or not, and perform different actions based on that detection?

Simple example. If GRUB is booted from the MBR on a a host system, I want it to default to entry #1 (and boot windows 7). If Grub is started inside VMWare (which not surprisingly is running under Windows 7) - I want it to know that under VMWare, it's to start entry #2 - Linux.

I know there are potentially fatal flaws to this design. It comes with the warning of "Don't do this if you value your data". But I've already done it in a play environment, and am looking to streamline it.

All I'm really looking for is a way for GRUB to default to Windows when the hardware boots (but make Linux and option). But when under VMWare, that same grub should default to Linux.

The current result, is that if I don't catch it, grub selects windows 7 by default and attempts to boot the same windows 7 it's running under, and that goes somewhat south in a hurry.

Anyway, just angling for clever ideas....

Thanks

-Ken

T3RM1NVT0R 05-07-2011 12:56 PM

@ Reply
 
Hi there,

Can you please let us know how your host machine is configured i.e. which OS is installed on it, what are the partitions available etc etc.

Also let us know about your virtual machine configuration (Guest Machine) i.e. How you have configured it and from where it is taking grub.cfg/grub.conf file

As of now from what you say I can understand that you have two OS installed on your host machine one is Windows 7 and not sure which is the other one. In your host machine grub has got two entries: default entry is 0 and entry 1 is Windows 7 you want the default entry to be set to 1 so that it automatically start Windows 7.

Now lets come to VMware part, I am bit confused here as to how you are using the host system grub in VMware.

Can you please make the things a bit straight so that all of us can understand as to what you are trying to do.

kdmorse 05-07-2011 02:47 PM

Sorry, the perils of asking questions in the wee hours of the morning may have obscured some information, apparently including the thread title (Should have been 'under vmware' of course), and what I'm really after.

The host hardware is a Thinkpad, nothing special. On this thinkpad two OS's are installed. At the front of the disk is Windows 7. After that is a linux system, Fedora 14. Grub is currently the bootloader stored in the MBR. (I was using windows bootmgr for a while, and while it worked for this, it was problematic). Either can be booted normally, bios -> grub -> one os or the other.

So, two OS's installed side by side. Under Windows 7 is installed VMWare player (I may switch to a different vmware product if I decide another will work better). VMWare player has a guest defined for the physical Linux Fedora 14 listed above. It's defined as raw disk access, there is no VMDK, no separate guest disk - it simply boots the other top level system up as a guest.

In doing so, it uses the same bootloader (grub in the MBR) as the host does when it boots. So the guest powers up, reads the mbr from it's 'virtual' disk, which happens to be mapped directly to the MBR of the physical disk. The same grub config gets loaded. And if you select Linux, the same linux that can be booted natively, now comes up as a guest under windows.

It would be correct to point out that this is slightly(*) dangerous. It's not as dangerous as you might think, as windows on the host will block any writes to any volumes it has mounted, but it's still not terribly sane. On the other hand, it works great, and is remarkably handy.

Now - back to the original dilemma. There is no way to configure grub that I can think of, that doesn't require constant manual selection. The host will boot Windows 7 90% of the time, so Windows 7 is the default. However, this means when bringing up the linux guest, windows 7 is the default (causing windows 7 to try to come up as a guest under itself, when ends badly). So, my main grub needs a generous timeout to allow for guest selection, which slows unattented host boots by the same amount.

Ideally, I would like to rig something so that grub is aware it's being started under vmware, or is somehow started differently under vmware, so that it, for that boot, defaults to linux without intervention. So that when powered up, the system boots to windows 7, and when vmware is started, linux boots - all with no human intervention or timeout interruption required.

It may be a crazy dream, and I'm very close, so I'm angling for clever ideas.

(And yes, there is a very specific reason why I'm heading down this road. If this works out, I will no longer have to carry two laptops with me everywhere I go).

Thanks,

-Ken

T3RM1NVT0R 05-07-2011 03:09 PM

@ Reply
 
Well that make the things a lot clearer.

As I can understand you are using Use Physical Disk option in VMware to allow your VM to get the direct access to the physical disk and from there you are booting another top level OS as guest in VMware.

Well in that case I would say you can go with an increased timeout of say 10 secs (I think that much delay in booting up the host machine is nominal). I am really not sure if there is a way to make grub aware that it is running in VMware (Anyways just a logic here, you run VMs in that way that it looks like you are working on a physical machine then why differentiating here ;-) ). Also using windows boot manager will not work as you are using physical disk grub will be the one that will get loaded in the memory and if you change windows boot manager that will make the changes at top level as well and can mess up with both of your OS.

So I would say be quick enough and change to Fedora when starting VM within 10 secs if you set timeout to 10 :-)


All times are GMT -5. The time now is 10:29 PM.