.\"
.\" CDDL HEADER START
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\" CDDL HEADER END
.\"
.\" Copyright 1989 AT&T
.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved
.\" Copyright 2022 Toomas Soome <tsoome@me.com>
.\"
.Dd March 30, 2022
.Dt FMTHARD 8
.Os
.Sh NAME
.Nm fmthard
.Nd populate label on hard disks
.Sh SYNOPSIS
.Nm
.Fl d Ar data | Fl n Ar volume_name | Fl s Ar datafile Op Fl i
.Sm off
.Ar /dev/rdsk/c? Oo t? Oc d?s2
.Sm on
.Sh DESCRIPTION
The
.Nm
command updates the
.Sy VTOC
.Pq Volume Table of Contents
on hard disks.
One or more of the options
.Fl s Ar datafile ,
.Fl d Ar data ,
or
.Fl n Ar volume_name
must be used to request modifications to the disk label.
To print disk label contents, see
.Xr prtvtoc 8 .
The
.Sm off
.Ar /dev/rdsk/c? Oo t? Oc d?s2
.Sm on
file must be the character special file of the device where the new label
is to be installed.
On x86 systems,
.Xr fdisk 8
must be run on the drive before
.Nm .
.Pp
If you are using an x86 system, note that the term
.Sq  partition
in this page refers to
.Em slices
within the x86
.Sy fdisk
partition on x86 machines.
Do not confuse the partitions created by
.Nm
with the partitions created by
.Xr fdisk 8 .
.Sh OPTIONS
The following options are supported:
.Bl -tag -width Ds
.It Fl d Ar data
The
.Ar data
argument of this option is a string representing the information
for a particular partition in the current
.Sy VTOC .
The string must be of the format
.Em part:tag:flag:start:size
where
.Em part
is the partition number,
.Em tag
is the
.Sy ID
TAG of the partition,
.Em flag
is the set of permission flags,
.Em start
is the starting sector number of the partition, and
.Em size
is the number of sectors in the partition.
See the description of the
.Ar datafile
below for more information on these fields.
.It Fl i
This option allows the command to create the desired
.Sy VTOC
table, but prints the information to standard output instead of modifying the
.Sy VTOC
on the disk.
.It Fl n Ar volume_name
This option is used to give the disk a
.Ar volume_name
up to 8 characters long.
.It Fl s Ar datafile
This option is used to populate the
.Sy VTOC
according to a
.Ar datafile
created by the user.
If the
.Ar datafile
is
.Sy \(mi Pq a hyphen ,
.Nm
reads from standard input.
The
.Ar datafile
format is described below.
This option causes all of the disk partition timestamp fields to be set
to zero.
.sp
Every
.Sy VTOC
generated by
.Nm
will also have partition 2, by convention, that corresponds to the whole disk.
If the input in
.Ar datafile
does not specify an entry for partition 2, a default partition 2 entry will be
created automatically in
.Sy VTOC
with the tag
.Sy V_BACKUP
and size equal to the full size of the disk.
.sp
The
.Ar datafile
contains one specification line for each partition, starting with partition 0.
Each line is delimited by a new-line character
.Pq Sy \en .
If the first character of a line is an asterisk
.Pq \&* ,
the line is treated as a comment.
Each line is composed of entries that are position-dependent,
separated by white space and having the following format:
.sp
.Em partition tag flag starting_sector size_in_sectors
.sp
where the entries have the following values:
.Bl -tag -width Ds
.It Em partition
The partition number.
Currently, for Solaris SPARC, a disk can have up to 8 partitions,
.Sy 0\(mi7 .
Even though the
.Em partition
field has 4 bits, only 3 bits are currently used.
For x86, all 4 bits are used to allow slices
.Sy 0\(mi15 .
Each Solaris
.Sy fdisk
partition can have up to 16 slices.
.It Em tag
The partition tag: a decimal number.
The following are reserved codes:
.Sy 0 Pq Sy V_UNASSIGNED ,
.Sy 1 Pq Sy V_BOOT ,
.Sy 2 Pq Sy V_ROOT ,
.Sy 3 Pq Sy V_SWAP ,
.Sy 4 Pq Sy V_USR ,
.Sy 5 Pq Sy V_BACKUP ,
.Sy 6 Pq Sy V_STAND ,
.Sy 7 Pq Sy V_VAR ,
and
.Sy 8 Pq Sy V_HOME .
.It Em flag
The flag allows a partition to be flagged as unmountable or read only, the
masks being:
.Sy V_UNMNT 0x01 ,
and
.Sy V_RONLY 0x10 .
For mountable partitions use
.Sy 0x00 .
.It Em starting_sector
The sector number (decimal) on which the partition starts.
.It Em size_in_sectors
The number (decimal) of sectors occupied by the partition.
.El
.sp
You can save the output of a
.Xr prtvtoc 8
command to a file, edit the file, and use it as the
.Ar datafile
argument to the
.Fl s
option.
.El
.Sh SEE ALSO
.Xr uname 1 ,
.Xr attributes 7 ,
.Xr format 8 ,
.Xr installboot 8 ,
.Xr prtvtoc 8
.Ss "x86 Only"
.Xr fdisk 8
.Sh NOTES
Special care should be exercised when overwriting an existing
.Sy VTOC ,
as incorrect entries could result in current data being inaccessible.
As a precaution, save the old
.Sy VTOC .
.sp
For disks under two terabytes,
.Nm
cannot write a
.Sy VTOC
on an unlabeled disk.
Use
.Xr format 8
for this purpose.