GUID Partition Table

• Unified Extensible Firmware Interface (UEFI) • GUID Partition Table (GPT) • gpart(8) • Root On ZFS • FreeBSD9 – bsdinstall • Soft-Update Journaling (SU+J)

bit processor mode processor bit -

2011 Aprilin v2.3.1UEFI Table) (GUIDPartition compatibility device Disk ARM) x64, (, compatibility Processor 16 space addressable 1MB

• • • • • UEFI UEFI advantages BIOS limitations

  Unified Unified Extensible Firmware Interface

Computer Center, CS, NCTU 2

size(4) 、 start LBA(4) 、

last CHS(3) last 、 ) (1)

73 –

type(1) bytes = 2TBytesbytes

、 41

first CHS(3) first 、 1) x 512 bytes ~ 2 bytesx 512 ~ 1) - 32 active(1) (2

  Maximum capacity: 8ZBytes (2 8ZBytes capacity: Maximum system BIOS onsome Used Partition record Partition capacity Maximum

• • • • GPT Limitation of MBR partition table MBR partitionof Limitation

  GUID Partition GUID Table

Computer Center, CS, NCTU 3

(2)

GPT data GPT 1: Secondary 1: - 34 ~ 34 - 128 partitions128

 WD (4K sector) (4KWD LBA LBA) (1KSSD LBA 0: Legacy MBR Legacy 0:LBA Header GPT LBA 1: Entries Partition LBA 2~33: Partitions LBA 34~:

• • • • • • • Misaligned block Misaligned GPT

  GUID Partition GUID Table

Computer Center, CS, NCTU 4

(3)

aware OSes: check the “protective MBR” “protective the check OSes: aware - A single partition of type 0xEE, and of whole disk size (max 2T) (max size disk whole of and 0xEE, type of partition single A space no partition, unknownGPT: read cannot which OSes For GPT For

• • •

Legacy MBR MBR (LBA 0) Legacy

 GUID Partition GUID Table

Computer Center, CS, NCTU 5

byte LBA) -

meaning meaning 92 bytes)

1)

-

)

5C 005C 00 00

UNIXes

Contents (4) on

– UUID

