becker@scyld.com
;
Rick Niles,
niles@scyld.com
;
Daniel Ridge,
newt@scyld.com
;The original Linux loopback driver mounted only partition images. It
used device names ``/dev/loop0, /dev/loop1, ... /dev/loop7
''.
This extended loopback module adds support for entire disk images via
the device files ``/dev/loopa, /dev/loopb, ...
''. Once these
partition table devices are connected via the ``losetup
''
command, access is available to the partitions within the disk
via the ``/dev/loopa1, /dev/loopa2, ...
'' device files.
To loop associate the disk image ``diskimg
'' use the command:
# losetup /dev/loopa diskimgOnce this connection is made. We can access the partitions within this disk image. Examples include:
# mke2fs /dev/loopa1 # mount /dev/loopa1 /mnt/floppy
To disconnection the disk image use ``losetup
'' again:
# losetup -d /dev/loopa
To loop associate the disk image ``diskimg
'' in read-only mode
use the command:
# losetup -r /dev/loopa diskimgTo see whether a given loop association is read-only or read-write use the command:
# losetup /dev/loopaAnd the supplied output will read as:
/dev/loopa: [device]:inode (diskimg) offset 0, no encryption, read-onlyfor read-only associations and as:
/dev/loopa: [device]:inode (diskimg) offset 0, no encryption, read-writefor read-write associations.
This loopback driver is not currently backward compatible with the old
Linux loopback driver. The behavior of just ``/dev/loop0
''
will work pretty much as before. That is, ``mount -o loop foo
/mnt/bar
'' WILL work for just one loopback at a time. However,
since this module extends loopback support to include all the overhead
of a full hard disk ``/dev/loop1
'' is by Linux default minor
number 1 and thus points to the first partition on the disk pointed to
by ``/dev/loop0
'' (minor number 0). To have more of the old
style devices working with this module change the minor number of
loop1 to be the same as loopb, (loop2 -> loopc, etc.). However,
change the minor number of these devices will break the old loopback
module. Also, it's not neccessary as you can use the losetup program
and the new device names to get the same result.
This loopback driver is intended for use on 2.2.x,2.3.x versions of the
Linux kernel and is derived from the loopback driver supplied with
those kernels. For 2.0.x kernels, a loopback driver with similar
functionality exists and is maintained by the NASA Office of Inspector General.
That driver is available from
ftp://ftp.hq.nasa.gov/pub/brazil/software
.
The loopback set geometry (losetgeo) program allows someone with root permission set the cylinders, heads, and sectors values for the loopback disk device. For example:
# losetgeo -c 10 -h 16 -s 20 /dev/loopawill set loopa as well as loopa1, loopa2, ..., loopa7 to report the geometry of 10 cylinders, 16 heads, and 20 sectors to programs that that subsequently open that device.
The loopback image information (loimginfo) is a simple program made to
be SUID root. LoImgInfo will print the partition table of the disk,
similar to sending the ``p'' command in fdisk. If the file
``diskimg
'' is a file containing a disk image:
# loimginfo diskimgNOTICE: Please install at your own risk, this program has not been audited for security.
The program Partition Information (partinfo) is a simple program taken from the e2fsprogs package. It can display basic information about a partition like geometry, start and end offsets. For example:
# partinfo /dev/loopb2 /dev/hda2: h= 16 s= 63 c=39770 start= 819504 size= 2 end= 819505
The kernel module supports a read-only mode, either globally supplied (via a module parameter) or per loop association (via -r
on the losetup
command line.
Many
filesystems do not interpret 'read-only' flag in the obvious way. Filesystems
may take this flag to mean that files are non-modifiable but metadata is
fair game for updating/altering. For example, the EXT2 filesystem driver
updates certian superblock information on mount (last mount time, mount count,
etc) even when mounted read-only.
To cause all loop associations to be read-only, load the module
with module options "read_only=1". When using -r
on the losetup
command line, users are further protected by a new file masquerading facility
introduced in losetup
. When read-only associating a disk image
/foo/diskimg via losetup, the original disk image file will be renamed
/foo/.diskimg.loop for the lifespan of the association thereby helping to
protect the original file from accidental writes.
With the read-only provisions in this loopback driver, you may use the loopback driver as a protective shield on top of a real block device. With relatively low overhead and hard drive features, it feels just like the real thing.