losstup /dev/loop0은 잠시 후 사라집니다.

losstup /dev/loop0은 잠시 후 사라집니다.

현재 저는 루프 장치를 사용하여 Linux/Ubuntu에서 몇 가지 테스트를 수행하고 있습니다. 작은 테스트 스크립트에는 다음 명령이 있습니다.

#!/bin/sh
rm testfile.x
dd if=/dev/zero of=testfile.x bs=1M count=1200
losetup /dev/loop0 testfile.x
cryptsetup --batch-mode --key-file k.kf --cipher aes-xts-plain64 --key-size 512 --hash sha512 --iter-time 5000 --use-random luksFormat /dev/loop0
losetup -d /dev/loop0

이제 내 질문은 다음과 같습니다.

때때로스크립트가 실행되는 동안 루프 장치가 (마법처럼) 사라지기 때문에 cryptsetup 행이 실패합니다.

오류가 발생합니다.

장치 /dev/loop0이 너무 작습니다.

그렇다면 이를 방지/비활성화할 수 있는 방법이 있습니까?

업데이트 1:

내 스크립트의 전체 출력은 다음과 같습니다(2회 실행: 1회 성공, 1회 실패).

root@test:/home/tester/test# ./x.sh
1200+0 records in
1200+0 records out
1258291200 bytes (1.3 GB) copied, 0.954065 s, 1.3 GB/s
Device /dev/loop0 is too small.
loop: can't delete device /dev/loop0: No such device or address
root@test:/home/tester/test# ./x.sh
1200+0 records in
1200+0 records out
1258291200 bytes (1.3 GB) copied, 0.953886 s, 1.3 GB/s

업데이트 2:

count100(~105MB) 으로 변경하면 dd문제가 없습니다(10번 테스트 성공). 따라서 자동 지우기/시간 초과 등이 있어야 합니다.

업데이트 3(해결책):

#!/bin/sh                   
FILE=testfile.x                 
cryptsetup --batch-mode --key-file k.kf --cipher aes-xts-plain64 --key-size 512 --hash sha512 --iter-time 5000 --use-random luksFormat $FILE
cryptsetup luksOpen -d k.kf $FILE hellohello
cryptsetup luksClose hellohello

@frostschutz 덕분에 버그 없이 작동합니다.

답변1

순환 장비에 몇 가지 결함이 있습니다. 많은 작업은 즉각적이지 않습니다. 예를 들어 losetup -d장치를 순환하면 더 이상 사용하지 않을 때까지 활성 상태로 유지됩니다. 모르더라도 백그라운드 프로세스가 장치에서 uuid 및 기타 사항을 검색하기 때문에 장치가 사용 중일 수 있습니다.

losetup를 사용하여 루핑 장치를 선택해야 할 수도 있습니다 --find --show. 어떤 이유로든 하나의 순환 장치를 사용할 수 없는 경우 다른 순환 장치를 선택해야 합니다. 그런 다음 스크립트를 조정하여 변수에 저장해야 합니다.

lodev=$(losetup --find --show textfile.x)
cryptsetup ... $lodev

cryptsetup자신만의 루핑 장치를 만드는 것도 가능하므로, 완전히 버리고 파일 자체를 losetup사용할 수 있습니다. cryptsetup이렇게 하면 오류가 덜 발생할 것입니다.

cryptsetup ... testfile.x

이는 또한 적용되며 luksOpen루프 장치는 luksClose더 이상 사용되지 않을 때까지 그대로 유지됩니다.

관련 정보