]> CyberLeo.Net >> Repos - FreeBSD/releng/9.3.git/blob - sbin/geom/class/part/gpart.8
Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.
[FreeBSD/releng/9.3.git] / sbin / geom / class / part / gpart.8
1 .\" Copyright (c) 2007, 2008 Marcel Moolenaar
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd April 2, 2014
28 .Dt GPART 8
29 .Os
30 .Sh NAME
31 .Nm gpart
32 .Nd "control utility for the disk partitioning GEOM class"
33 .Sh SYNOPSIS
34 .\" ==== ADD ====
35 .Nm
36 .Cm add
37 .Fl t Ar type
38 .Op Fl a Ar alignment
39 .Op Fl b Ar start
40 .Op Fl s Ar size
41 .Op Fl i Ar index
42 .Op Fl l Ar label
43 .Op Fl f Ar flags
44 .Ar geom
45 .\" ==== BACKUP ====
46 .Nm
47 .Cm backup
48 .Ar geom
49 .\" ==== BOOTCODE ====
50 .Nm
51 .Cm bootcode
52 .Op Fl b Ar bootcode
53 .Op Fl p Ar partcode Fl i Ar index
54 .Op Fl f Ar flags
55 .Ar geom
56 .\" ==== COMMIT ====
57 .Nm
58 .Cm commit
59 .Ar geom
60 .\" ==== CREATE ====
61 .Nm
62 .Cm create
63 .Fl s Ar scheme
64 .Op Fl n Ar entries
65 .Op Fl f Ar flags
66 .Ar provider
67 .\" ==== DELETE ====
68 .Nm
69 .Cm delete
70 .Fl i Ar index
71 .Op Fl f Ar flags
72 .Ar geom
73 .\" ==== DESTROY ====
74 .Nm
75 .Cm destroy
76 .Op Fl F
77 .Op Fl f Ar flags
78 .Ar geom
79 .\" ==== MODIFY ====
80 .Nm
81 .Cm modify
82 .Fl i Ar index
83 .Op Fl l Ar label
84 .Op Fl t Ar type
85 .Op Fl f Ar flags
86 .Ar geom
87 .\" ==== RECOVER ====
88 .Nm
89 .Cm recover
90 .Op Fl f Ar flags
91 .Ar geom
92 .\" ==== RESIZE ====
93 .Nm
94 .Cm resize
95 .Fl i Ar index
96 .Op Fl a Ar alignment
97 .Op Fl s Ar size
98 .Op Fl f Ar flags
99 .Ar geom
100 .\" ==== RESTORE ====
101 .Nm
102 .Cm restore
103 .Op Fl lF
104 .Op Fl f Ar flags
105 .Ar provider
106 .Op Ar ...
107 .\" ==== SET ====
108 .Nm
109 .Cm set
110 .Fl a Ar attrib
111 .Fl i Ar index
112 .Op Fl f Ar flags
113 .Ar geom
114 .\" ==== SHOW ====
115 .Nm
116 .Cm show
117 .Op Fl l | r
118 .Op Fl p
119 .Op Ar geom ...
120 .\" ==== UNDO ====
121 .Nm
122 .Cm undo
123 .Ar geom
124 .\" ==== UNSET ====
125 .Nm
126 .Cm unset
127 .Fl a Ar attrib
128 .Fl i Ar index
129 .Op Fl f Ar flags
130 .Ar geom
131 .\"
132 .Sh DESCRIPTION
133 The
134 .Nm
135 utility is used to partition GEOM providers, normally disks.
136 The first argument is the action to be taken:
137 .Bl -tag -width ".Cm bootcode"
138 .\" ==== ADD ====
139 .It Cm add
140 Add a new partition to the partitioning scheme given by
141 .Ar geom .
142 The partition begins on the logical block address given by the
143 .Fl b Ar start
144 option.
145 Its size is given by the
146 .Fl s Ar size
147 option.
148 SI unit suffixes are allowed.
149 One or both
150 .Fl b
151 and
152 .Fl s
153 options can be omitted.
154 If so they are automatically calculated.
155 The type of the partition is given by the
156 .Fl t Ar type
157 option.
158 Partition types are discussed below in the section entitled
159 .Sx "PARTITION TYPES" .
160 .Pp
161 Additional options include:
162 .Bl -tag -width 12n
163 .It Fl a Ar alignment
164 If specified, then
165 .Nm
166 utility tries to align
167 .Ar start
168 offset and partition
169 .Ar size
170 to be multiple of
171 .Ar alignment
172 value.
173 .It Fl i Ar index
174 The index in the partition table at which the new partition is to be
175 placed.
176 The index determines the name of the device special file used
177 to represent the partition.
178 .It Fl l Ar label
179 The label attached to the partition.
180 This option is only valid when used on partitioning schemes that support
181 partition labels.
182 .It Fl f Ar flags
183 Additional operational flags.
184 See the section entitled
185 .Sx "OPERATIONAL FLAGS"
186 below for a discussion
187 about its use.
188 .El
189 .\" ==== BACKUP ====
190 .It Cm backup
191 Dump a partition table to standard output in a special format used by the
192 .Cm restore
193 action.
194 .\" ==== BOOTCODE ====
195 .It Cm bootcode
196 Embed bootstrap code into the partitioning scheme's metadata on the
197 .Ar geom
198 (using
199 .Fl b Ar bootcode )
200 or write bootstrap code into a partition (using
201 .Fl p Ar partcode
202 and
203 .Fl i Ar index ) .
204 Not all partitioning schemes have embedded bootstrap code, so the
205 .Fl b Ar bootcode
206 option is scheme-specific in nature (see the section entitled
207 .Sx BOOTSTRAPPING
208 below).
209 The
210 .Fl b Ar bootcode
211 option specifies a file that contains the bootstrap code.
212 The contents and size of the file are determined by the partitioning
213 scheme.
214 The
215 .Fl p Ar partcode
216 option specifies a file that contains the bootstrap code intended to be
217 written to a partition.
218 The partition is specified by the
219 .Fl i Ar index
220 option.
221 The size of the file must be smaller than the size of the partition.
222 .Pp
223 Additional options include:
224 .Bl -tag -width 10n
225 .It Fl f Ar flags
226 Additional operational flags.
227 See the section entitled
228 .Sx "OPERATIONAL FLAGS"
229 below for a discussion
230 about its use.
231 .El
232 .\" ==== COMMIT ====
233 .It Cm commit
234 Commit any pending changes for geom
235 .Ar geom .
236 All actions are committed by default and will not result in
237 pending changes.
238 Actions can be modified with the
239 .Fl f Ar flags
240 option so that they are not committed, but become pending.
241 Pending changes are reflected by the geom and the
242 .Nm
243 utility, but they are not actually written to disk.
244 The
245 .Cm commit
246 action will write all pending changes to disk.
247 .\" ==== CREATE ====
248 .It Cm create
249 Create a new partitioning scheme on a provider given by
250 .Ar provider .
251 The
252 .Fl s Ar scheme
253 option determines the scheme to use.
254 The kernel must have support for a particular scheme before
255 that scheme can be used to partition a disk.
256 .Pp
257 Additional options include:
258 .Bl -tag -width 10n
259 .It Fl n Ar entries
260 The number of entries in the partition table.
261 Every partitioning scheme has a minimum and maximum number of entries.
262 This option allows tables to be created with a number of entries
263 that is within the limits.
264 Some schemes have a maximum equal to the minimum and some schemes have
265 a maximum large enough to be considered unlimited.
266 By default, partition tables are created with the minimum number of
267 entries.
268 .It Fl f Ar flags
269 Additional operational flags.
270 See the section entitled
271 .Sx "OPERATIONAL FLAGS"
272 below for a discussion
273 about its use.
274 .El
275 .\" ==== DELETE ====
276 .It Cm delete
277 Delete a partition from geom
278 .Ar geom
279 and further identified by the
280 .Fl i Ar index
281 option.
282 The partition cannot be actively used by the kernel.
283 .Pp
284 Additional options include:
285 .Bl -tag -width 10n
286 .It Fl f Ar flags
287 Additional operational flags.
288 See the section entitled
289 .Sx "OPERATIONAL FLAGS"
290 below for a discussion
291 about its use.
292 .El
293 .\" ==== DESTROY ====
294 .It Cm destroy
295 Destroy the partitioning scheme as implemented by geom
296 .Ar geom .
297 .Pp
298 Additional options include:
299 .Bl -tag -width 10n
300 .It Fl F
301 Forced destroying of the partition table even if it is not empty.
302 .It Fl f Ar flags
303 Additional operational flags.
304 See the section entitled
305 .Sx "OPERATIONAL FLAGS"
306 below for a discussion
307 about its use.
308 .El
309 .\" ==== MODIFY ====
310 .It Cm modify
311 Modify a partition from geom
312 .Ar geom
313 and further identified by the
314 .Fl i Ar index
315 option.
316 Only the type and/or label of the partition can be modified.
317 To change the type of a partition, specify the new type with the
318 .Fl t Ar type
319 option.
320 To change the label of a partition, specify the new label with the
321 .Fl l Ar label
322 option.
323 Not all partitioning schemes support labels and it is invalid to
324 try to change a partition label in such cases.
325 .Pp
326 Additional options include:
327 .Bl -tag -width 10n
328 .It Fl f Ar flags
329 Additional operational flags.
330 See the section entitled
331 .Sx "OPERATIONAL FLAGS"
332 below for a discussion
333 about its use.
334 .El
335 .\" ==== RECOVER ====
336 .It Cm recover
337 Recover a corrupt partition's scheme metadata on the geom
338 .Ar geom .
339 See the section entitled
340 .Sx RECOVERING
341 below for the additional information.
342 .Pp
343 Additional options include:
344 .Bl -tag -width 10n
345 .It Fl f Ar flags
346 Additional operational flags.
347 See the section entitled
348 .Sx "OPERATIONAL FLAGS"
349 below for a discussion
350 about its use.
351 .El
352 .\" ==== RESIZE ====
353 .It Cm resize
354 Resize a partition from geom
355 .Ar geom
356 and further identified by the
357 .Fl i Ar index
358 option.
359 New partition size is expressed in logical block
360 numbers and can be given by the
361 .Fl s Ar size
362 option.
363 If
364 .Fl s
365 option is omitted then new size is automatically calculated
366 to maximum available from given geom
367 .Ar geom .
368 .Pp
369 Additional options include:
370 .Bl -tag -width 12n
371 .It Fl a Ar alignment
372 If specified, then
373 .Nm
374 utility tries to align partition
375 .Ar size
376 to be multiple of
377 .Ar alignment
378 value.
379 .It Fl f Ar flags
380 Additional operational flags.
381 See the section entitled
382 .Sx "OPERATIONAL FLAGS"
383 below for a discussion
384 about its use.
385 .El
386 .\" ==== RESTORE ====
387 .It Cm restore
388 Restore the partition table from a backup previously created by the
389 .Cm backup
390 action and read from standard input.
391 Only the partition table is restored.
392 This action does not affect the content of partitions.
393 After restoring the partition table and writing bootcode if needed,
394 user data must be restored from backup.
395 .Pp
396 Additional options include:
397 .Bl -tag -width 10n
398 .It Fl F
399 Destroy partition table on the given
400 .Ar provider
401 before doing restore.
402 .It Fl l
403 Restore partition labels for partitioning schemes that support them.
404 .It Fl f Ar flags
405 Additional operational flags.
406 See the section entitled
407 .Sx "OPERATIONAL FLAGS"
408 below for a discussion
409 about its use.
410 .El
411 .\" ==== SET ====
412 .It Cm set
413 Set the named attribute on the partition entry.
414 See the section entitled
415 .Sx ATTRIBUTES
416 below for a list of available attributes.
417 .Pp
418 Additional options include:
419 .Bl -tag -width 10n
420 .It Fl f Ar flags
421 Additional operational flags.
422 See the section entitled
423 .Sx "OPERATIONAL FLAGS"
424 below for a discussion
425 about its use.
426 .El
427 .\" ==== SHOW ====
428 .It Cm show
429 Show current partition information for the specified geoms, or all
430 geoms if none are specified.
431 The default output includes the logical starting block of each
432 partition, the partition size in blocks, the partition index number,
433 the partition type, and a human readable partition size.
434 Block sizes and locations are based on the device's Sectorsize
435 as shown by
436 .Cm gpart list .
437 Additional options include:
438 .Bl -tag -width 10n
439 .It Fl l
440 For partitioning schemes that support partition labels, print them
441 instead of partition type.
442 .It Fl p
443 Show provider names instead of partition indexes.
444 .It Fl r
445 Show raw partition type instead of symbolic name.
446 .El
447 .\" ==== UNDO ====
448 .It Cm undo
449 Revert any pending changes for geom
450 .Ar geom .
451 This action is the opposite of the
452 .Cm commit
453 action and can be used to undo any changes that have not been committed.
454 .\" ==== UNSET ====
455 .It Cm unset
456 Clear the named attribute on the partition entry.
457 See the section entitled
458 .Sx ATTRIBUTES
459 below for a list of available attributes.
460 .Pp
461 Additional options include:
462 .Bl -tag -width 10n
463 .It Fl f Ar flags
464 Additional operational flags.
465 See the section entitled
466 .Sx "OPERATIONAL FLAGS"
467 below for a discussion
468 about its use.
469 .El
470 .El
471 .Sh PARTITIONING SCHEMES
472 Several partitioning schemes are supported by the
473 .Nm
474 utility:
475 .Bl -tag -width ".Cm VTOC8"
476 .It Cm APM
477 Apple Partition Map, used by PowerPC(R) Macintosh(R) computers.
478 Requires the
479 .Cd GEOM_PART_APM
480 kernel option.
481 .It Cm BSD
482 Traditional BSD disklabel, usually used to subdivide MBR partitions.
483 .Po
484 This scheme can also be used as the sole partitioning method, without
485 an MBR.
486 Partition editing tools from other operating systems often do not
487 understand the bare disklabel partition layout, so this is sometimes
488 called
489 .Dq dangerously dedicated .
490 .Pc
491 Requires the
492 .Cm GEOM_PART_BSD
493 kernel option.
494 .It Cm LDM
495 The Logical Disk Manager is an implementation of volume manager for
496 Microsoft Windows NT.
497 Requires the
498 .Cd GEOM_PART_LDM
499 kernel option.
500 .It Cm GPT
501 GUID Partition Table is used on Intel-based Macintosh computers and
502 gradually replacing MBR on most PCs and other systems.
503 Requires the
504 .Cm GEOM_PART_GPT
505 kernel option.
506 .It Cm MBR
507 Master Boot Record is used on PCs and removable media.
508 Requires the
509 .Cm GEOM_PART_MBR
510 kernel option.
511 The
512 .Cm GEOM_PART_EBR
513 option adds support for the Extended Boot Record (EBR),
514 which is used to define a logical partition.
515 The
516 .Cm GEOM_PART_EBR_COMPAT
517 option enables backward compatibility for partition names
518 in the EBR scheme.
519 It also prevents any type of actions on such partitions.
520 .It Cm PC98
521 An MBR variant for NEC PC-98 and compatible computers.
522 Requires the
523 .Cm GEOM_PART_PC98
524 kernel option.
525 .It Cm VTOC8
526 Sun's SMI Volume Table Of Contents, used by
527 .Tn SPARC64
528 and
529 .Tn UltraSPARC
530 computers.
531 Requires the
532 .Cm GEOM_PART_VTOC8
533 kernel option.
534 .El
535 .Sh PARTITION TYPES
536 Partition types are identified on disk by particular strings or magic
537 values.
538 The
539 .Nm
540 utility uses symbolic names for common partition types so the user
541 does not need to know these values or other details of the partitioning
542 scheme in question.
543 The
544 .Nm
545 utility also allows the user to specify scheme-specific partition types
546 for partition types that do not have symbolic names.
547 Symbolic names currently understood are:
548 .Bl -tag -width ".Cm ms-ldm-metadata"
549 .It Cm bios-boot
550 The system partition dedicated to second stage of the boot loader program.
551 Usually it is used by the GRUB 2 loader for GPT partitioning schemes.
552 The scheme-specific type is
553 .Qq Li "!21686148-6449-6E6F-744E-656564454649" .
554 .It Cm efi
555 The system partition for computers that use the Extensible Firmware
556 Interface (EFI).
557 In such cases, the GPT partitioning scheme is used and the
558 actual partition type for the system partition can also be specified as
559 .Qq Li "!c12a7328-f81f-11d2-ba4b-00a0c93ec93b" .
560 .It Cm fat16
561 A partition that contains a FAT16 filesystem.
562 The scheme-specific type is
563 .Qq Li "!6"
564 for MBR.
565 .It Cm fat32
566 A partition that contains a FAT32 filesystem.
567 The scheme-specific type is
568 .Qq Li "!11"
569 for MBR.
570 .It Cm freebsd
571 A
572 .Fx
573 partition subdivided into filesystems with a
574 .Bx
575 disklabel.
576 This is a legacy partition type and should not be used for the APM
577 or GPT schemes.
578 The scheme-specific types are
579 .Qq Li "!165"
580 for MBR,
581 .Qq Li "!FreeBSD"
582 for APM, and
583 .Qq Li "!516e7cb4-6ecf-11d6-8ff8-00022d09712b"
584 for GPT.
585 .It Cm freebsd-boot
586 A
587 .Fx
588 partition dedicated to bootstrap code.
589 The scheme-specific type is
590 .Qq Li "!83bd6b9d-7f41-11dc-be0b-001560b84f0f"
591 for GPT.
592 .It Cm freebsd-swap
593 A
594 .Fx
595 partition dedicated to swap space.
596 The scheme-specific types are
597 .Qq Li "!FreeBSD-swap"
598 for APM,
599 .Qq Li "!516e7cb5-6ecf-11d6-8ff8-00022d09712b"
600 for GPT, and tag 0x0901 for VTOC8.
601 .It Cm freebsd-ufs
602 A
603 .Fx
604 partition that contains a UFS or UFS2 filesystem.
605 The scheme-specific types are
606 .Qq Li "!FreeBSD-UFS"
607 for APM,
608 .Qq Li "!516e7cb6-6ecf-11d6-8ff8-00022d09712b"
609 for GPT, and tag 0x0902 for VTOC8.
610 .It Cm freebsd-vinum
611 A
612 .Fx
613 partition that contains a Vinum volume.
614 The scheme-specific types are
615 .Qq Li "!FreeBSD-Vinum"
616 for APM,
617 .Qq Li "!516e7cb8-6ecf-11d6-8ff8-00022d09712b"
618 for GPT, and tag 0x0903 for VTOC8.
619 .It Cm freebsd-zfs
620 A
621 .Fx
622 partition that contains a ZFS volume.
623 The scheme-specific types are
624 .Qq Li "!FreeBSD-ZFS"
625 for APM,
626 .Qq Li "!516e7cba-6ecf-11d6-8ff8-00022d09712b"
627 for GPT, and 0x0904 for VTOC8.
628 .It Cm mbr
629 A partition that is sub-partitioned by a Master Boot Record (MBR).
630 This type is known as
631 .Qq Li "!024dee41-33e7-11d3-9d69-0008c781f39f"
632 by GPT.
633 .It Cm ms-basic-data
634 A basic data partition (BDP) for Microsoft operating systems.
635 In the GPT this type is the equivalent to partition types
636 .Cm fat16 , fat32
637 and
638 .Cm ntfs
639 in MBR.
640 The scheme-specific type is
641 .Qq Li "!ebd0a0a2-b9e5-4433-87c0-68b6b72699c7"
642 for GPT.
643 .It Cm ms-ldm-data
644 A partition that contains Logical Disk Manager (LDM) volumes.
645 The scheme-specific types are
646 .Qq Li "!66"
647 for MBR,
648 .Qq Li "!af9b60a0-1431-4f62-bc68-3311714a69ad"
649 for GPT.
650 .It Cm ms-ldm-metadata
651 A partition that contains Logical Disk Manager (LDM) database.
652 The scheme-specific type is
653 .Qq Li "!5808c8aa-7e8f-42e0-85d2-e1e90434cfb3"
654 for GPT.
655 .It Cm ntfs
656 A partition that contains a NTFS or exFAT filesystem.
657 The scheme-specific type is
658 .Qq Li "!7"
659 for MBR.
660 .It Cm vmware-vmfs
661 A partition that contains a VMware File System (VMFS).
662 The scheme-specific types are
663 .Qq Li "!251"
664 for MBR and
665 .Qq Li "!aa31e02a-400f-11db-9590-000c2911d1b8"
666 for GPT.
667 .It Cm vmware-vmkdiag
668 A partition that contains a VMware diagostic filesystem.
669 The scheme-specific types are
670 .Qq Li "!252"
671 for MBR and
672 .Qq Li "!9d275380-40ad-11db-bf97-000c2911d1b8"
673 for GPT.
674 .It Cm vmware-reserved
675 A VMware reserved partition.
676 The scheme-specific type is
677 .Qq Li "!9198effc-31c0-11db-8f-78-000c2911d1b8"
678 for GPT.
679 .It Cm vmware-vsanhdr
680 A partition claimed by VMware VSAN.
681 The scheme-specific type is
682 .Qq Li "!381cfccc-7288-11e0-92ee-000c2911d0b2"
683 for GPT.
684 .El
685 .Sh ATTRIBUTES
686 The scheme-specific attributes for EBR:
687 .Bl -tag -width ".Cm active"
688 .It Cm active
689 .El
690 .Pp
691 The scheme-specific attributes for GPT:
692 .Bl -tag -width ".Cm bootfailed"
693 .It Cm bootme
694 When set, the
695 .Nm gptboot
696 stage 1 boot loader will try to boot the system from this partition.
697 Multiple partitions can be marked with the
698 .Cm bootme
699 attribute.
700 See
701 .Xr gptboot 8
702 for more details.
703 .It Cm bootonce
704 Setting this attribute automatically sets the
705 .Cm bootme
706 attribute.
707 When set, the
708 .Nm gptboot
709 stage 1 boot loader will try to boot the system from this partition only once.
710 Multiple partitions can be marked with the
711 .Cm bootonce
712 and
713 .Cm bootme
714 attribute pairs.
715 See
716 .Xr gptboot 8
717 for more details.
718 .It Cm bootfailed
719 This attribute should not be manually managed.
720 It is managed by the
721 .Nm gptboot
722 stage 1 boot loader and the
723 .Pa /etc/rc.d/gptboot
724 start-up script.
725 See
726 .Xr gptboot 8
727 for more details.
728 .El
729 .Pp
730 The scheme-specific attributes for MBR:
731 .Bl -tag -width ".Cm active"
732 .It Cm active
733 .El
734 .Pp
735 The scheme-specific attributes for PC98:
736 .Bl -tag -width ".Cm bootable"
737 .It Cm active
738 .It Cm bootable
739 .El
740 .Sh BOOTSTRAPPING
741 .Fx
742 supports several partitioning schemes and each scheme uses different
743 bootstrap code.
744 The bootstrap code is located in a specific disk area for each partitioning
745 scheme, and may vary in size for different schemes.
746 .Pp
747 Bootstrap code can be separated into two types.
748 The first type is embedded in the partitioning scheme's metadata, while the
749 second type is located on a specific partition.
750 Embedding bootstrap code should only be done with the
751 .Cm gpart bootcode
752 command with the
753 .Fl b Ar bootcode
754 option.
755 The GEOM PART class knows how to safely embed bootstrap code into
756 specific partitioning scheme metadata without causing any damage.
757 .Pp
758 The Master Boot Record (MBR) uses a 512-byte bootstrap code image, embedded
759 into the partition table's metadata area.
760 There are two variants of this bootstrap code:
761 .Pa /boot/mbr
762 and
763 .Pa /boot/boot0 .
764 .Pa /boot/mbr
765 searches for a partition with the
766 .Cm active
767 attribute (see the
768 .Sx ATTRIBUTES
769 section) in the partition table.
770 Then it runs next bootstrap stage.
771 The
772 .Pa /boot/boot0
773 image contains a boot manager with some additional interactive functions
774 for multi-booting from a user-selected partition.
775 .Pp
776 A BSD disklabel is usually created inside an MBR partition (slice)
777 with type
778 .Cm freebsd
779 (see the
780 .Sx "PARTITION TYPES"
781 section).
782 It uses 8 KB size bootstrap code image
783 .Pa /boot/boot ,
784 embedded into the partition table's metadata area.
785 .Pp
786 Both types of bootstrap code are used to boot from the GUID Partition Table.
787 First, a protective MBR is embedded into the first disk sector from the
788 .Pa /boot/pmbr
789 image.
790 It searches through the GPT for a
791 .Cm freebsd-boot
792 partition (see the
793 .Sx "PARTITION TYPES"
794 section) and runs the next bootstrap stage from it.
795 The
796 .Cm freebsd-boot
797 partition should be smaller than 545 KB.
798 It can be located either before or after other
799 .Fx
800 partitions on the disk.
801 There are two variants of bootstrap code to write to this partition:
802 .Pa /boot/gptboot
803 and
804 .Pa /boot/gptzfsboot .
805 .Pp
806 .Pa /boot/gptboot
807 is used to boot from UFS partitions.
808 .Cm gptboot
809 searches through
810 .Cm freebsd-ufs
811 partitions in the GPT and selects one to boot based on the
812 .Cm bootonce
813 and
814 .Cm bootme
815 attributes.
816 If neither attribute is found,
817 .Pa /boot/gptboot
818 boots from the first
819 .Cm freebsd-ufs
820 partition.
821 .Pa /boot/loader
822 .Pq the third bootstrap stage
823 is loaded from the first partition that matches these conditions.
824 See
825 .Xr gptboot 8
826 for more information.
827 .Pp
828 .Pa /boot/gptzfsboot
829 is used to boot from ZFS.
830 It searches through the GPT for
831 .Cm freebsd-zfs
832 partitions, trying to detect ZFS pools.
833 After all pools are detected,
834 .Pa /boot/zfsloader
835 is started from the first one found.
836 .Pp
837 The VTOC8 scheme does not support embedding bootstrap code.
838 Instead, the 8 KBytes bootstrap code image
839 .Pa /boot/boot1
840 should be written with the
841 .Cm gpart bootcode
842 command with the
843 .Fl p Ar bootcode
844 option to all sufficiently large VTOC8 partitions.
845 To do this the
846 .Fl i Ar index
847 option could be omitted.
848 .Pp
849 The APM scheme also does not support embedding bootstrap code.
850 Instead, the 800 KBytes bootstrap code image
851 .Pa /boot/boot1.hfs
852 should be written with the
853 .Cm gpart bootcode
854 command to a partition of type
855 .Cm freebsd-boot ,
856 which should also be 800 KB in size.
857 .Sh OPERATIONAL FLAGS
858 Actions other than the
859 .Cm commit
860 and
861 .Cm undo
862 actions take an optional
863 .Fl f Ar flags
864 option.
865 This option is used to specify action-specific operational flags.
866 By default, the
867 .Nm
868 utility defines the
869 .Ql C
870 flag so that the action is immediately
871 committed.
872 The user can specify
873 .Dq Fl f Cm x
874 to have the action result in a pending change that can later, with
875 other pending changes, be committed as a single compound change with
876 the
877 .Cm commit
878 action or reverted with the
879 .Cm undo
880 action.
881 .Sh RECOVERING
882 The GEOM PART class supports recovering of partition tables only for GPT.
883 The GPT primary metadata is stored at the beginning of the device.
884 For redundancy, a secondary
885 .Pq backup
886 copy of the metadata is stored at the end of the device.
887 As a result of having two copies, some corruption of metadata is not
888 fatal to the working of GPT.
889 When the kernel detects corrupt metadata, it marks this table as corrupt
890 and reports the problem.
891 .Cm destroy
892 and
893 .Cm recover
894 are the only operations allowed on corrupt tables.
895 .Pp
896 If the first sector of a provider is corrupt, the kernel can not detect GPT
897 even if the partition table itself is not corrupt.
898 The protective MBR can be rewritten using the
899 .Xr dd 1
900 command, to restore the ability to detect the GPT.
901 The copy of the protective MBR is usually located in the
902 .Pa /boot/pmbr
903 file.
904 .Pp
905 If one GPT header appears to be corrupt but the other copy remains intact,
906 the kernel will log the following:
907 .Bd -literal -offset indent
908 GEOM: provider: the primary GPT table is corrupt or invalid.
909 GEOM: provider: using the secondary instead -- recovery strongly advised.
910 .Ed
911 .Pp
912 or
913 .Bd -literal -offset indent
914 GEOM: provider: the secondary GPT table is corrupt or invalid.
915 GEOM: provider: using the primary only -- recovery suggested.
916 .Ed
917 .Pp
918 Also
919 .Nm
920 commands such as
921 .Cm show , status
922 and
923 .Cm list
924 will report about corrupt tables.
925 .Pp
926 If the size of the device has changed (e.g.,\& volume expansion) the
927 secondary GPT header will no longer be located in the last sector.
928 This is not a metadata corruption, but it is dangerous because any
929 corruption of the primary GPT will lead to loss of the partition table.
930 This problem is reported by the kernel with the message:
931 .Bd -literal -offset indent
932 GEOM: provider: the secondary GPT header is not in the last LBA.
933 .Ed
934 .Pp
935 This situation can be recovered with the
936 .Cm recover
937 command.
938 This command reconstructs the corrupt metadata using known valid
939 metadata and relocates the secondary GPT to the end of the device.
940 .Pp
941 .Em NOTE :
942 The GEOM PART class can detect the same partition table visible through
943 different GEOM providers, and some of them will be marked as corrupt.
944 Be careful when choosing a provider for recovery.
945 If you choose incorrectly you can destroy the metadata of another GEOM class,
946 e.g.,\& GEOM MIRROR or GEOM LABEL.
947 .Sh SYSCTL VARIABLES
948 The following
949 .Xr sysctl 8
950 variables can be used to control the behavior of the
951 .Nm PART
952 GEOM class.
953 The default value is shown next to each variable.
954 .Bl -tag -width indent
955 .It Va kern.geom.part.check_integrity : No 1
956 This variable controls the behaviour of metadata integrity checks.
957 When integrity checks are enabled, the
958 .Nm PART
959 GEOM class verifies all generic partition parameters obtained from the
960 disk metadata.
961 If some inconsistency is detected, the partition table will be
962 rejected with a diagnostic message:
963 .Sy "GEOM_PART: Integrity check failed (provider, scheme)" .
964 .It Va kern.geom.part.ldm.debug : No 0
965 Debug level of the Logical Disk Manager (LDM) module.
966 This can be set to a number between 0 and 2 inclusive.
967 If set to 0 minimal debug information is printed,
968 and if set to 2 the maximum amount of debug information is printed.
969 .It Va kern.geom.part.ldm.show_mirrors : No 0
970 This variable controls how the Logical Disk Manager (LDM) module handles
971 mirrored volumes.
972 By default mirrored volumes are shown as partitions with type
973 .Cm ms-ldm-data
974 (see the
975 .Sx "PARTITION TYPES"
976 section).
977 If this variable set to 1 each component of the mirrored volume will be
978 present as independent partition.
979 .Em NOTE :
980 This may break a mirrored volume and lead to data damage.
981 .El
982 .Sh EXIT STATUS
983 Exit status is 0 on success, and 1 if the command fails.
984 .Sh EXAMPLES
985 Create a GPT scheme on
986 .Pa ada0 :
987 .Bd -literal -offset indent
988 /sbin/gpart create -s GPT ada0
989 .Ed
990 .Pp
991 Embed GPT bootstrap code into a protective MBR:
992 .Bd -literal -offset indent
993 /sbin/gpart bootcode -b /boot/pmbr ada0
994 .Ed
995 .Pp
996 Create a dedicated
997 .Cm freebsd-boot
998 partition that can boot
999 .Fx
1000 from a
1001 .Cm freebsd-ufs
1002 partition, and install bootstrap code into it.
1003 This partition must be larger than the bootstrap code
1004 .Po
1005 usually either
1006 .Pa /boot/gptboot
1007 or
1008 .Pa /boot/gptzfsboot
1009 .Pc ,
1010 but smaller than 545 kB since the first-stage loader will load the
1011 entire partition into memory during boot, regardless of how much data
1012 it actually contains.
1013 This example uses 88 blocks (44 kB) so the next partition will be
1014 aligned on a 64 kB boundary without the need to specify an explicit
1015 offset or alignment.
1016 The boot partition itself is aligned on a 4 kB boundary.
1017 .Bd -literal -offset indent
1018 /sbin/gpart add -b 40 -s 88 -t freebsd-boot ada0
1019 /sbin/gpart bootcode -p /boot/gptboot -i 1 ada0
1020 .Ed
1021 .Pp
1022 Create a 512MB-sized
1023 .Cm freebsd-ufs
1024 partition to contain a UFS filesystem from which the system can boot.
1025 .Bd -literal -offset indent
1026 /sbin/gpart add -s 512M -t freebsd-ufs ada0
1027 .Ed
1028 .Pp
1029 Create an MBR scheme on
1030 .Pa ada0 ,
1031 then create a 30GB-sized
1032 .Fx
1033 slice, mark it active and
1034 install the
1035 .Nm boot0
1036 boot manager:
1037 .Bd -literal -offset indent
1038 /sbin/gpart create -s MBR ada0
1039 /sbin/gpart add -t freebsd -s 30G ada0
1040 /sbin/gpart set -a active -i 1 ada0
1041 /sbin/gpart bootcode -b /boot/boot0 ada0
1042 .Ed
1043 .Pp
1044 Now create a
1045 .Bx
1046 scheme
1047 .Pf ( Bx
1048 label) with space for up to 20 partitions:
1049 .Bd -literal -offset indent
1050 /sbin/gpart create -s BSD -n 20 ada0s1
1051 .Ed
1052 .Pp
1053 Create a 1GB-sized UFS partition and a 4GB-sized swap partition:
1054 .Bd -literal -offset indent
1055 /sbin/gpart add -t freebsd-ufs -s 1G ada0s1
1056 /sbin/gpart add -t freebsd-swap -s 4G ada0s1
1057 .Ed
1058 .Pp
1059 Install bootstrap code for the
1060 .Bx
1061 label:
1062 .Bd -literal -offset indent
1063 /sbin/gpart bootcode -b /boot/boot ada0s1
1064 .Ed
1065 .Pp
1066 Create a VTOC8 scheme on
1067 .Pa da0 :
1068 .Bd -literal -offset indent
1069 /sbin/gpart create -s VTOC8 da0
1070 .Ed
1071 .Pp
1072 Create a 512MB-sized
1073 .Cm freebsd-ufs
1074 partition to contain a UFS filesystem from which the system can boot.
1075 .Bd -literal -offset indent
1076 /sbin/gpart add -s 512M -t freebsd-ufs da0
1077 .Ed
1078 .Pp
1079 Create a 15GB-sized
1080 .Cm freebsd-ufs
1081 partition to contain a UFS filesystem and aligned on 4KB boundaries:
1082 .Bd -literal -offset indent
1083 /sbin/gpart add -s 15G -t freebsd-ufs -a 4k da0
1084 .Ed
1085 .Pp
1086 After creating all required partitions, embed bootstrap code into them:
1087 .Bd -literal -offset indent
1088 /sbin/gpart bootcode -p /boot/boot1 da0
1089 .Ed
1090 .Pp
1091 Create a backup of the partition table from
1092 .Pa da0 :
1093 .Bd -literal -offset indent
1094 /sbin/gpart backup da0 > da0.backup
1095 .Ed
1096 .Pp
1097 Restore the partition table from the backup to
1098 .Pa da0 :
1099 .Bd -literal -offset indent
1100 /sbin/gpart restore -l da0 < /mnt/da0.backup
1101 .Ed
1102 .Pp
1103 Clone the partition table from
1104 .Pa ada0
1105 to
1106 .Pa ada1
1107 and
1108 .Pa ada2 :
1109 .Bd -literal -offset indent
1110 /sbin/gpart backup ada0 | /sbin/gpart restore -F ada1 ada2
1111 .Ed
1112 .Sh SEE ALSO
1113 .Xr dd 1 ,
1114 .Xr geom 4 ,
1115 .Xr boot0cfg 8 ,
1116 .Xr geom 8 ,
1117 .Xr gptboot 8
1118 .Sh HISTORY
1119 The
1120 .Nm
1121 utility appeared in
1122 .Fx 7.0 .
1123 .Sh AUTHORS
1124 .An Marcel Moolenaar Aq marcel@FreeBSD.org