Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 118646 - I think /etc/init.d/checkroot has some incorrect logic when trying to remount / read-write
Summary: I think /etc/init.d/checkroot has some incorrect logic when trying to remount...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-11 04:35 UTC by Alun Jones
Modified: 2006-01-26 16:19 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alun Jones 2006-01-11 04:35:15 UTC
Maybe I'm just having a brainstorm, in which case, Sorry!

Trying to set up a netboot based system using unionfs. The setup I've built means that / is mounted rw by the time checkroot runs. However, the system still tries to remount / rw. I think there's a bug in /etc/init.d/checkroot:

        # Should we mount root rw ?
        if mount -vf -o remount / 2> /dev/null | \
           awk '{ if ($6 ~ /rw/) exit 0; else exit 1; }'
        then
                ebegin "Remounting root filesystem read/write"

Shouldn't the awk exit codes be the other way around? Even if I run this code
fragment on a normal, disk based system, with root mounted read-write, it reports that it needs to remount.

I suspect this hasn't been noticed before because "mount -o remount,rw /" will
normally succeed on a simple mount. The unionfs mount comes back with an error, highlighting the bug.
Comment 1 SpanKY gentoo-dev 2006-01-11 05:26:59 UTC
no, the awk exit codes are correct
Comment 2 Alun Jones 2006-01-11 07:03:06 UTC
(In reply to comment #1)
> no, the awk exit codes are correct
> 

I'm not convinced!

Isn't "exit 0" true in Bourne shell, so won't the "if" will execute if
/ is mounted rw?

Not trusting my own brain, I have tried it out on another machine. 
This is on an up to date Gentoo box (not netboot, it's my desktop machine):

penguin tmp # cat mountcheck 
# Should we mount root rw ?
if mount -vf -o remount / 2> /dev/null | \
    awk '{ if ($6 ~ /rw/) exit 0; else exit 1; }'
then
    echo "Remounting root filesystem read/write"
fi
penguin tmp # mount -vf -o remount /
/dev/sda2 on / type ext3 (rw)
penguin tmp # sh mountcheck
Remounting root filesystem read/write
penguin tmp # 

There's certainly something wrong there!
Comment 3 SpanKY gentoo-dev 2006-01-11 07:15:08 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > no, the awk exit codes are correct
> 
> I'm not convinced!

it doesnt really matter whether you're convinced, it doesnt change the facts :)

> Isn't "exit 0" true in Bourne shell, so won't the "if" will execute if
> / is mounted rw?

yes, but the reason this hasnt been an issue before is on every normal system, the / is read only at this point, especially considering the fact we remounted / readonly earlier in the same script
Comment 4 Alun Jones 2006-01-11 07:38:18 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > no, the awk exit codes are correct
> > 
> > I'm not convinced!
> 
> it doesnt really matter whether you're convinced, it doesnt change the facts :)

:-)

> > Isn't "exit 0" true in Bourne shell, so won't the "if" will execute if
> > / is mounted rw?
> 
> yes, but the reason this hasnt been an issue before is on every normal system,
> the / is read only at this point, especially considering the fact we remounted
> / readonly earlier in the same script

... if /fastboot doesn't exist. If /fastboot exists then root doesn't get
remounted readonly, and then subsequently it attempts to remount it 
read-write when it doesn't need to. This causes problems if remounting
read-write isn't a supported option (which will be true for readonly
NFS or unionfs root filesystems).

I'm not really that obsessed about this, I've fixed it in my own script. I'd
just like it addressed (or I'd like to understand why I'm wrong!) so I don't have to worry whenever I do an update that it's going to break the 200 machines that'll be booting off this image. At the moment, this is the only change I've had to make to any init script to get my netboot system working with Gentoo.
Comment 5 Alun Jones 2006-01-11 08:43:49 UTC
(In reply to comment #4)
> This causes problems if remounting
> read-write isn't a supported option (which will be true for readonly
> NFS or unionfs root filesystems).

Duh! I've just realised, NFS won't be read-write beforehand anyway. It's probably only unionfs that's an issue because it starts out read-write
but doesn't like remounting read-write. I'll shut up now!
Comment 6 SpanKY gentoo-dev 2006-01-11 15:38:11 UTC
not just nfs but most systems ... the kernel mounts / readonly when first booting, so the check above is just a sanity check

this should fix it though for everyone:
        if mount -vf -o remount / 2> /dev/null | \
-          awk '{ if ($6 ~ /rw/) exit 0; else exit 1; }'
+          awk '{ if ($6 ~ /rw/) exit 0; else exit 1; }' && \
+          ! touch -c / >& /dev/null
        then
Comment 7 SpanKY gentoo-dev 2006-01-26 16:19:11 UTC
ok, ive added my proposed touch check to svn