Skip to contentSkip to conversation

linux-2.6.25: 'mkdir -p' does not work with rootdir as mount point inside a read only filesystem

DISCUSSION Lothar Waßmann 6 participants 11 messages Apr 30, 2008 – May 5, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

when trying to create a directory path with 'mkdir -p' with the root being a mount point of a writeable filesystem that exists inside a read-only file system, mkdir return -EROFS.

This was tested with the latest git-tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6

The last kernel I know of this has been working was 2.6.22.

E.g.:

|root@triton1:/# mount
|rootfs on / type rootfs (rw)
|/dev/root on / type jffs2 (ro)
|proc on /proc type proc (rw)
|sysfs on /sys type sysfs (rw)
|/dev/root on /dev/.static/dev type jffs2 (ro)
|tmpfs on /dev type tmpfs (rw,size=10240k,mode=755)
|tmpfs on /var type tmpfs (rw)
|tmpfs on /tmp type tmpfs (rw)
|devpts on /dev/pts type devpts (rw,gid=5,mode=620)
|tmpfs on /dev/shm type tmpfs (rw)
|root@triton1:/# mkdir -p /dev/.udev/db
|mkdir: Cannot create directory `/dev/': Read-only file system

While:

|root@triton1:/# cd /dev
|root@triton1:/# mkdir -p .udev/db
works as expected...

Has anyone else encountered this problem already?
I've searched the archives but could not find anything related to this problem.

Lothar Wa�mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra�e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch�ftsf�hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________
#1 lore raw
Quoted 1 line · On Wed, 30 Apr 2008 16:50:20 +0200 Lothar Wa__mann <[email protected]>…

Hi,

(y'know that ~4000 people read your email and hit 'n'? Except for me? That's one bug I'd like to get fixed)

Quoted 24 lines

when trying to create a directory path with 'mkdir -p' with the root being a mount point of a writeable filesystem that exists inside a read-only file system, mkdir return -EROFS.

This was tested with the latest git-tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6

The last kernel I know of this has been working was 2.6.22.

E.g.:

|root@triton1:/# mount
|rootfs on / type rootfs (rw)
|/dev/root on / type jffs2 (ro)
|proc on /proc type proc (rw)
|sysfs on /sys type sysfs (rw)
|/dev/root on /dev/.static/dev type jffs2 (ro)
|tmpfs on /dev type tmpfs (rw,size=10240k,mode=755)
|tmpfs on /var type tmpfs (rw)
|tmpfs on /tmp type tmpfs (rw)
|devpts on /dev/pts type devpts (rw,gid=5,mode=620)
|tmpfs on /dev/shm type tmpfs (rw)
|root@triton1:/# mkdir -p /dev/.udev/db
|mkdir: Cannot create directory `/dev/': Read-only file system
Quoted 8 lines

While:

|root@triton1:/# cd /dev
|root@triton1:/# mkdir -p .udev/db
works as expected...

Has anyone else encountered this problem already?
I've searched the archives but could not find anything related to this problem.

I had a shot at scripting this, but for me, everything works OK.

#!/bin/sh
dd if=/dev/zero of=file1 bs=1M count=32
dd if=/dev/zero of=file2 bs=1M count=32
yes | mkfs -t ext2 file1
yes | mkfs -t ext2 file2
mkdir -p mountpoint
mount -o loop file1 mountpoint
mkdir mountpoint/dir
umount mountpoint
mount -o loop,ro file1 mountpoint
mount -o loop file2 mountpoint/dir
mkdir -p $(/bin/pwd)/mountpoint/dir/subdir

are you able to modify the above so that it demonstrates the failure?

Thanks.

#2 lore raw
Quoted 7 lines · Andrew Morton
Quoted 1 line · On Wed, 30 Apr 2008 16:50:20 +0200 Lothar Wa__mann <[email protected]>…

Hi,

