Create Linux Loopback File System On Disk File

本文介绍如何使用Linux的循环设备特性,在普通文件上创建Linux循环文件系统,而非直接使用磁盘分区。步骤包括创建虚拟磁盘文件、设置循环设备、创建EXT3文件系统并挂载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Create Linux Loopback File System On Disk File – Walker News

http://www.walkernews.net/2007/07/01/create-linux-loopback-file-system-on-disk-file/

Can you create a Linux file system without using partition DIRECTLY – sort of file system within file system management?

The answer is certainly YES!

With a loopback device in Linux (a feature that’s not natively available in Windows Vista and its predecessors) one can easily create a Linux loopback file system on a regular disk file, and not directly using a disk partition!

How to create a Linux loopback file system with a regular disk file?
To complete this Linux tricks, you need to login with a root user ID for all the steps given below

  1. Type dd if=/dev/zero of=/virtualfs bs=1024 count=30720 to create a 30MB disk file (zero-filled) called virtualfs in the root (/) directory
  2. Type losetup /dev/loop0 to confirm that the current system is not using any loopback devices. Replace /dev/loop0 with /dev/loop1, /dev/loop2, etc, until a free Linux loopback device is found. In this case, let’s assume that /dev/loop0 is free for usage
  3. Tpye losetup /dev/loop0 /virtualfs to attach the first Linux loopback device (/dev/loop0) with regular disk file (/virtualfs) created in step 1
  4. Type echo $? to confirm the previous step is completed successfully without error – a zero will be returned to indicate success. Alternative, type losetup /dev/loop0 to confirm
  5. Type mkfs -t ext3 -m 1 -v /dev/loop0 to create a Linux EXT3 file system with 1% reserved block count on the loopback device that’s currently associated with a regular disk file. Hence, we are creating a file system within file system, or creating a file system (mkfs) without using a disk partition directly
  6. Type mkdir /mnt/vfs to create a directory (as mount point) in /mnt
  7. Type mount -t ext3 /dev/loop0 /mnt/vfs to mount the loopback device (regular disk file) to /mnt/vfs as a “regular” Linux EXT3 file system! Now, all the Linux file system-related commands can be act on this unusual Linux file system. For example, you can type df -h to confirm its “disk usage”, type tune2fs -l /dev/loop0 to print its file system settings, create / remove files or directories, etc.
  8. To un-mount the loopback file system, type umount /mnt/vfs follow with losetup -d /dev/loop0 to effectively remove the loopback file system and release loopback device subsequently.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值