On 7/2/17 12:53 PM, Robert Peichaer wrote:
> On Sun, Jul 02, 2017 at 12:50:36PM -0400, RD Thrush wrote:
>>> Synopsis: reorder_kernel requires writable /usr/share
>>> Category: system
>>> Environment:
>> System : OpenBSD 6.1
>> Details : OpenBSD 6.1-current (GENERIC.MP) #73: Sat Jul 1 10:53:54
>> MDT 2017
>>
>> [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
>>
>> Architecture: OpenBSD.amd64
>> Machine : amd64
>>> Description:
>> /etc/rc: reorder_kernel() requires /usr/share to be writeable
>>> How-To-Repeat:
>> On a system w/ a separate read-only partition containing /usr/share,
>> restart and observe:
>> > cat /var/log/kernel_relink.log
>> sh makegap.sh 0xcccccccc
>> makegap.sh[69]: cannot create gap.link: Read-only file system
>> ld: cannot open output file gap.o: Read-only file system
>> *** Error 1 in /usr/share/compile/GENERIC.MP (Makefile:966 'gap.o')
>>
>>> Fix:
>> In _reorder_libs() a similar read-only problem was resolved.
>> I used that as the basis for the appended patch:
>
> revision 1.506
> date: 2017/06/30 17:06:03; author: rpe; state: Exp; lines: +24 -18;
> commitid: sUDtacXshDGSqeZm;
> Improve reorder_kernel()
>
> - check for and exit if /usr/share is on a nfs mounted filesystem
> - add trap handlers that mail the logfile to the admin user
> - use $_compile instead of $_compile_dir like in the installer
> - use $_compile/$_kernel instead of $_kernel_dir
> - remove the now redundant sha256 -h ... after make newinstall
> - write stdout/stderr of the background subshell to a logfile
>
> OK tb@ deraadt@
My patch was against revision 1.506. I'm unsure how to interpret
your reply (of the associated commit message) to the bug report.
I've attached the patch in case there was a whitespace issue w/ the
inline version.
Index: rc
===================================================================
RCS file: /cvs/OpenBSD/src/etc/rc,v
retrieving revision 1.506
diff -u -p -u -p -r1.506 rc
--- rc 30 Jun 2017 17:06:03 -0000 1.506
+++ rc 2 Jul 2017 17:16:58 -0000
@@ -222,7 +222,8 @@ reorder_libs() {
# Re-link the kernel, placing the objects in a random order.
# Replace current with relinked kernel and inform root about it.
reorder_kernel() {
- local _dkdev=$(df /usr/share | sed '1d;s/ .*//')
+ local _dkdev=$(df /usr/share | sed '1d;s/ .*//') \
+ _mp=$(mount | grep "^$_dkdev") _remount=false _error=false
# Skip if /usr/share is on a nfs mounted filesystem.
[[ $(mount | grep "^$_dkdev") == *" type nfs "* ]] && return
@@ -239,6 +240,16 @@ reorder_kernel() {
_kernel=${_kernel%#*}
_sha256=/var/db/kernel.SHA256
+ # Remount read-write, if /usr/share is on a read-only ffs filesystem.
+ if [[ $_mp == *' type ffs '*'read-only'* ]]; then
+ if mount -u -w $_dkdev; then
+ _remount=true
+ else
+ echo 'reorder_kernel: mount -uw failed.'
+ return
+ fi
+ fi
+
if [[ -f $_compile.tgz ]]; then
rm -rf $_compile
mkdir -m 700 -p $_compile
@@ -251,6 +262,16 @@ reorder_kernel() {
cd $_compile/$_kernel
make newbsd
make newinstall
+
+ # Restore previous mount state if it was changed.
+ if $_remount; then
+ mount -u -r $_dkdev || _error=true
+ fi
+
+ if $_error; then
+ echo 'reorder_kernel: mount -ur failed.'
+ return
+ fi
echo "\nKernel has been relinked and is active on next reboot.\n"
cat $_sha256