# Installing dual boot with Linux grub2 and GAG OS selector



## neilms (Oct 9, 2012)

Hello,
I have installed FreeBSD on a netbook. I partitioned my drive so FreeBSD occupies around 114GB and left 120GB unallocated.

I can see that /dev/ada0p2 is mounted under / and is of type ufs.
/dev/ada0p3 is 4GB of swap space.

I am confused as /dev/ada0p1 seems to be a file, but it appears to be in machine code and is unreadable. I do need to know what this is and how my disc is laid out because I need to install grub2 and have no idea where or how to do so. I have downloaded it from the repository using *pkg_add -r grub2* and done no more.

After getting grub2 installed I plan on installing a Linux distribution and if I can dual boot Linux or FreeBSD then my problem is solved. 

However, if grub2 only works for booting Linux I may need to install GAG. The instructions for GAG say that grub must be installed in the 'superblock' and that the program (which is an operating system selector) goes in the MBR. But if /dev/ada0p1 is the MBR, would installing GAG wipe vital FreeBSD data?

In passing, I read in these forums that a single freebsd-swap partition will also work with Linux. Is this true or not?

To summarise this is what I want:
1. To install FreeBSD (done)
2. To install a Linux distribution (not yet done)
3. To simply be able to boot either FreeBSD or Linux, using grub2 and or GAG, if it is needed (not yet done)

I sure could use some help with this.
Thank you


----------



## lbc (Oct 10, 2012)

Hi,



> I am confused as /dev/ada0p1 seems to be a file


/dev/ada0p1 is a device node, a special type of file that represents... well, a device, in this case it represents the forst partition of your hard drive. They're not made to be accessed directly, rather they're used with commands such as mount(8), and configuration files such as fstab(5).



> After getting grub2 installed I plan on installing a Linux distribution and if I can dual boot Linux or FreeBSD then my problem is solved.
> 
> However, if grub2 only works for booting Linux [...]


GRUB 2 is able to boot both Linux and FreeBSD, natively. It can either load the FreeBSD loader(8), or it can directly load the kernel, its modules, set up kernel variables, and start everything, replacing loader(8) functionality altogether.



> But if /dev/ada0p1 is the MBR, would installing GAG wipe vital FreeBSD data?


/dev/ada0p1 is not] your MBR, and it doesn't contain it. /dev/ada0p1 represents a partition of your hard drive ; the MBR is located outside of the partitions (on the first sector of the disk). You might be confusing it with another kind of boot record though, that is stored at the beginning of your /dev/ada0p1 partition, and which is equally important for the boot process to work and start the operating system on that partition.

Any bootloader or boot manager, GRUB, GAG or otherwise, will quite actively manipulate the MBR and partition boot records (at the very least), when you set it up, so it can easily render a system unbootable if you or a Linux installer sets it up unproperly.
I wouldn't go so far as to say it can destroy vital pieces of your FreeBSD installation, but it can leave you unable to use an operating system before you repair everything.

I would suggest that you don't run GRUB from your FreeBSD system, but rather let the installation system of your Linux distribution handle setting it up for you. You probably will still need to change its configuration to load FreeBSD, but you'll be able to boot into Linux with it, and work at doing that from there.




> I read in these forums that a single freebsd-swap partition will also work with Linux. Is this true or not?


Yes, it can, but you'll need to add stuff to the Linux startup scripts, so that the swap partition is initialized every time Linux starts up. Look into the Linux mkswap(8) and swapon(8) programs, and the /etc/rc.local user-modifiable script once you have your distribution installed.


----------



## wblock@ (Oct 10, 2012)

neilms said:
			
		

> To summarise this is what I want:
> 1. To install FreeBSD (done)
> 2. To install a Linux distribution (not yet done)
> 3. To simply be able to boot either FreeBSD or Linux, using grub2 and or GAG, if it is needed (not yet done)



The goal is fine, but the order is backwards.

If you want the extra complications of multibooting (and I'll repeat what I've said elsewhere, VMs are easier, safer, and more convenient), the partition layout is the first concern.  Some boot loaders want a small partition for themselves.  Many cannot handle GPT.

ada0p1 indicates that you used GPT partitioning.  Few multi-boot loaders can deal with that.

So back up a step.  Find out what grub or gag will require for space and type of partitions.  Back up your FreeBSD install and repartition as required.  Then install the multi-boot loader and operating systems.


----------



## neilms (Oct 10, 2012)

1.You are saying grub will work to boot FreeBSD.
2.The Linux distribution does not install grub2. I have installed Backtrack 5.


----------



## neilms (Oct 10, 2012)

wblock@ said:
			
		

> The goal is fine, but the order is backwards.
> 
> If you want the extra complications of multibooting (and I'll repeat what I've said elsewhere, VMs are easier, safer, and more convenient), the partition layout is the first concern.  Some boot loaders want a small partition for themselves.  Many cannot handle GPT.
> 
> ...



I don't think a virtual machine is an option for me as I want to use Backtrack 5. I understand that it does not work properly within a VM. That is why I am going for a dual boot option. I am sure that things never used to be this difficult to set up. I have previously set up FreeBSD 6 and 7 versions to dual boot with Linux and at the time it was all automated. I wonder what has changed.

The first reply says grub2 will boot FreeBSD! But he suggests I don't install it from FreeBSD.


----------



## lbc (Oct 10, 2012)

> 1.You are saying grub will work to boot FreeBSD.


Yes I am. I have a virtual machine which dual boots Linux and FreeBSD, using GRUB 2, on a GPT partitioned disk. GRUB 2 is quite flexible.



> 2.The Linux distribution does not install grub2. I have installed Backtrack 5.


Are you aware that _Backtrack_ is a specialized Linux distribution that is made for IT security work ? I'm not surprised that it isn't being user-friendly in helping you setup GRUB ; last time I looked at Backtrack, it purposely left the network unconfigured, for stealth reasons. A more mainstream distribution will assist you in setting up the bootloader.

Also, I agree with *wblock* that you should consider repartitioning your drive, but not for the same reasons. Both FreeBSD and Linux can run out of a single, large root partition holding everything (kernel in /boot, and bootcode in the partition bootsector). But neither operating systems will require more than a few 10's of gigabytes, and that's a very generous estimation. Since you might be reinstalling operating systems later in time, you would benefit from reserving a large partition dedicated to your user data. You would be able to mount(8) it from both operating systems, and you would be able to reinstall FreeBSD or Linux at will without having to format it.


----------

