Skip to content

criu 入门小记

Posted on:April 16, 2023 at 12:48 PM

本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。


[迁移博客]

最近小组的大家都在选择想要参加的开源社区,在 GSoC 的组织里发现了 criu 这个很有趣的项目.
在初看之下,感觉 criu 的组成就是 Linux kernel + Linux System Programming + Container,用的语言是 C + Golang,这两个我最近很感兴趣的语言,所以在初见之下就对这个项目很感兴趣.
这篇博客主要记录自己对 criu 的入门

System: Linux archlinux 6.2.2-arch1-1 x86_64 GNU/Linux

CRIU:
  Version: 3.17
  GitID: v3.17-177-gcd9680ce8

$SHELL: /usr/zsh

OverView

安装与编译

git clone https://github.com/checkpoint-restore/criu
cd criu
make

安装成功

./criu/criu --version

sudo ./criu/criu check

简单的使用示例

为一个循环打印当前时间的shell script创建快照

  1. 编辑 test.sh 文件
> vim test.sh
----

#!/bin/sh
while :; do
	sleep 1
	date
done
EOF

:wq
  1. 设置执行权限
> chmod +x test.sh
  1. 在特定会话运行 test.sh(消除对当前终端的依赖)
> setsid ./test.sh  < /dev/null &> test.log &

  1. 获取 PID
> ps -C test.sh

  1. Dump
> criu dump -t 141117 -vvv -o dump.log && echo OK

  1. 检查 dump files
> ls
  1. restore
> criu restore -d -vvv -o restore.log && echo OK

基本原理

代码组成

compel

crit

criu

crtools

OTHER

Refer

  1. MRAS 项目技术调研报告 CRIU-Checkpoint/Restore in User-space