# Installation of FreeBSD onto a Logical Partition



## Panarchy (Apr 3, 2009)

Hello

I currently have Mac OS X, Windows Vista 64-bit, Windows 7 64-bit, Windows Server 2008 64-bit, Fedora 10 64-bit & Ubuntu 8.10 64-bit installed on within my MBR on my hard-drive.

(Primaries: Mac OS X & Windows 7 64-bit)

I plan on adding Solaris and OpenSolaris (OpenSolaris on logical, was told this is possible from Sun.com LiveChat) as well.

As well as these 8 aforementioned Operating Systems, I wish to install FreeBSD.

After all these operating systems have been installed, I'd still have over 100GB spare for FreeBSD.

Please tell me if there is any way possible to install FreeBSD onto a logical (UFS or ZFS) partition.

Thanks in advance,

Panarchy


----------



## tangram (Apr 3, 2009)

Only on primary partitions.


----------



## Panarchy (Apr 3, 2009)

Oh...

So there's no possible way to get around the aforementioned limitation?


----------



## tangram (Apr 3, 2009)

It's no limitation. The BSD, OSX and I think Solaris work like that.

So you have a few options: get another disk, remove one of your OS that take up a primary partition or use FreeBSD in a virtual machine.


----------



## Panarchy (Apr 5, 2009)

tangram said:
			
		

> It's no limitation. The BSD, OSX and I think Solaris work like that.
> 
> So you have a few options: get another disk, remove one of your OS that take up a primary partition or use FreeBSD in a virtual machine.



It is a limitation.

OpenSolaris doesn't have that limitation, and either does Solaris (as long as one or the other has a primary for the boot-partition)

Please remove the aforementioned limitation.


----------



## Djn (Apr 5, 2009)

Wait, did you just say Solaris/Opensolaris requires a primary boot partition but can have the rest of the file system in a logical partition? That's ... no better than FreeBSD.


----------



## Panarchy (Apr 5, 2009)

Djn said:
			
		

> Wait, did you just say Solaris/Opensolaris requires a primary boot partition but can have the rest of the file system in a logical partition? That's ... no better than FreeBSD.



Ah, okay. Now we're getting somewhere.

Since FreeBSD can use ZFS as it's root partition, and since Solaris's and OpenSolaris's GRUB menu both have the added capability to boot ZFS, would that mean that I can install FreeBSD onto a logical partition, and use the ZFS4GRUB as /Boot?

Or if I were to install FreeBSD onto a primary partition, then install FreeBSD again onto a logical partition, then remove the FreeBSD from the Primary partition, and install Solaris or OpenSolaris there instead, subsequently adding FreeBSD to that GRUB menu...

Would either of the aforementioned methods work?

Panarchy


----------



## Djn (Apr 5, 2009)

Hmm - I was pondering similar things when I wrote that.
I think it might be possible to prod Grub into starting the FreeBSD loader from a logical partition, and if vfs.root.mountfrom is then set to the right device that might actually be all it takes. I'll have to play with it a bit.

The issue with booting the loader from a ZFS partition is that it will want to grab a kernel and possibly some modules, in addition to its config files. I wouldn't bet on it having ZFS support.  Of course, you could make grub load the kernel directly, but that has its own issues, mainly that I'm not sure if grub will let you preload modules or send config strings to the FreeBSD kernel. 

As for the actual install, well - you'll have to bodge it onto there somehow. I'd suggest a FreeBSD live CD, that will give you a few options.
The "cleanest" is probably to compile up a world+kernel somewhere (another computer, possibly inside a virtual machine), mounting /usr/src and /usr/obj from that, setting DESTDIR right, and doing a make installworld installkernel. 
Alternatively, you can dump the entire file system of a working install onto the partition - I recently did something like that with pax, nc, a FIXIT shell from the amd64 install CD, and a small FreeBSD install in virtualbox as the source.
You can also manually do whatever sysinstall does - I'm sure it's easy, but I've never looked at where it extracts from or how.

But now - sleep. I should ideally have been in bed seven hours ago - it's getting annoyingly bright outside. x)


----------



## Panarchy (Apr 5, 2009)

Thanks

That looked/sounded complicated.

So here are my options (to summarise) in order to install FreeBSD successfully onto a Logical Partition, I'd have to do one of the following;

Install FreeBSD onto a primary partition, then install another FreeBSD onto a logical partition, next remove FreeBSD from the Primary partition, then install Solaris or OpenSolaris in its stead. Then [try and] add FreeBSD to its GRUB.
Install Solaris or OpenSolaris onto a Primary Partition. This includes a modified version of GRUB with an added capability which can boot ZFS. Then installing FreeBSD onto a Logical Partition.
Use the convert tool included in Acronis Disk Director (and GParted?) which allows for conversion from Primary to logical and vice-versa.
Mess around with sysinstall, add the capability to install to logical partition
Create a working FreeBSD installation within a Virtual Machine, then 'dump' that virtual machine to the logical partition
I'll try the 1st one 1st, since I've been having a little trouble with Solaris and OpenSolaris...

Wish me luck!

Panarchy

PS: If there are any other ideas on how I could get FreeBSD successfully installed onto a Logical Partition, please post 'em!


----------



## Djn (Apr 5, 2009)

There is one more alternative that's probably easier:
Boot from the amd64 CD, start a Fixit shell, and extract freeBSD onto the logical partition in whatever way and from whatever source sysinstall normally does. 

I'll play a bit with this and post here later.


----------



## Panarchy (Apr 5, 2009)

Sure, though keep in mind that I need to know the exact commands, as I've never done something like this before.

Thanks


----------



## fbsduser (Apr 5, 2009)

Why not move your OSX or Vista to a logical partition and put BSD in the partition left by whichever one of the two you moved around.


----------



## Brandybuck (Apr 5, 2009)

I did this once years ago, but forgot the details. Anyway, you can put /boot on a primary partition, and everything else on a "logical" partition. But you can't do it from the installer, you have to get the system there with other means (buildworld for example).

p.s. You might also need some other stuff on the primary partition, like /sbin, but I can't remember.


----------



## jb_fvwm2 (Apr 5, 2009)

I had (I think) /tmp and /usr in an extended fat32 partition
in 5.0 or 5.1, and panic-reboots often.  I don't know if the panics
were due to inadequate cooling or not.  If your data is valuable I'd
somehow manage to put it on something conventional.  Also, if you
concentrate only on two (osx/linux) (osx/bsd) (linux/bsd) etc, you
have more time to keep each upto speed for usefulness, ports/programs
updated, and more time to backup data.    (Not applicable if you have
a genuine reason to need more)


----------



## Panarchy (Apr 6, 2009)

Well I'll be installing all these operating systems for 3 main reasons.

Learn each operating system to an adequete extent (usable, can do everything I need to)
Benchmark every operating system against eachother (speed)
Benchmark Virtual Machines running on VMware with each OS

:stud

BrandyBuck, could I use the /boot from Solaris?

FBSDuser, I need Windows 7 to have the primary, otherwise I don't have a bootloader for my windows partitions. I couldn't install any version of Windows without having 1 primary boot partition.

Djn: Still waiting for what commands I should use.

Thanks for all antecedent and subsequent replies,

Panarchy


----------



## Djn (Apr 6, 2009)

It's kind of a research project, and I've been slightly busy today - afraid to say so, but you don't get _top_ priority. 
I'll make an attempt to look at it tomorrow, though.


----------



## Panarchy (Apr 6, 2009)

Djn said:
			
		

> It's kind of a research project, and I've been slightly busy today - afraid to say so, but you don't get _top_ priority.
> I'll make an attempt to look at it tomorrow, though.



Awww... I'm not your top priority?

