9 # KEYWORD: nojail shutdown
14 desc="Harvest and save entropy for random device"
15 start_cmd="random_start"
16 stop_cmd="random_stop"
18 extra_commands="saveseed"
19 saveseed_cmd="${name}_stop"
25 debug "saving entropy to $f"
26 dd if=/dev/random of="$f" bs=4096 count=1 2>/dev/null
34 if [ -f "$f" -a -r "$f" -a -s "$f" ] ; then
35 if dd if="$f" of=/dev/random bs=4096 2>/dev/null ; then
36 debug "entropy read from $f"
46 if [ ${harvest_mask} -gt 0 ]; then
47 echo -n 'Setting up harvesting: '
48 ${SYSCTL} kern.random.harvest.mask=${harvest_mask} > /dev/null
49 ${SYSCTL_N} kern.random.harvest.mask_symbolic
52 echo -n 'Feeding entropy: '
54 if [ ! -w /dev/random ] ; then
55 warn "/dev/random is not writeable"
59 # Reseed /dev/random with previously stored entropy.
60 case ${entropy_dir:=/var/db/entropy} in
64 if [ -d "${entropy_dir}" ] ; then
65 feed_dev_random "${entropy_dir}"/*
70 case ${entropy_file:=/entropy} in
74 feed_dev_random "${entropy_file}" /var/db/entropy-file
75 save_dev_random "${entropy_file}"
79 case ${entropy_boot_file:=/boot/entropy} in
83 save_dev_random "${entropy_boot_file}"
92 # Write some entropy so when the machine reboots /dev/random
95 case ${entropy_file:=/entropy} in
99 echo -n 'Writing entropy file:'
100 rm -f ${entropy_file} 2> /dev/null
103 if touch ${entropy_file} 2> /dev/null; then
104 entropy_file_confirmed="${entropy_file}"
106 # Try this as a reasonable alternative for read-only
107 # roots, diskless workstations, etc.
108 rm -f /var/db/entropy-file 2> /dev/null
109 if touch /var/db/entropy-file 2> /dev/null; then
110 entropy_file_confirmed=/var/db/entropy-file
113 case ${entropy_file_confirmed} in
115 warn 'write failed (read-only fs?)'
118 dd if=/dev/random of=${entropy_file_confirmed} \
119 bs=4096 count=1 2> /dev/null ||
120 warn 'write failed (unwriteable file or full fs?)'
127 case ${entropy_boot_file:=/boot/entropy} in
131 echo -n 'Writing early boot entropy file:'
132 rm -f ${entropy_boot_file} 2> /dev/null
135 if touch ${entropy_boot_file} 2> /dev/null; then
136 entropy_boot_file_confirmed="${entropy_boot_file}"
138 case ${entropy_boot_file_confirmed} in
140 warn 'write failed (read-only fs?)'
143 dd if=/dev/random of=${entropy_boot_file_confirmed} \
144 bs=4096 count=1 2> /dev/null ||
145 warn 'write failed (unwriteable file or full fs?)'