(in bytes, usually

", 45 46 49 20 50 41 5220 4546 50 54) ", 49 41 zero forpartitions (primary 1) + partition table last LBA little endian

(location thisof header copy) (location theof other header copy)

EFI EFI PART LBA (secondary partition table first LBA LBA ) of header (0 to header size), with this field zeroed during calculation

Size a ofpartition entry (usually 128) ofCRC32 partition array Reserved; must be zeroes forthe rest of the block (420 bytes for a 512 Current LBA LBA First usable LBA Last usable Disk GUID (also referred as Partition(always 2in entries primary startingcopy) LBA Number of partition entries Signature (" version Revision1.0 (through (For at least GPT versionUEFI 2.3.1), the value is 000100 00 Header size in CRC32 Reserved; must be

* bytes

8 bytes 4 bytes 4 bytes 4 bytes 8 bytes 8 bytes 4 bytes 4 bytes 8 bytes 8 bytes 4 bytes 4 bytes 8 bytes

Length 16

Partition header table (LBA (LBA 1) header table Partition

8 0 92 72 80 84 88 40 48 56 16 20 24 32 12  GUID Partition GUID Table Offset

Computer Center, CS, NCTU 6

...| \

(5)

hd – =512 count=1 skip=1 | skip=1 | =512 count=1 bs /ada0

dev

if=/

Partition header table (LBA (LBA 1) header table Partition

dd

 GUID Partition GUID Table * 00000200 00000030 0e 60 38 3a 00 00 00 00 7f a3 90 90 46 b4 de 11 |.`8:...... F...| b4 0e 60 38 3a 00 00 00 00 7f a3 90 00000030 de 11 46 90 00 00 00 00 00 |...!.."t...... |8e b8 00 21 85 12 22 74 02 00 00 00000040 00 00 00 00 |...... R....|1a 52 00 00 80 e0 9d 00 00 80 00 00000050 00 |...... |00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000060 00 # PART.... 00 |EFI 00 00 00 5c 00 01 46 52 00 50 49 54 41 45 20 00000000 00 |..'...... |00 00 00 01 00 00 00 00 00 96 f0 00 e6 00 00000010 27 00000020 2f 60 38 00 00 3a 00 00 00 22 00 00 00 00 00 00 |/`8:...."...... |

Computer Center, CS, NCTU 7

only) -

codeunits)

16LE

-

(6) UTF

Contents

endian) - –

(36 Total GUID (little (inclusive, usually odd) usually(inclusive, Partition name Partition Partition typePartition GUID Unique partition LBA First LastLBA 60 denotesread(e.g.flags bitAttribute

8 bytes8 bytes8 bytes8 Length 72 bytes72 16 bytes16 bytes16

0

32 40 48 56 16 128 128 bytes for each partition entry partition each for bytes 128

Offset •

Partition entries (LBA 2~33) (LBA entries Partition

 GUID Partition GUID Table

Computer Center, CS, NCTU 8

001560B84F0F - 00022D09712B 00022D09712B 00022D09712B 00022D09712B 00022D09712B - - - - - 8FF8 BE0B

8FF8 8FF8 8FF8 8FF8 ------(7)

11D6 11DC 11D6 11D6 11D6 11D6 ------– 7F41 6ECF - 6ECF 6ECF 6ECF 6ECF - - - - -

516E7CB6 516E7CB8 516E7CBA 83BD6B9D 516E7CB4 516E7CB5

ufs vinum boot swap - - - - -

Partition type GUID type Partition

freebsd freebsd freebsd freebsd freebsd  GUID Partition GUID Table

Computer Center, CS, NCTU 9

ad0s1a)

ad0s1)

 ad0s1)

ad0p1) 

 

(1)

ad0s1

ad0

ad0

bsd F ] ad0 ] F s - - mbr gpt t freebsd ad0 t freebsd(ad0 s s - gpart - -

– GEOM_PART_BSD (ad0s1GEOM_PART_BSD –

F: forced destroying of the partition table of the partition destroying forced F: gpart add gpart create - GEOM_PART_MBR (ad0GEOM_PART_MBR (ad0GEOM_PART_GPT      gpart create create gpart create gpart [ destroy gpart Control utility for the GEOM class (ad0) class GEOM partitioning disk the for utility Control

• • • •

gpart(8)

 FreeBSD FreeBSD

Computer Center, CS, NCTU 10

zfs,freebsd -

ufs, freebsd -

swap, freebsdswap, sector HDD -

-

(2) p ] ad0 ] p -

ad0

r ] [ ] r a 4k for 4K [ … ] ad0 [ … - - boot,freebsd - : index l | l i - gpart – type

t : used on partitioning schemes that support partition labelsthat partition on support partitioningschemes used :

-

– start alignment size label index

p: show providerindexes insteadnames partitionp: show of l typepartitioninstead of labelsl:printpartition GUID r: show b s a i - - - - type: freebsd type: - - - -          gpart delete delete gpart [ show gpart gpart add gpart

• • • gpart(8)

 FreeBSD FreeBSD

Computer Center, CS, NCTU 11

] ad0 ]

index

i - boot partition

- zfs partition to run /boot/zfsloader run to partition zfs

- ufs partition to run /boot/loader run to partition ufs - boot partition boot - partcode

p -

] [ ]

(3)

bootcode b - /boot/gptzfsboot searches the freebsdsearchesthe /boot/gptzfsboot /boot/boot0 has a boot manager a boot has/boot/boot0 freebsdsearchesthe /boot/pmbr freebsd thesearches /boot/gptboot /boot/mbr searches partition with active attributeactive searchespartition with /boot/mbr gpart

» » » » » – /boot/boot in partitionBSD table’s metadata /boot/pmbr in the first (Protective MBR) /boot/gptboot or /boot/gptzfsboot in freebsd /boot/mbr /boot/mbr or /boot/boot0 in partition table’s metadata – – – –

b: embed bootstrap code into the partitioning scheme’s metadata intothe partitioningscheme’s b: embed bootstrapcode codep: write bootstrapintoa partition Bootstraping for GPT for GPT scheme Bootstraping - - for scheme MBR Bootstraping     gpart bootcode [ bootcode gpart

• gpart(8)

 FreeBSD FreeBSD

Computer Center, CS, NCTU 12

] ad0 ]

] ad0 ]