x(

LOL

Okay, well in the meantime, whilst you get your other priorites out of the way I'll go back to working with my Virtual Machines, creating Group Policies and my own Linux distributions...

Good luck (and wish me the same!)

Panarchy

ï¿½e


----------



## jb_fvwm2 (Apr 6, 2009)

for step 2 I'd save time and check the
freebsd-questions list over the last several years.
Maybe even step 3. 
As to step 1, IMHO Freebsd by itself you could spend 24 hours a day
and not even approach learning all you can do with it. (in 2004 there
were maybe 9000 ports, now probably twice that)


----------



## Panarchy (Apr 6, 2009)

As for step 1, as soon as I work out how to use it's APT equivalent, then I'll be well on my way to achieving my goal.


----------



## phoenix (Apr 6, 2009)

Panarchy said:
			
		

> Well I'll be installing all these operating systems for 3 main reasons.
> 
> Learn each operating system to an adequete extent (usable, can do everything I need to)
> Benchmark every operating system against eachother (speed)
> Benchmark Virtual Machines running on VMware with each OS



Unless you install all three OSes into the same location on the disk (ie clean installs for each OS), your benchmarks won't really be valid.  HDs have different performance for the inner parts of the disk, compared to the outer part of the disk.  Seek times and latency are also different.

Using a single disk with multiple partitions for each OS is almost pointless.  You're better off to go with either clean installs for each OS on the same disk, of using multiple identical disks.  Although the latter can also lead to inaccuracies in the benchmark results.


----------



## Brandybuck (Apr 6, 2009)

Panarchy said:
			
		

> BrandyBuck, could I use the /boot from Solaris?



I seriously doubt it. The /boot contains the kernel, modules and other boot stuff. If it was on a filesystem native to both OS's, and there were no name clashes, then I suppose it might work, but that's a lot of assuming.


----------



## Panarchy (Apr 7, 2009)

But the /boot/grub from Solaris can redirect to ZFS...


----------



## Djn (Apr 7, 2009)

Right, I have managed to install FreeBSD to a logical partition using only the 7.1 amd64 livefs CD. All of this was done in a virtualbox, but it should be equally doable on real hardware.
I have *not* tried to boot it. I can't even guarantee that the existing grub will be happy afterwards, though I don't think it will interfere.

*edit:* Right, I've messed up some detail in the partition layout. Oops - let me find out what I did wrong before anyone attempts to duplicate this. And *sigh* - 8 AM is no time to be going to bed ...


*The starting point*
I'm using a 20GB hard disk image.
I installed openSuSE (i386) with a custom partition layout:
One extended partition covering the disk, carved into three logical partitions: 512MB swap, 8GB root file system, and 11.5GB unformatted.






The extended partition is the first (and only) partition on the disk, so it'll be s1 in FreeBSD. If it's on the first ata HD, it's ad0s1 - which is what it was called for me, and what I'll use.

*Fun with fixit*
I only had an amd64 livefs image at hand and couldn't be bothered downloading an i386 one for this - it shouldn't matter.
At the loader menu, press 6 (_Escape to loader prompt_):

```
[b]OK[/b] load geom_part_mbr
[b]OK[/b] boot
```

In sysinstall, choose Fixit, CD/DVD . This will drop you at a shell.

```
[b]Fixit#[/b] geom part list ad0s1 | less
```
This will give you some information on the extended partition and the logical partitions in it. You're interested in the "first" and "last" numbers for the entire partition, and the "length" and "offset" for all the detected logical partitions (which will be under "Providers"). The logical partitions will have names like "ad0s1s1" and "ad0s1s2". (You can read these names as descending into a hierarchy: atadisk0 -> slice 1 -> slice 1 )


If the empty logical partition you want to use is listed here, great. If not, you have to create it; this was the case for me.
The first/last numbers are 512-byte sectors, while the length/offset numbers are in bytes. For me, the numbers looked like this:






*ad0s1*:
First->last (sectors): 63 -> 41913584 
First->last (bytes): 32256 -> 21459755008
Length (calculated) : 21459722752 bytes / 41913521 sectors

*ad0s1s1* (linux swap):
Offset: 32256 bytes
Length: 534610944 bytes
Position (bytes): 32256 -> 534643200

*ad0s1s2* (linux / ):
Offset: 534643200 bytes
Length: 8587192320 bytes
Position (bytes): 534643200 -> 9121835520

The free space is between the end of the last logical partition and the end of the extended partition:
Offset (bytes):  9121835520 (end of previous logical partition)
Length (bytes): 21459755008 - 9121835520 = 12337919488

To create the partition, I use gpart add, which wants all number in blocks: Just dividing by 512 will work.


```
[B]Fixit# [/B]gpart add -b 17816085 -s 24097499 -t freebsd ad0s1
ad0s1s3 added
```


With the logical partition in place, the next step is to use bsdlabels to carve it up a bit. My desired layout looks like this:

```
a: 2GB /
b: 1GB swap
(c: reserved)
d: the rest /usr
```

First, create a new disklabel and look at it:

```
[B]Fixit# [/B]bsdlabel -w ad0s1s3
If you don't like vi:
[B]Fixit# [/B]export EDITOR="ee"
[B]Fixit# [/B]bsdlabel -e ad0s1s3
```






The partition called _a_ covers the entire usable area, so we'll split that up into parts. The length and offset numbers are in 512 byte sectors again. Using the rough numbers from above, we want this:

```
a: 4194304 long, starting at 16 : ends before 4194320
b: 2097152 long, starting at 4194320: ends before 6291472
d: 24097421 - (4194304 + 2097152) = 17805965 long , starting at 6291472
```

Editing the disklabel to fit gives this:




Save and exit - that will write the label.

Now, to format and mount the new partitons, and leave the fixit shell. I'll use softupdates (-S) on /usr but not on / ; it's arguably a conservative choice.

```
[B]Fixit# [/B]newfs /dev/ad0s1s3a
[B]Fixit# [/B]newfs -S /dev/ad0s1s3d
[B]Fixit# [/B]mkdir /dest
[B]Fixit# [/B]mount /dev/ad0s1s3a /dest
[B]Fixit# [/B]mkdir /dest/usr
[B]Fixit# [/B]mount /dev/ad0s1s3d /dest/usr
[B]Fixit# [/B]exit
```
Back in sysinstall, leave the fixit menu, and go to Configure.
Under Options, set _Install Root_ to /dest .
Under distributions, check the ones you want - for now, just base and kernel (and probably man) will do.
This should take you to the media select screen, if not, select Media.
If your network card works, I'd suggest an FTP install - I didn't get a CD install to work, so I suspect the relevant files aren't on the livefs image. 

When that finishes, you have a very sparse FreeBSD install in a logical partition.

*Post-install setup*
I haven't tried to make this boot yet, that's definitely for another evening (the sun is already up here and I need a few hours of sleep).  I'd suggest doing a few things now, though; they seem sensible.

Go back to the Fixit shell, and edit /etc/fstab (with vi or ee, as you prefer); you want something like this:

```
/dev/ad0s1s3a    /      ufs    rw    1  1
/dev/ad0s1s3d    /usr   ufs    rw    2  2
/dev/ad0s1s3b    none   swap   sw    0  0
```

You most likely want to load geom_part_mbr at boot, too. Edit /boot/loader.conf, and add _geom_part_mbr_load="YES"_.

The next step is to set up grub. I think. Assuming that the above can be made to boot.


----------



## plamaiziere (Apr 7, 2009)

Djn said:
			
		

> Right, I have managed to install FreeBSD to a logical partition



Cool! I don't have the time to test this for the moment.

It would be nice to move your post to the Howtos & FAQ section of the forum.


----------



## Djn (Apr 7, 2009)

Maybe when I've gotten it to work.


----------



## Panarchy (Apr 7, 2009)

Djn: This is what I've been waiting for!

*Thanks!*

I can't wait to hear if you can successfully add it to GRUB!

Please keep us informed!

+17

Keep up the good stuff 

Panarchy


----------



## DutchDaemon (Apr 7, 2009)

Regarding requests to 'HOWTO' this: it is still a work in progress, and the outcome is uncertain. To prevent people from blindly following an incomplete HOWTO (we've all done it!) without reading all the way to the end I propose leaving this here and moving it to the HOWTO section on successful completion. I'll leave it up to Djn to define that moment.


----------



## Panarchy (Apr 7, 2009)

Sorry, must've jumped the gun a little... just sooooo EXCITED!

(I'd PM'd him asking to sticky this topic)

Good luck Djn, I'm 'root'ing for ya!

Panarchy


----------



## Djn (Apr 7, 2009)

Hah, thanks - this is vaguely more worthwhile than my _last_ "I wonder if that'll work", which was FreeBSD on an ext2 root. (For the curious, the answer is that it installed fine, but I never managed to make it mount / read+write. Looked doable, though not advisable.) 

I'll get back to it a bit later today.


----------



## Djn (Apr 7, 2009)

Right, it seems the position of the logical partition I'm creating isn't legal. For now, I'll create it with a gpart live CD instead, and rewrite the original post to reflect it.

edit: It seems geom_part_mbr doesn't seem to do what I expected it to. I have three logical partitions inside the extended partition ad0s1 , and they show up as ad0s1s1, ad0s1s1s1, ad0s1s1s2, ad0s1s2s1, and ad0s1s2s2. At least one of them have the right size and type to be the third one, but it can't be used to read it. *sigh*

It's not a _huge_ problem, since ad0s5, ad0s6 and ad0s7 works - but it means I can't use gpart to get the size and type of the logical partitions, nor to create one.


----------



## Djn (Apr 7, 2009)

Temporary status update:
Grub 1 has some odd issue where it doesn't want to recognize an logical, UFS-formatted partition no matter the presence/absence of a disklabel (and yes, I've got the right partition type).

Grub 2 can read it fine, but can only load 32-bit FreeBSD kernels.

I'm not sure if I should try to hack in 64-bit support or just settle for a 32-bit FreeBSD isntall - the latter is, of course, way easier.

(edit: I dropped it here for today - we'll see what I do tomorrow. 32-bit FreeBSD as a proof-of-concept seems likely.)


----------



## Panarchy (Apr 8, 2009)

Djn: Sweet, thanks.

So from what you've described, GRUB2 can only load 32-bit FreeBSD kernels.

Keep hacking away at that, and I'll see what I can do from the GRUB end.

Thanks,

Panarchy


----------



## Panarchy (Apr 8, 2009)

Ah, okay.

Well perhaps we should start reading into other Boot-Loaders?

Perhaps installing the BootLoader of FreeBSD into another OS (Such as Linux, Windows & Solaris) partition.

What are you thoughts?

Any recommendations on standalone boot-loaders?

Thanks in advance,

Panarchy


----------



## Djn (Apr 8, 2009)

The issue is that at some point, something needs to load and start the FreeBSD kernel.
The only alternatives I'm aware of that can do it are GRUB and the FreeBSD loader - and the latter doesn't seem to like logical partitions. It also only reads UFS2, so you'd have to format a primary partition UFS2 and put the loader+kernel on it, and at that point you might as well just install the rest of FreeBSD there as well.

I'll dig up a FreeBSD/x86 CD image and see if I can make that work, though. That'd still be a significant step forward.


----------



## Djn (Apr 8, 2009)

So far, so good:






The downside is that I have to specify the root device at boot (ufs:ad0s7 , in this case), but if I find out how to pass parameters from GRUB that should be fine: It's just a matter of setting vfs.root.mountfrom .

Oh, and a curious virtualbox/FreeBSD bug: I use a PS/2 keyboard but have a USB one plugged in. Inside vbox, the ps/2 one stops working when the kernel has booted.

edit:

```
root (hd0,7)
freebsd /boot/kernel/kernel
freebsd_loadenv /boot/device.hints
set FreeBSD.vfs.root.mountfrom=ufs:ad0s7
boot
```

That, in grub2, works. Now, to set up a reasonable grub.conf.


----------



## Djn (Apr 8, 2009)

I guess it's time to do another step-by-step guide to getting this done:

*Partitions*
I used a gparted live CD to create three logical partitions, for /, /usr, and swap. For the lack of a better option I formatted them fat32 - that also makes it possible to check if you've got the right partition later on (it'll mount with mount_msdosfs, be empty, and have the appropriate size and perhaps label).





*FreeBSD*
I then rebooted into a FreeBSD 7.2-BETA1 livefs CD, and in the fixit shell did this:

```
[B]Fixit# [/B]newfs /dev/ad0s7
[B]Fixit# [/B]newfs -U /dev/ad0s9
[B]Fixit# [/B]mkdir /new
[B]Fixit# [/B]mount /dev/ad0s7 /new
[B]Fixit# [/B]mkdir /new/usr
[B]Fixit# [/B]mount /dev/ad0s9 /new/usr
[B]Fixit# [/B]exit
```

In sysinstall, choose Configure.
In the configure menu, first go to _Options _and change _Install Root_ to /new .
Then go to _Distributions_, and select _base_ and _kernels_ (picking the GENERIC kernel).
Exiting the Distributions selection will bring up the media selection. Pick whatever works for you, but keep in mind that you can't install off a livefs CD. I used FTP.

When that finishes, exit out to the main menu and start the fixit shell again - it'll complain a bit (about linker cache and mounting /bin, I seem to remember), but that's harmless.
At the shell, do this:

```
[B]Fixit# [/B]cd /boot
[B]Fixit# [/B]mv GENERIC kernel
[B]Fixit# [/B]ee /etc/fstab
```
In the fstab, add something like this:

```
/dev/ad0s7    /      ufs   rw     1 1
/dev/ad0s9    /usr   ufs   rw     2 2
/dev/ad0s8    none   swap  sw     0 0
```

Save, exit, exit the fixit shell, and get ready to mess with grub2 - but first, a small fix.

*Partition types*
Going back to the gparted live CD, open a shell, start cfdisk, and change the type of the FreeBSD partitions to A5 - the FreeBSD id.
(This could probably have been done straight after the partitioning step. Oh well.)

*GRUB 2*
To be written - but essentially, "install it and use the commands in the previous post to boot FreeBSD".


----------



## Panarchy (Apr 9, 2009)

Thanks

I know that with 32-bit Windows, up to 3.25GB of RAM is supported.

Is it the same, or is it 4GB for 32-bit FreeBSD?

As I only have 4GB of RAM, so maybe if this is the only way... I'll install 32-bit FreeBSD instead.

Thanks,

Panarchy


----------



## Djn (Apr 9, 2009)

I think a plain 32-bit kernel will have the same problem as windows, though I'm not sure.
You can compile a new kernel with PAE to use all 4 GB, but some drivers have problems with that, and each single process is still limited to seeing a 4GB memory space (minus whatever holes there might be) since they'll keep using 32-bit pointers.


----------



## Panarchy (Apr 9, 2009)

*Oh...*

Darn!

Well is there a way to install the FreeBSD BootLoader into ZFS, Ext3 or NTFS (none of them containing FreeBSD)

As that could save a lot of trouble...


----------



## Djn (Apr 9, 2009)

Essentially? No. It wants UFS2, and it wants a primary partition.
I'm not sure how the project to make FreeBSD boot from ZFS is going - the official way of having the root file system be on ZFS is still to boot from a UFS file system and then mount / from ZFS later on.


----------



## Panarchy (Apr 10, 2009)

Djn said:
			
		

> Essentially? No. It wants UFS2, and it wants a primary partition.
> I'm not sure how the project to make FreeBSD boot from ZFS is going - the official way of having the root file system be on ZFS is still to boot from a UFS file system and then mount / from ZFS later on.



http://wiki.freebsd.org/ZFS

http://wiki.freebsd.org/ZFSOnRoot

Do you know of any 3rd-party boot-loaders that can boot directly to FreeBSD 64-bit?

I have recently been recommended these two; can they do the trick?

http://www2.arnes.si/~fkomar/xosl.org/

http://www.terabyteunlimited.com/bootit-next-generation.htm

Panarchy


----------



## Panarchy (Apr 10, 2009)

Hello

I've just been getting some replies on the GRUB2 development mailing-list.

http://lists.gnu.org/archive/html/grub-devel/2009-04/msg00138.html

Please have a look, and if you don't want to join the mailing list, then please tell me what to write.

Thanks in advance,

Panarchy


----------



## Djn (Apr 10, 2009)

Looks promising enough.
I'm sort of moving to Oslo the next days, so I might be a bit distracted. I'll see what I can get done, though.


----------



## Panarchy (Apr 10, 2009)

Certainly, thanks.

Panarchy


----------



## Panarchy (Apr 13, 2009)

Hello

Check it out: http://lists.gnu.org/archive/html/grub-devel/2009-04/msg00248.html

They've been (phpcoder and Bean... though Bean one the initial race ) working on a patch for GRUB2 that will enable the bootloader to directly call the 64-bit kernel of FreeBSD. It's virtually completed, though features are still being added.



Panarchy


----------



## Djn (Apr 13, 2009)

Mh, I noticed. 
I have just moved ... and managed to forget the HD with the vista install and the virtual machines I've been testing on. I'll go fetch it in a few days (along with the power cable to my second monitor, argh), and polish the howto when I've got it.


----------



## Panarchy (Apr 13, 2009)

Thanks

I'll be looking forward to it.

BTW: I start work today


----------



## Panarchy (Apr 23, 2009)

**bump**


----------



## Djn (Apr 23, 2009)

Busy, busy, busy. x)
I'll take a look tomorrow.

