Print a Disk's VTOC Partition Table on Solaris with prtvtoc

prtvtoc prints a Solaris disk's label, with its geometry, slice table, tags and flags; run it before you repartition, relabel or clone a disk with fmthard.

Purpose

prtvtoc reports a disk's geometry and partitioning. It reads the disk label , which on an SMI (VTOC) disk is the first sector and holds the geometry and the slice table. Then it prints that label as plain text. It changes nothing on the disk.

SMI is the traditional VTOC (Volume Table of Contents) label for disks smaller than 2 TB. EFI is the label for disks larger than 2 TB, which need a 64-bit kernel, and format -e can also put an EFI label on a disk of 2 TB or less. Slices you create stay unavailable until the disk is labeled, so the label is the layout the system uses. Admins read it before they repartition a disk or copy one disk's layout to another.

The command below was used on Solaris 7 through 10 systems. It is one of the commands collected on the Solaris commands and scripts page .

Code

1prtvtoc /dev/dsk/c0t0d0s0

Code Breakdown

The device argument

/dev/dsk/c0t0d0s0 is a block device name. prtvtoc accepts either a raw device name in the form /dev/rdsk/c?t?d?s2 or a block device name in the form /dev/dsk/c?t?d?s2.

To examine a disk label , use the raw form, # prtvtoc /dev/rdsk/device-name, where device-name is the raw disk device you want to examine. You don't have to name slice 2. Slice 0 works too, as in this sample from a 1.05 GB disk :

 1# prtvtoc /dev/rdsk/c0t1d0s0
 2* /dev/rdsk/c0t1d0s0 partition map
 3*
 4* Dimensions:
 5*     512 bytes/sector
 6*      72 sectors/track
 7*      14 tracks/cylinder
 8*    1008 sectors/cylinder
 9*    2038 cylinders
10*    2036 accessible cylinders
11*
12* Flags:
13*   1: unmountable
14*  10: read-only
15*
16*                          First     Sector    Last
17* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
18       0      2    00          0    303408    303407   /
19       1      3    01     303408    225792    529199
20       2      5    00          0   2052288   2052287
21       6      4    00     529200   1523088   2052287   /usr

The Dimensions header

The Dimensions section describes the physical size and layout of the drive. On a VTOC disk it gives bytes per sector, sectors per track, tracks per cylinder, sectors per cylinder, total cylinders and accessible cylinders. In the sample, 72 sectors times 14 tracks gives the 1008 sectors per cylinder. The two cylinders that are not accessible are the ones format shows as "2036 + 2 (reserved cylinders)".

An EFI-labeled disk prints something else. The EFI label stores no cylinder, head or sector information, so its Dimensions block lists only bytes per sector, total sectors and accessible sectors.

The partition table columns

Each row is one slice:

  • Partition: the slice number.
  • Tag: what the slice is for (see below).
  • Flags: whether it can be mounted, and how.
  • First Sector: the first sector of the slice.
  • Sector Count: the total number of sectors in the slice.
  • Last Sector: the last sector number in the slice.
  • Mount Directory: the last mount point directory for the file system.

In the sample, the slices sit end to end: slice 0 ends at 303407 and slice 1 starts at 303408. Gaps between slices are allowed, though. prtvtoc -f reports free space, and on Solaris 11.4 an "Unallocated space" block lists it; Oracle's 11.4 EFI example shows unallocated sectors 3221209040 to 3221209054 between slice 0 and slice 8. Slice 2 (tag 5, BACKUP) starts at 0 and covers 2052288 sectors, which is 2036 accessible cylinders times 1008 sectors. By convention, every VTOC that fmthard writes has a partition 2 that covers the whole disk.

Tag and Flags codes

The Tag column prints a decimal number. The codes are:

TagCodeTagCode
UNASSIGNED0x00VAR0x07
BOOT0x01HOME0x08
ROOT0x02ALTSCTR0x09
SWAP0x03CACHE0x0a
USR0x04RESERVED0x0b
BACKUP0x05
STAND0x06

A row that reads 8 11 00 on an EFI disk is slice 8 with tag 11 decimal, which is 0x0b, RESERVED.

The Flags column has three values: 00 is mountable, read and write; 01 is not mountable; 10 is mountable, read only. In the sample, the swap slice (tag 3) carries 01. Tags and flags are labels assigned by convention and need no upkeep. The mount command does not check the "not mountable" bit.

Options -f, -h, -s, -m and -t

The Solaris 10 synopsis is prtvtoc [ -fhs ] [ -t vfstab ] [ -m mnttab ] device.

  • -f reports free space: the starting block of the free space, the number of blocks, and the unused partitions.
  • -h drops the headers from the normal output.
  • -s drops every header except the column header.
  • -m mnttab reads a different file as the list of mounted file systems, in place of /etc/mnttab.
  • -t vfstab reads a different file as the list of file system defaults, in place of /etc/vfstab.

