Mic_chen

It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

问题来源:

因为ssh服务的dropbear依赖了随机子系统,导致系统起来后很久才能使用ssh服务。

问题表现:

要几百秒才能初始化完成:

random: crng init done
[ 268.035120] random: 7 urandom warning(s) missed due to ratelimiting

解决方案:

应用上支持haveged,目前采用在buildroot中打开haveged来解决。

 

 

以下转自http://blog.chinaunix.net/uid-31410005-id-5831556.html

 

因 systemd 在系统启动时需要熵信息,且内核在可用熵较少时会阻塞相应的调用,所以系统启动时可能挂起数分钟至数小时,直至随机子系统充分得到初始化( random: crng init done )。对于支持 RDRAND 指令的 amd64 系统,Debian 的内核已可以避免这个问题,因为内核默认将尝试使用该指令( CONFIG_RANDOM_TRUST_CPU )。

非 amd64 架构的系统和某些虚拟机可能需要从其它来源获取熵以保证快速启动。Debian 安装程序内部选择了 haveged 作为替代方案,在硬件熵不可用时,这可能是个可以使用的解决方案。在虚拟机上,请考虑经由 virtio_rng 将主机的熵转发至虚拟机中。

终于进安装界面了,方法是第一项install deepin ,删除“quiet splash”,加上ivrs=ioapic[32]=00:14.0 spec_store_bypass_disable=prctl iommu=soft,这三个参数,已安装完成。另安装完成后进系统启动项也需要加上上面三个参数,进系统后修改 /etc/default/grub文件 在GRUB_CMDLINE_LINUX_DEFAULT="在这里加内容" 里面添加上刚才的三个参数,这样每次开机直接按回车启动就可以了 记得update-grub来更新下grub的菜单以生效

由3.10升级到4.14内核后,启动系统random的初始化需要比较长的时间。通过dmesg | grep -I randdom 发现需要400多秒才能初始化完成。
dmesg | grep -i random
[    0.051406] random: get_random_bytes called from setup_net+0x33/0x120 with crng_init=0
[    0.637733] random: hwclock: uninitialized urandom read (8 bytes read)
[    0.821425] random: sh: uninitialized urandom read (8 bytes read)
[   11.923501] random: fast init done
[   13.111697] random: modprobe: uninitialized urandom read (8 bytes read)
[   20.464349] random: modprobe: uninitialized urandom read (8 bytes read)
[   20.475650] random: head: uninitialized urandom read (8192 bytes read)
[   23.335865] random: modprobe: uninitialized urandom read (8 bytes read)
[   28.286856] random: modprobe: uninitialized urandom read (8 bytes read)
[   28.747431] random: modprobe: uninitialized urandom read (8 bytes read)
[   33.718262] random: modprobe: uninitialized urandom read (8 bytes read)
[   33.736726] random: modprobe: uninitialized urandom read (8 bytes read)
[  429.269251] random: crng init done


所以一些应用程序在调用random的函数可能会阻塞。
通过调查发现有两个解决方案,内核的方式和用户态的方式
方案一:打入以下内核patch
内核的patch:https://lkml.org/lkml/2018/7/17/1279
增加了config RANDOM_TRUST_CPU这个选项,默认此选择没有打开。
大致的意思是,此选项是信任cpu处理器的厂商,他们会产生没有危险用户的random的行为。也列举了反例,列举了美国制裁中国,中国决定自给自足CPU。凭什么就相信intel,不相信解放军控制的公司等

用户态的方案:
Haveged使用HAVEGE(HArdware Volatile Entropy Gathering and Expansion)来维护一个1M的随机字节池,
当/dev/random中的随机位供应低于设备的低水位时(/proc/sys/kernel/random/entropy_avail),这个随机字节池用于填充/dev/random。
容器里可以使用如下:
1 wget http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/h/haveged-1.9.1-1.el7.x86_64.rpm
2 rpm -ivh haveged-1.9.1-1.el7.x86_64.rpm
3 运行haveged -w 1024 -v 1

服务器可以使用:
yum install haveged -y
systemctl start haveged
systemctl enable haveged
————————————————
版权声明:本文为CSDN博主「xiaofeng_yan」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xiaofeng_yan/java/article/details/101073770

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install Fedora 31' --class red --class gnu-linux --class gnu --class os {
    linux /images/pxeboot/vmlinuz
    initrd /images/pxeboot/initrd.img
}
grub里面安装install增加,grub命令行下操作

It's a kernel bug that can happen with different kernel.

"apt-get install rng-tools" run as root in a terminal should work.

posted on 2021-01-15 17:21  Mic_chen  阅读(5335)  评论(0编辑  收藏  举报