Anonymous user
Loopback Device: Difference between revisions
→Formatting the partition
[unchecked revision] | [unchecked revision] |
m (Missed a few..) |
|||
(11 intermediate revisions by 7 users not shown) | |||
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 [
== Loopback Device under Linux==
Line 8:
=== Floppy Disk Images With GRUB and EXT2 ===
First, lets create
dd if=/dev/zero of=floppy.img bs=512 count=2880
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 ===
dd if=/dev/zero of=floppy.img bs=512 count=2880
losetup /dev/loop0 floppy.img
mkdosfs /dev/loop0
Line 69:
mount -t msdos /dev/loop0 /mnt/myfloppy
=== Floppy Disk Images With FAT12 ===
The steps mentioned below will be useful for the BrokenThorn Entertainment tutorials
Create an empty image.
dd if=/dev/zero of=floppy.img bs=512 count=2880▼
Set it up for mounting.
Format it to FAT12.
mkdosfs -F 12 /dev/loop0
Mount!
mount /dev/loop0 /mnt -t msdos -o "fat=12"
Unmount
Destroy loopback device
losetup -d /dev/loop0
=== Hard Disk Images ===
Line 185 ⟶ 212:
For ext2fs, use:
mke2fs -b1024 /dev/loop0 #blocks
Explanation:
Line 191 ⟶ 218:
|-
| mke2fs
| Create an
|-
| -b1024
Line 203 ⟶ 230:
|}
This gives us a clean
Note: mke2fs is smart enough to figure out block size and #blocks for itself, but if you ever want to use multiple partitions you'll need to know how to use those values.
Line 209 ⟶ 236:
For FAT32, use:
mkdosfs -F32 /dev/loop0 #blocks
Explanation:
Line 239 ⟶ 266:
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▼
|-
| -text2 / -tvfat
|-
| /dev/loop0
|-
| /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 ⟶ 291:
/dev/loop0 vfat 492M 4.0K 492M 1% /mnt/wherever
...or for ext2fs
Filesystem Type Size Used Avail Use% Mounted on
Line 271 ⟶ 308:
Explanation:
{| {{Wikitable}}
|-
/dev/loop0 The device that was mounted▼
| umount
|-
| /dev/loop0
|}
==== Making it Easier ====
Line 278 ⟶ 321:
One final thing to do, which is to simplify mounting and unmounting that partition.
Mounting:
mount -text2 -oloop=/dev/loop0,offset=32256 /path/to/c.img /mnt/wherever
Unmounting:
umount /path/to/c.img
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 ⟶ 333:
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:
==== The End ====▼
/path/to/c.img /mnt/wherever ext2 user,loop 0 0
That's it, you now know how to handle hard disk images under Linux. Whilst mounted you can use it in exactly the same way you use a normal disk partition. Multiple partitions are an extension of this, just change the offset of the losetup command according to the partition you want to use (And format using the correct number of blocks).▼
now you can just call:
Things to remember:▼
losetup type command will give you the equivalent of a raw disk device (Eg /dev/hda)▼
losetup -o type command will give you the equivalent of a raw partition device (Eg /dev/hda1)▼
mount /mnt/wherever
== Loopback Device under FreeBSD ==▼
umount /mnt/wherever
▲==== The End ====
▲That's it, you now know how to handle hard disk images under Linux. Whilst mounted you can use it in exactly the same way you use a normal disk partition. Multiple partitions are an extension of this, just change the offset of the losetup command according to the partition you want to use (And format using the correct number of blocks).
▲Things to remember:
▲* losetup type command will give you the equivalent of a raw disk device (Eg /dev/hda)
▲ dd if=/dev/zero of=floppy.img bs=512 count=2880
▲* losetup -o type command will give you the equivalent of a raw partition device (Eg /dev/hda1)
▲ vnconfig vn0 floppy.img
Don't forget to flush the filesystem buffers when manipulating with files on mounted disk image. On a Unix-like system, this can be simply done by executing the <tt>sync</tt> program in your shell.
▲== Loopback Device under FreeBSD ==
▲ umount /mnt/myfloppy
FreeBSD uses mdconfig. First, use DD to create an empty floppy image (1.44 MB in size). Memdisks are allocated dynamically, and the name is displayed after the mdconfig command. This assumes that "md0" is printed.
▲Memdisks are allocated dynamically, and the name is displayed after the mdconfig command. This assumes that "md0" is printed.)
To mount:
|