LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Permission denied on /dev/hda1 after chrooting (http://www.linuxquestions.org/questions/linux-general-1/permission-denied-on-dev-hda1-after-chrooting-359458/)

pwaring 09-02-2005 07:12 AM

Permission denied on /dev/hda1 after chrooting
 
I've got a copy of uVex installed on a Compact Flash card which is connected to an IDE interface so it appears as the first disk to Linux. At the moment I'm booting off a Damn Small Linux USB key pen but I want to use it to get the uVex installation setup properly so that I can run the machine off that. So far I've managed to mount the flash card and chroot into it without any problems using the following commands:

Code:

mount /mnt/hda1
chroot /mnt/hda1 /usr/bin/env HOME=/root /bin/bash

However, when I try to run lilo -v I get the following error echoed to the console:

Code:

Reading boot sector from /dev/hda1
Fatal: open /dev/hda1: Permission denied

I'm running this as root though, so how on earth can I get a permission denied error? Just to make doubly sure I ran ls -l /dev/ | grep hda and the permissions showed up as:

Code:

brw-r---- root root /dev/hda1
(same for all the other hda partitions). The permissions on /dev/ are set to allow root read/write access as well, and the compact flash partition is mounted as rw so I don't think that's the problem either.

Can anyone think of a reason why I might be getting this error? My best guess is that it has something to do with me being in a chroot but I don't know for sure.

Emerson 09-02-2005 08:17 AM

Re: Permission denied on /dev/hda1 after chrooting
 
Quote:

Originally posted by pwaring
Can anyone think of a reason why I might be getting this error? My best guess is that it has something to do with me being in a chroot but I don't know for sure.
I'm not familiar with the H/W used to connect a flashcard to IDE. Maybe the OS is just unable to write the boot sector using your current hardware? (Also, I remember a friend of mine had a virus in his W95 box which marked entire partition table read-only - don't know about HDD access in depth but things like that seem to be possible.)

pwaring 09-02-2005 08:20 AM

I can't see any reason why it wouldn't be able to write to the boot sector - the flash card is on a normal IDE interface so it should just be treated like a hard disk from the kernel's point of view (at least that's how it came up when I copied the initial data onto it).

It's definitely not a virus - this is a brand new CF card, only bought two days ago and it's only been used on Linux machines for specific purposes.

Emerson 09-02-2005 08:46 AM

Well, in situation like that best I can recommend is to try if some other utility can write the sector in question. Could you try reading the boot sector to a file and writing it back with dd?

pwaring 09-02-2005 08:49 AM

How would I actually do that? Things like 'cat /dev/hda' also fail with a permission denied error.

Emerson 09-02-2005 09:16 AM

Do not chroot or mount it.

read it:

# dd if=/dev/hda of=/path/mbr-backup bs=512 count=1

and write back with:

# dd if=/path/mbr-backup of=/dev/hda bs=512 count=1

pwaring 09-02-2005 09:29 AM

That worked without any errors, but when I mounted and chrooted again I still couldn't access /dev/hda. :(

saikee 09-02-2005 09:36 AM

I do have quite a few distros in the box and have to chroot to replicate their boot loaders when moving them around between hard disks.

My guess is the distro from which you chroot to or the one after you chroot to may not have been put together to do such things. Small distributions are made small by dropping out a lot of functionality.

Try a larger distro like the current Knoppix, Mepis or Slax.

Emerson 09-02-2005 09:41 AM

It shows there is no H/W restriction. Good. Are you sure you mounted it in rw mode? How it responds to 'mount | grep hda' ?

pwaring 09-02-2005 10:36 AM

Quote:

My guess is the distro from which you chroot to or the one after you chroot to may not have been put together to do such things. Small distributions are made small by dropping out a lot of functionality.
The distro is specifically for compact flash readers, that's the whole point. I don't want to use a big distro because the card only has 1Gb of space (and most of that is going to be used for data - I'm unlikely to have more than 128Mb for the O/S).

Quote:

Originally posted by Emerson
It shows there is no H/W restriction. Good. Are you sure you mounted it in rw mode? How it responds to 'mount | grep hda' ?
Code:

/dev/hda1 on /mnt/hda1 type ext2 (rw,nosuid,nodev)
I'm guessing that nodev part might have something to do with it?

Emerson 09-02-2005 10:49 AM

Yes, I believe it restricts the usage of dev files. Too lazy to look it up.

Edit: Looked it up. Definitely this is the problem. Dev files from a nodev mounted partition cannot be used, and this is what you wanted (had to) to do after chroot. I wonder where it (nodev) comes from. Is it in your fstab?

pwaring 09-05-2005 03:53 AM

nodev isn't anywhere to be found in /etc/fstab on the Damn Small Linux USB key, the relevant lines that I can find are:

Code:

# Added by KNOPPIX
/dev/hda1 /mnt/hda1 ext2 noauto,users,exec 0 0
# Added by KNOPPIX
/dev/hda2 /mnt/hda2 ext2 noauto,users,exec 0 0

So I don't know where the nodev stuff is coming from, unless you can somehow say "nodev is the default unless I say otherwise" (but I wouldn't have thought so, because you'd at least need it for the root partition).

Edit: Ah, apparently the users option implies nodev (and noexec/nosuid). :)


All times are GMT -5. The time now is 01:45 PM.