LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sudo help required (https://www.linuxquestions.org/questions/linux-newbie-8/sudo-help-required-464178/)

greengrocer 07-14-2006 10:49 PM

sudo help required
 
Hello all,

I am still building this Ubuntu 5.10 (Breezy) computer for a friend.

When I open Xine from the Applications menu in Gnome desktop and play a DVD, the DVD playback is jittery and tends to jump a little.

If I open a Terminal and type in "hdparm -d1 -dma -c1 /dev/dvd", this fixes the problem.

I dont want the end user to have to type this command for two reasons:

1) They shouldnt need to.
2) They need the SU password to do it.

So, I was thinking of doing the following (but it doesnt seem to work)

1) I made the following shell script and placed it in /usr/bin:

sudo -u <username> hdparm -d1 -dma -c1 /dev/dvd
xine

2) I added the following to /etc/sudoers file:

user ALL=(ALL) NOPASSWD: /etc/default/hdparm -d1 -dma -c1 /dev/dvd

3) I edited the menu item in Gnome so that it ran my shell script.


What happens is that xine launches, but the hdparm command does not get executed properly.

If I type "sudo -u <username> hdparm -d1 -dma -c1 /dev/dvd" in the command line I get the following:

setting 32-bit IO_support flag to 1
HDIO_SET_32BIT failed: Permission denied
setting using_dma to 1 (on)
HDIO_SET_DMA failed: Permission denied
HDIO_GET_MULTCOUNT failed: Invalid argument
IO_support = 0 (32-bit)
using_dma = 0 (off)
readahead = 256 (on)


It appears that hdparm is being run with user priviledges but it needs SU priviledges.

I must be doing something wrong, but I cannot work it out :( ..... I tried :)

Can somebody point out where I am getting this wrong?

Thanx
Greenie

nadroj 07-14-2006 10:54 PM

do you need to run this command after every time you open the player to watch a dvd? ie, you run the command to fix the hdparam's, open the player and it works fine. later on you open another player--do you have to run the command again?

if you only have to run the command once, then you could just put 'hdparm -d1 -dma -c1 /dev/dvd' in one of your startup scripts (i think debian-based systems have them in /etc/init.d/ though i may be wrong). check out that folder and add the command. in slackware there is a 'local' script that is used for stuff like this (misc extra commands to run at boot).

hope this helps.

rickh 07-14-2006 11:05 PM

Maybe, put the hdparm command at the end of /etc/hdparm.conf

greengrocer 07-14-2006 11:06 PM

Hi nadroj (Jordan???),

Thank you so much for the quick reply,
and you have a good point.

The command need only be run once. Once it is run, Xine will always playback DVD's fine.

So I could put use command "hdparm -d1 -dma -c1 /dev/dvd" at system startup.

I have /etc/init.d/ (init.d is a directory)

Inside /etc/init.d/ are a bunch of files that I dont want to touch with my noobness. So should I just make a shell script with the command inside that directory? And will it run as SU?

nadroj 07-14-2006 11:10 PM

:p yes!

im not sure if those kind of scripts are like the slackware (bsd)-based ones. ie, for slackware, any executable file in the folder is executed at boot.

check out what rickh said as it seems alot more logical and would be the more appropriate place

your welcome

greengrocer 07-14-2006 11:23 PM

Hi Rickh,

putting the line: "hpdparm -d1 -dma -c1 /dev/dvd" in /etc/hdparm.conf doesn't solve this issue :(

I noticed that in my hdparm.conf file, everything exitsing in that file is #'d out.

I added the command to the end of the file and rebooted the system, but output of hdparm /dev/dvd is like this:

IO_support = 0 (default 16-bit)
unmaskirq = 0 (off)
using_dma = 0 (off)
keepsettings = 0 (off)
readonly = 0 (off)
readahead = 256 (on)
HDIO_GETGEO failed: Invalid argument


Regards,
Greenie

nadroj 07-14-2006 11:27 PM

running this command with sudo doesnt produce this output, correct?
can you post this file?

rickh 07-14-2006 11:28 PM

That should work. I use it to turn dma off on mine ... a hardware quirk. Maybe hdparm is running before your hardware aliases are fixed ... Try identifying it as /dev/hdc (or whatever the right hd? would be.)

Also, I wonder what "keepsettings=1" would do.

Quote:

putting the line: "hpdparm -d1 -dma -c1 /dev/dvd" in /etc/hdparm.conf doesn't solve this issue
Did you do it per the example:
Code:

command_line {
      hpdparm -d1 -dma -c1 /dev/dvd
}


HappyTux 07-14-2006 11:37 PM

Quote:

Originally Posted by greengrocer
Hi Rickh,

putting the line: "hpdparm -d1 -dma -c1 /dev/dvd" in /etc/hdparm.conf doesn't solve this issue :(

I noticed that in my hdparm.conf file, everything exitsing in that file is #'d out.

I added the command to the end of the file and rebooted the system, but output of hdparm /dev/dvd is like this:

IO_support = 0 (default 16-bit)
unmaskirq = 0 (off)
using_dma = 0 (off)
keepsettings = 0 (off)
readonly = 0 (off)
readahead = 256 (on)
HDIO_GETGEO failed: Invalid argument


Regards,
Greenie


Why not try using the actual device that /dev/dvd is linked to like /dev/hdc in the command. BTW where are you getting the idea that -dma is to be used in the line the -d1 you are using turns on the dma it is not even a parameter to be used AFAIK. You may want to try putting it in the file /etc/init.d/bootmisc.sh near the bottom I had to use this once upon a time when the hdparm.conf did not want to work for me.

greengrocer 07-14-2006 11:47 PM

I added:

command_line {
hpdparm -d1 -dma -c1 /dev/dvd
}


to the end of /etc/hdparm.conf


Rebooted but no joy :(


@ HappyTux,

If I type "sudo hdparm -d1 -dma -c1 /dev/dvd" in a terminal and then enter the su password then Xine will playback a DVD flawlessly.

If I don't issue the above command, DVD playback will be all jumpy and jittery.

Thats why I am using that command, it seems to solve the problem. All I need now is for the end user to not have to type that command in each time they want to play a DVD.

I wondered about the -dma switch, I also think that it probably doesnt do anything, and that it is the -d and -c switches that are doing the work here.

nadroj 07-14-2006 11:51 PM

did you try adding the command to a startup script?

rickh 07-14-2006 11:54 PM

Appears to me that all you need to do is turn on DMA. Mysterious to me why it's turned off by default. Humor me once, and change that coding to:

command_line {
hpdparm -d1 /dev/hdc
}

greengrocer 07-15-2006 12:04 AM

HappyTux's suggestion worked.

If I add the line "hdparm -d1 -dma -c1 /dev/dvd" to the file /etc/init.d/bootmisc.sh, above the line ": exit 0" the dma problem is then solved.


@ rickh,

I read somewhere that dma is switched off by default in Ubuntu Breezy. I cannot recall the reason why (if there was a reason at all).


So my immediate DMA problem is solved. I still dont know why my sudoers method did not work. Does anyone know why my sudoers method did not work (theoretically the sudo method should work if it is implemented correctly).

Electro 07-15-2006 02:16 AM

The option -dma is incorrect for hdparm. You just need -d1. Depending on the drive, including -k1 and -K1 forces the keep setting optin. It will not hurt anything. You may need to include -X66 to activate DMA-2.

Depending on your boot loader. Add hdX=dma on the kernel or append line of your boot loader config file. X designates the letter of the drive. If your DVD drive is on Secondary Master, it will be hdc. You should recompile the kernel to always enable DMA.


All times are GMT -5. The time now is 02:48 AM.