xref: /titanic_51/usr/src/man/man1m/lofiadm.1m (revision ee4e24edd0ef9555c11f6ddc0a08fcb87f401944)
1'\" te
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]
8.Dd Jun 14, 2016
9.Dt LOFIADM 1M
10.Os
11.Sh NAME
12.Nm lofiadm
13.Nd administer files available as block devices through lofi
14.Sh SYNOPSIS
15.Nm
16.Op Fl r
17.Op Fl l
18.Fl a Ar file Op Ar device
19.Nm
20.Op Fl r
21.Fl c
22.Ar crypto_algorithm
23.Fl a
24.Ar file Op Ar device
25.Nm
26.Op Fl r
27.Fl c Ar crypto_algorithm
28.Fl k Ar raw_key_file
29.Fl a  Ar file Op Ar device
30.Nm
31.Op Fl r
32.Fl c Ar crypto_algorithm
33.Fl T Ar token_key
34.Fl a Ar file Op Ar device
35.Nm
36.Op Fl r
37.Fl c Ar crypto_algorithm
38.Fl T Ar token_key
39.Fl k Ar wrapped_key_file
40.Fl a Ar file Op Ar device
41.Nm
42.Op Fl r
43.Fl c Ar crypto_algorithm
44.Fl e
45.Fl a Ar file Op Ar device
46.Nm
47.Fl C Ar algorithm
48.Op Fl s Ar segment_size
49.Ar file
50.Nm
51.Fl d Ar file Ns | Ns Ar device
52.Nm
53.Fl U Ar file
54.Nm
55.Op Ar file Ns | Ns device
56.Sh DESCRIPTION
57.Nm
58administers
59.Sy lofi ,
60the loopback file driver.
61.Sy lofi
62allows a file to be associated with a block device. That file can then be
63accessed through the block device. This is useful when the file contains an
64image of some filesystem (such as a floppy or
65.Sy CD-ROM
66image), because the block device can then be used with the normal system
67utilities for mounting, checking or repairing filesystems. See
68.Xr fsck 1M
69and
70.Xr mount 1M .
71.Pp
72Use
73.Nm
74to add a file as a loopback device, remove such an
75association, or print information about the current associations.
76.Pp
77Encryption and compression options are mutually exclusive on the command line.
78Further, an encrypted file cannot be compressed later, nor can a compressed
79file be encrypted later.
80.Pp
81In the global zone,
82.Nm
83can be used on both the global
84zone devices and all devices owned by other non-global zones on the system.
85.Ss Labeled Devices
86If the command line flag,
87.Fl l ,
88is used while creating a loopack device,
89.Sy lofi
90will create a labeled loopback
91device, and will generate device links in
92.Pa /dev/{dsk,rdsk}
93directories for partitions or slices.
94.Pp
95Before using these devices, users should create or verify
96partitioning by using partition management tools such as
97.Xr format 1M and
98.Xr fdisk 1M .
99Once the device has been appropriately partitioned, the labeled
100device can be used as normal disk to create and mount file systems and to store
101data.  Mappings created by
102.Nm
103are not permanent and not persisted by the system. If power is lost or the system
104is rebooted, then the mappings will need to be created again.
105.Pp
106The partition table requires space from the mapped file.
107.Sy lofi
108does not support converting previously created unlabeled loopback device images
109to labeled loopback devices. If an unlabeled device is used as a labeled device,
110writing to it will corrupt it.
111.Sh OPTIONS
112The following options are supported:
113.Bl -tag -width Ds
114.It Fl a Ar file Op Ar device
115Add
116.Sy file
117as a block device.
118.Pp
119If
120.Sy device
121is not specified, an available device is picked.
122.Pp
123If
124.Sy device
125is specified,
126.Nm
127attempts to assign it to
128.Sy file .
129.Sy device
130must be available or
131.Nm
132will fail. The ability to specify a device is provided for use in scripts that
133wish to reestablish a particular set of associations.
134A device may not be specified when using a labeled lofi device.
135.It Fl C Ar {gzip | gzip-N | lzma}
136Compress the file with the specified compression algorithm.
137.Pp
138The
139.Sy gzip
140compression algorithm uses the same compression as the open-source
141.Sy gzip
142command. You can specify the
143.Sy gzip
144level by using the value gzip-\fR\fIN\fR where \fIN\fR is 6 (fast) or 9
145(best compression ratio). Currently,
146.Sy gzip ,
147without a number, is equivalent to
148.Sy gzip-6
149(which is also the default for the
150.Sy gzip
151command).
152.Pp
153.Sy lzma
154stands for the LZMA (Lempel-Ziv-Markov) compression algorithm.
155.Pp
156Note that you cannot write to a compressed file, nor can you mount a compressed
157file read/write.
158.It Fl d Ar file Ns | Ns Ar device
159Remove an association by
160.Sy file
161or
162.Sy device
163name, if the associated block device is not busy, and deallocates the block
164device.
165.It Fl l
166This option should be used with
167.Fl a
168option to create labeled loopback device. If created in local zone, the device
169has to be enabled in zone configuration.
170.It Fl r
171If the
172.Fl r
173option is specified before the
174.Fl a
175option, the
176.Sy device
177will be opened read-only.
178.It Fl s Ar segment_size
179The segment size to use to divide the file being compressed.
180.Sy segment_size
181can be an integer multiple of 512.
182.It Fl U Ar file
183Uncompress a compressed file.
184.El
185.Pp
186The following options are used when the file is encrypted:
187.Bl -tag -width Ds
188.It Fl c Ar crypto_algorithm
189Select the encryption algorithm. The algorithm must be specified when
190encryption is enabled because the algorithm is not stored in the disk image.
191.Pp
192If none of
193.Fl e ,
194.Fl k ,
195or
196.Fl T
197is specified,
198.Nm
199prompts for a passphrase, with a minimum length of eight characters, to be
200entered.
201The 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
203Path to raw or wrapped symmetric encryption key. If a PKCS#11 object is also
204given with the
205.Fl T
206option, then the key is wrapped by that object. If
207.Fl T
208is not specified, the key is used raw.
209.It Fl T Ar token_key
210The key in a PKCS#11 token to use for the encryption or for unwrapping the key
211file.
212.Pp
213If
214.Fl k
215is also specified,
216.Fl T
217identifies the unwrapping key, which must be an RSA private key.
218.It Fl e
219Generate an ephemeral symmetric encryption key.
220.El
221.Sh OPERANDS
222The following operands are supported:
223.Bl -tag -width Ds
224.It Ar crypto_algorithm
225One of:
226.Sy aes-128-cbc ,
227.Sy aes-192-cbc ,
228.Sy aes-256-cbc ,
229.Sy des3-cbc ,
230.Sy blowfish-cbc .
231.It Ar device
232Display the file name associated with the block device
233.Sy device .
234.Pp
235Without arguments, print a list of the current associations. Filenames must be
236valid absolute pathnames.
237.Pp
238When a file is added, it is opened for reading or writing by root. Any
239restrictions apply (such as restricted root access over
240.Sy NFS Ns ).
241The file is held open until the association is removed. It is not actually
242accessed until the block device is used, so it will never be written to if the
243block device is only opened read-only.
244.Pp
245Note that the filename may appear as "?" if it is not possible to resolve the
246path in the current context (for example, if it's an NFS path in a non-global
247zone).
248.It Ar file
249Display the block device associated with
250.Sy file .
251.It Ar raw_key_file
252Path to a file of the appropriate length, in bits, to use as a raw symmetric
253encryption key.
254.It Ar token_key
255PKCS#11 token object in the format:
256.Pp
257.Ar token_name Ns : Ns Ar manufacturer_id Ns : Ns Ar serial_number Ns : Ns Ar key_label
258.Pp
259All but the key label are optional and can be empty. For example, to specify a
260token object with only its key label
261.Sy MylofiKey ,
262use:
263.Pp
264.Fl T Ar ::: Ns Ar MylofiKey
265.It Ar wrapped_key_file
266Path to file containing a symmetric encryption key wrapped by the RSA private
267key specified by
268.Fl T .
269.El
270.Sh ENVIRONMENT
271See
272.Xr environ 5
273for descriptions of the following environment variables
274that affect the execution of
275.Nm
276:
277.Sy LC_CTYPE ,
278.Sy LC_MESSAGES
279and
280.Sy NLSPATH .
281.Sh EXIT STATUS
282The following exit values are returned:
283.Bl -tag -width Ds
284.It Sy 0
285Successful completion.
286.It Sy >0
287An error occurred.
288.El
289.Sh EXAMPLES
290.Bl -tag -width Ds
291.It Sy Example 1 No Mounting an Existing CD-ROM Image
292You should ensure that Solaris understands the image before creating the
293.Sy CD .
294.Sy lofi
295allows you to mount the image and see if it works.
296.Pp
297This example mounts an existing
298.Sy CD-ROM
299image
300.Pf ( Sy sparc.iso Ns ),
301of the
302.Sy Red Hat 6.0 CD
303which was downloaded from the Internet. It was created
304with the
305.Sy mkisofs
306utility from the Internet.
307.Pp
308Use
309.Nm
310to attach a block device to it:
311.Bd -literal
312# lofiadm -a /home/mike_s/RH6.0/sparc.iso
313/dev/lofi/1
314.Ed
315.Pp
316.Nm
317picks the device and prints the device name to the standard
318output. You can run
319.Nm
320again by issuing the following command:
321.Bd -literal
322# lofiadm
323Block Device     File                           Options
324/dev/lofi/1      /home/mike_s/RH6.0/sparc.iso   -
325.Ed
326.Pp
327Or, you can give it one name and ask for the other, by issuing the following
328command:
329.Bd -literal
330# lofiadm /dev/lofi/1
331/home/mike_s/RH6.0/sparc.iso
332.Ed
333.Pp
334Use the
335.Xr mount 1M
336command to mount the image:
337.Bd -literal
338# mount -F hsfs -o ro /dev/lofi/1 /mnt
339.Ed
340.Pp
341Check to ensure that Solaris understands the image:
342.Bd -literal
343# df -k /mnt
344Filesystem            kbytes    used   avail capacity  Mounted on
345/dev/lofi/1           512418  512418       0   100%    /mnt
346# ls /mnt
347\&./            RedHat/       doc/          ls-lR         rr_moved/
348\&../           TRANS.TBL     dosutils/     ls-lR.gz      sbin@
349\&.buildlog     bin@          etc@          misc/         tmp/
350COPYING       boot/         images/       mnt/          usr@
351README        boot.cat*     kernels/      modules/
352RPM-PGP-KEY   dev@          lib@          proc/
353.Ed
354.Pp
355Solaris can mount the CD-ROM image, and understand the filenames. The image was
356created properly, and you can now create the
357.Sy CD-ROM
358with confidence.
359.Pp
360As a final step, unmount and detach the images:
361.Bd -literal
362# umount /mnt
363# lofiadm -d /dev/lofi/1
364# lofiadm
365Block Device             File             Options
366.Ed
367.It Sy Example 2 No Mounting a Floppy Image
368This is similar to the first example.
369.Pp
370Using
371.Sy lofi
372to help you mount files that contain floppy images is helpful
373if a floppy disk contains a file that you need, but the machine which you are
374on does not have a floppy drive. It is also helpful if you do not want to take
375the time to use the
376.Sy dd
377command to copy the image to a floppy.
378.Pp
379This is an example of getting to
380.Sy MDB
381floppy for Solaris on an x86 platform:
382.Bd -literal
383# lofiadm -a /export/s28/MDB_s28x_wos/latest/boot.3
384/dev/lofi/1
385# mount -F pcfs /dev/lofi/1 /mnt
386# ls /mnt
387\&./            COMMENT.BAT*  RC.D/         SOLARIS.MAP*
388\&../           IDENT*        REPLACE.BAT*  X/
389APPEND.BAT*   MAKEDIR.BAT*  SOLARIS/
390# umount /mnt
391# lofiadm -d /export/s28/MDB_s28x_wos/latest/boot.3
392.Ed
393.It Sy Example 3 No Making a Sy UFS No Filesystem on a File
394Making a
395.Sy UFS
396filesystem on a file can be useful, particularly if a test
397suite requires a scratch filesystem. It can be painful (or annoying) to have to
398repartition a disk just for the test suite, but you do not have to. You can
399.Sy newfs
400a file with
401.Sy lofi .
402.Pp
403Create the file:
404.Bd -literal
405# mkfile 35m /export/home/test
406.Ed
407.Pp
408Attach it to a block device. You also get the character device that
409.Sy newfs
410requires, so
411.Sy newfs
412that:
413.Bd -literal
414# lofiadm -a /export/home/test
415/dev/lofi/1
416# newfs /dev/rlofi/1
417newfs: 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)
420super-block backups (for fsck -F ufs -o b=#) at:
421 32, 9664, 19296, 28928, 38560, 48192, 57824, 67456,
422.Ed
423.Pp
424Note that
425.Sy ufs
426might not be able to use the entire file. Mount and use the filesystem:
427.Bd -literal
428# mount /dev/lofi/1 /mnt
429# df -k /mnt
430Filesystem            kbytes    used   avail capacity  Mounted on
431/dev/lofi/1            33455       9   30101     1%    /mnt
432# ls /mnt
433\&./           ../          lost+found/
434# umount /mnt
435# lofiadm -d /dev/lofi/1
436.Ed
437.It Sy Example 4 No Creating a PC (FAT) File System on a Unix File
438The following series of commands creates a
439.Sy FAT
440file system on a Unix file. The file is associated with a block device created by
441.Nm
442.
443.Bd -literal
444# mkfile 10M /export/test/testfs
445# lofiadm -a /export/test testfs
446/dev/lofi/1
447.Ed
448.Pp
449Note use of
450.Sy rlofi ,
451not
452.Sy lofi ,
453in following command.
454.Bd -literal
455# mkfs -F pcfs -o nofdisk,size=20480 /dev/rlofi/1
456Construct a new FAT file system on /dev/rlofi/1: (y/n)? y
457# mount -F pcfs /dev/lofi/1 /mnt
458# cd /mnt
459# df -k .
460Filesystem            kbytes    used   avail capacity  Mounted on
461/dev/lofi/1            10142       0   10142     0%    /mnt
462.Ed
463.It Sy Example 5 No Compressing an Existing CD-ROM Image
464The following example illustrates compressing an existing CD-ROM image
465.Pf ( Sy solaris.iso Ns ),
466verifying that the image is compressed, and then uncompressing it.
467.Bd -literal
468# lofiadm -C gzip /export/home/solaris.iso
469.Ed
470.Pp
471Use
472.Nm
473to attach a block device to it:
474.Bd -literal
475# lofiadm -a /export/home/solaris.iso
476  /dev/lofi/1
477.Ed
478.Pp
479Check if the mapped image is compressed:
480.Bd -literal
481# lofiadm
482Block Device      File                            Options
483/dev/lofi/1       /export/home/solaris.iso        Compressed(gzip)
484/dev/lofi/2       /export/home/regular.iso        -
485.Ed
486.Pp
487Unmap the compressed image and uncompress it:
488.Bd -literal
489# lofiadm -d /dev/lofi/1
490# lofiadm -U /export/home/solaris.iso
491.Ed
492.It Sy Example 6 No Creating an Encrypted UFS File System on a File
493This example is similar to the example of making a UFS filesystem on a file,
494above.
495.Pp
496Create the file:
497.Bd -literal
498# mkfile 35m /export/home/test
499.Ed
500.Pp
501Attach the file to a block device and specify that the file image is encrypted.
502As a result of this command, you obtain the character device, which is
503subsequently used by
504.Sy newfs :
505.Bd -literal
506# lofiadm -c aes-256-cbc -a /export/home/secrets
507Enter passphrase: My-M0th3r;l0v3s_m3+4lw4ys!           (not echoed)
508Re-enter passphrase: My-M0th3r;l0v3s_m3+4lw4ys!        (not echoed)
509/dev/lofi/1
510
511# newfs /dev/rlofi/1
512newfs: 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)
515super-block backups (for fsck -F ufs -o b=#) at:
51632, 9664, 19296, 28928, 38560, 48192, 57824, 67456,
517.Ed
518.Pp
519The mapped file system shows that encryption is enabled:
520.Bd -literal
521# lofiadm
522Block Device    File                     Options
523/dev/lofi/1     /export/home/secrets     Encrypted
524.Ed
525.Pp
526Mount and use the filesystem:
527.Bd -literal
528# mount /dev/lofi/1 /mnt
529# cp moms_secret_*_recipe /mnt
530# ls /mnt
531\&./         moms_secret_cookie_recipe    moms_secret_soup_recipe
532\&../        moms_secret_fudge_recipe     moms_secret_stuffing_recipe
533lost+found/  moms_secret_meatloaf_recipe  moms_secret_waffle_recipe
534# umount /mnt
535# lofiadm -d /dev/lofi/1
536.Ed
537.Pp
538Subsequent attempts to map the filesystem with the wrong key or the wrong
539encryption algorithm will fail:
540.Bd -literal
541# lofiadm -c blowfish-cbc -a /export/home/secrets\fR
542Enter passphrase: mommy                                (not echoed)
543Re-enter passphrase: mommy                             (not echoed)
544lofiadm: could not map file /root/lofi: Invalid argument
545# lofiadm
546Block Device    File                    Options
547#
548.Ed
549.Pp
550Attempts to map the filesystem without encryption will succeed, however
551attempts to mount and use the filesystem will fail:
552.Bd -literal
553# lofiadm -a /export/home/secrets
554/dev/lofi/1
555# lofiadm
556Block Device    File                     Options
557/dev/lofi/1     /export/home/secrets     -
558# mount /dev/lofi/1 /mnt
559mount: /dev/lofi/1 is not this fstype
560#
561.Ed
562.El
563.Sh SEE ALSO
564.Xr fdisk 1M ,
565.Xr format 1M ,
566.Xr fsck 1M ,
567.Xr mount 1M ,
568.Xr mount_ufs 1M ,
569.Xr newfs 1M ,
570.Xr attributes 5 ,
571.Xr lofi 7D ,
572.Xr lofs 7FS
573.Sh NOTES
574Just as you would not directly access a disk device that has mounted file
575systems, you should not access a file associated with a block device except
576through the
577.Sy lofi
578file driver. It might also be appropriate to ensure that
579the file has appropriate permissions to prevent such access.
580.Pp
581The abilities of
582.Nm
583, and who can use them, are controlled by the
584permissions of
585.Pa /dev/lofictl .
586Read-access allows query operations, such as
587listing all the associations. Write-access is required to do any state-changing
588operations, like adding an association. As shipped,
589.Pa /dev/lofictl
590is owned by
591.Sy root ,
592in group
593.Sy sys ,
594and mode
595.Sy 0644 ,
596so all users can do query operations but only root can change anything.
597The administrator can give users write-access, allowing them to add or
598delete associations, but that is very likely a security hole and should
599probably only be given to a trusted group.
600.Pp
601When mounting a filesystem image, take care to use appropriate mount options.
602In particular, the
603.Sy nosuid
604mount option might be appropriate for
605.Sy UFS
606images whose origin is unknown. Also, some options might not be useful or
607appropriate, like
608.Sy logging
609or
610.Sy forcedirectio
611for
612.Sy UFS .
613For compatibility purposes, a raw device is also exported along with the block
614device. For example,
615.Xr newfs 1M
616requires one.
617.Pp
618The output of
619.Nm
620(without arguments) might change in future releases.
621