The -f output is a single line of shell-style variables. On a 424 MB Solaris 10 disk, it reads FREE_START=0 FREE_SIZE=0 FREE_COUNT=0 FREE_PART=34. That disk has no free space, and slices 3 and 4 are the unused ones. On a Solaris 11.4 disk, it reads FREE_START=34 FREE_SIZE=222 FREE_COUNT=1 FREE_PART=134567. There, 222 free blocks start at block 34, and slices 1, 3, 4, 5, 6 and 7 are unused.

Key Points

  • Only the superuser can run prtvtoc on Solaris 10 and illumos . On Solaris 11.4 , any user with read access to the device file can run it, which is normally limited to the root user.
  • The man page is in section 1M on Solaris 10 (package SUNWcsu) and in section 8 on Solaris 11.4 (package system/core-os) and illumos. The synopsis is the same on all three.
  • Solaris 11.4 adds a Label: line that reads SMI/VTOC or EFI/GPT, an "Unallocated space" block, and two tags: SYSTEM 0x0c and BOOT 0x18.
  • On an EFI disk no slice can start at sector 0, because the label itself takes the first sectors, usually 34, so slices start at sector 34 or later (the Solaris 11.4 sample starts slice 0 at sector 48). Slice 2 is an ordinary slice, not the whole disk. Slice 8 holds what the last two cylinders (the alternate cylinders) held on a VTOC disk.
  • On illumos, fmthard allows up to 8 slices (0-7) on SPARC and up to 16 (0-15) in each Solaris fdisk partition on x86, and fdisk must be run on an x86 drive before fmthard. On Solaris 10 x86, the Solaris fdisk partition of a VTOC disk holds 10 slices (0-9).

Insights and Best Practices

Safe usage

prtvtoc only reads the label. The risk comes with the tools you run next. Changing a disk's label type destroys all data on the disk. A wrong fmthard entry can leave current data unreachable. Save the old VTOC with prtvtoc before you write a new one.

prtvtoc versus format

format also shows the partition table, but it works interactively and, as Oracle's About Disk Labels example shows, gives cylinder ranges and sizes in megabytes. prtvtoc runs without prompts, prints sectors, and its output can go straight to a file or a pipe. Sectors are also the unit fmthard expects, because its data file gives each slice as partition tag flag starting_sector size_in_sectors.

Scripting: cloning a label with fmthard

fmthard updates the VTOC on hard disks. You can save prtvtoc output to a file, edit it, and pass it to fmthard -s. If the data file is -, fmthard reads standard input. Lines that start with * count as comments, so the prtvtoc headers do no harm.

To label several disks with the same geometry , pipe one into the other:

1# for i in 1 2 3 5
2> do
3> prtvtoc /dev/rdsk/c2t0d0s0 | fmthard -s - /dev/rdsk/c2t${i}d0s2
4> done

The loop overwrites the VTOC on each target disk, so check the disk numbers before you run it. Each disk that takes the label prints fmthard: New volume table of contents now in place. For a dry run, add -i. With it, fmthard builds the VTOC and prints it to standard output instead of writing it to the disk.

What to log

Keep a prtvtoc file for every disk, named after the device, and refresh it after each layout change. Keep the full output, since fmthard -s accepts it as it is.

When to Run This

  • After you add a disk, to confirm it carries a label and the slices you expect.
  • Ahead of replacing a failed disk, so the new one can get the same layout.
  • When you need the free space and unused slices on a disk, with -f.
  • On Solaris 11.4, to check whether a disk has an SMI/VTOC or an EFI/GPT label.

Troubleshooting Common Issues

Permission denied as a normal user. On Solaris 10 and illumos, run the command as root. On Solaris 11.4, check the device file with ls -lL /dev/rdsk/c0t0d0s2. Your account needs read access to it.

"Warning: Could not read primary label." The primary label is corrupt. To recover it , boot to single-user mode, from a Solaris DVD or the network if you need to. Run format and select the disk. If format asks "Disk not labeled. Label it now?", answer no: answering yes writes a default label over the one you are trying to recover. Then type verify to search for the backup label. If the backup label looks right, use the backup command to write it as the primary. Then check the file systems on the disk with fsck.

"corrupt label - wrong magic number". You added an EFI-labeled disk to a system running an older Solaris release, which does not recognize the EFI label. Move the disk to a release that supports the EFI label.

"disk has 2576941056 blocks, which is too large for a 32-bit kernel". The system booted a 32-bit SPARC or x86 kernel with a disk larger than 1 TB attached. Boot the 64-bit kernel. EFI support for disks larger than 2 TB needs a 64-bit Solaris kernel.

fmthard will not write to a new disk. For disks under 2 TB, fmthard cannot write a VTOC to an unlabeled disk. Label the disk with format first. Then run the prtvtoc | fmthard pipe.

A slice flagged 01 got mounted anyway. mount does not check the "not mountable" bit. Confirm the flag with prtvtoc, and take the slice out of /etc/vfstab if it should never be mounted.

The Mount Directory column is empty. prtvtoc takes mount points from /etc/mnttab and /etc/vfstab. When the right lists are in other files, pass them with -m and -t.

References