全内存系统 for Arch Linux
之前在github上和绿檀发过帖子【1】介绍了当前流行的几种全内存系统实现及其优缺点,以及我给出的兼具性能和优雅的实现。不过当时给出的例子是Gentoo Linux上的,有烧友告诉我现在Arch Linux aur的ramroot目前有些问题不能用了,我就在pve里装了个Arch把之前的全内存系统脚本迁移过来,在这简单介绍。【1】http://erji.net/forum.php?mod=viewthread&tid=2328383&extra=
本帖最后由 中关村东路 于 2024-4-4 18:00 编辑
首先看看你当前的initramfs是什么格式的,6.0以后默认是zstd,如果是别的格式下面的脚本略有不同但操作类似:
file /boot/initramfs-linux.img
initramfs-linux-ramroot.img.zst: Zstandard compressed data (v0.8+), Dictionary ID: None
接下来我们来看看mkinitcpio是怎么打包zstd格式的initramfs的,
nano /usr/bin/mkinitcpio
按ctrl+w搜索关键字zstd,找到这段可以看到命令参数只有一个-T0,最终我们就要用zstd -T0来打包。如果你用的是其他压缩格式也是类似的。
zstd)
COMPRESSION_OPTIONS=('-T0' "${COMPRESSION_OPTIONS[@]}")
现在来解压缩当前正常运行的initramfs,
mkdir ramroot
cd ramroot
cp /boot/initramfs-linux.img initramfs-linux.img.zst
zstd -d initramfs-linux.img.zst
cpio -iF initramfs-linux.img
rm initramfs-linux.img.zst initramfs-linux.img
在启动脚本的最后,大约最后一个if之后,修改成如下:
nano init
if []
fi
mkdir /ram_root
mount -t tmpfs -o rw,noatime none /ram_root
cp -a /new_root/* /ram_root/
mount --move /proc /ram_root/proc
mount --move /sys /ram_root/sys
mount --move /dev /ram_root/dev
umount /new_root
# this should always be the last thing we do before the switch_root.
rdlogger_stop
exec env -i \
"TERM=$TERM" \
/usr/bin/switch_root /ram_root "$init" "$@"
# /usr/bin/switch_root /new_root "$init" "$@"
# vim: set ft=sh ts=4 sw=4 et:注意上面这段假定硬盘根目录下容量小于内存的一半。如果不是,请参考【1】中的rsync --exclude技巧。
保存之后就可以打包了,注意最后一段,是假定了之前initramfs是用zstd格式压缩的,其他格式需要对应修改。
find . -print0 | cpio --quiet --null -o -H newc --owner root:root --force-local | zstd -T0 > /boot/initramfs-linux-ramroot.img
接下来修改/boot/grub/grub.cfg文件,找到这一段,复制个一模一样的,最后一行改成ramroot的版本。现在重启就会启动到ramroot里了,如果你想切回去就在启动系统时候选第二项。
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Arch Linux in ramroot' ... {
...
initrd/boot/initramfs-linux-ramroot.img
}
menuentry 'Arch Linux' ... {
...
initrd/boot/initramfs-linux.img
}
打完收工。 顶一下
qdatmjxb 发表于 2024-4-5 10:23
顶一下
{:4_115:} 顶一下, 好帖子收藏了 顶!继续学习 完美实现。:victory: xsyzm 发表于 2024-4-7 15:38
完美实现。
恭喜恭喜
页:
[1]