Documentation of filesite.io.
https://filesite.io
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.1 KiB
74 lines
1.1 KiB
2 years ago
|
|
||
|
# CentOS 7如何创建loop设备读取iso磁盘镜像文件内容?
|
||
|
|
||
|
|
||
|
## 创建loop device虚拟设备
|
||
|
|
||
|
假设你的iso磁盘镜像文件名为:test.iso
|
||
|
|
||
|
```
|
||
|
losetup -fP test.iso
|
||
|
```
|
||
|
|
||
|
如果没有,可以用下面命令创建一个1G大小的空文件:
|
||
|
```
|
||
|
dd if=/dev/zero of=test.iso bs=1M count=1024
|
||
|
```
|
||
|
|
||
|
|
||
|
查看新创建的虚拟设备:
|
||
|
|
||
|
```
|
||
|
losetup -a
|
||
|
```
|
||
|
|
||
|
|
||
|
## 挂载虚拟设备到指定目录
|
||
|
|
||
|
假设你的系统之前没有loop device,新创建的为/dev/loop0
|
||
|
|
||
|
```
|
||
|
mkdir /mnt/test
|
||
|
mount -o loop /dev/loop0 /mnt/test
|
||
|
```
|
||
|
|
||
|
查看挂载结果:
|
||
|
|
||
|
```
|
||
|
df -Th
|
||
|
```
|
||
|
|
||
|
|
||
|
## 进入iso磁盘
|
||
|
|
||
|
挂载成功后,就可以像普通目录一样进入iso文件内部了:
|
||
|
|
||
|
```
|
||
|
cd /mnt/test
|
||
|
ls -l
|
||
|
```
|
||
|
|
||
|
|
||
|
## 卸载虚拟设备
|
||
|
|
||
|
```
|
||
|
umount /mnt/test
|
||
|
```
|
||
|
|
||
|
|
||
|
## 删除loop device虚拟设备
|
||
|
|
||
|
```
|
||
|
losetup -d /dev/loop0
|
||
|
```
|
||
|
|
||
|
|
||
|
掌握了loop device虚拟设备的创建、挂载、卸载和删除,
|
||
|
就可以在linux中读取网上下载的iso磁盘镜像文件内容了,
|
||
|
如软件光盘、视频DVD文件等。
|
||
|
|
||
|
|
||
|
|
||
|
## 参考
|
||
|
> https://www.thegeekdiary.com/how-to-create-virtual-block-device-loop-device-filesystem-in-linux/
|