Wednesday, December 1, 2010

Loopback Filesystem

Ok, so it took quit a bit of expirimentation and FM reading, but here's the lowdown on creating loopback filesystems:

Create a file to hold the system, in my case, it's gonna be 10 megs:

peter@slacktop:~$ dd if=/dev/zero of=/home/peter/fsfile bs=1k count=10240
10240+0 records in                                                     
10240+0 records out                                                    
10485760 bytes (10 MB) copied, 0.0606135 s, 173 MB/s

Next set up the loopback system and point it at your spiffy new file:
peter@slacktop:~$ sudo /sbin/losetup /dev/loop0 /home/peter/fsfile

From here you can create and mount your filesystem:

peter@slacktop:~$ sudo /sbin/mkfs.ext2 /dev/loop0
mke2fs 1.41.8 (11-July-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
2560 inodes, 10240 blocks
512 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1280 inodes per group
Superblock backups stored on blocks:
        8193

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


peter@slacktop:~$ sudo mkdir /mnt/lo
peter@slacktop:~$ sudo mount /dev/loop0 /mnt/lo

Tada... loopback filesystem.

No comments:

Post a Comment