How to use the loop device on Unix?

L'Antre du Tryphon

schedule
2012-01-21 | 22:45h
update
2013-06-08 | 19:25h
person
www.ctheroux.com
domain
www.ctheroux.com

How to use the loop device on Unix?

The loop device on Unix lets access a file as a block device.  Disks are block devices.  So, it is possible to use a file as a disk.  The first step, create a file that will be used as a disk.

dd if=/dev/zero bs=1M count=100 of=/tmp/mydiskfile

Format your file as a file system.  If /dev/loop0 is already used, use /dev/loop1.

losetup /dev/loop0 /tmp/mydiskfile mkfs.ext4 /dev/loop0 losetup -d /dev/loop0

losetup -d /dev/loop0 deletes the loop device

mount -o loop /tmp/mydiskfile /mnt

The file /tmp/mydiskfile  can now be used as a disk with /mnt as the mount point!

Advertisement

Imprint
Responsible for the content:
www.ctheroux.com
Privacy & Terms of Use:
www.ctheroux.com
Mobile website via:
WordPress AMP Plugin
Last AMPHTML update:
23.04.2024 - 04:15:31
Privacy-Data & cookie usage: