Penguin
Annotated edit history of LoopDevice version 3, including all changes. View license author blame.
Rev Author # Line
1 JohnMcPherson 1 Under some OperatingSystem~s (especially [Unix]-like ones), you can mount(8) a
2 single file onto your VirtualFileSystem. There are several reasons why you might want
3 to do this:
4 * You have a cdrom [ISO] or other disk image, and want to access it
5 * You want to have access to a particular filesystem type
6 * You want to simulate a filesystem condition, such as low disk space, to test your software
7
3 MattBrown 8 !!!Example under Linux
1 JohnMcPherson 9 This is what I did to make sure to test that my software failed gracefully when
10 disk space ran out.
11
3 MattBrown 12 ! 1. Create a file containing a filesystem
1 JohnMcPherson 13 <pre>
14 ''create a 2 MB file with an ext2 filesystem''
15 $ dd if=/dev/zero of=/tmp/loop.fs bs=1M count=2
16 $ mke2fs -F /tmp/loop.fs
17 </pre>
18
3 MattBrown 19 ! 2. mount it as a loop back device (must be done as root)
1 JohnMcPherson 20 <pre>
21 ''load the loop.ko kernel module if support is not compiled into the kernel''
22 # modprobe loop
23 ''where I want it to be mounted''
24 # mount /tmp/loop.fs /mnt/directory -o loop
25 </pre>
26
27 Now /mnt/directory will only allow around 2MB (minus filesystem overhead) of data to be written to it, and then the device will be out of space.
3 MattBrown 28
29 ! 3. Determining Partition Offsets
30
31 If you're trying to mount a partition of a disk image that has been created via dd(1) or similar you will likely need to specify an offset to where the partition starts in the disk image. This offset can then be passed as an option to the mount command.
32
33 The offset can be determined by using fdisk to find out which sector the partition starts on and then multiplying that number by the sector size (which is also helpfully printed by fdisk). See the example below:
34
35 <verbatim>
36 matt@argon:~/crcnet/ecn$ fdisk -u -l ecn-base.img
37 You must set cylinders.
38 You can do this from the extra functions menu.
39
40 Disk ecn-base.img: 0 MB, 0 bytes
41 4 heads, 62 sectors/track, 0 cylinders, total 0 sectors
42 Units = sectors of 1 * 512 = 512 bytes
43
44 Device Boot Start End Blocks Id System
45 ecn-base.img1 62 250727 125333 83 Linux
46 </verbatim>
47
48 There is one partition, starting at sector 62 which equates to offset (62*512 = 31774) which can then be mounted like so:
49
50 <verbatim>
51 matt@argon:~/crcnet/ecn$ sudo mount -o loop,offset=31744 -t ext2 ecn-base.img img/
52 matt@argon:~/crcnet/ecn$ cd img/
53 matt@argon:~/crcnet/ecn/img$ ls
54 bin dev lib packages root tmp var
55 boot etc lost+found proc sbin usr var.tgz
56 </verbatim>
57
2 IanMcDonald 58 ----
59 CategoryDiskNotes

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach()