# Advanced partitioning help needed



## neilms (Jan 23, 2013)

I have a 232gb hard disc and want to partition it like this:
FreeBSD - 132gb
Linux Backtrack 5 - 100gb

As simple as that.
However I have tried using the FreeBSD installer to do this but cannot figure it out
It seems to demand all the disc. I have tried a debian installer too and that is the same. Is it even possible to do this with these tools? 
I don't want any answers where people tell me to use virtualbox etc. I want to achieve the above partition scheme.
How can it be done?


----------



## mlsemon (Jan 24, 2013)

Try harder.  Don't let the FreeBSD installer auto-partition the disk.  I mean, you can let it do so but only as a guide.  FreeBSD likes that tiny boot partition of type freebsd-boot, and it's good at calculating swap size.  However, if it thinks that your / partition should be 230 GB, then delete it and make the / partition 130 GB.

Your Linux may have a utility shell on the installer disk.  Some, like Debian's install disk, have a shell environment that is hard to reach, and it isn't that great once you get there.  Others, like Slackware, boot you right to the shell and act like a live CD.  I don't know what your install disk does.

LILO can boot both Linux and FreeBSD.  GRUB is *supposed* to boot both Linux and FreeBSD, but I didn't fight hard enough through the rather incomplete and frustrating GRUB documentation to actually do it.

I don't know whether to install FreeBSD first or last.  [I install FreeBSD first.]  I do know that if you end up using GPT partitions, gpart on FreeBSD makes a better partition table than does Linux, and Linux likes the partitions just as much as if you used some gdisk/gptfdisk/whatever tool on Linux.  If you go with MBR partitions, the cfdisk tool makes more coherent partitions for Linux than does fdisk.  Use a GPT partition if you can, though: FreeBSD seems to hate the Linux version of MBR extended partitions and is fickle to change them, and Linux hates things like nested BSD disklabels and won't read some of them.


----------



## J65nko (Jan 24, 2013)

You could try GParted.

Besides FreeBSD I also use OpenBSD a lot and prefer the OpenBSD fdisk to create partitions for Linux as well as for FreeBSD.

Re: partition types


```
[cmd=#]fdisk wd0[/cmd]
Disk: wd0       geometry: 10337/240/63 [156301488 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: A6      0   1   1 -   4161   4  51 [          63:    62914560 ] OpenBSD     
*1: 83   4161   4  52 -   8322   8  39 [    62914623:    62914560 ] Linux files*
 2: 83   8322   8  40 -  10125  34  17 [   125829183:    27262976 ] Linux files*
 3: 82  10125  34  18 -  10337  95  63 [   153092159:     3209329 ] Linux swap
```

So in your case you would need a FreeBSD MBR partition with id A5 instead of the OpenBSD A6 identifier.

For the Linux part one single *83* partition for the Linux "/"  and a *82* partition for Linux swap would do.

If you want to use FreeBSD, boot the install disk and break out to the shell or live CD.
and create those partitions manually.

The preferred way since FreeBSD 9.0 is to use gpart(8) That man page has the following example to use the MBR style of partitioning;


```
Create an MBR scheme on ada0, then create a 30GB-sized FreeBSD slice,
     mark it active and install the boot0 boot manager:

	   /sbin/gpart create -s MBR ada0
	   /sbin/gpart add -t freebsd -s 30G ada0
	   /sbin/gpart set -a active -i 1 ada0
	   /sbin/gpart bootcode -b /boot/boot0 ada0

     Now create a BSD scheme (BSD label) with space for up to 20 partitions:

	   /sbin/gpart create -s BSD -n 20 ada0s1

     Create a 1GB-sized UFS partition and a 4GB-sized swap partition:

	   /sbin/gpart add -t freebsd-ufs -s 1G ada0s1
	   /sbin/gpart add -t freebsd-swap -s 4G ada0s1

     Install bootstrap code for the BSD label:

	   /sbin/gpart bootcode -b /boot/boot ada0s1
```


----------



## wblock@ (Jan 24, 2013)

Some basic questions affect the choice of tool.  MBR or GPT is the most basic.  GPT is far superior, easier to set up and manage.  MBR is only needed if the disk is to be shared with another operating system.  Linux should be able to deal with GPT.

Another question is whether the disk uses 4K blocks.  If it does, fdisk(8) and bsdlabel(8) cannot align partitions to even 4K blocks, so they are out.

Disk Setup On FreeBSD shows example setups for both GPT and MBR.  If you set up all the partitions first and then reboot, bsdinstall(8) will see them and should be able to use them.


----------



## J65nko (Jan 24, 2013)

*Creating Linux MBR partitions with gpart*

This is a FreeBSD disk with 2 FreeBSD MBR partitions/slices:


```
[cmd=#]gpart show ada0[/cmd]
=>       63  240121665  ada0  MBR  (114G)
         63         63        - free -  (31k)
        126    8388513     1  freebsd  [active]  (4G)
    8388639         63        - free -  (31k)
    8388702   41942943     2  freebsd  (20G)
   50331645  189790083        - free -  (90G)
```

So I still have 90 GB left to create a Linux data and swap partition:


```
[cmd=#]gpart add -t linux-data -a 4k -s 40g ada0[/cmd]
ada0s3 added
[cmd=#]gpart add -t linux-swap -a 4k -s 1g ada0[/cmd]
ada0s4 added
[cmd=#]gpart show ada0[/cmd]
=>       63  240121665  ada0  MBR  (114G)
         63         63        - free -  (31k)
        126    8388513     1  freebsd  [active]  (4G)
    8388639         63        - free -  (31k)
    8388702   41942943     2  freebsd  (20G)
   50331645         63        - free -  (31k)
   50331708   83886012     3  linux-data  (40G)
  134217720    2097144     4  linux-swap  (1G)
  136314864  103806864        - free -  (49G)
```

The output of the depreciatedfdisk showing the two Linux partitions:

```
The data for partition 3 is:
sysid 131 (0x83),(Linux native)
    start 50331708, size 83886012 (40959 Meg), flag 0
        beg: cyl 1023/ head 255/ sector 63;
        end: cyl 1023/ head 255/ sector 63
The data for partition 4 is:
sysid 130 (0x82),(Linux swap or Solaris x86)
    start 134217720, size 2097144 (1023 Meg), flag 0
        beg: cyl 1023/ head 255/ sector 63;
        end: cyl 1023/ head 255/ sector 63
```


----------



## wblock@ (Jan 24, 2013)

J65nko said:
			
		

> This is a FreeBSD disk with 2 FreeBSD MBR partitions/slices:
> 
> 
> ```
> ...



The Linux slices are not 4K aligned.  Although gpart(8) was told to align them, it has to go through the kernel, and the kernel says MBR partitions are CHS aligned.  In practical terms, an MBR slice will end up as if -a63 was used with gpart(8).  That is part of the MBR standard, and FreeBSD sticks to it even when it would be easier for the user if it did not.  Please, please, use GPT.


----------

