Skip to content

Commit b142eaa

Browse files
committed
Clean up error message and return codes
Update documentation to match the new behavior.
1 parent 4490d15 commit b142eaa

File tree

3 files changed

+290
-105
lines changed

3 files changed

+290
-105
lines changed

luksmeta.8

Lines changed: 118 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "LUKSMETA" "1" "May 2017" "" ""
4+
.TH "LUKSMETA" "1" "June 2017" "" ""
55
.
66
.SH "NAME"
77
\fBluksmeta\fR \- Utility for storing metadata in a LUKSv1 header
@@ -25,10 +25,10 @@
2525
\fBluksmeta wipe\fR \-d DEVICE \-s SLOT [\-u UUID] [\-f]
2626
.
2727
.SH "OVERVIEW"
28-
The \fBluksmeta\fR utility enables an administrator to store metadata in the gap between the end of the LUKSv1 header and the start of the encrypted data\.
28+
The \fBluksmeta\fR utility enables an administrator to store metadata in the gap between the end of the LUKSv1 header and the start of the encrypted data\. This is useful for storing data that is available before the volume is unlocked, usually for use during the volume unlock process\.
2929
.
3030
.P
31-
The metadata is stored in a series of UUID\-typed slots, allowing multiple blocks of metadata\. Although the \fBluksmeta\fR slots are inspired by the LUKS slots, they are functionally independent and share only a casual relationship\.
31+
The metadata is stored in a series of UUID\-typed slots, allowing multiple blocks of metadata\. Although the \fBluksmeta\fR slots are inspired by the LUKS slots, they are functionally independent and share only a casual relationship\. Slots merely provide a hint that a given chunk of metadata is associated with a specific LUKSv1 password (in a slot with the same number)\. However, \fBluksmeta\fR itself is indifferent to the relationship between a LUKSv1 slot and the correspondly numbered \fBluksmeta\fR slot, with one exception (detailed below)\.
3232
.
3333
.P
3434
After a LUKSv1 volume is initialized using \fBcryptsetup\fR(8), it must also be initialized for metadata storage by \fBluksmeta init\fR\. Once this is complete, the device is ready to store medata\.
@@ -37,16 +37,25 @@ After a LUKSv1 volume is initialized using \fBcryptsetup\fR(8), it must also be
3737
Data can be written to a slot using \fBluksmeta save\fR or read from a slot using \fBluksmeta load\fR\. You can also erase the data in an existing slot using \fBluksmeta wipe\fR or query the slots using \fBluksmeta show\fR\.
3838
.
3939
.SH "UUID GENERATION"
40-
It is often presumed that saving metadata to a slot requires a specific UUID\. This is incorrect\. The UUID is not in any way special, it simply identifies the type of data you store in the slot\. If you are defining a new type of metadata, simply generate a random UUID and use it to identify your metadata\. The easiest way to generate a UUID is to use \fBuuidgen\fR(1)\.
40+
It is often presumed that saving metadata to a slot requires a specific UUID or that there is an official registry of UUID types\. This is incorrect\.
41+
.
42+
.P
43+
UUID stands for Universally Unique IDentifier\. UUIDs are a standardized, widely\-used data type used for identification without a central registry\. For the relevant standards, see ISO 9834\-8:2005 and RFC 4122\.
44+
.
45+
.P
46+
UUIDs are large enough that collision is practically impossible\. So if your application wants to store data in a \fBluksmeta\fR slot, just generate your own UUID and use it consistently to refer to your type of data\. If you have multiple types of data, feel free to generate multiple UUIDs\.
47+
.
48+
.P
49+
The easiest way to generate a UUID is to use \fBuuidgen\fR(1)\. However, any compliant UUID generator will suffice\.
4150
.
4251
.SH "INITIALIZATION"
4352
Before reading or writing metadata, the LUKSv1 block device must be initialized for metadata storage\. Two commands help with this process: \fBluksmeta test\fR and \fBluksmeta init\fR\.
4453
.
4554
.P
46-
The \fBluksmeta test\fR command simply checks an existing block device to see if it is initialized for metadata storage\. It returns zero if the device is already initialized\. Otherwise, it returns non\-zero\.
55+
The \fBluksmeta test\fR command simply checks an existing block device to see if it is initialized for metadata storage\. This command does not provide any output, so be sure to check its return code (see below)\.
4756
.
4857
.P
49-
The \fBluksmeta init\fR command initializes the LUKSv1 block device for metadata storage\. This process will wipe out any data in the LUKSv1 header gap\. For this reason, you should use great care with this command\. However, if the block device already contains a \fBluksmeta\fR header, no modifications will be performed\. Because initialization is a destructive operation, this command will require user confirmation before any data is written, unless the \fB\-f\fR option is supplied\.
58+
The \fBluksmeta init\fR command initializes the LUKSv1 block device for metadata storage\. This process will wipe out any data in the LUKSv1 header gap\. For this reason, this command will require user confirmation before any data is written, unless the \fB\-f\fR option is supplied\. Note that this command succeeds if the device is already initialized\.
5059
.
5160
.SH "METADATA STATE"
5261
The \fBluksmeta show\fR command displays the current state of slots on the LUKSv1 block device\. If no slot is specified, it prints a table consisting of the slot number, the corresponding LUKSv1 slot state and the UUID of the data stored in the \fBluksmeta\fR slot (or "empty" if no data is stored)\. If a slot is specified, this command simply prints out the UUID of the data in the slot\. If the slot does not contain data, it prints nothing\.
@@ -55,41 +64,135 @@ The \fBluksmeta show\fR command displays the current state of slots on the LUKSv
5564
Managing the metadata in the slots is performed with three commands: \fBluksmeta save\fR, \fBluksmeta load\fR and \fBluksmeta wipe\fR\. These commands write metadata to a slot, read metadata from a slot and erase metadata in a slot, respectively\.
5665
.
5766
.P
58-
The \fBluksmeta save\fR command reads metadata on standard input and writes it to the specified slot using the specified UUID\. If no slot is specified, the metadata is written to the first empty slot using the specified UUID\. In this case, the slot written to is printed to standard output\. This command will never overwrite existing data\. To replace data in a slot you will need to execute \fBluksmeta wipe\fR before \fBluksmeta save\fR\.
67+
The \fBluksmeta save\fR command reads metadata on standard input and writes it to the specified slot using the specified UUID\. If no slot is specified, \fBluksmeta\fR will search for the first slot number for which the LUKSv1 slot is inactive and the \fBluksmeta\fR slot is empty\. This represents the only official correlation between LUKSv1 slots and \fBluksmeta\fR slots\. In this case, the metadata is written to the first applicable slot using the specified UUID and the slot number is printed to standard output\. In either case, this command will never overwrite existing data\. To replace data in a slot you will need to execute \fBluksmeta wipe\fR before \fBluksmeta save\fR\.
5968
.
6069
.P
6170
The \fBluksmeta load\fR command reads data from the specified slot and writes it to standard output\. If a UUID is specified, the command will verify that the UUID associated with the metadata in the slot matches the specified UUID\. This type check helps to ensure that you always receive the type of data you are expecting as output\. If the UUIDs do not match, the command will fail\.
6271
.
6372
.P
64-
The \fBluksmeta wipe\fR command erases the data from the given slot\. If a UUID is specified, the command will verify that the UUID associated with the metadata in the slot matches the specified UUID\. This type check helps to ensure that you only erase the data you intended to erase\. Because this is a destructive operation, this command will require user confirmation before any data is erased, unless the \fB\-f\fR option is supplied\.
73+
The \fBluksmeta wipe\fR command erases the data from the given slot\. If a UUID is specified, the command will verify that the UUID associated with the metadata in the slot matches the specified UUID\. This type check helps to ensure that you only erase the data you intended to erase\. Because this is a destructive operation, this command will require user confirmation before any data is erased, unless the \fB\-f\fR option is supplied\. Note that this command succeeds if you attempt to wipe a slot that is already empty\.
6574
.
6675
.SH "CAVEATS"
67-
The ammount of storage in the LUKSv1 header gap is extremely limited\. It also varies based upon the configuration used by LUKSv1 at device initialization time\. In some LUKSv1 configurations, there is not even enough space for all the metadata slots even at the smallest possible slot size\.
76+
The amount of storage in the LUKSv1 header gap is extremely limited\. It also varies based upon the configuration used by LUKSv1 at device initialization time\. In some LUKSv1 configurations, there is not even enough space for all the metadata slots even at the smallest possible slot size\.
6877
.
6978
.P
70-
During the design of this utility, we considered it likely that users would want to reduce the number of available slots in exchange for more storage space in the remaining slots\. In order to provide this flexibility, the amount of storage available per\-slot is dynamic\. Put simply, slots are not a fixed size\. This means that it is possible (and even somewhat likely) to encounter an error during \fBluksmeta save\fR indicating that there is insufficient space\.
79+
During the design of this utility, we considered it likely that users would want to reduce the number of usable slots in exchange for more storage space in the slots used\. In order to provide this flexibility, the amount of storage available per\-slot is dynamic\. Put simply, slots are not a fixed size\. This means that it is possible (and even somewhat likely) to encounter an error during \fBluksmeta save\fR indicating that there is insufficient space\.
7180
.
7281
.P
7382
This error is not a programming bug\. If you encounter this error it likely means that either all space is being consumed by the already\-written slots or that the metadata you are attempting to write simply does not fit\.
7483
.
84+
.P
85+
You can attempt to resolve this problem by calling \fBluksmeta wipe\fR on slots that are no longer in use\. This will release the storage space for use by other slots\. Note that \fBluksmeta\fR does not, however, currently perform defragmentation since the number of usable blocks is rather limited\. You can attempt to manually get around this by extracting all slot data, wiping the slots and reloading them in order\. However, this operation is potentially dangerous and should be undertaken with great care\.
86+
.
7587
.SH "OPTIONS"
7688
.
7789
.TP
78-
\fB\-d\fR \fIDEVICE\fR
90+
\fB\-d\fR \fIDEVICE\fR, \fB\-\-device\fR=\fIDEVICE\fR
7991
The device on which to perform the operation\.
8092
.
8193
.TP
82-
\fB\-s\fR \fISLOT\fR
83-
The slot on which to perform the operation\.
94+
\fB\-s\fR \fISLOT\fR, \fB\-\-slot\fR=\fISLOT\fR
95+
The slot number on which to perform the operation\.
8496
.
8597
.TP
86-
\fB\-u\fR \fIUUID\fR
98+
\fB\-u\fR \fIUUID\fR, \fB\-\-uuid\fR=\fIUUID\fR
8799
The UUID to associate with the operation\.
88100
.
89101
.TP
90-
\fB\-f\fR
102+
\fB\-f\fR, \fB\-\-force\fR
91103
Forcibly suppress all user prompting\.
92104
.
105+
.SH "RETURN VALUES"
106+
This command uses the return values as defined by \fBsysexit\.h\fR\. The following are general errors whose meaning is shared by all \fBluksmeta\fR commands:
107+
.
108+
.IP "\(bu" 4
109+
\fBEX_OK\fR : The operation was successful\.
110+
.
111+
.IP "\(bu" 4
112+
\fBEX_OSERR\fR : An undefined operating system error occurred\.
113+
.
114+
.IP "\(bu" 4
115+
\fBEX_USAGE\fR : The program was called with invalid parameters\.
116+
.
117+
.IP "\(bu" 4
118+
\fBEX_IOERR\fR : An IO error occurred when writing to the device\.
119+
.
120+
.IP "\(bu" 4
121+
\fBEX_OSFILE\fR : The device is not initialized or is corrupted\.
122+
.
123+
.IP "\(bu" 4
124+
\fBEX_NOPERM\fR : The user did not grant permission during confirmation\.
125+
.
126+
.IP "\(bu" 4
127+
\fBEX_NOINPUT\fR : An error occured while reading from standard input\.
128+
.
129+
.IP "\(bu" 4
130+
\fBEX_DATAERR\fR : The specified UUID does not match the slot UUID\.
131+
.
132+
.IP "\(bu" 4
133+
\fBEX_CANTCREAT\fR : There is insufficient space in LUKSv1 header\.
134+
.
135+
.IP "" 0
136+
.
137+
.P
138+
Additionally, \fBluksmeta save\fR will return \fBEX_UNAVAILABLE\fR when you attempt to save data into a slot that is already used\. Likewise, \fBluksmeta load\fR will return \fBEX_UNAVAILABLE\fR when you attempt to read from an empty slot\.
139+
.
140+
.SH "EXAMPLES"
141+
Ensure that a device is initialized:
142+
.
143+
.IP "" 4
144+
.
145+
.nf
146+
147+
$ luksmeta test \-d /dev/sdz || luksmeta init \-f \-d /dev/sdz
148+
.
149+
.fi
150+
.
151+
.IP "" 0
152+
.
153+
.P
154+
Write some data to a slot:
155+
.
156+
.IP "" 4
157+
.
158+
.nf
159+
160+
$ UUID=`uuidgen`
161+
$ echo $UUID
162+
31c25e3b\-b8e2\-4eaa\-a427\-23aa882feef2
163+
$ echo "Hello, World" | luksmeta save \-d /dev/sdz \-s 0 \-u $UUID
164+
.
165+
.fi
166+
.
167+
.IP "" 0
168+
.
169+
.P
170+
Read the data back:
171+
.
172+
.IP "" 4
173+
.
174+
.nf
175+
176+
$ luksmeta load \-d /dev/sdz \-s 0 \-u $UUID
177+
Hello, World
178+
.
179+
.fi
180+
.
181+
.IP "" 0
182+
.
183+
.P
184+
Wipe the data from the slot:
185+
.
186+
.IP "" 4
187+
.
188+
.nf
189+
190+
$ luksmeta wipe \-d /dev/sdz \-s 0 \-u $UUID
191+
.
192+
.fi
193+
.
194+
.IP "" 0
195+
.
93196
.SH "AUTHOR"
94197
Nathaniel McCallum <npmccallum@redhat\.com>
95198
.

0 commit comments

Comments
 (0)