Loopback Device: Difference between revisions

Jump to navigation Jump to search
m
Formatting.
[unchecked revision][unchecked revision]
No edit summary
m (Formatting.)
Line 1:
A Loopback Device is a mechanism used to interpret files as real devices. The main advantage of this method is that all tools used on real disks can be used with a loopback device.
 
Note: This article only covers UNIX environments (including [[Cygwin]]). For information on how to use loopback devices on Windows, see [http://wiki.osdev.org/[Windows_Tools#diskpart | diskpart]].
 
== Loopback Device under Linux==
Line 46:
setup (fd0)
 
NOTE: You must unmount /mnt/myfloppy before using a emulator to directly read /dev/loop0, such as.:
 
qemu -fda /dev/loop0
 
NOTE: When deleting the loop device, the original floppy.img file will be saved with the modified contents.
 
=== Floppy Disk Images With FAT16 ===
 
First, lets createCreate an empty image.
dd if=/dev/zero of=floppy.img bs=512 count=2880
 
Now, lets setSet it up for mounting.
 
losetup /dev/loop0 floppy.img
 
Now lets makeMake it MSDOS formatted.
 
mkdosfs /dev/loop0
Line 185:
For ext2fs, use:
 
mke2fs -b1024 /dev/loop0 #blocks
 
Explanation:
Line 209:
For FAT32, use:
 
mkdosfs -F32 /dev/loop0 #blocks
 
Explanation:
Line 239:
mount -text2 /dev/loop0 /mnt/wherever
 
or:
 
mount -tvfat /dev/loop0 /mnt/wherever
 
Explanation:
{| {{Wikitable}}
mount Linux command to mount a filesystem
|-
-text2/-tvfat Filesystem being used, Linux can usually figure this out on its own.
| mount
/dev/loop0 The device representing our PARTITION
/mnt/wherever| ALinux directorycommand to mount thea partition on.filesystem
|-
| -text2 / -tvfat
-text2/-tvfat| Filesystem being used, Linux can usually figure this out on its own.
|-
| /dev/loop0
/dev/loop0| The device representing our PARTITIONpartition
|-
| /mnt/wherever
| A directory to mount the partition on.
|}
 
This should leave you with a nicely mounted partition. If you run df -Th you should end up with a line similar to:
Line 254 ⟶ 264:
/dev/loop0 vfat 492M 4.0K 492M 1% /mnt/wherever
 
...or for ext2fs...:
 
Filesystem Type Size Used Avail Use% Mounted on
Line 271 ⟶ 281:
 
Explanation:
{| {{Wikitable}}
umount Linux command to unmount a filesystem.
|-
/dev/loop0 The device that was mounted
| umount
mount| Linux command to mountunmount a filesystem.
|-
| /dev/loop0
/dev/loop0| The device that was mounted
|}
 
==== Making it Easier ====
Line 278 ⟶ 294:
One final thing to do, which is to simplify mounting and unmounting that partition.
 
Command:
Mounting:
 
mount -text2 -oloop=/dev/loop0,offset=32256 /path/to/c.img /mnt/wherever
 
Unmounting:
 
umount /path/to/c.img
 
Explanation:
 
This is essentially a combination of the losetup and mount commands we used previously when formatting the partition. If used it also means we lose access to the raw 'disk' or 'partition' through /dev/loop0.
Line 293 ⟶ 306:
See also http://www.pixelbeat.org/scripts/lomount.sh
 
Finally, if you have to mount and umount that image very frequently and you're too lazy to type the sudo password each time, just add to /etc/fstab:
 
/path/to/c.img /mnt/wherever ext2 user,loop 0 0
now you can just
 
now you can just call:
 
mount /mnt/wherever
umount /mnt/wherever
Line 305 ⟶ 321:
 
Things to remember:
 
losetup type command will give you the equivalent of a raw disk device (Eg /dev/hda)
losetup* -olosetup type command will give you the equivalent of a raw partitiondisk device (Eg /dev/hda1hda)
* losetup -o type command will give you the equivalent of a raw diskpartition device (Eg /dev/hdahda1)
 
== Loopback Device under FreeBSD ==
448

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu