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