edit: Or not - I have apparently promised two different people to meet & drink beer with them tomorrow. Saturday, then.


----------



## Panarchy (Apr 24, 2009)

Great, thanks.

Hahahaha, well it's Friday here, and I had some drinks with my work-mates.

XD

Sure, Saturday.


----------



## Djn (Apr 26, 2009)

Right, I'm about halfway through writing the sort-of final version of this, but I've got a practical problem: This computer is connected to the internet by a rather dubious temporary hack, and I just can't get sysinstall to work with FTP. Too many layers of NAT, I suspect, or possibly some problem with WinXP ICS.

I'll have to get back to you when I have bought myself a long TP cable.

For the time being, here's the first half:



*Software*
FreeBSD, specifically a liveFS CD. 
A partitioning program that can create logical partitions (e.g. gPartEd)
GRUB 2
Some way to install GRUB 2, I'm using an Ubuntu install [1].

*Outline*

Create the logical partitions
Format, mount, and install FreeBSD to them from the livefs CD
Install GRUB2 (from Linux) [2]
Configure it to boot FreeBSD.

*Step by step*
I'll install Ubuntu and do the partitioning from their liveCD, just to cut down on the number of steps. The details of partitioning and installing a linux are beyond the scope here, so I'll just show the partition layout when it was done:






The next step is to install FreeBSD. I'm using the amd64 7.1 livefs iso, though the i386 version would also be fine.

When sysinstall starts, chose [font="Courier New"]Fixit -> CDROM/DVD[/font]. This drops you at a shell.




Note the [font="Courier New"]ad [/font]devices - they correspond to the partitions in the partition editor screenshot above. ad0s1 is the extended partition, and ad0s5+ are the logical partitions inside it.

In this case, we're interested in ad0s7 (which will be our / partition), ad0s8 (which will be /usr), and ad0s9, which will be swap.

First, we need to format it. I'll do UFS2 with softupdates on both: 
[font="Courier New"]*Fixit#* newfs -U /dev/ad0s7[/font]
[font="Courier New"]*Fixit#* newfs -U /dev/ad0s8[/font]

Next, mount this somewhere. /mnt will do nicely:
[font="Courier New"]*Fixit#* mount /dev/ad0s7 /mnt[/font]
We also have to mount the other partitions in the appropriate subdirectories:
[font="Courier New"]*Fixit#* mkdir /mnt/usr[/font]
[font="Courier New"]*Fixit#* mount /dev/ad0s8 /mnt/usr[/font]


Leave the fixit shell (the exit command, or Ctrl D). Leave the [font="Courier New"]Fixit [/font]menu, and go to [font="Courier New"]Configure[/font]. Select [font="Courier New"]Options[/font], and change Install Root to where you mounted the partition(s), e.g. /mnt.





Work in progress

Leave the Options menu, and go to [font="Courier New"]Distributions[/font]. Pick Base and Kernels (where you want the GENERIC kernel), and leave the distributions menu: This will take you to the media select screen, where you can pick something suitable - I used FTP, since the liveFS CD doesn't contains the neccesary files. 

The details around this are the same as for a normal install,. so I'll just skip to when the installation finishes. There's a few more things we need to do in the fixit shell. I've had some weird problems with starting it again, so I'd suggest leaving sysinstall and rebooting now, starting up from the liveFS CD again, and then starting the fixit shell. If you do, repeat the [font="Courier New"]mount [/font]commands from earlier.

What's left to do is to set the GENERIC kernel as default, and to write a suitable fstab. Assuming the new isntall is mounted at /mnt :
[font="Courier New"]*Fixit#* cd /mnt/boot
*Fixit#* mv GENERIC kernel
*Fixit#* ee /etc/fstab [/font]
With the partitions above, you'd want something like this:


```
/dev/ad0s7     /      ufs    rw    0 0
/dev/ad0s8     /usr   ufs    rw    1 1
/dev/ad0s9     none   swap   sw    0 0
```

Save and exit. Leave the fixit shell, exit sysinstall, reboot.
That's it for the FreeBSD side: What's left is to install grub2 and config it to boot the FreeBSD install (not to mention whatever else you've got installed, but I'll leave that to you.)


*GRUB 2*
I'll be working in Ubuntu 9.04 from here on, since that's what I happen to have in the VM I'm testing this in. You might be able to install GRUB2 on and from FreeBSD. If so, I might come back to that later.

Support for booting 64-bit FreeBSD was only very recently added, so until it makes it into the packages of assorted linux distros, you probably have to compile it yourself.

To do this, I had to install subversion, autoconf, and bison. It might also be smart to deinstall grub, since we'll be installing to some of the same locations as it (and would risk an update to grub overwriting grub2 files).

*#* svn co svn://svn.sv.gnu.org/grub/trunk/grub2
*#* cd grub2
*#* ./autogen.sh
*#* ./configure
*#* make install

To be continued (now that I've finally got myself a decent network connection).



[1] As a variation from the SuSE last time.
[2] I think it's possible to compile it on FreeBSD as well - but one experimental thing at the time.


----------



## Panarchy (Apr 30, 2009)

Thanks, so that's all involved?

Which should I make bigger, /mnt or /mnt/usr?

Would it be at all possible to have both on the same hard-drive?

Could you please include a tutorial on how to compile the GRUB2 patch for FreeBSD 64-bit?

Thanks in advance,

Panarchy

PS: Once again, thanks a heap for all your help!


----------



## Djn (May 2, 2009)

I'm actually not in the same town as my experimental machine ATM, which is inconvenient. But yes, part 2 would be "how to compile and config grub2".

And yes, that's essentially it: Create partitions first, boot a liveFS cd, format and mount the paritions, and install to them.

As for how you do your partitioning, that's one of those religious things I wouldn't dare say anything final about.  Remember that /mnt (or whatever you use) will correspond to / in the installed system, and /mnt/usr to /usr - then dig up the handbook or any of the endless debates here and other places. 

As a starter, remember that /usr will hold all installed ports and all home directories (except for root's), not to mention /usr/ports and /usr/src, so it will typically need to be as big as possible. If you're only using those two, / will need to hold e.g. /var, so it should get a few GB as well.  

And "same HD"? Yes, that's what I did ...
(If you meant "same partition", it's entirely possible to use just one partition. It's not without downsides, but if you need to make the most out of limited space it can be the best option.)


----------



## Panarchy (May 2, 2009)

Thanks, so I can install both onto the same partition, great!

Looking forward to Part2 'How to compile and configure GRUB2 for FreeBSD 64-bit'



Panarchy


----------



## Djn (May 2, 2009)

Both what? I'm still not entirely sure I get what you're asking. 

If you mean directories: Remember that any directory can be mounted from anywhere, split however you want. If you'd like to spread out over 200 partitions, that should be as doable as using just one.


----------



## Panarchy (May 3, 2009)

Both /mnt & /mnt/usr.



Okay, well I think it's committed now, or soon will be.

http://lists.gnu.org/archive/html/grub-devel/2009-05/msg00027.html

Panarchy


----------



## Djn (May 3, 2009)

Ah, good - that saves a patching step.


----------



## Panarchy (May 3, 2009)

Indeed! Well, almost. Still needs this;

Here's how to add support to GRUB2 for the 64-bit FreeBSD kernel;


			
				Felix Zielcke said:
			
		

> Just checkout the source code and then apply the patch with `cd grub2]
> 
> Perhaps amalgamate all the tutorials you've given so far (and the above) into your next post?
> 
> ...


----------



## DutchDaemon (May 3, 2009)

Staff are everywhere, in case you hadn't noticed 

Anyway, we don't usually pin/stickify developing threads (would require clean-up and summarising first), but it has the potential to be turned into a HOWTO and posted in the appropriate forum, of course. I suggest waiting for a definitive outcome, though.


----------



## Panarchy (May 3, 2009)

How about this, we wait till I've tested it?


----------



## Djn (May 3, 2009)

I know it works - I booted it (32bit) last time I tried.
What's missing is a reasonably clear write up of the parts I've said are missing - and that's waiting for me to get it done (I've got some practical issues that need sorting). I'll contact someone when I feel done.


----------



## Panarchy (May 4, 2009)

Certainly, we'll be looking forward to it.

In the meantime, I'll give it a go


----------



## Panarchy (May 11, 2009)

That is, once I've gotten my other OS's to work. Trying to save as many primary as possible, so trying to get ALL my Windows onto logical partitions.

That way I'll have plenty spare for Solaris etc.

So as soon as I can work out how to get this to work, I'll install FreeBSD.

Thanks for all the help.

Panarchy


----------



## jessa_jr (May 18, 2009)

*Problem installing*

Hi DJN

I try to follow your instruction from your first edit.



> Originally Posted by DJN
> FreeBSD
> I then rebooted into a FreeBSD 7.2-BETA1 livefs CD, and in the fixit shell did this:
> Code:
> ...



When itry to do this the mv Generic kernel, it gives me an error message generic kernel cannot be rename.



> In the fstab, add something like this:
> Code:
> /dev/ad0s7    /      ufs   rw     1 1
> /dev/ad0s9    /usr   ufs   rw     2 2
> ...



How will I'm going to do this do I need to press the tab key in the keyboard for spacing?

How will I'm going to boot this if I'm using the easybcd bootmanager?

Hope to hear from you.

Thanks


----------



## Djn (May 18, 2009)

jessa_jr said:
			
		

> Hi DJN
> 
> I try to follow your instruction from your first edit.
> When I try to do this the mv Generic kernel, it gives me an error message generic kernel cannot be rename.



Hmm. You're just trying to rename a directory, nothing very complicated. Are you sure you were in the right directory? Check that it exists there, and that you typed it right (remember, it has to be all-uppercase). 



> How will I'm going to do this do I need to press the tab key in the keyboard for spacing?


It's quite forgiving - use as many spaces or tabs (or both) as you think looks good.



> How will I'm going to boot this if I'm using the easybcd bootmanager?
> 
> Hope to hear from you.
> 
> Thanks



EasyBCD is a tool to make configuring the vista bootmanager easier - and I don't think it can load FreeBSD kernels directly. The easiest might be to configure it to boot grub2 from a file on your windows partition, and then use that to load FreeBSD. It's a bit beyond what I'm doing here, but if I find the time I might look at it.

If you've got a spare primary partition I'd recommend you use that instead, though - it's significantly easier to set up (both the install and the bootloader part).


----------



## jessa_jr (May 18, 2009)

> Originally Posted by DJN
> Hmm. You're just trying to rename a directory, nothing very complicated. Are you sure you were in the right directory? Check that it exists there, and that you typed it right (remember, it has to be all-uppercase).



I don't actually I do even make it all small letters and all caps.  I will try this again this weekend.



> EasyBCD is a tool to make configuring the vista bootmanager easier - and I don't think it can load FreeBSD kernels directly. The easiest might be to configure it to boot grub2 from a file on your windows partition, and then use that to load FreeBSD. It's a bit beyond what I'm doing here, but if I find the time I might look at it.
> 
> If you've got a spare primary partition I'd recommend you use that instead, though - it's significantly easier to set up (both the install and the bootloader part).



But easybcd boot the freebsd when I install it in the primary partition.  But now I don't have a spare primary partition to put the freebsd because I will need to install also the solaris and opensolaris to the primary partition.


----------



## Panarchy (May 18, 2009)

*Grub4dos*



			
				jessa_jr said:
			
		

> I don't actually I do even make it all small letters and all caps.  I will try this again this weekend.
> 
> 
> 
> But easybcd boot the freebsd when I install it in the primary partition.  But now I don't have a spare primary partition to put the freebsd because I will need to install also the solaris and opensolaris to the primary partition.



Grub4DOS should do the trick. (easybcd=neogrub )

Okay?

EDIT: (that's right, I can edit now!)
Djn: Any chance of a summarised tutorial, or would you like me to write one based off of what you've written so far?

PS: Once again, thank you Bean for porting GRUB2 to FreeBSD 64-bit.


----------



## Djn (May 18, 2009)

I've still got a section left (the "configuring grub2"-part), and I think I can put something together when that's done. 
What would be good is if you could test it when I'm done, though - I might have forgotten to write some step down, or assumed something that'll fail for others.

jessa_jr: The reason EasyBCD can load freebsd when it's on a primary partition is that it just lets the FreeBSD bootloader handle it. That won't work when you're using a logical partition, since the FreeBSD loader doesn't support them. (What I'm doing is essentially to replace the FreeBSD loader with GRUB2)


----------



## Panarchy (May 18, 2009)

Certainly, there's no reason I can't test it once you've finished the tutorial.


----------



## jessa_jr (May 19, 2009)

@Panarchy


> Originally Posted by Panarchy
> Grub4DOS should do the trick. (easybcd=neogrub )



How can I do this?  So is this means when you install grub4DOS bootloader to the "root partion"(if im right or where will I install grub4DOS) of the freebsd in the logical drive, I will just call that partition using easybcd manager.

@DJN
I hope you can finished the tutorial so I can also try it.  Just wanna ask where you will install the grub bootloader is that in the "root partition" only not all the partition.  If you can do that I think I can call the freebsd using the easybcd because it support grub.


----------



## Panarchy (May 19, 2009)

You certainly can.

Install Vista/7/Server_2008
Install EasyBCD
Add NeoGRUB entry
Edit menu.lst

Enjoy


----------



## jessa_jr (May 20, 2009)

*grub4dos*

I have vista and easybcd installed already and I know how to edit the menu.lst.  Im just asking how will im going to install grub4dos and in what partition root,usr or swap (I know its in the root partition) but how?  Then I will call that partition using easybcd.


----------



## Panarchy (May 20, 2009)

http://neosmart.net/wiki/display/EBCD/NeoGrub

:stud

No need to download and install GRUB4DOS. EasyBCD includes a version for you


----------



## jessa_jr (May 21, 2009)

*How will I do it*

@Panarchy

I'm very sorry but its not clear for me so did you mean that I dont need to install grub4dos, How will I add freebsd in my menu list, will I "to it to the root partition of the freebsd in the logical partition and use grub instead of freebsd" 

Thanks


----------



## Panarchy (May 21, 2009)

*Not so hard*

Merely install NeoGRUB from within EasyBCD, then edit the menu.lst to add the partititon containing FreeBSD.

chainload


----------



## jessa_jr (May 22, 2009)

*try this tomorrow*

@Panarchy

I will try this tomorrow and I'll give you feedback if I can boo it using easybcd.

Thanks.


----------



## Panarchy (May 22, 2009)

I know it's different to the usual setup, but no need to scare your system!

x(


----------



## Djn (May 22, 2009)

Lovely. I just tried Asus' BIOS update tool in vista 64, which it supposedly supports: In short, it doesn't, and I need to rescue or replace my MB. This might cause some delays.


----------



## Panarchy (May 23, 2009)

*beep**beep**beep**beep*, I mean damn!

That's terrible!!!

Whenever I do BIOS upgrades I always put it on a USB then reboot and do it that way. You may still be able to recover with that method. I think press F2.

Good luck!


----------



## Djn (May 23, 2009)

It is a bit annoying, yeah - good thing I also have a laptop.
I've tried the most obvious recovery things - but it doesn't seem too keen on working. Will try a few things today, or it's downtown to buy a new MB. 

(I'll RMA this one if I do, then use it to build a server or something when I get it back.)


----------



## Panarchy (May 24, 2009)

RMA? Is that warranty?

Excellent 

Keep us informed!


----------



## Djn (May 24, 2009)

RMA. Essentially, I send it in and will most likely get it back after they fix it - if that's not possible, they usually send a new identical one. So yes, warranty. (2 years and 2 months into a 3 year warranty, if I'm not mistaken.)

Anyway, I bought another MB - a P5Q-E. Time will show how it works with FreeBSD (some people have had problems with the sata controllers; some claim it works fine); for now I'm just happy I didn't have to reinstall vista. 

This means I have a working 64-bit OS for my VMs again, so I'll try to finish tomorrow. An annoying segfault bug in grub2 just got fixed in SVN as well, which is a bonus.


----------



## jessa_jr (May 25, 2009)

*@neogrub still dont work after a x times of boot kernel panic*

@Panarchy 

I still dont get it when I install the neogrub in the easybcd and It keep installing in the xp partition not in the root partition of the freebsd?  How will I do it?

After a couple times of reboot I experience kernel panic I cant boot in any os.  This is the second times it happen to me after installing the freebsd in the logical drive.  I cant use also gparted it will just shutdown.  The solution I did in the first is doing a master-slave hd in my other pc box and format using symantec partition manager.  I will try this again because I run out of time yesterday.

Hope you can help me.

Thanks.


----------



## Djn (May 25, 2009)

One issue: If FreeBSD is indeed in a logical partition, it isn't enough to chainload it. You actually have to make grub load and start the FreeBSD kernel for you - so you need a grub that understands BSD-style partitions, UFS, and FreeBSD kernels. I know GRUB2 does (that's why I use it), but I can't talk for neoGRUB.


----------



## jessa_jr (May 26, 2009)

*grub2 installation*

So that means I cannot use the easybcd to load it, if I will install grub2 to the root partition and call the partition using easybcd do you think I can load it.  

How will Im going to install grub2 to load it.


----------



## Djn (May 27, 2009)

If you can install grub2 onto any partition, then yes; that should work.
One option would be to create a small ext3 partition with a linux boot CD, and install grub2 onto that from there - slightly messy, but I would expect it to work.

Alternatively, if you have a linux isntalled already you can do it from there, and to that partition.
There's also the possibility that grub2 might compile and work on freeBSD with an UFS partition, but I honestly don't know. I've been way busy, so I can't promise looking at it _very_ soon ...


----------



## jessa_jr (May 27, 2009)

*ubuntu and fedora installed*

@DJN

I have fedora kde and ubuntu installed on my pc but I dont know what to do, If you can just put me to the right direction maybe you can help me out.

Thanks.


----------



## Panarchy (May 30, 2009)

Oh, you already have the Linux's installed?

Well that makes things much simpler. In fact, I have the same Linux's as you installed.

Simply PATCH the latest GRUB2 with the FreeBSD 64-bit patch, (which I requested, thanks again Bean), then install it within the BootSector of your Linux partition(s).


----------



## fbsduser (Jun 14, 2009)

Neogrub is based on vanilla grub 0.9x hence it won't work for BSD on a logical partition.


----------



## Panarchy (Jun 17, 2009)

*NeoGRUB*

I thought that NeoGRUB was based off of Grub4DOS?

Also, Djn, do you have a working computer now?

I'd really like to see the finished tutorial :stud

Thanks,

Panarchy


----------



## Djn (Jun 18, 2009)

I do, yes - what I've been lacking lately is time and energy. I'll see what I can do.


----------



## jessa_jr (Jun 19, 2009)

*Still cant do it*

@panarchy,

I still cant do it instead I just install it in the primary partition and I have a quad boot machine xp, vista, opensolaris and freebsd using easybcd. I will install ubuntu, fedora, opensure, windows seven and macos this weekend and hope dont messed it.

But if sir DJN can make a good tutorial for us I will try it again to have a running freebsd in the logical partition.

@fbsduser

Thats why I cant make it run using easybcd.  Thanks for the comment.


----------



## Panarchy (Jun 20, 2009)

Can't GRUB2 -> with FreeBSD 64-bit patches -> be installed onto the FreeBSD Logical Partition?

In which case it could be chainloaded through the BCD [EasyBCD], GRUB4DOS, GRUB1, GRUB2 or NeoGRUB, right?

Thanks Djn, really looking forward to a complete tutorial.

Panarchy


----------



## Djn (Jul 24, 2009)

I'll have to dig up the relevant virtualboxes and finish this soon. x)
First, though - I think I'll see if I can build and install grub2 from FreeBSD; that would make things a touch cleaner.


----------



## Panarchy (Jul 24, 2009)

Okay, looking forward to it's completion!

Thanks!


----------



## xelalien (Dec 2, 2009)

How about implementing the steps used in this guide?

First, installing FreeBSD on a primary, then backing up the disk first (for other OS installations), then restore the BSD disk image into a logical drive, then editing the PT (using ptedit), and setting up the bootloader (GRUB4DOS)...

What do you think?


----------



## Panarchy (Dec 6, 2009)

Well for one the GRUB4DOS Bootloader doesn't support ZFS partitions or calling the FreeBSD bootloader.

However, now that a module has been written for GRUB, one can use that instead of the FreeBSD bootloader, which can be easily chainloaded and booted from logical partitions, through your method or Djn's.

On that note, Djn, did you finish the guide?

Regards,

Panarchy


----------



## allanjude@ (Aug 9, 2011)

Djn said:
			
		

> ```
> [B]Fixit# [/B]newfs /dev/ad0s1s3a
> [B]Fixit# [/B]newfs -S /dev/ad0s1s3d
> [B]Fixit# [/B]mkdir /dest
> ...




You'll want to do 
	
	



```
newfs -U /dev/ad0s1s3d
```
 to enable soft-updates, -S is to specify sector size, and will give you an error if you do not provide it the expected size parameter.


----------



## nox@ (Jul 22, 2012)

Djn said:
			
		

> So far, so good:
> [...]
> Oh, and a curious virtualbox/FreeBSD bug: I use a PS/2 keyboard but have a USB one plugged in. Inside vbox, the ps/2 one stops working when the kernel has booted.
> 
> ...



Btw I just found that grub2 won't boot FreeBSD/amd64 9.1 nor head kernels and got a patch for grub 2.00 (or bzr) by one of the grub developers:
http://paste.debian.net/180121/
[Edit: paste expired so I mirrored the patch here: http://people.freebsd.org/~nox/tmp/grub2-paste_180121.patch.  This (or a similar) patch meanwhile also has been committed to grub2 bzr.]

Mailing list thread is here: http://lists.freebsd.org/pipermail/freebsd-stable/2012-July/068924.html

(The sysutils/grub2 port will hopefully be updated soon.)

HTH, 
  Juergen


----------

