guid partition table
DESCRIPTION
GUID Partition Table. Unified Extensible Firmware Interface (UEFI) GUID Partition Table (GPT) gpart(8) Root On ZFS FreeBSD9 – bsdinstall Soft-Update Journaling (SU+J). Unified Extensible Firmware Interface. BIOS limitations 16-bit processor mode 1MB addressable space UEFI advantages - PowerPoint PPT PresentationTRANSCRIPT
GUID Partition TableGUID Partition Table
• Unified Extensible Firmware Interface (UEFI)
• GUID Partition Table (GPT)
• gpart(8)
• Root On ZFS
• FreeBSD9 – bsdinstall
• Soft-Update Journaling (SU+J)
Com
pu
ter C
en
ter, C
S, N
CTU
2
Unified Extensible Firmware InterfaceUnified Extensible Firmware Interface
BIOS limitations• 16-bit processor mode
• 1MB addressable space
UEFI advantages• UEFI v2.3.1 in April 2011
• Disk device compatibility (GUID Partition Table)
• Processor compatibility (x86, x64, ARM)
Com
pu
ter C
en
ter, C
S, N
CTU
3
GUID Partition Table – (1)GUID Partition Table – (1)
Limitation of MBR partition table• Partition record
active(1) 、 first CHS(3) 、 type(1) 、 last CHS(3) 、 start LBA(4) 、 size(4)
• Maximum capacity (232-1) x 512 bytes ~ 241 bytes = 2TBytes
GPT• Maximum capacity: 8ZBytes (273 bytes)
• Used on some BIOS system
Com
pu
ter C
en
ter, C
S, N
CTU
4
GUID Partition Table – (2)GUID Partition Table – (2)
GPT• LBA 0: Legacy MBR
• LBA 1: GPT Header
• LBA 2~33: Partition Entries 128 partitions
• LBA 34~: Partitions
• LBA -34 ~ -1: Secondary GPT data
Misaligned block• SSD (1K LBA)
• WD (4K sector)
Com
pu
ter C
en
ter, C
S, N
CTU
5
GUID Partition Table – (3)GUID Partition Table – (3)
Legacy MBR (LBA 0)• A single partition of type 0xEE, and of whole disk size (max 2T)
• For OSes which cannot read GPT: unknown partition, no space
• For GPT-aware OSes: check the “protective MBR”
Com
pu
ter C
en
ter, C
S, N
CTU
6
GUID Partition Table – (4)GUID Partition Table – (4)
Partition header table (LBA 1)Offset Length Contents
0 8 bytes Signature ("EFI PART", 45 46 49 20 50 41 52 54)
8 4 bytesRevision (For GPT version 1.0 (through at least UEFI version 2.3.1), the value is 00 00 01 00)
12 4 bytes Header size in little endian (in bytes, usually 5C 00 00 00 meaning 92 bytes)16 4 bytes CRC32 of header (0 to header size), with this field zeroed during calculation20 4 bytes Reserved; must be zero24 8 bytes Current LBA (location of this header copy)32 8 bytes Backup LBA (location of the other header copy)40 8 bytes First usable LBA for partitions (primary partition table last LBA + 1)48 8 bytes Last usable LBA (secondary partition table first LBA - 1)56 16 bytes Disk GUID (also referred as UUID on UNIXes)72 8 bytes Partition entries starting LBA (always 2 in primary copy)80 4 bytes Number of partition entries84 4 bytes Size of a partition entry (usually 128)88 4 bytes CRC32 of partition array92 * Reserved; must be zeroes for the rest of the block (420 bytes for a 512-byte LBA)
Com
pu
ter C
en
ter, C
S, N
CTU
7
GUID Partition Table – (5)GUID Partition Table – (5)
Partition header table (LBA 1)
# dd if=/dev/ada0 bs=512 count=1 skip=1 | hd00000000 45 46 49 20 50 41 52 54 00 00 01 00 5c 00 00 00 |EFI PART....\...|00000010 e6 f0 27 96 00 00 00 00 01 00 00 00 00 00 00 00 |..'.............|00000020 2f 60 38 3a 00 00 00 00 22 00 00 00 00 00 00 00 |/`8:....".......|00000030 0e 60 38 3a 00 00 00 00 7f a3 90 90 46 b4 de 11 |.`8:........F...|00000040 8e b8 00 21 85 12 22 74 02 00 00 00 00 00 00 00 |...!.."t........|00000050 80 00 00 00 80 00 00 00 e0 9d 1a 52 00 00 00 00 |...........R....|00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|*00000200
Com
pu
ter C
en
ter, C
S, N
CTU
8
GUID Partition Table – (6)GUID Partition Table – (6)
Partition entries (LBA 2~33)• 128 bytes for each partition entry
Offset Length Contents
0 16 bytes Partition type GUID
16 16 bytes Unique partition GUID
32 8 bytes First LBA (little-endian)
40 8 bytes Last LBA (inclusive, usually odd)
48 8 bytes Attribute flags (e.g. bit 60 denotes read-only)
56 72 bytes Partition name (36 UTF-16LE code units)
128 Total
Com
pu
ter C
en
ter, C
S, N
CTU
9
GUID Partition Table – (7)GUID Partition Table – (7)
Partition type GUID
freebsd-boot 83BD6B9D-7F41-11DC-BE0B-001560B84F0F
freebsd 516E7CB4-6ECF-11D6-8FF8-00022D09712B
freebsd-swap 516E7CB5-6ECF-11D6-8FF8-00022D09712B
freebsd-ufs 516E7CB6-6ECF-11D6-8FF8-00022D09712B
freebsd-vinum 516E7CB8-6ECF-11D6-8FF8-00022D09712B
freebsd-zfs 516E7CBA-6ECF-11D6-8FF8-00022D09712B
Com
pu
ter C
en
ter, C
S, N
CTU
10
FreeBSD – gpart (1)FreeBSD – gpart (1)
gpart(8)• Control utility for the disk partitioning GEOM class (ad0)
GEOM_PART_MBR (ad0 ad0s1)– GEOM_PART_BSD (ad0s1 ad0s1a)
GEOM_PART_GPT (ad0 ad0p1)
• gpart create -s mbr ad0 gpart add -t freebsd ad0 (ad0 ad0s1) gpart create -s bsd ad0s1
• gpart create -s gpt ad0
• gpart destroy [ -F ] ad0 -F: forced destroying of the partition table
Com
pu
ter C
en
ter, C
S, N
CTU
11
FreeBSD – gpart (2)FreeBSD – gpart (2)
gpart(8)• gpart add -t type [ … ] ad0
type: freebsd-boot, freebsd-swap, freebsd-ufs, freebsd-zfs, freebsd -b start -s size -a alignment: -a 4k for 4K-sector HDD -i index -l label: used on partitioning schemes that support partition labels
• gpart delete –i index ad0
• gpart show [ -l | -r ] [ -p ] ad0 -l: print partition labels instead of partition type -r: show GUID -p: show provider names instead of partition indexes
Com
pu
ter C
en
ter, C
S, N
CTU
12
FreeBSD – gpart (3)FreeBSD – gpart (3)
gpart(8)• gpart bootcode [ -b bootcode ] [ -p partcode -i index ] ad0
-b: embed bootstrap code into the partitioning scheme’s metadata -p: write bootstrap code into a partition Bootstraping for MBR scheme
– /boot/mbr or /boot/boot0 in partition table’s metadata» /boot/mbr searches partition with active attribute
» /boot/boot0 has a boot manager
– /boot/boot in BSD partition table’s metadata
Bootstraping for GPT scheme– /boot/pmbr in the first disk sector (Protective MBR)
» /boot/pmbr searches the freebsd-boot partition
– /boot/gptboot or /boot/gptzfsboot in freebsd-boot partition» /boot/gptboot searches the freebsd-ufs partition to run /boot/loader
» /boot/gptzfsboot searches the freebsd-zfs partition to run /boot/zfsloader
Com
pu
ter C
en
ter, C
S, N
CTU
13
FreeBSD – gpart (4)FreeBSD – gpart (4)
gpart(8)• gpart modify -i index [ -l label ] [ -t type ] ad0
• gpart resize -i index [ -a alignment ] [ -s size ] ad0
• gpart { set | unset } -a attrib -i index ad0 Set "Active" for MBR scheme
– gpart set -a active –i 1 ad0
• gpart { backup | restore } ad0
• gpart recover ad0 GPT-only
• gpart { command … -f x | commit | undo } ad0
Com
pu
ter C
en
ter, C
S, N
CTU
14
Root On ZFS – (1)Root On ZFS – (1)
Root On ZFS• Using MBR disk
UFS /boot FreeBSD-ZFS partition in a FreeBSD MBR slice
– dd if=/mnt2/boot/zfsboot of=/dev/ad0s3 count=1
– dd if=/mnt2/boot/zfsboot of=/dev/ad0s3a skip=1 seek=1024
FreeBSD MBR slice– Fails to boot
• Using GPT disk Disadvantage
– Can’t dual boot using FreeBSD commercial bootcode
– Using GPT-aware grub setup and hybrid GPT/MBR
http://wiki.freebsd.org/RootOnZFS now for 8.x• 9.0 http://www.aisecure.net/2011/05/01/root-on-zfs-freebsd-current/
Com
pu
ter C
en
ter, C
S, N
CTU
15
Root On ZFS – (2)Root On ZFS – (2)
Creating a bootable ZFS Filesystem• Create GPT disk
gpart create -s gpt ad0
• Create the boot, swap and zfs partitions gpart add -s 64k -t freebsd-boot ad0 gpart add -s 4g -t freebsd-swap -l swap0 ad0 gpart add -t freebsd-zfs -l disk0 ad0
• Install the Protected MBR (pmbr) and gptzfsboot loader gpart bootcode -b pmbr -p gptzfsboot -i 1 ad0
• Load ZFS kernel module kldload zfs
• Create ZFS Pool zroot zpool create zroot /dev/gpt/disk0 zpool set bootfs=zroot zroot
Com
pu
ter C
en
ter, C
S, N
CTU
16
Root On ZFS – (3)Root On ZFS – (3)
Installing FreeBSD to the ZFS filesystem• Create ZFS filesystem hierarchy
Com
pu
ter C
en
ter, C
S, N
CTU
17
Root On ZFS – (4)Root On ZFS – (4)
Installing FreeBSD to the ZFS filesystem• Install FreeBSD to zroot
Manually install base, kernel(s), lib32, games, doc, …
• Make /var/empty readonly zfs set readonly=on zroot/var/empty
• Manually configure chroot /etc/rc.conf
– hostname, networks, zfs_enable, sshd, ntpd, …
/boot/loader.conf– zfs_load, vfs.root.mountfrom
root password Time zone …
Com
pu
ter C
en
ter, C
S, N
CTU
18
Root On ZFS – (5)Root On ZFS – (5)
Installing FreeBSD to the ZFS filesystem• Install zpool.cache to the ZFS filesystem
zpool export zroot zpool import –o cachefile=/tmp/zpool.cache zroot Copy /tmp/zpool.cache into zroot/boot/zfs/
Finish install• Create /etc/fstab
swap
• Set mount points for zfs filesystems zfs set mountpoint=blah zroot/blah Alternatively, you can specify these in /etc/fstab
Com
pu
ter C
en
ter, C
S, N
CTU
19
Root On ZFS – (6)Root On ZFS – (6)
gpart show
swapinfo
# gpart show=> 34 83886013 ada0 GPT (40G) 34 128 1 freebsd-boot (64k) 162 4194304 2 freebsd-swap (2.0G) 4194466 79691581 3 freebsd-zfs (38G)# swapinfoDevice 1K-blocks Used Avail Capacity/dev/gpt/swap0 2097152 0 2097152 0%
Com
pu
ter C
en
ter, C
S, N
CTU
20
Root On ZFS – (7)Root On ZFS – (7)
zpool status -v# zpool status -v pool: zroot state: ONLINE scan: none requestedconfig:
NAME STATE READ WRITE CKSUM zroot ONLINE 0 0 0 ada0p3 ONLINE 0 0 0
errors: No known data errors
Com
pu
ter C
en
ter, C
S, N
CTU
21
Root On ZFS – (8)Root On ZFS – (8)
zfs list# zfs listNAME USED AVAIL REFER MOUNTPOINTzroot 657M 36.5G 344M legacyzroot/home 31K 36.5G 31K legacyzroot/tmp 36K 36.5G 36K /tmpzroot/usr 311M 36.5G 311M /usrzroot/usr/ports 95K 36.5G 33K /usr/portszroot/usr/ports/distfiles 31K 36.5G 31K /usr/ports/distfileszroot/usr/ports/packages 31K 36.5G 31K /usr/ports/packageszroot/usr/src 31K 36.5G 31K /usr/srczroot/var 461K 36.5G 126K /varzroot/var/crash 31.5K 36.5G 31.5K /var/crashzroot/var/db 116K 36.5G 85K /var/dbzroot/var/db/pkg 31K 36.5G 31K /var/db/pkgzroot/var/empty 31K 36.5G 31K /var/emptyzroot/var/log 45K 36.5G 45K /var/logzroot/var/mail 31K 36.5G 31K /var/mailzroot/var/run 48.5K 36.5G 48.5K /var/runzroot/var/tmp 32K 36.5G 32K /var/tmp
Com
pu
ter C
en
ter, C
S, N
CTU
22
Root On ZFS – (9)Root On ZFS – (9)
mount
# mountzroot on / (zfs, local, noatime)devfs on /dev (devfs, local, multilabel)zroot/tmp on /tmp (zfs, local, nosuid)zroot/usr on /usr (zfs, local, noatime)zroot/usr/ports on /usr/ports (zfs, local, noatime, nosuid)zroot/usr/ports/distfiles on /usr/ports/distfiles (zfs, local, noatime, noexec, nosuid)zroot/usr/ports/packages on /usr/ports/packages (zfs, local, noatime, noexec, nosuid)zroot/usr/src on /usr/src (zfs, local, noatime, noexec, nosuid)zroot/var on /var (zfs, local, noatime)zroot/var/crash on /var/crash (zfs, local, noatime, noexec, nosuid)zroot/var/db on /var/db (zfs, local, noatime, noexec, nosuid)zroot/var/db/pkg on /var/db/pkg (zfs, local, noatime, nosuid)zroot/var/empty on /var/empty (zfs, local, noatime, noexec, nosuid, read-only)zroot/var/log on /var/log (zfs, local, noatime, noexec, nosuid)zroot/var/mail on /var/mail (zfs, local, noatime, noexec, nosuid)zroot/var/run on /var/run (zfs, local, noatime, noexec, nosuid)zroot/var/tmp on /var/tmp (zfs, local, nosuid)
Com
pu
ter C
en
ter, C
S, N
CTU
23
bsdinstall (FreeBSD 9) – (1)bsdinstall (FreeBSD 9) – (1)
http://www.freebsd.org/doc/handbook/bsdinstall.html
Com
pu
ter C
en
ter, C
S, N
CTU
24
bsdinstall (FreeBSD 9) – (2)bsdinstall (FreeBSD 9) – (2)
Install 、 Shell 、 Live CD
Com
pu
ter C
en
ter, C
S, N
CTU
25
bsdinstall (FreeBSD 9) – (3)bsdinstall (FreeBSD 9) – (3)
Setting hostname
Com
pu
ter C
en
ter, C
S, N
CTU
26
bsdinstall (FreeBSD 9) – (4)bsdinstall (FreeBSD 9) – (4)
Selecting components to install
Com
pu
ter C
en
ter, C
S, N
CTU
27
bsdinstall (FreeBSD 9) – (5)bsdinstall (FreeBSD 9) – (5)
Partitioning methods• Shell – gpart(8) 、 fdisk(8) 、 bsdlabel(8)
Com
pu
ter C
en
ter, C
S, N
CTU
28
bsdinstall (FreeBSD 9) – (6)bsdinstall (FreeBSD 9) – (6)
Guided Partitioning• Select disk
• Replace { ad | da } by ada
• { ad | da }’s are linkedto ada’s
• How to partition the disk Entire Disk Partition – use free space
Com
pu
ter C
en
ter, C
S, N
CTU
29
bsdinstall (FreeBSD 9) – (7)bsdinstall (FreeBSD 9) – (7)
Guided Partitioning result
Com
pu
ter C
en
ter, C
S, N
CTU
30
bsdinstall (FreeBSD 9) – (8)bsdinstall (FreeBSD 9) – (8)
Manual Partitioning
Com
pu
ter C
en
ter, C
S, N
CTU
31
bsdinstall (FreeBSD 9) – (9)bsdinstall (FreeBSD 9) – (9)
Choose a partitioning scheme• GPT 、 MBR
• DON’T use BSD!!!
Com
pu
ter C
en
ter, C
S, N
CTU
32
bsdinstall (FreeBSD 9) – (10)bsdinstall (FreeBSD 9) – (10)
Add partitions• freebsd-boot
FreeBSD boot code. This partition must be first on the disk.
Com
pu
ter C
en
ter, C
S, N
CTU
33
bsdinstall (FreeBSD 9) – (11)bsdinstall (FreeBSD 9) – (11)
Final confirmation
Com
pu
ter C
en
ter, C
S, N
CTU
34
bsdinstall (FreeBSD 9) – (12)bsdinstall (FreeBSD 9) – (12)
Fetching Checksum Verification Extraction
Com
pu
ter C
en
ter, C
S, N
CTU
35
bsdinstall (FreeBSD 9) – (13)bsdinstall (FreeBSD 9) – (13)
Post-installation• root password
• Network interfaces Wired – Static IPv4 / DHCP / Static IPv6 / SLAAC Wireless DNS
• Time Zone
• Services
• Add users
Com
pu
ter C
en
ter, C
S, N
CTU
36
bsdinstall (FreeBSD 9) – (14)bsdinstall (FreeBSD 9) – (14)
Final configuration
Com
pu
ter C
en
ter, C
S, N
CTU
37
Soft Updates Journaling – (1)Soft Updates Journaling – (1)
To maintain filesystem metadata consistency• Synchronous write
• Non-Volatile RAM
• Journaling
• COW
• Soft Updates
Com
pu
ter C
en
ter, C
S, N
CTU
38
Soft Updates Journaling – (2)Soft Updates Journaling – (2)
Ordering constrains• Name in on-disk directory must be deleted
• Deallocate on-disk inode
• Release file’s blocks to free-space bitmap
Soft Updates• Dependency structures
Only inconsistencies• Blocks marked in use that are free
• Inodes marked in use that are free
Com
pu
ter C
en
ter, C
S, N
CTU
39
Soft Updates Journaling – (3)Soft Updates Journaling – (3)
Soft Updates Journaling (SUJ, SU+J)• Only need to journal operations that orphan resources
Increased link count Decreased link count …
• Need a maximum 16Mb .sujournal (a 32Mb file…)
• Recovery steps Scan the journal Modify link counts Free inodes with zero count or unlinked Free unallocated blocks
Com
pu
ter C
en
ter, C
S, N
CTU
40
Soft Updates Journaling – (4)Soft Updates Journaling – (4)
First appeared in 9.0-CURRENT (r207141) in April 2010• Now 9.0-RC3 …
Enable SU+J• newfs –j …
tunefs –j { enable | disable } for SUJ
• Different from gjournal (-J) tunefs –J { enable | disable } for gjournal