View Single Post
  #1   (View Single Post)  
Old 5th January 2009
graudeejs's Avatar
graudeejs graudeejs is offline
Real Name: Aldis Berjoza
ISO Quartermaster
 
Join Date: Jul 2008
Location: Riga, Latvia
Posts: 589
Post [DEPRECATED] FreeBSD [GUID] GPT howto

The next hot thing after 7.1R is GPT
old limit of 4 partitions is finally history
with GUID Partition table you can have up to 128 partitions.
Should i also say, that GPT will easily handle partitions over 2TB
MBR had problems with that

As soon as i heard [thanks to nsayers post]that it's possible to boot FreeBSD from GPT i had to test it

I have encountered some problems that i resolved on my own.
That's why i'm making this howto, so you don't have to spend few hours, just because something went wrong.

OK, here we go:
=================================
Preparing:

You'll need (or other media):
usb-flash
FreeBSD 7.1R DVD or FreeBSD-7.1R fixit cd

Backup data

During process we will delete all data on HDD, so
backup your valuable data and system, if you already have 7.1R on your PC

If you don't you need to upgrade your system to 7.1 [dunno if GPT works with 6.4]
before and after upgrading backup all data

I suggest you use GENERIC kernel, if you won't have right option, you can create system on GPT, but you can't boot it [another my fallback]


Copy necessary data
You need to make copy of /boot/pmbr and /boot/gptboot
because they are not on disks and this was my fallback nr1

You will need these files later.
I will copy them to my usb-flash

Once you have copied these files to some where, where you can get them, reboot in fixit mode [use cd]


Creating GUID partition tables

1) Erase MBR and write GPT table
Code:
$ gpt create -f ad0
You don't need to specify full path to device

2) Mount flash to /mnt

3) Create gpt boot partition
Code:
$ gpt boot -b /mnt/pmbr -g /mnt/gptboot ad0
by default this will create 64K partition, you can change this with -s and reduce to minimum (8K)
value behind argument -s must be size in sectors
1 sector is 512B
I suggest no changing it, who know if in 7.2 size might change
Also don't improvise to much, make sure boot partition is Nr 1 and root partition is Nr 2, otherwise you can't boot at all [another my fallback]


Note that when i say boot partition it doesn't mean /boot, it's different. /boot is in same partition as root

4) Create root partition (i'll make 256MB)
Code:
$ gpt add -t ufs -s 268435456 ad0
5) To check what have you done
Code:
$ gpt show ad0
here's example output from one of my [already finished] test setup
Code:
fixit# gpt show ad0
      start        size  index     content
          0           1            PMBR
          1           1            Pri GPT header
          2          32            Pri GPT table
         34         128      1     GPT part - FreeBSD boot
        162     1048576      2     GPT part - FreeBSD UFS/UFS2
    1048738     2097152      3     GPT part - FreeBSD UFS/UFS2
    3145890     2097152      5     GPT part - FreeBSD UFS/UFS2
    5243042     1048576      6     GPT part - FreeBSD UFS/UFS2
   16777378     6291456      7     GPT part - FreeBSD UFS/UFS2
   23068834   168926701     11     GPT part - FreeBSD UFS/UFS2
  191995535    10485760     10     GPT part - FreeBSD UFS/UFS2
  202401295   109051904      9     GPT part - FreeBSD UFS/UFS2
  311533199     1048576      8     GPT part - FreeBSD swap
  312581775          32            Sec GPT table
  312581807           1            Sec GPT header
in this table might be mistakes [writing by hand sux], later i made better lay-out



Partitions that you already have created are accessible as
/dev/ad0p1 and /dev/ad0p2

6) Create more partitions /usr (4GB) and /var (512MB) and /tmp (512MB)
Code:
$ gpt add -t ufs -s 10485760 ad0
$ gpt add -t ufs -s 1048576 ad0
$ gpt add -t ufs -s 1048576 ad0
7) Create 512MB swap
Code:
$ gpt add -t swap -s 1048576 ad0
8) Create home partition with remaining free space
Code:
$ gpt add -t ufs ad0
9) Format partitions
Code:
$ newfs -nL root /dev/ad0p2
$ newfs -nUL usr /dev/ad0p3
$ newfs -nUL var /dev/ad0p4
$ newfs -nUL tmp /dev/ad0p5
I like labeling partitions, because i don't need to edit /etc/fstab each time something changes
It's also easier to track partitions if you got many of them

10) Mount root and run restore, then mount and restore usr, var and home.

After you're done, if you didn't use labels edit /etc/fstab
remember labels are placed in /dev/ufs/ directory

so for root it would look something like
Code:
/dev/ufs/root     /      ufs      rw    1 1
you need to edit your swap entry in fstab
when you create partition without using -i key, which is used to change partition NR, GPT will start with 1 and increment automatically.

so in this example swap will be /dev/ad0p5
and /home will be /dev/ad0p6

After you're done you can unmount partitions and reboot system.
It should boot with GENERIC.
If not, post here, I can resolve problems... like i did when i had to on my PC

Note also that you don't need to create bsdlabels anymore

TIP: it's also very easy to set up swap on most outer tracks of HDD if you're interested in this look at -b parameter in manual

kernel options [make sure you have this in kernel config
Code:
options         GEOM_PART_GPT           # GUID Partition Tables.
For some reason, when i had all GEOM_PART_* in my kernel config i couldn't boot



common partition size cheat sheet
for megabytes:
sector count = 1024^2/512*MB_count
for gigabytes:
sector count = 1024^3/512*GB_count
==========
8KB = 16 sectors
32KB = 64 sect
64KB = 128 sect
256MB = 524288 sect
512MB = 1048576 sect
1GB = 2097152 sect
2GB = 4194304 sect
5GB = 10485760 sect
10GB = 20971520 sect



If there's anything unclear please ask, i will answer and explain

resources:
man gpt


EDIT:
made few inaccuracy fixes


Original thread
https://forums.freebsd.org/showthread.php?t=1305

Last edited by graudeejs; 19th December 2010 at 07:14 PM.
Reply With Quote