- Linux Shell Scripting Cookbook(Third Edition)
- Clif Flynt Sarath Lakshman Shantanu Tushar
- 162字
- 2021-07-09 19:46:33
Creating partitions inside loopback images
Suppose we want to create a loopback file, partition it, and finally mount a sub-partition. In this case, we cannot use mount -o loop. We must manually set up the device and mount the partitions in it.
To partition a file of zeros:
# losetup /dev/loop1 loopback.img # fdisk /dev/loop1
fdisk is a standard partitioning tool on Linux systems. A very concise tutorial on creating partitions using fdisk is available at http://www.tldp.org/HOWTO/Partition/fdisk_partitioning.html (make sure to use /dev/loop1 instead of /dev/hdb in this tutorial).
Create partitions in loopback.img and mount the first partition:
# losetup -o 32256 /dev/loop2 loopback.img
Here, /dev/loop2 represents the first partition,-o is the offset flag, and 32256 bytes are for a DOS partition scheme. The first partition starts 32256 bytes from the start of the hard disk.
We can set up the second partition by specifying the required offset. After mounting, we can perform all regular operations as we can on physical devices.