作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在/tmp 文件夹中设置了 5 个带有备份文件的循环设备作为原始 40 MB 文件。
$ losetup -l
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE
/dev/loop1 0 0 1 0 /tmp/1
/dev/loop2 0 0 0 0 /tmp/2
/dev/loop3 0 0 0 0 /tmp/3
/dev/loop4 0 0 0 0 /tmp/4
/dev/loop5 0 0 0 0 /tmp/5
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 100M 0 part /boot/efi
├─sda2 8:2 0 900M 0 part
├─sda3 8:3 0 128M 0 part
├─sda4 8:4 0 372.6G 0 part
├─sda5 8:5 0 140.5G 0 part /
├─sda6 8:6 0 15G 0 part
├─sda7 8:7 0 186.3G 0 part
├─sda8 8:8 0 37.3G 0 part [SWAP]
├─sda9 8:9 0 93.1G 0 part
└─sda10 8:10 0 40.8G 0 part
loop1 7:1 0 78.1M 0 loop
├─vol_vg-raid4_rmeta_0 252:0 0 4M 0 lvm
│ └─vol_vg-raid4 252:8 0 48M 0 lvm
└─vol_vg-raid4_rimage_0 252:1 0 16M 0 lvm
└─vol_vg-raid4 252:8 0 48M 0 lvm
loop2 7:2 0 78.1M 0 loop
├─vol_vg-raid4_rmeta_1 252:2 0 4M 0 lvm
│ └─vol_vg-raid4 252:8 0 48M 0 lvm
└─vol_vg-raid4_rimage_1 252:3 0 16M 0 lvm
└─vol_vg-raid4 252:8 0 48M 0 lvm
loop3 7:3 0 78.1M 0 loop
├─vol_vg-raid4_rmeta_2 252:4 0 4M 0 lvm
│ └─vol_vg-raid4 252:8 0 48M 0 lvm
└─vol_vg-raid4_rimage_2 252:5 0 16M 0 lvm
└─vol_vg-raid4 252:8 0 48M 0 lvm
loop4 7:4 0 78.1M 0 loop
├─vol_vg-raid4_rmeta_3 252:6 0 4M 0 lvm
│ └─vol_vg-raid4 252:8 0 48M 0 lvm
└─vol_vg-raid4_rimage_3 252:7 0 16M 0 lvm
└─vol_vg-raid4 252:8 0 48M 0 lvm
$ sudo losetup -d /dev/loop1
shehbaz@donjaffer:~$
$ losetup -l
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE
/dev/loop1 0 0 1 0 /tmp/1
/dev/loop2 0 0 0 0 /tmp/2
/dev/loop3 0 0 0 0 /tmp/3
/dev/loop4 0 0 0 0 /tmp/4
/dev/loop5 0 0 0 0 /tmp/5
shehbaz@donjaffer:~$
$ sudo strace losetup -d /dev/loop1
execve("/sbin/losetup", ["losetup", "-d", "/dev/loop1"], [/* 17 vars */]) = 0
brk(0) = 0x1985000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc13f271000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=108331, ...}) = 0
mmap(NULL, 108331, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc13f256000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libsmartcols.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260R\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=134536, ...}) = 0
mmap(NULL, 2233952, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc13ee2e000
mprotect(0x7fc13ee4e000, 2093056, PROT_NONE) = 0
mmap(0x7fc13f04d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7fc13f04d000
mmap(0x7fc13f04f000, 1632, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc13f04f000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\v\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1869392, ...}) = 0
mmap(NULL, 3972864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc13ea64000
mprotect(0x7fc13ec24000, 2097152, PROT_NONE) = 0
mmap(0x7fc13ee24000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7fc13ee24000
mmap(0x7fc13ee2a000, 16128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc13ee2a000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc13f255000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc13f253000
arch_prctl(ARCH_SET_FS, 0x7fc13f253740) = 0
mprotect(0x7fc13ee24000, 16384, PROT_READ) = 0
mprotect(0x7fc13f04d000, 4096, PROT_READ) = 0
mprotect(0x60f000, 4096, PROT_READ) = 0
mprotect(0x7fc13f273000, 4096, PROT_READ) = 0
munmap(0x7fc13f256000, 108331) = 0
brk(0) = 0x1985000
brk(0x19a6000) = 0x19a6000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=7216688, ...}) = 0
mmap(NULL, 7216688, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc13e382000
close(3) = 0
stat("/sys/block", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
uname({sys="Linux", node="donjaffer", ...}) = 0
stat("/dev/loop-control", {st_mode=S_IFCHR|0660, st_rdev=makedev(10, 237), ...}) = 0
stat("/dev/loop1", {st_mode=S_IFBLK|0660, st_rdev=makedev(7, 1), ...}) = 0
open("/dev/loop1", O_RDONLY|O_CLOEXEC) = 3
ioctl(3, LOOP_CLR_FD) = 0
close(3) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
+++ exited with 0 +++
shehbaz@donjaffer:~$
$ umount -l /dev/loop1
umount: /dev/loop1: not mounted
shehbaz@donjaffer:~$
最佳答案
关于上述 Tom hale 代码片段的重要说明:
bash 脚本中使用的lostup 命令对IFS 的值敏感。
试试这个来亲眼看看:
line="/dev/loop8 /somefile"
losetup $line # this works
IFS=""
losetup $line # this one will fail
关于device-driver - Lostup -d 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34093405/
我在/tmp 文件夹中设置了 5 个带有备份文件的循环设备作为原始 40 MB 文件。 $ losetup -l NAME SIZELIMIT OFFSET AUTOCLEAR RO BA
我是一名优秀的程序员,十分优秀!