사용자 공간만 다시 시작

사용자 공간만 다시 시작

사용자 공간만 다시 시작할 수 있나요? 커널 이전의 모든 것을 종료하고 PID 1에서 다시 시작하는 것과 같은가요?

내 루트 btrfs 파일 시스템의 스냅샷을 만들고 해당 스냅샷으로 빠르게 부팅하고 싶습니다.

답변1

macOS의 기능에서 영감을 얻었을 수 있습니다 . 이 기능은 launchctl reboot userspace불행히도 누락되어 있지만 ( 자체 재시작을 사용할 수 있지만 이로 인해 모든 하위 키가 종료되지는 않습니다) Linux 커널의 기능을 사용하면 macOS보다 더 나은 결과를 얻을 수 있습니다.systemdsystemdsystemctl daemon-reexecreboot userspacekexec

그것이 하는 일은 모든 사용자 공간 프로세스와 모든 커널 스레드를 종료한 다음 현재 로드된(사용자가 지정한 대기까지 포함) 커널을 다시 시작하는 것입니다. 이는 부트로더가 초기화를 커널에 전달하는 순간부터 효과적으로 시작됩니다. 필요한 하드웨어 재설정 단계를 시작합니다. .

kexec(8)매뉴얼 페이지 에서 :

DESCRIPTION
       kexec  is  a system call that enables you to load and boot into another
       kernel from the currently running kernel.  kexec performs the  function
       of  the  boot loader from within the kernel. The primary difference be‐
       tween a standard system boot and a kexec boot is that the hardware ini‐
       tialization  normally  performed  by the BIOS or firmware (depending on
       architecture) is not performed during a kexec boot. This has the effect
       of reducing the time required for a reboot.

하나 있다루비 스크립트kexeckexec 매개변수를 배우고 싶지 않은 경우 사용을 단순화하고 grub 구성 파일을 구문 분석하여 다른 커널을 선택할 수도 있지만 Fedora의 새로운 기능을 이해하지 못하는 것 같습니다.부트로더 사양kexec이 경우 기본 도구를 사용하여 작업을 수행해야 합니다.

참고로 EFI의 Ubuntu 22.04에서 kexec-reboot를 실행한 결과는 다음과 같습니다.

$ sudo kexec-reboot -iv
Read GRUB configuration from /boot/grub/grub.cfg

Select a kernel to stage:

1: Ubuntu
2: Ubuntu, with Linux 5.19.0-35-generic
3: Ubuntu, with Linux 5.19.0-35-generic (recovery mode)
4: Ubuntu, with Linux 5.15.0-67-generic
5: Ubuntu, with Linux 5.15.0-67-generic (recovery mode)
6: Ubuntu, with Linux 5.15.0-58-generic
7: Ubuntu, with Linux 5.15.0-58-generic (recovery mode)

Your selection: 1
Staging Ubuntu
Staging kernel Ubuntu
Unloading previous kexec target, if any
Running /sbin/kexec -l /boot/vmlinuz-5.19.0-35-generic 
--append='root=UUID=9e994b93-047b-46a6-9a71-51dfcb4e9598 ro intel_iommu=on iommu=pt 
i915.enable_gvt=1 zswap.enabled=1 zswap.compressor=zstd resume=/dev/disk/by-
uuid/01b394fe-b29e-499c-a722-5f8d56cec3cd quiet splash $vt_handoff' --initrd=/boot
/initrd.img-5.19.0-35-generic

-r다시 시작하는 동안 추가

API 호출 자체는 다음과 같이 말합니다.파일 시스템이 마운트 해제되지 않았습니다.그러나 kexec 도구는 시스템의 다시 시작 부분을 뺀 종료 시퀀스를 호출하여 파일 시스템을 동기화하는 것으로 보이므로 서비스와 프로세스가 정상적으로 종료되는 것처럼 정상적으로 종료되어야 합니다.

답변2

무엇을 실행하고 있는지 기억하세요(솔직히 말하면 실제로 무엇을 실행하고 있는지 알려주지는 않습니다.systemd: 실행 중인 타겟을 얻는 방법

systemctl get-default 

단일 사용자 모드로 전환:

systemctl isolate rescue.target

나머지 프로세스 중 일부를 종료할 수도 있습니다.

원래 모드(일반적으로 graphical.target)로 다시 전환합니다.

systemctl isolate graphical.target

사용할 수도 init 1있으며 init 5여전히 지원됩니다.

관련 정보