Re: /proc/mounts, /dev/root
"Patrick J. LoPresti" wrote: > > Try "cat /proc/sys/kernel/real-root-dev". Convert to hex and maybe > you will see something familiar. Or maybe not :-). This is exactly what I need! Thanks! Andrew Clausen
Re: /proc/mounts, /dev/root
On Fri, Mar 17, 2000 at 06:11:54PM +1100, Andrew Clausen wrote: > I'm writing partition program, that needs to find out > if a partition is mounted. Sometimes, /etc/mtab is > not available (eg / is mounted read-only). Therefore, > I should check /proc/mounts first, if it's available. > But /proc/mounts has this /dev/root brain damage. So > I need to find out what /dev/root really is. I think you should avoid both /etc/mtab and /proc/mounts. Both are unreliable - /etc/mtab because it is just a file and in principle can have arbitrary contents, and /proc/mounts because /proc may not exist, and /dev/root is unresolved, and spaces in names may make it impossible to parse /proc/mounts uniquely, changes in names since things were mounted may make it impossible to interpret a /proc/mounts line, etc. Indeed, it is a bad idea in general to take some imprecise output meant for human consumption only, and use that in a program, except possibly as a vague heuristic to generate a warning. Why do you want to check whether a partition is mounted? I can see two reasons: (i) If a partition is in use then a subsequent BLKRRPART will fail. This is worth a warning but is not catastrophic. The new table will be used after a reboot or after a command like "blockdev --rereadpt device". (ii) The sectors describing logical partitions are scattered all over the disk. If one of these overwrites a sector on an active partition (mounted, or in use as swap) then terrible things may happen. My point of view is that (ii) is so serious that it does not suffice to rely on the heuristic provided by looking at /proc/mounts and /proc/swaps. Fortunately there is a very easy way to get much more reliable information: use the BLKPG_DEL_PARTITION ioctl. Andries
[patch-2.3.99-pre4] Re: /proc/mounts, /dev/root
> > Hm. The chroot(2) call changes the apparent root to a directory. This > isn't necessarily the root of a mounted FS. So /dev/root should stay > as the root filesystem. I know - I thought that is all he wanted - perhaps I haven't read his message carefully enough, i.e. current->fs->root->d_inode->i_dev > To get the apparent root, look at /proc/self/root instead. > I forgot about /proc/self/root :) (btw, shouldn't vfs_readlink() return EFAULT if copy_to_user() fails? It acts on userspace buffer and readlink(2) manpage documents EFAULT if buffer is invalid, cc;d Linus to confirm and if so, the patch is below) Regards, Tigran. --- namei.c.0 Sat Mar 18 08:06:38 2000 +++ namei.c Sat Mar 18 08:07:08 2000 @@ -1506,7 +1506,8 @@ len = strlen(link); if (len > buflen) len = buflen; - copy_to_user(buffer, link, len); + if(copy_to_user(buffer, link, len)) + return -EFAULT; out: return len; }
Re: [patch-2.3.99-pre4] Re: /proc/mounts, /dev/root
Tigran Aivazian writes: > > > > Hm. The chroot(2) call changes the apparent root to a directory. This > > isn't necessarily the root of a mounted FS. So /dev/root should stay > > as the root filesystem. > > I know - I thought that is all he wanted - perhaps I haven't read his > message carefully enough, i.e. current->fs->root->d_inode->i_dev > > > To get the apparent root, look at /proc/self/root instead. > > > > I forgot about /proc/self/root :) (btw, shouldn't vfs_readlink() return > EFAULT if copy_to_user() fails? It acts on userspace buffer and > readlink(2) manpage documents EFAULT if buffer is invalid, cc;d Linus to > confirm and if so, the patch is below) > > --- namei.c.0 Sat Mar 18 08:06:38 2000 > +++ namei.c Sat Mar 18 08:07:08 2000 > @@ -1506,7 +1506,8 @@ > len = strlen(link); > if (len > buflen) > len = buflen; > - copy_to_user(buffer, link, len); > + if(copy_to_user(buffer, link, len)) > + return -EFAULT; > out: > return len; > } Mm. Patch looks reasonable to me. Nicely spotted. Resend it to Linus with [BUGFIX] in the subject and a short (< 5 line) description right at the top. Linus has been known to ignore messages if the first 5 lines aren't interesting. Actually, he's been known to ignore interesting messages regardless ;-) Regards, Richard Permanent: [EMAIL PROTECTED] Current: [EMAIL PROTECTED]
Re: /proc/mounts, /dev/root
Tigran Aivazian wrote: > > if rdev is not there you copy it using cp(1) command. I didn't explain myself very well. Sorry. I'll try again... I'm writing partition program, that needs to find out if a partition is mounted. Sometimes, /etc/mtab is not available (eg / is mounted read-only). Therefore, I should check /proc/mounts first, if it's available. But /proc/mounts has this /dev/root brain damage. So I need to find out what /dev/root really is. I want to allow users to use Parted with chroot, because this could be useful in a rescue situation. Obviously, I can't force/recommend users use devfs. Also, Parted will be run *after* any chroot, so copying rdev is out of the question. Anyone have any other suggestions? Thanks, Andrew Clausen
Re: /proc/mounts, /dev/root
Tim Waugh wrote: > > On Fri, 17 Mar 2000, Andrew Clausen wrote: > > > > stat / > > > > Doesn't work with chroot :-( > > Can you mount proc? stat /proc/1/cwd..? Permission denied (even as root), for obvious reasons. Andrew Clausen
Re: /proc/mounts, /dev/root
On Fri, Mar 17, 2000 at 03:50:35AM +1100, Andrew Clausen wrote: > Tigran Aivazian wrote: > > even if you chroot somewhere, rdev will still show the correct root: > > What if rdev isn't on the chroot'ed root? Also, does rdev need find > the kernel image, or does it ask the kernel? You need to *have* rdev at all;) For Alpha it doesn't exist;( MfG, JBG -- Fehler eingestehen, Größe zeigen: Nehmt die Rechtschreibreform zurück!!! keyID=0x8399E1BB fingerprint=250D 3BCF 7127 0D8C A444 A961 1DBD 5E75 8399 E1BB PGP signature
Re: /proc/mounts, /dev/root
if rdev is not there you copy it using cp(1) command. On Fri, 17 Mar 2000, Andrew Clausen wrote: > Tigran Aivazian wrote: > > even if you chroot somewhere, rdev will still show the correct root: > > What if rdev isn't on the chroot'ed root? Also, does rdev need find > the kernel image, or does it ask the kernel? > > Thanks! > Andrew Clausen >
Re: /proc/mounts, /dev/root
Tigran Aivazian writes: > > > Richard, > > Using devfs /dev/root is fine to the real original root but not fine > to find the device of the filesystem which contains the chroot;d > environment. But rdev works fine in that case. Try it and see > (using devfs was the first thing that came to my mind when I thought > of answering his question but having tried I saw that only rdev > would give what he wants). Hm. The chroot(2) call changes the apparent root to a directory. This isn't necessarily the root of a mounted FS. So /dev/root should stay as the root filesystem. To get the apparent root, look at /proc/self/root instead. Regards, Richard Permanent: [EMAIL PROTECTED] Current: [EMAIL PROTECTED]
Re: /proc/mounts, /dev/root
Richard, Using devfs /dev/root is fine to the real original root but not fine to find the device of the filesystem which contains the chroot;d environment. But rdev works fine in that case. Try it and see (using devfs was the first thing that came to my mind when I thought of answering his question but having tried I saw that only rdev would give what he wants). Regards, tigran.
Re: /proc/mounts, /dev/root
Tigran Aivazian wrote: > even if you chroot somewhere, rdev will still show the correct root: What if rdev isn't on the chroot'ed root? Also, does rdev need find the kernel image, or does it ask the kernel? Thanks! Andrew Clausen
Re: /proc/mounts, /dev/root
> Is there any way to find out what /dev/root is? > (My motivation is to check if a partition is mounted) > > I don't think checking /etc/fstab for "/" would be a > good solution. If a user chroot's, to run Parted off > the hard disk (after booting off a floppy), /etc/fstab > wouldn't match. even if you chroot somewhere, rdev will still show the correct root: # chroot /data/out/root # rdev 0x0821 / # exit # df FilesystemType 1k-blocks Used Available Use% Mounted on /dev/sda3 ext2 3984704 2250460 1531828 59% / none proc 0 0 0 - /proc nonedevpts 0 0 0 - /dev/pts none devfs 0 0 0 - /devfs none shm 4194304 0 4194304 0% /var/shm /dev/sdb1 ext2 4391488288304 4013956 7% /sco /dev/sdc1 ext2 4391488 3406828984660 78% /data /dev/hda iso9660 596796596796 0 100% /cd2 # rdev /dev/sda3 / # chroot /data/out/root # rdev 0x0821 / # ls -l /dev/sdc1 brw-rw 1 root disk 8, 33 May 5 1998 /dev/sdc1 and hex 21 is decimal 33. Regards, Tigran.
Re: /proc/mounts, /dev/root
Tim Waugh wrote: > > On Thu, 16 Mar 2000, Andrew Clausen wrote: > > > Is there any way to find out what /dev/root is? > > (My motivation is to check if a partition is mounted) > > stat / Doesn't work with chroot :-( /proc isn't smart enough to tell if it's mounted on a chroot'ed fs. I think this whole /dev/root in /proc/mounts business is a bit dubious. Is there a reason why it doesn't have /dev/PARTITION...? Andrew Clausen
Re: /proc/mounts, /dev/root
Andrew Clausen writes: > Hi all, > > On my machine, this happens: > > satisfactory:~$ cat /proc/mounts > /dev/root / ext2 rw 0 0 > /proc /proc proc rw 0 0 > none /dev/pts devpts rw 0 0 > /dev/hda1 /mnt/dosc vfat rw 0 0 > automount(pid216) /misc autofs rw 0 0 > > Is there any way to find out what /dev/root is? > (My motivation is to check if a partition is mounted) > > I don't think checking /etc/fstab for "/" would be a > good solution. If a user chroot's, to run Parted off > the hard disk (after booting off a floppy), /etc/fstab > wouldn't match. Set CONFIG_DEVFS_FS=y. With devfs, /dev/root is a symlink to the real inode. Make sure you read the documentation. Regards, Richard Permanent: [EMAIL PROTECTED] Current: [EMAIL PROTECTED]
/proc/mounts, /dev/root
Hi all, On my machine, this happens: satisfactory:~$ cat /proc/mounts /dev/root / ext2 rw 0 0 /proc /proc proc rw 0 0 none /dev/pts devpts rw 0 0 /dev/hda1 /mnt/dosc vfat rw 0 0 automount(pid216) /misc autofs rw 0 0 Is there any way to find out what /dev/root is? (My motivation is to check if a partition is mounted) I don't think checking /etc/fstab for "/" would be a good solution. If a user chroot's, to run Parted off the hard disk (after booting off a floppy), /etc/fstab wouldn't match. Any ideas? Andrew Clausen