
내 거이전 질문암호화된 스왑 파일을 추가하는 명령을 생성합니다.
# One-time setup:
fallocate -l 4G /root/swapfile.crypt
chmod 600 /root/swapfile.crypt
# On every boot:
loop=$(losetup -f)
losetup ${loop} /root/swapfile.crypt
cryptsetup open --type plain --key-file /dev/urandom ${loop} swapfile
mkswap /dev/mapper/swapfile
swapon /dev/mapper/swapfile
하지만아키텍처Linux사용체계, 스왑 파일을 자동으로 활성화하기 위해 systemd를 얻는 가장 좋은 방법을 알 수 없습니다. 시스템 교환dev-mapper-swapfile.swap
다음과 같은 유닛이 있어야 한다는 제안이 있었습니다 :
[Unit]
Description=Encrypted Swap File
[Swap]
What=/dev/mapper/swapfile
그러면 swapon
명령이 실행됩니다. 하지만 prepare 명령을 실행하는 방법을 잘 모르겠습니다 /dev/mapper/swapfile
. 다른 유닛에 대한 종속성을 선언해야 한다고 생각 dev-mapper-swapfile.swap
하지만 해당 유닛이 어떤 모습이어야 할지 잘 모르겠습니다.
답변1
다음 사항을 확인해 보세요.
- 비밀번호 테이블(5)
- [이메일 보호됨](8)
- systemd-cryptsetup-generator(8)
이는 블록 장치가 지원하는 암호화된 볼륨에 적용됩니다. 파일 지원 볼륨에서도 작동해야 합니다.
고쳐 쓰다:
이것은 나에게 효과적입니다.
# Automatically generated by systemd-cryptsetup-generator
[Unit]
Description=Cryptography Setup for %I
Documentation=man:[email protected](8) man:crypttab(5)
SourcePath=/etc/crypttab
Conflicts=umount.target
DefaultDependencies=no
BindsTo=dev-mapper-%i.device
After=systemd-readahead-collect.service systemd-readahead-replay.service
Before=umount.target
Before=cryptsetup.target
After=systemd-random-seed-load.service
[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutSec=0
ExecStart=/usr/lib/systemd/systemd-cryptsetup attach 'swap2' '/swap.test' '/dev/urandom' 'swap'
ExecStop=/usr/lib/systemd/systemd-cryptsetup detach 'swap2'
ExecStartPost=/sbin/mkswap '/dev/mapper/swap2'
이 파일을 얻는 단계:
- /etc/crypttab에 항목을 만듭니다.
swap2 /swap.test /dev/urandom swap
- 다음 명령을 실행하세요.
/usr/lib/systemd/system-generators/systemd-cryptsetup-generator
그러면 디렉터리에 유닛 파일이 생성됩니다/tmp/
. - 생성된 유닛 파일을 검색합니다.
- 그것을 열고제거하다
swap.test.device
항목After=
및 지시어BindsTo=
. 이는 정의상 파일 교환을 위한 장치가 없기 때문에 중요합니다. 이렇게 하면 유닛 파일이 시작되지 않습니다. - 유닛 파일을 다음 위치에 복사합니다.
/etc/systemd/system/
- 좋아하는 목표를 위해 활성화하세요.
답변2
이것이 내 최종 결과입니다.t-8ch의답변.
이것을 넣으세요:/etc/systemd/system/[email protected]
# Automatically generated by systemd-cryptsetup-generator
# then manually tweaked
[Unit]
Description=Cryptography Setup for %I
Documentation=man:[email protected](8) man:crypttab(5)
SourcePath=/etc/crypttab
Conflicts=umount.target
DefaultDependencies=no
BindsTo=dev-mapper-%i.device
After=systemd-readahead-collect.service systemd-readahead-replay.service
Before=umount.target
Before=cryptsetup.target
After=systemd-random-seed-load.service
[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutSec=0
ExecStart=/usr/lib/systemd/systemd-cryptsetup attach 'swapfile' '/root/swapfile.crypt' '/dev/urandom' 'swap,cipher=aes-cbc-essiv:sha256,size=256'
ExecStop=/usr/lib/systemd/systemd-cryptsetup detach 'swapfile'
ExecStartPost=/sbin/mkswap '/dev/mapper/swapfile'
이것을 넣으십시오 /etc/systemd/system/dev-mapper-swapfile.swap
:
[Unit]
Description=Encrypted Swap File
[email protected]
[email protected]
Before=swap.target
[Swap]
What=/dev/mapper/swapfile
[Install]
WantedBy=swap.target
일회성 설정(루트로)은 스왑 파일을 생성하고 향후 시작을 위해 활성화하며 즉시 사용하기 시작합니다.
fallocate -l 4G /root/swapfile.crypt
chmod 600 /root/swapfile.crypt
systemctl enable dev-mapper-swapfile.swap
systemctl start dev-mapper-swapfile.swap
명령의 크기에 fallocate
따라 스왑 파일의 크기가 결정됩니다.
/etc/crypttab
작성할 필요는 없습니다. 이는 단지 작성 방법일 뿐입니다 [email protected]
. 일단 완료되면 더 이상 필요하지 않습니다.