losetup
rose1 发表于 2020-09-27 08:59浏览次数:
在Linux操作系统上,Lostup命令设置并控制循环设备。
On Linux operating systems, the losetup command sets up and controls loop devices.
目录:
1 losetup 运行系统环境
2 losetup 语法
3 losetup 选件
4 losetup 加密
5 losetup 退出状态
6 losetup 局限性
7 losetup 例子
losetup 运行系统环境
losetup 语法
losetup loopdev
losetup -a
losetup -j file [-o offset]
losetup -d loopdev...
losetup -f
losetup [{-e|-E} encryption] [-o offset] [--sizelimit size] [-p pfd]
[-r] {-f[--show]|loopdev} file
losetup -c loopdev
losttup用于将循环设备与常规文件或块设备关联,分离循环设备并查询循环设备的状态。
循环设备,也称为vnd(vnode磁盘)或lofi(环回文件接口)是使文件可作为块设备访问的伪设备。
如果仅给出loopdev参数,则显示相应循环设备的状态。
losetup loopdev
losetup -a
losetup -j file [-o offset]
losetup -d loopdev...
losetup -f
losetup [{-e|-E} encryption] [-o offset] [--sizelimit size] [-p pfd]
[-r] {-f[--show]|loopdev} file
losetup -c loopdev
losetup is used to associate loop devices with regular files or block devices, to detach loop devices and to query the status of a loop device.
A loop device, also known as vnd (vnode disk) or lofi (loopback file interface) is a pseudo-device that makes a file accessible as a block device.
If only the loopdev argument is given, the status of the corresponding loop device is shown.
losetup 选件
大小和偏移量参数后可以跟二进制(2 ^ N)后缀KiB,MiB,GiB,TiB,PiB和EiB(“ iB”是可选的,例如,“ K”的含义与“ KiB”相同)或十进制(10 ^ N)后缀KB,MB,GB,PB和EB。
-a, --all
|
显示所有回路设备的状态
|
-c, --set-capacity loopdev
|
强制循环驱动程序重新读取与指定循环设备关联的文件的大小
|
-d, --detach loopdev...
|
分离与指定循环设备关联的文件或设备
|
-e, -E, --encryption encryption_type
|
启用具有指定名称或编号的数据加密
|
-f, --find
|
查找第一个未使用的环路设备。如果存在文件参数,请使用此设备。否则,请打印其名称。
|
-h, --help
|
打印帮助
|
-j, --associated file
|
显示与给定文件关联的所有循环设备的状态
|
-k, --keybits num
|
将密钥中使用的位数设置为num。
|
-N, --nohashpass
|
不要哈希密码。默认情况下,Debian系统通过哈希函数运行密码,而非Debian系统可能不会。
|
-o, --offset offset
|
数据开始将偏移字节移到指定的文件或设备中
|
--sizelimit size
|
数据开始后,数据结束设置为不超过大小字节
|
-r, --read-only
|
设置只读循环设备
|
--show
|
如果存在-f选项和文件参数,则打印设备名称。不建议使用此选项的缩写形式(-s)。这种简短形式可能与Loop- AES实现冲突,后者对--sizelimit使用相同的选项。
|
The size and offset arguments may be followed by binary (2^N) suffixes KiB, MiB, GiB, TiB, PiB, and EiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB") or decimal (10^N) suffixes KB, MB, GB, PB, and EB.
-a, --all
|
show status of all loop devices
|
-c, --set-capacity loopdev
|
force loop driver to reread size of the file associated with the specified loop device
|
-d, --detach loopdev...
|
detach the file or device associated with the specified loop device(s)
|
-e, -E, --encryption encryption_type
|
enable data encryption with specified name or number
|
-f, --find
|
find the first unused loop device. If a file argument is present, use this device. Otherwise, print its name.
|
-h, --help
|
print help
|
-j, --associated file
|
show status of all loop devices associated with given file
|
-k, --keybits num
|
set the number of bits to use in key to num.
|
-N, --nohashpass
|
Do not hash the password. By default, Debian systems run the password through a hash function, non-Debian systems may not.
|
-o, --offset offset
|
the data start is moved offset bytes into the specified file or device
|
--sizelimit size
|
the data end is set to no more than size bytes after the data start
|
-r, --read-only
|
setup read-only loop device
|
--show
|
print device name if the -f option and a file argument are present. The short form of this option (-s) is deprecated. This short form could be in collision with Loop-AES implementation where the same option is used for --sizelimit.
|
losetup 加密
可以使用-E和-e选项之一指定传输函数(用于加密 /解密或其他目的)。有两种机制可以指定所需的加密:按数字和按名称。如果通过数字指定了加密,则必须确保Linux内核知道该数字的加密,这可能是通过修补内核来实现的。始终存在的标准编号为0(不加密)和1(XOR加密)。加载(或编译到其中)cryptoloop模块时,它使用数字18。此cryptoloop模块采用任意加密类型的名称,并找到知道如何执行该加密的模块。
It is possible to specify transfer functions (for encryption/decryption or other purposes) using one of the -E and -e options. There are two mechanisms to specify the desired encryption: by number and by name. If an encryption is specified by number then one has to make sure that the Linux kernel knows about the encryption with that number, probably by patching the kernel. Standard numbers that are always present are 0 (no encryption) and 1 (XOR encryption). When the cryptoloop module is loaded (or compiled in), it uses number 18. This cryptoloop module takes the name of an arbitrary encryption type and find the module that knows how to perform that encryption.
losetup 退出状态
losetup返回退出状态的0成功,非零失败。当Lostup显示循环设备的状态时,如果未配置该设备,则返回1;如果发生错误,则返回2,该错误阻止了Lostup确定设备的状态。
losetup returns an exit status of 0 on success, nonzero on failure. When losetup displays the status of a loop device, it returns 1 if the device is not configured and 2 if an error occurred which prevented losetup from determining the status of the device.
losetup 局限性
DES加密非常缓慢。另一方面,简单的XOR方法非常薄弱。与更新算法相比,两者都被认为是不安全的。此外,某些密码可能需要许可才能使用。
不赞成使用Cryptoloop,而建议使用dm-crypt。有关更多详细信息,请参见cryptsetup。
DES encryption is painfully slow. On the other hand, the simple XORmethod is terribly weak. Both are considered insecure compared to newer algorithms. Additionally, some ciphers may require a license for you to be allowed to use them.
Cryptoloop is deprecated in favor of dm-crypt. For more details see cryptsetup.
losetup 例子
如果使用的是可加载回路设备模块,则必须首先使用以下命令加载模块:
modprobe loop
可能还需要加密模块。
modprobe des
modprobe cryptoloop
以下命令是使用循环设备的示例:
dd if=/dev/zero of=/file bs=1k count=100
losetup -e des /dev/loop0 /file
Password:
Init (up to 16 hex digits):
mkfs -t ext2 /dev/loop0 100
mount -t ext2 /dev/loop0 /mnt
...
umount /dev/loop0
losetup -d /dev/loop0
如果使用的是可加载模块,则可以使用以下命令删除该模块:
rmmod loop
If you are using the loadable loop device module, you must have the module loaded first with the command:
modprobe loop
Encryption modules may also be needed.
modprobe des
modprobe cryptoloop
The following commands are an example of using the loop device:
dd if=/dev/zero of=/file bs=1k count=100
losetup -e des /dev/loop0 /file
Password:
Init (up to 16 hex digits):
mkfs -t ext2 /dev/loop0 100
mount -t ext2 /dev/loop0 /mnt
...
umount /dev/loop0
losetup -d /dev/loop0
If you are using the loadable module, you may remove the module with the command:
rmmod loop