2 .\" Copyright 2016 Toomas Soome <tsoome@me.com>
3 .\" Copyright 2013 Nexenta Systems, Inc. All rights reserved.
4 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
5 .\" 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.
6 .\" 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
7 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .Nd administer files available as block devices through lofi
18 .Fl a Ar file Op Ar device
27 .Fl c Ar crypto_algorithm
29 .Fl a Ar file Op Ar device
32 .Fl c Ar crypto_algorithm
34 .Fl a Ar file Op Ar device
37 .Fl c Ar crypto_algorithm
39 .Fl k Ar wrapped_key_file
40 .Fl a Ar file Op Ar device
43 .Fl c Ar crypto_algorithm
45 .Fl a Ar file Op Ar device
48 .Op Fl s Ar segment_size
51 .Fl d Ar file Ns | Ns Ar device
55 .Op Ar file Ns | Ns device
60 the loopback file driver.
62 allows a file to be associated with a block device. That file can then be
63 accessed through the block device. This is useful when the file contains an
64 image of some filesystem (such as a floppy or
66 image), because the block device can then be used with the normal system
67 utilities for mounting, checking or repairing filesystems. See
74 to add a file as a loopback device, remove such an
75 association, or print information about the current associations.
77 Encryption and compression options are mutually exclusive on the command line.
78 Further, an encrypted file cannot be compressed later, nor can a compressed
79 file be encrypted later.
83 can be used on both the global
84 zone devices and all devices owned by other non-global zones on the system.
86 If the command line flag,
88 is used while creating a loopack device,
90 will create a labeled loopback
91 device, and will generate device links in
93 directories for partitions or slices.
95 Before using these devices, users should create or verify
96 partitioning by using partition management tools such as
99 Once the device has been appropriately partitioned, the labeled
100 device can be used as normal disk to create and mount file systems and to store
101 data. Mappings created by
103 are not permanent and not persisted by the system. If power is lost or the system
104 is rebooted, then the mappings will need to be created again.
106 The partition table requires space from the mapped file.
108 does not support converting previously created unlabeled loopback device images
109 to labeled loopback devices. If an unlabeled device is used as a labeled device,
110 writing to it will corrupt it.
112 The following options are supported:
114 .It Fl a Ar file Op Ar device
121 is not specified, an available device is picked.
127 attempts to assign it to
132 will fail. The ability to specify a device is provided for use in scripts that
133 wish to reestablish a particular set of associations.
134 A device may not be specified when using a labeled lofi device.
135 .It Fl C Ar {gzip | gzip-N | lzma}
136 Compress the file with the specified compression algorithm.
140 compression algorithm uses the same compression as the open-source
142 command. You can specify the
144 level by using the value gzip-\fR\fIN\fR where \fIN\fR is 6 (fast) or 9
145 (best compression ratio). Currently,
147 without a number, is equivalent to
149 (which is also the default for the
154 stands for the LZMA (Lempel-Ziv-Markov) compression algorithm.
156 Note that you cannot write to a compressed file, nor can you mount a compressed
158 .It Fl d Ar file Ns | Ns Ar device
159 Remove an association by
163 name, if the associated block device is not busy, and deallocates the block
166 This option should be used with
168 option to create labeled loopback device. If created in local zone, the device
169 has to be enabled in zone configuration.
173 option is specified before the
177 will be opened read-only.
178 .It Fl s Ar segment_size
179 The segment size to use to divide the file being compressed.
181 can be an integer multiple of 512.
183 Uncompress a compressed file.
186 The following options are used when the file is encrypted:
188 .It Fl c Ar crypto_algorithm
189 Select the encryption algorithm. The algorithm must be specified when
190 encryption is enabled because the algorithm is not stored in the disk image.
199 prompts for a passphrase, with a minimum length of eight characters, to be
201 The passphrase is used to derive a symmetric encryption key using PKCS#5 PBKD2.
202 .It Fl k Ar raw_key_file | Ar wrapped_key_file
203 Path to raw or wrapped symmetric encryption key. If a PKCS#11 object is also
206 option, then the key is wrapped by that object. If
208 is not specified, the key is used raw.
209 .It Fl T Ar token_key
210 The key in a PKCS#11 token to use for the encryption or for unwrapping the key
217 identifies the unwrapping key, which must be an RSA private key.
219 Generate an ephemeral symmetric encryption key.
222 The following operands are supported:
224 .It Ar crypto_algorithm
232 Display the file name associated with the block device
235 Without arguments, print a list of the current associations. Filenames must be
236 valid absolute pathnames.
238 When a file is added, it is opened for reading or writing by root. Any
239 restrictions apply (such as restricted root access over
241 The file is held open until the association is removed. It is not actually
242 accessed until the block device is used, so it will never be written to if the
243 block device is only opened read-only.
245 Note that the filename may appear as "?" if it is not possible to resolve the
246 path in the current context (for example, if it's an NFS path in a non-global
249 Display the block device associated with
252 Path to a file of the appropriate length, in bits, to use as a raw symmetric
255 PKCS#11 token object in the format:
257 .Ar token_name Ns : Ns Ar manufacturer_id Ns : Ns Ar serial_number Ns : Ns Ar key_label
259 All but the key label are optional and can be empty. For example, to specify a
260 token object with only its key label
264 .Fl T Ar ::: Ns Ar MylofiKey
265 .It Ar wrapped_key_file
266 Path to file containing a symmetric encryption key wrapped by the RSA private
273 for descriptions of the following environment variables
274 that affect the execution of
282 The following exit values are returned:
285 Successful completion.
291 .It Sy Example 1 No Mounting an Existing CD-ROM Image
292 You should ensure that Solaris understands the image before creating the
295 allows you to mount the image and see if it works.
297 This example mounts an existing
300 .Pf ( Sy sparc.iso Ns ),
303 which was downloaded from the Internet. It was created
306 utility from the Internet.
310 to attach a block device to it:
312 # lofiadm -a /home/mike_s/RH6.0/sparc.iso
317 picks the device and prints the device name to the standard
320 again by issuing the following command:
323 Block Device File Options
324 /dev/lofi/1 /home/mike_s/RH6.0/sparc.iso -
327 Or, you can give it one name and ask for the other, by issuing the following
330 # lofiadm /dev/lofi/1
331 /home/mike_s/RH6.0/sparc.iso
336 command to mount the image:
338 # mount -F hsfs -o ro /dev/lofi/1 /mnt
341 Check to ensure that Solaris understands the image:
344 Filesystem kbytes used avail capacity Mounted on
345 /dev/lofi/1 512418 512418 0 100% /mnt
347 \&./ RedHat/ doc/ ls-lR rr_moved/
348 \&../ TRANS.TBL dosutils/ ls-lR.gz sbin@
349 \&.buildlog bin@ etc@ misc/ tmp/
350 COPYING boot/ images/ mnt/ usr@
351 README boot.cat* kernels/ modules/
352 RPM-PGP-KEY dev@ lib@ proc/
355 Solaris can mount the CD-ROM image, and understand the filenames. The image was
356 created properly, and you can now create the
360 As a final step, unmount and detach the images:
363 # lofiadm -d /dev/lofi/1
365 Block Device File Options
367 .It Sy Example 2 No Mounting a Floppy Image
368 This is similar to the first example.
372 to help you mount files that contain floppy images is helpful
373 if a floppy disk contains a file that you need, but the machine which you are
374 on does not have a floppy drive. It is also helpful if you do not want to take
377 command to copy the image to a floppy.
379 This is an example of getting to
381 floppy for Solaris on an x86 platform:
383 # lofiadm -a /export/s28/MDB_s28x_wos/latest/boot.3
385 # mount -F pcfs /dev/lofi/1 /mnt
387 \&./ COMMENT.BAT* RC.D/ SOLARIS.MAP*
388 \&../ IDENT* REPLACE.BAT* X/
389 APPEND.BAT* MAKEDIR.BAT* SOLARIS/
391 # lofiadm -d /export/s28/MDB_s28x_wos/latest/boot.3
393 .It Sy Example 3 No Making a Sy UFS No Filesystem on a File
396 filesystem on a file can be useful, particularly if a test
397 suite requires a scratch filesystem. It can be painful (or annoying) to have to
398 repartition a disk just for the test suite, but you do not have to. You can
405 # mkfile 35m /export/home/test
408 Attach it to a block device. You also get the character device that
414 # lofiadm -a /export/home/test
417 newfs: construct a new file system /dev/rlofi/1: (y/n)? y
418 /dev/rlofi/1: 71638 sectors in 119 cylinders of 1 tracks, 602 sectors
419 35.0MB in 8 cyl groups (16 c/g, 4.70MB/g, 2240 i/g)
420 super-block backups (for fsck -F ufs -o b=#) at:
421 32, 9664, 19296, 28928, 38560, 48192, 57824, 67456,
426 might not be able to use the entire file. Mount and use the filesystem:
428 # mount /dev/lofi/1 /mnt
430 Filesystem kbytes used avail capacity Mounted on
431 /dev/lofi/1 33455 9 30101 1% /mnt
435 # lofiadm -d /dev/lofi/1
437 .It Sy Example 4 No Creating a PC (FAT) File System on a Unix File
438 The following series of commands creates a
440 file system on a Unix file. The file is associated with a block device created by
444 # mkfile 10M /export/test/testfs
445 # lofiadm -a /export/test testfs
453 in following command.
455 # mkfs -F pcfs -o nofdisk,size=20480 /dev/rlofi/1
456 Construct a new FAT file system on /dev/rlofi/1: (y/n)? y
457 # mount -F pcfs /dev/lofi/1 /mnt
460 Filesystem kbytes used avail capacity Mounted on
461 /dev/lofi/1 10142 0 10142 0% /mnt
463 .It Sy Example 5 No Compressing an Existing CD-ROM Image
464 The following example illustrates compressing an existing CD-ROM image
465 .Pf ( Sy solaris.iso Ns ),
466 verifying that the image is compressed, and then uncompressing it.
468 # lofiadm -C gzip /export/home/solaris.iso
473 to attach a block device to it:
475 # lofiadm -a /export/home/solaris.iso
479 Check if the mapped image is compressed:
482 Block Device File Options
483 /dev/lofi/1 /export/home/solaris.iso Compressed(gzip)
484 /dev/lofi/2 /export/home/regular.iso -
487 Unmap the compressed image and uncompress it:
489 # lofiadm -d /dev/lofi/1
490 # lofiadm -U /export/home/solaris.iso
492 .It Sy Example 6 No Creating an Encrypted UFS File System on a File
493 This example is similar to the example of making a UFS filesystem on a file,
498 # mkfile 35m /export/home/test
501 Attach the file to a block device and specify that the file image is encrypted.
502 As a result of this command, you obtain the character device, which is
506 # lofiadm -c aes-256-cbc -a /export/home/secrets
507 Enter passphrase: My-M0th3r;l0v3s_m3+4lw4ys! (not echoed)
508 Re-enter passphrase: My-M0th3r;l0v3s_m3+4lw4ys! (not echoed)
512 newfs: construct a new file system /dev/rlofi/1: (y/n)? y
513 /dev/rlofi/1: 71638 sectors in 119 cylinders of 1 tracks, 602 sectors
514 35.0MB in 8 cyl groups (16 c/g, 4.70MB/g, 2240 i/g)
515 super-block backups (for fsck -F ufs -o b=#) at:
516 32, 9664, 19296, 28928, 38560, 48192, 57824, 67456,
519 The mapped file system shows that encryption is enabled:
522 Block Device File Options
523 /dev/lofi/1 /export/home/secrets Encrypted
526 Mount and use the filesystem:
528 # mount /dev/lofi/1 /mnt
529 # cp moms_secret_*_recipe /mnt
531 \&./ moms_secret_cookie_recipe moms_secret_soup_recipe
532 \&../ moms_secret_fudge_recipe moms_secret_stuffing_recipe
533 lost+found/ moms_secret_meatloaf_recipe moms_secret_waffle_recipe
535 # lofiadm -d /dev/lofi/1
538 Subsequent attempts to map the filesystem with the wrong key or the wrong
539 encryption algorithm will fail:
541 # lofiadm -c blowfish-cbc -a /export/home/secrets\fR
542 Enter passphrase: mommy (not echoed)
543 Re-enter passphrase: mommy (not echoed)
544 lofiadm: could not map file /root/lofi: Invalid argument
546 Block Device File Options
550 Attempts to map the filesystem without encryption will succeed, however
551 attempts to mount and use the filesystem will fail:
553 # lofiadm -a /export/home/secrets
556 Block Device File Options
557 /dev/lofi/1 /export/home/secrets -
558 # mount /dev/lofi/1 /mnt
559 mount: /dev/lofi/1 is not this fstype
574 Just as you would not directly access a disk device that has mounted file
575 systems, you should not access a file associated with a block device except
578 file driver. It might also be appropriate to ensure that
579 the file has appropriate permissions to prevent such access.
583 , and who can use them, are controlled by the
586 Read-access allows query operations, such as
587 listing all the associations. Write-access is required to do any state-changing
588 operations, like adding an association. As shipped,
596 so all users can do query operations but only root can change anything.
597 The administrator can give users write-access, allowing them to add or
598 delete associations, but that is very likely a security hole and should
599 probably only be given to a trusted group.
601 When mounting a filesystem image, take care to use appropriate mount options.
604 mount option might be appropriate for
606 images whose origin is unknown. Also, some options might not be useful or
613 For compatibility purposes, a raw device is also exported along with the block
620 (without arguments) might change in future releases.