(y'know that ~4000 people read your email and hit 'n'? Except for me? That's one bug I'd like to get fixed)

Tricky....

Quoted 4 lines
Quoted 4 lines

when trying to create a directory path with 'mkdir -p' with the root being a mount point of a writeable filesystem that exists inside a read-only file system, mkdir return -EROFS.

My guess is that you have an old/buggy version of mkdir.

What does

    mkdir --version

say?
Mine says:
mkdir (GNU coreutils) 6.10
Copyright (C) 2008 Free Software Foundation, Inc.
etc...

What does

strace mkdir -p /dev/.udev/db

show ???

NeilBrown

#3 lore raw
Quoted 18 lines · NeilBrown
Quoted 7 lines · Andrew Morton
Quoted 1 line · On Wed, 30 Apr 2008 16:50:20 +0200 Lothar Wa__mann <[email protected]>…

Hi,

(y'know that ~4000 people read your email and hit 'n'? Except for me? That's one bug I'd like to get fixed)

Tricky....

Quoted 4 lines
Quoted 4 lines

when trying to create a directory path with 'mkdir -p' with the root being a mount point of a writeable filesystem that exists inside a read-only file system, mkdir return -EROFS.

My guess is that you have an old/buggy version of mkdir.

Quoted 8 lines

What does

    mkdir --version

say?
Mine says:
mkdir (GNU coreutils) 6.10
Copyright (C) 2008 Free Software Foundation, Inc.
etc...

I would bet this is the problem for the reporter.

I tried the same here, and cannot exhibit the problem. Just like the reporter, my / is ro and /dev is rw :

# mkdir --version
mkdir (coreutils) 5.2.1
...
# uname -a
Linux alix-2C3 2.6.25-wt4-alix #3 Thu Apr 24 08:30:05 CEST 2008 i586 i586 i386 GNU/Linux

(this is essentially 2.6.25+squashfs+some geode patches)

# mount
/dev/sda4 on / type ext3 (ro,errors=continue,data=ordered)
/dev on /dev type tmpfs (rw,size=0k,nr_inodes=4096,mode=755)
# mkdir -p /dev/a/b/c
# ls -lad /dev/a/b/c
drwxr-xr-x  2 root root 40 Jan  3 00:49 /dev/a/b/c/
# rmdir -p /dev/a/b/c
rmdir: `/dev': Read-only file system
# strace mkdir -p /dev/a/b/c

stat64("/dev/a/b/c", 0xbf9175dc) = -1 ENOENT (No such file or directory)
umask(0) = 022
open(".", O_RDONLY|O_LARGEFILE|O_DIRECTORY) = 3
chdir("/") = 0
mkdir("dev", 0755) = -1 EEXIST (File exists)
stat64("dev", {st_mode=S_IFDIR|0755, st_size=17080, ...}) = 0

chdir("dev")                            = 0
mkdir("a", 0755)                        = 0
chdir("a")                              = 0
mkdir("b", 0755)                        = 0
chdir("b")                              = 0
umask(022)                              = 0
mkdir("c", 0777)                        = 0
fchdir(3)                               = 0
close(3)                                = 0

Regards,
Willy

#4 lore raw

Hi,

Quoted 11 lines · Willy Tarreau
Quoted 10 lines

My guess is that you have an old/buggy version of mkdir.

What does

    mkdir --version

say?
Mine says:
mkdir (GNU coreutils) 6.10
Copyright (C) 2008 Free Software Foundation, Inc.
etc...

Quoted 5 lines

I would bet this is the problem for the reporter.

I tried the same here, and cannot exhibit the problem. Just like the reporter, my / is ro and /dev is rw :

I'm using busybox 1.0 (on an embedded PXA320 system).

Quoted 6 lines

stat64("/dev/a/b/c", 0xbf9175dc) = -1 ENOENT (No such file or directory)
umask(0) = 022
open(".", O_RDONLY|O_LARGEFILE|O_DIRECTORY) = 3
chdir("/") = 0
mkdir("dev", 0755) = -1 EEXIST (File exists)
stat64("dev", {st_mode=S_IFDIR|0755, st_size=17080, ...}) = 0

Quoted 10 lines
chdir("dev")                            = 0
mkdir("a", 0755)                        = 0
chdir("a")                              = 0
mkdir("b", 0755)                        = 0
chdir("b")                              = 0
umask(022)                              = 0
mkdir("c", 0777)                        = 0
fchdir(3)                               = 0
close(3)                                = 0

This is what strace shows in my case:
mkdir("/", 0777) = -1 EEXIST (File exists)
stat64("/", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
mkdir("/dev/", 0777) = -1 EROFS (Read-only file system)
umask(022) = 022
write(2, "mkdir: ", 7mkdir: ) = 7
write(2, "Cannot create directory /dev/\'", 31Cannot create directory /dev/') = 31 write(2, ": Read-only file system\n", 24: Read-only file system
) = 24
io_submit(0x1, 0x1, 0xfbad2088 <unfinished ... exit status 1>

Lothar Wa�mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra�e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch�ftsf�hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________
#5 lore raw
Quoted 1 line · Lothar Waßmann

I'm using busybox 1.0 (on an embedded PXA320 system).

OK

Quoted 16 lines
Quoted 6 lines

stat64("/dev/a/b/c", 0xbf9175dc) = -1 ENOENT (No such file or directory)
umask(0) = 022
open(".", O_RDONLY|O_LARGEFILE|O_DIRECTORY) = 3
chdir("/") = 0
mkdir("dev", 0755) = -1 EEXIST (File exists)
stat64("dev", {st_mode=S_IFDIR|0755, st_size=17080, ...}) = 0

Quoted 10 lines
chdir("dev")                            = 0
mkdir("a", 0755)                        = 0
chdir("a")                              = 0
mkdir("b", 0755)                        = 0
chdir("b")                              = 0
umask(022)                              = 0
mkdir("c", 0777)                        = 0
fchdir(3)                               = 0
close(3)                                = 0
Quoted 10 lines

This is what strace shows in my case:
mkdir("/", 0777) = -1 EEXIST (File exists)
stat64("/", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
mkdir("/dev/", 0777) = -1 EROFS (Read-only file system)
umask(022) = 022
write(2, "mkdir: ", 7mkdir: ) = 7
write(2, "Cannot create directory /dev/\'", 31Cannot create directory /dev/') = 31 write(2, ": Read-only file system\n", 24: Read-only file system
) = 24
io_submit(0x1, 0x1, 0xfbad2088 <unfinished ... exit status 1>

So you should send this trace to the busybox maintainer. It obviously exhibits a small but easily fixable bug in the program ; it should check whether the directory exists in case of error. It seems it only checks for EEXIST.

What puzzles me is why you have this problem only with a new kernel. I suspect that previous ones did report EEXIST and now we report EROFS for an existing directory on an ro fs.

Willy

#6 lore raw

Hi,

Quoted 3 lines · Willy Tarreau
Quoted 3 lines
Quoted 3 lines

open(".", O_RDONLY|O_LARGEFILE|O_DIRECTORY) = 3
chdir("/") = 0
mkdir("dev", 0755) = -1 EEXIST (File exists)

                                                   ^^^^^^

[...]

Quoted 4 lines
Quoted 4 lines

This is what strace shows in my case:
mkdir("/", 0777) = -1 EEXIST (File exists)
stat64("/", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
mkdir("/dev/", 0777) = -1 EROFS (Read-only file system)

                                                 ^^^^^
Quoted 4 lines

What puzzles me is why you have this problem only with a new kernel. I suspect that previous ones did report EEXIST and now we report EROFS for an existing directory on an ro fs.

Interestingly your strace output showed a return value of EEXIST where mine had EROFS.

Lothar Wa�mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra�e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch�ftsf�hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________
#7 lore raw
Quoted 12 lines · Lothar Waßmann

Hi,

Quoted 3 lines · Willy Tarreau
Quoted 3 lines
Quoted 3 lines

open(".", O_RDONLY|O_LARGEFILE|O_DIRECTORY) = 3
chdir("/") = 0
mkdir("dev", 0755) = -1 EEXIST (File exists)

                                                   ^^^^^^

[...]

Quoted 4 lines
Quoted 4 lines

This is what strace shows in my case:
mkdir("/", 0777) = -1 EEXIST (File exists)
stat64("/", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
mkdir("/dev/", 0777) = -1 EROFS (Read-only file system)

Quoted 7 lines
                                                 ^^^^^
Quoted 4 lines

What puzzles me is why you have this problem only with a new kernel. I suspect that previous ones did report EEXIST and now we report EROFS for an existing directory on an ro fs.

Interestingly your strace output showed a return value of EEXIST where mine had EROFS.

Oh you're right! I did not notice. There's something odd here. And I can reproduce it right now (2.6.25.1). I really have EEXIST.

Willy

#8 lore raw

Hi,

Quoted 7 lines · Willy Tarreau
Quoted 2 lines

Interestingly your strace output showed a return value of EEXIST where mine had EROFS.

Oh you're right! I did not notice. There's something odd here. And I can reproduce it right now (2.6.25.1). I really have EEXIST.

As I noted in my first message I have this problem with the kernel from git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
which is currently 2.6.26-rc1 and still exhibits this behaviour.

So, this problem obviously does not exist in the 2.6.25 release kernel but would probably hit mainline in the 2.6.26 release.

Lothar Wa�mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra�e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch�ftsf�hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________
#9 lore raw
Quoted 10 lines · Lothar Wa?mann

Hi,

Quoted 7 lines · Willy Tarreau
Quoted 2 lines

Interestingly your strace output showed a return value of EEXIST where mine had EROFS.

Oh you're right! I did not notice. There's something odd here. And I can reproduce it right now (2.6.25.1). I really have EEXIST.

Quoted 6 lines

As I noted in my first message I have this problem with the kernel from git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
which is currently 2.6.26-rc1 and still exhibits this behaviour.

So, this problem obviously does not exist in the 2.6.25 release kernel but would probably hit mainline in the 2.6.26 release.

Aye. That's ro-bind fallout we'd not noticed; will fix...

And a fine example of the reasons why
* relying on which particular errno value you get when several
are applicable is a Bad Idea(tm) and
* changing the choice of the errno value in such situation might
be legal, but is to be done with care; sometimes it really has impact...

#10 lore raw
In reply to Andrew Morton
Quoted 25 lines · Andrew Morton
Quoted 14 lines
|root@triton1:/# mount
|rootfs on / type rootfs (rw)
|/dev/root on / type jffs2 (ro)
|proc on /proc type proc (rw)
|sysfs on /sys type sysfs (rw)
|/dev/root on /dev/.static/dev type jffs2 (ro)
|tmpfs on /dev type tmpfs (rw,size=10240k,mode=755)
|tmpfs on /var type tmpfs (rw)
|tmpfs on /tmp type tmpfs (rw)
|devpts on /dev/pts type devpts (rw,gid=5,mode=620)
|tmpfs on /dev/shm type tmpfs (rw)
|root@triton1:/# mkdir -p /dev/.udev/db
|mkdir: Cannot create directory `/dev/': Read-only file system
Quoted 8 lines

While:

|root@triton1:/# cd /dev
|root@triton1:/# mkdir -p .udev/db
works as expected...

Has anyone else encountered this problem already?
I've searched the archives but could not find anything related to this problem.

I had a shot at scripting this, but for me, everything works OK.

Quoted 12 lines

#!/bin/sh
dd if=/dev/zero of=file1 bs=1M count=32 dd if=/dev/zero of=file2 bs=1M count=32 yes | mkfs -t ext2 file1
yes | mkfs -t ext2 file2
mkdir -p mountpoint
mount -o loop file1 mountpoint mkdir mountpoint/dir
umount mountpoint
mount -o loop,ro file1 mountpoint mount -o loop file2 mountpoint/dir mkdir -p $(/bin/pwd)/mountpoint/dir/subdir

Hmmm. The thing you are doing differently is that the reporter's root filesystem is mounted read only but in your case (and the quick try I had at it) the read only file system is mounted below root.

However, I tried reproducing that scenario with a chroot and I still couldn't get it to happen. No time to try a real root mount ro this morning but perhaps others can.

Cheers,
Dan

Signature · 3 lines
                    /--------------- - -  -  -   -   -
                    |  Dan Noé
                    |  http://isomerica.net/~dpn/