size

s - ad0

type ] [ ] t

-

index ] [ ]

i

-

label alignment l i 1 ad0 - – a (4) attrib f x | commit | undo } ad0 } | undo | commit f x - [

- a

[

-

a active - index i index - i

gpart -

– only gpart set - command … command –

GPT Set "Active" for MBR scheme MBR "Active" for Set   gpart { backup | restore } ad0 | restore { backup gpart ad0 recover gpart { gpart gpart modify modify gpart resize gpart } | unset { set gpart

• • • • • • gpart(8)

 FreeBSD FreeBSD

Computer Center, CS, NCTU 13

current/ -

freebsd

-

zfs

-

on - now 8.x now for

(1)

aware aware grub setup and hybrid GPT/MBR -

ZFS partition in a FreeBSD MBR slice in a FreeBSD partitionZFS -

Fails to boot Can’t dual boot using FreeBSD commercial bootcode Using GPT ddif=/mnt2/boot/zfsboot of=/dev/ad0s3 count=1 dd if=/mnt2/boot/zfsboot of=/dev/ad0s3a skip=1 seek=1024 – – – – – Disadvantage UFS /boot UFS FreeBSD MBR sliceFreeBSD http://www.aisecure.net/2011/05/01/root     9.0 Using GPT disk GPT Using Using MBR disk MBR Using

• • • http://wiki.freebsd.org/RootOnZFS Root On ZFS Root On

  Root On ZFS ZFS Root On

Computer Center, CS, NCTU 14

i ad0 1 -

l swap0 ad0 l swap0 -

boot ad0 boot - swap swap - p gptzfsboot l ad0 disk0 - -

zfs - (2) t freebsd -

t freebsd b pmbr - -

– s gpt ad0 s -

s 64k s 4g t freebsd - - - zpoolcreatezroot /dev/gpt/disk0 zroot zpoolset bootfs=zroot gpart bootcode zfs kldload gpart create gpart add gpart add gpart add         Install the Protected MBR (pmbr) and gptzfsboot loader gptzfsbootand (pmbr) MBR Protected the Install module ZFS kernel Load zroot Pool ZFS Create Create GPT disk GPT Create partitions andzfs swap boot, the Create

• • • • • Creating a bootable ZFS FilesystemZFS a bootable Creating

 Root On ZFS ZFS Root On

Computer Center, CS, NCTU 15

(3)

– Create ZFS filesystem hierarchy filesystem ZFS Create

• Installing FreeBSD to the ZFS ZFS filesystemthe FreeBSD to Installing

 Root On ZFS ZFS Root On

Computer Center, CS, NCTU 16

(4)

hostname, hostname, networks, zfs_enable, sshd,ntpd,… zfs_load, vfs.root.mountfrom

– – Time zone Time … chroot /etc/rc.conf /boot/loader.conf root password Manually install base, kernel(s),games, doc,… install base, lib32, Manually zroot/var/empty zfs set readonly=on         Install FreeBSD to zroot to FreeBSD Install readonly /var/empty Make configure Manually

• • • Installing FreeBSD to the ZFS ZFS filesystemthe FreeBSD to Installing

 Root On ZFS ZFS Root On

Computer Center, CS, NCTU 17

(5)

o cachefile=/tmp/zpool.cache zrooto cachefile=/tmp/zpool.cache –

Alternatively, you can specify these in /etc/fstabthese specifycan you Alternatively, swap zroot/blah zfs set mountpoint=blah zpoolexport zroot zpool import intozroot/boot/zfs/ /tmp/zpool.cacheCopy       Create /etc/fstab Create zfs filesystems for points mount Set Install zpool.cache to the ZFS filesystem ZFS the to zpool.cache Install

• • • installFinish Installing FreeBSD to the ZFS ZFS filesystemthe FreeBSD to Installing

  Root On ZFS ZFS Root On

Computer Center, CS, NCTU 18

(38G)

boot (64k) boot (2.0G) swap zfs - - - freebsd freebsd freebsd

blocks Used Avail Avail Used blocks (6) -

/swap0 2097152 0 2097152 0% 2097152 0 2097152 /swap0 show 1 128 34

2 4194304 162

gpt / 4194466 79691581 3 3 79691581 4194466 swapinfo gpart dev # 1K Device Capacity / # (40G) GPT ada0 83886013 34 =>

swapinfo

gpart show gpart

  Root On ZFS ZFS Root On

Computer Center, CS, NCTU 19

ONLINE 0 0 0 0 0 ONLINE (7)

v – -

v ada0p3 ONLINE 0 0 0 0 0 ONLINE ada0p3 - status status zroot CKSUM WRITE READ STATE NAME zroot

: zpool pool: state: ONLINE state: requested none scan: errors data known No errors: # config

zpool status zpool

 Root On ZFS ZFS Root On

Computer Center, CS, NCTU 20

distfiles

pkg /

src db db tmp /ports /ports/ /ports/packages / /crash / / /empty /log /mail /run /

var var var var var var var tmp usr usr usr usr usr var var 31K 36.5G 31K / 31K 36.5G 31K / 32K 36.5G 32K 36K 36.5G 36K / 36K 36.5G 36K / 31K 36.5G 31K / 31K 36.5G 31K

116K 36.5G 85K / 85K 36.5G 116K 657M 36.5G 344M legacy 344M 36.5G 657M / 311M 36.5G 311M / 126K 36.5G 461K

(8)

distfiles

pkg / tmp src db db

/mail 31K 36.5G 31K / 31K 36.5G 31K /mail / 48.5K 36.5G 48.5K /run / /ports/packages 31K 36.5G 31K / 31K 36.5G 31K /ports/packages / / 31.5K 36.5G 31.5K /crash / / / 31K 36.5G 31K /empty / 45K 36.5G 45K /log / 33K 36.5G 95K /ports /ports/

var var var usr usr var var var var var var list tmp usr usr usr / / / / / / / / / / / legacy 31K 36.5G 31K /home / / / /

zfs zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot # MOUNTPOINT REFER AVAIL USED NAME zfs list

 Root On ZFS ZFS Root On

Computer Center, CS, NCTU 21

)

) nosuid , nosuid , only) noexec - , noexec ,

) read ,

) noatime

) ) ) noatime nosuid nosuid ) )

