1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.


Discussion in 'Howtos and FAQs (Moderated)' started by graudeejs, Jan 5, 2009.

  1. graudeejs

    graudeejs Member

    Likes Received:
    DEPRECATED: use gpart(8) instead

    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 :D
    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:

    You'll need (or other media):
    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 :D

    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
    $ gpt create -f ad0
    You don't need to specify full path to device :D

    2) Mount flash to /mnt

    3) Create gpt boot partition
    $ 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)
    $ gpt add -t ufs -s 524288 ad0
    5) To check what have you done
    $ gpt show ad0
    here's example output from one of my [already finished] test setup
    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 (5GB) and /var (512MB) and /tmp (512MB)
    $ 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
    $ gpt add -t swap -s 1048576 ad0
    8) Create home partition with remaining free space
    $ gpt add -t ufs ad0
    9) Format partitions
    $ 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
    /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
    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
    3GB = 6291456 sect
    4GB = 8388608 sect
    5GB = 10485760 sect
    6GB = 12582912 sect
    7GB = 14680064 sect
    8GB = 16777216 sect
    9GB = 18874368 sect

    12GB = 25165824 sect
    14GB = 29360128 sect
    15GB = 31457280 sect
    25GB = 52428800 sect

    tip: 10GB can easily be calculated by adding 0 to 1GB sector count (this works for others as well ;) )

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


    made few inaccuracy fixes

    Important note

    you you're adding gpt on top of geli and and used -s 4096 key, when you created geli, then
    you will have to use these formulas:
    for megabytes:
    sector count = 1024^2/4096*MB_count
    for gigabytes:
    sector count = 1024^3/4096*GB_count

    replace 4096 to value you have used

    if you won't do that, you will get 32GB instead of 6GB partition

    if you want to do new install on gpt, create gpt partitions and fallow this guide:
  2. nsayer

    nsayer New Member

    Likes Received:
    I would put your swap space adjacent to your boot partition. There are some very good reasons to do this:

    1. By putting the swap near the beginning of the disk, it will boost its performance somewhat compared to it being at the end of the disk.

    2. If you ever need to replace the boot partition (for example, if you move to an EFI machine, you'll need an EFI system partition instead), you'd simply delete the boot and swap partitions, make the new boot and then from the remaining space, make a swap partition.
  3. graudeejs

    graudeejs Member

    Likes Received:
    Beginning of the disk is in center, isn't it (inner track/cylinder)? [i'm not sure]

    for data cd/dvd it is, so my guess would be it's also same for HDD
    and if I'm right, and i hope I am, my swap is in outer track/cylinder of HDD
  4. nsayer

    nsayer New Member

    Likes Received:
    Seeks are the costly thing, regardless of whether block 0 is on the inside or outside of the disk. If you put the swap at the end of the disk, then you're setting up a situation where the machine is going to need to fiddle with lots of files from filesystems on the early blocks on the disk, and swap blocks in and out of swap space at the end of the disk. Lots of long seeks. Bad mojo.
  5. trev

    trev New Member

    Likes Received:
    1. The same file?
    2. "they" ?
  6. graudeejs

    graudeejs Member

    Likes Received:
    Thank you for noticing, I fixed my mistake [it was about 2 or 3 am when i wrote this :) ]
    You need to make copy of [B]/boot/pmbr[/B] and [B][color="Red"]/boot/gptboot[/color][/B]
    because [color="Red"][B]they[/B][/color] are not on disks and this was my fallback nr1
  7. trash

    trash New Member

    Likes Received:
    anyone know how to fix corrupt gpt tables when migrating from solaris ?
  8. graudeejs

    graudeejs Member

    Likes Received:
    sorry, i dunno
    but search forum, I remember there was 1 or 2 threads about this problem.
  9. trash

    trash New Member

    Likes Received:
    hi, thanks for the reply, yes ive also added my question to those threads, at least i think ive found all of them - almost asked the entire internet the question now :)
  10. graudeejs

    graudeejs Member

    Likes Received:
    To all looking at this howto.... ;) yup, i saw you bluefish....
    This is abit outdates. on FreeBSD 8 you need to use gpart for makeing gpt partitions... gpt is removed :D