, nosuid ) , nosuid , nosuid nosuid , , , local, local, , , nosuid nosuid noexec nosuid local, , noexec , , zfs , noexec , ( , zfs noexec , noexec noexec , , , noexec

) noatime , noatime noatime noatime noatime distfiles noatime noatime nosuid ) noatime

) )

) noatime , local, local, , , local, local, , , local, local, , local, , /ports/ zfs , local, local, , /ports/packages ( /ports/packages (

(9) zfs ) nosuid noatime zfs noatime zfs

, local, local, , local, , local, , usr local, , zfs multilabel usr , local, local, , pkg – zfs zfs zfs zfs / ( on / on ( zfs db

( / noatime /crash ( /crash ( /empty /ports ( /ports , local, local, , ( /mail tmp , local, local, , local, , src db var ( /log ( /run / / var / var , local, local, , usr zfs var zfs zfs ( var var var ( ( usr var / on

distfiles , local, local, , devfs var / on ( tmp usr / on on / on pkg

/ zfs on / on db db tmp dev / on / on src / on /crash / / / on /empty / on /log / on /mail / on /run / / on /ports /ports/ / on /ports/packages /

var var var var var var var usr usr usr var var on / on tmp usr usr on / ( / on / / / / / / / / / / / / / / /

mount

zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot zroot devfs zroot zroot zroot # mount # zroot  Root On ZFS ZFS Root On

Computer Center, CS, NCTU 22

(1)

– (FreeBSD (FreeBSD 9)

http://www.freebsd.org/doc/handbook/bsdinstall.html

 bsdinstall

Computer Center, CS, NCTU 23

(2)

Live CD Live 、 (FreeBSD (FreeBSD 9)

Shell 、

Install

 bsdinstall

Computer Center, CS, NCTU 24

(3)

(FreeBSD (FreeBSD 9)

Setting hostname Setting

 bsdinstall

Computer Center, CS, NCTU 25

(4)

– (FreeBSD (FreeBSD 9)

Selecting components to install components Selecting

 bsdinstall

Computer Center, CS, NCTU 26

(5)

– bsdlabel(8) 、

(8) 、 (FreeBSD (FreeBSD 9)

gpart(8)

– Shell Shell

• Partitioning methods Partitioning

 bsdinstall

Computer Center, CS, NCTU 27

(6)

use free spaceuse free

(FreeBSD (FreeBSD 9)

Entire Disk Entire Partition   How to partition the disk the partition How to Select disk Select } da { ad | Replace ada by linked are }’s | da { ad ada’s to

• • • • Guided Partitioning

 bsdinstall

Computer Center, CS, NCTU 28

(7)

(FreeBSD (FreeBSD 9)

Guided Partitioning result Guided Partitioning

 bsdinstall

Computer Center, CS, NCTU 29

(8)

(FreeBSD (FreeBSD 9)

Manual Partitioning Manual

 bsdinstall

Computer Center, CS, NCTU 30

(9)

(FreeBSD (FreeBSD 9)

MBR 、 GPT BSD!!! use DON’T

• • Choose a partitioning scheme a partitioningChoose

 bsdinstall

Computer Center, CS, NCTU 31

(10)

(FreeBSD (FreeBSD 9)

boot - FreeBSD boot code. This partition must thedisk. must be first on This partitioncode. bootFreeBSD  freebsd

• Add partitions

 bsdinstall

Computer Center, CS, NCTU 32

(11)

(FreeBSD (FreeBSD 9)

Final confirmation Final

 bsdinstall

Computer Center, CS, NCTU 33

Extraction

 (12)

– Checksum Verification Checksum

(FreeBSD (FreeBSD 9)

Fetching

 bsdinstall

Computer Center, CS, NCTU 34

(13)

Static IPv4 / DHCP SLAAC IPv6 /DHCP IPv4 // Static Static

(FreeBSD (FreeBSD 9)

Wired Wireless DNS installation    - Time Zone Time Services users Add root password root interfaces Network

• • • • • Post

 bsdinstall

Computer Center, CS, NCTU 35

(14)

(FreeBSD (FreeBSD 9)

Final configuration Final

 bsdinstall

Computer Center, CS, NCTU 36

(1)

Volatile RAM Volatile - Synchronous write Synchronous Non Journaling COW Updates Soft

• • • • • To maintain filesystem metadata consistency metadata filesystem To maintain

 Soft Soft UpdatesJournaling

Computer Center, CS, NCTU 37

(2)

space bitmap space -

disk inode disk - disk directory must be deleted be must directory disk -

Dependency structures Dependency freeare that use in marked Blocks free are that use in marked Inodes Name in on in Name on Deallocate freeto blocks file’s Release

• • • • • • Only inconsistencies Soft Updates Soft Ordering constrainsOrdering

   Soft Soft UpdatesJournaling

Computer Center, CS, NCTU 38

(3)

Scan the journal the Scan linkcounts Modify countor with inodes unlinkedFreezero blocksunallocatedFree Increased link count link Increased count link Decreased … 32Mb file…)(a .sujournal         Recovery steps Recovery Only need to journal operations that orphan resources orphan that operations journal to need Only 16Mb maximum a Need

• • • Soft Updates Journaling (SUJ, (SUJ, SU+J) Updates JournalingSoft

 Soft Soft UpdatesJournaling

Computer Center, CS, NCTU 39

(4)

J) - CURRENT 2010 April (r207141)in CURRENT -

J { enable | for disablegjournalJ { enable } | j { enable | disable } for SUJ } | disable j { enable – – RC3 … RC3 - j … j – tunefs tunefs   Now9.0 newfs ( gjournal from Different

• • •

Enable SU+J Enable First appeared in 9.0 in Firstappeared

  Soft Soft UpdatesJournaling

Computer Center, CS, NCTU 40