The Ubuntu startup/login sound can be very loud, but I do like having it. I wrote a script that uses amixer to set the volume to 25%. This is the level I like to have it at, but when I use TV out or headphones I have to turn up the volume. I cannot seem to get the script to run before the login sound plays. I have tried a cron @reboot, and putting a symlink to the script in /etc/rc3.d/, and in my .bash_profile script. Only the 3rd method actually sets the volume correctly, but after the login sound plays.
Ubuntu启动/登录声音可能非常响亮,但我确实喜欢它。我写了一个脚本,使用amixer将音量设置为25%。这是我喜欢的水平,但是当我使用电视或耳机时,我必须调高音量。在登录声音播放之前,我似乎无法让脚本运行。我已经尝试了一个cron @reboot,并在/etc/rc3.d/和我的.bash_profile脚本中为脚本添加了一个符号链接。只有第3种方法实际上正确设置了音量,但是在播放登录声音之后。
Ideally I want to have the script run when I am logging out for the night, or just before the ubuntu login screen displays.
理想情况下,我希望在我退出当晚或在ubuntu登录屏幕显示之前运行脚本。
Here is the command to set the volume:
以下是设置音量的命令:
`/usr/bin/amixer -c 0 sset Master,0 25% > /dev/null`
Suggestions for other methods to try are appreciated.
其他方法的建议值得赞赏。
7 个解决方案
#1
You might want to try adding that line to your like to /etc/rc.local
This may not be soon enough though, since rc.local will be called after gdm.
您可能想尝试将该行添加到/etc/rc.local中,但这可能不会很快,因为rc.local将在gdm之后调用。
Also note, the default runlevel on Ubuntu is 2, not 3. Your link in rc3.d probably didn't work simply because you where not using runlevel 3. The default runlevel is setup by /etc/event.d/rc-default
另请注意,Ubuntu上的默认运行级别是2而不是3.您在rc3.d中的链接可能不起作用,因为您没有使用运行级别3.默认运行级别由/etc/event.d/rc-default设置
#2
Ahh, yes, but do they also contain an "alsactl store" on shutdown?
啊,是的,但他们在关机时还包含一个“alsactl商店”吗?
#3
Rob,
I am trying to solve the same issue. I took you "amixer" line above and did alot of poking around learning about runlevels, the /etc/rc#.d folders and the update-rc.d command. It's not perfect. It still doesn't run during a restart the way I would want it to, but its a start.
我正在努力解决同样的问题。我在上面给你带了“amixer”行,并且在学习运行级别,/ etc / rc = .dad文件夹和update-rc.d命令方面做了很多。这不完美。它仍然不会像我希望的那样在重启期间运行,但它是一个开始。
Suggestions to improve it would would be welcome.
我们欢迎提出改进建议。
And, here is my code below.....
而且,这是我的代码......
sudo echo "#!/bin/bash" > /etc/init.d/lowvol.sh
sudo echo“#!/ bin / bash”> /etc/init.d/lowvol.sh
sudo echo "/usr/bin/amixer -c 0 sset Master,0 35% > /dev/null" >> /etc/init.d/lowvol.sh
sudo echo“/ usr / bin / amixer -c 0 sset Master,0 35%> / dev / null”>> /etc/init.d/lowvol.sh
sudo chmod +x /etc/init.d/lowvol.sh
sudo chmod + x /etc/init.d/lowvol.sh
sudo chown root:root /etc/init.d/lowvol.sh
sudo chown root:root /etc/init.d/lowvol.sh
sudo update-rc.d lowvol.sh stop 20 0 6 .
sudo update-rc.d lowvol.sh stop 20 0 6。
#4
I've used this method to achieve that before, but on Arch Linux. Now, I'm not too familiar with the init system Ubuntu uses, but I guess you could try adapting this to Ubuntu.
我之前使用过这种方法来实现它,但是在Arch Linux上。现在,我不太熟悉Ubuntu使用的init系统,但我想你可以尝试将其改编为Ubuntu。
#5
I believe that Ubuntu's startup scripts already include an "alsactl restore". You should be able to run "alsactl store" with the volume already set to 25% and affect all future reboots.
我相信Ubuntu的启动脚本已经包含了“alsactl restore”。您应该能够运行“alsactl store”,其中卷已设置为25%并影响所有将来的重新启动。
#6
What you can do is to write a script to lower down your volume when you shut down your computer. Something like this:
您可以做的是在关闭计算机时编写一个脚本来降低音量。像这样的东西:
#!/bin/sh
amixer -- sset Master playback -40dB
exit 1
then run this script at shutdown.
然后在关机时运行此脚本。
#7
Create a unit configuration and enable it for startup.
创建单元配置并启用它以进行启动。
Assuming ALSA and systemd (Ubuntu uses systemd version after 14 onwards)
假设ALSA和systemd(Ubuntu在14之后使用systemd版本)
/etc/systemd/system/alsavolume.service
Create a unit file here. You can adjust the command to run /usr/bin/amixer sset PCM -- 97%
. Remember not to use quotations (otherwise systemd will interpret the whole thing as a command).
在此处创建单元文件。您可以调整命令以运行/ usr / bin / amixer sset PCM - 97%。记住不要使用引号(否则systemd会将整个事物解释为命令)。
[Unit]
Description="Set volume level."
After=sound.target
[Service]
Type=simple
ExecStart=/usr/bin/amixer sset PCM -- 97%
[Install]
WantedBy=multi-user.target
Enable it (this means creating a symbolic link to /etc/systemd/system/multi-user.target.wants
to run at startup, but the following commands take care of it for you.)
启用它(这意味着创建一个符号链接到/etc/systemd/system/multi-user.target.wants以在启动时运行,但以下命令会为您处理它。)
-
Reload daemons
systemctl daemon-reload
-
Enable service
systemctl enable alsavolume.service
systemctl enable alsavolume.service
You can add the parameter
--now
to run the unit immediately.您可以添加参数 - 现在立即运行该单元。
重新加载守护进程systemctl守护进程重新加载
#1
You might want to try adding that line to your like to /etc/rc.local
This may not be soon enough though, since rc.local will be called after gdm.
您可能想尝试将该行添加到/etc/rc.local中,但这可能不会很快,因为rc.local将在gdm之后调用。
Also note, the default runlevel on Ubuntu is 2, not 3. Your link in rc3.d probably didn't work simply because you where not using runlevel 3. The default runlevel is setup by /etc/event.d/rc-default
另请注意,Ubuntu上的默认运行级别是2而不是3.您在rc3.d中的链接可能不起作用,因为您没有使用运行级别3.默认运行级别由/etc/event.d/rc-default设置
#2
Ahh, yes, but do they also contain an "alsactl store" on shutdown?
啊,是的,但他们在关机时还包含一个“alsactl商店”吗?
#3
Rob,
I am trying to solve the same issue. I took you "amixer" line above and did alot of poking around learning about runlevels, the /etc/rc#.d folders and the update-rc.d command. It's not perfect. It still doesn't run during a restart the way I would want it to, but its a start.
我正在努力解决同样的问题。我在上面给你带了“amixer”行,并且在学习运行级别,/ etc / rc = .dad文件夹和update-rc.d命令方面做了很多。这不完美。它仍然不会像我希望的那样在重启期间运行,但它是一个开始。
Suggestions to improve it would would be welcome.
我们欢迎提出改进建议。
And, here is my code below.....
而且,这是我的代码......
sudo echo "#!/bin/bash" > /etc/init.d/lowvol.sh
sudo echo“#!/ bin / bash”> /etc/init.d/lowvol.sh
sudo echo "/usr/bin/amixer -c 0 sset Master,0 35% > /dev/null" >> /etc/init.d/lowvol.sh
sudo echo“/ usr / bin / amixer -c 0 sset Master,0 35%> / dev / null”>> /etc/init.d/lowvol.sh
sudo chmod +x /etc/init.d/lowvol.sh
sudo chmod + x /etc/init.d/lowvol.sh
sudo chown root:root /etc/init.d/lowvol.sh
sudo chown root:root /etc/init.d/lowvol.sh
sudo update-rc.d lowvol.sh stop 20 0 6 .
sudo update-rc.d lowvol.sh stop 20 0 6。
#4
I've used this method to achieve that before, but on Arch Linux. Now, I'm not too familiar with the init system Ubuntu uses, but I guess you could try adapting this to Ubuntu.
我之前使用过这种方法来实现它,但是在Arch Linux上。现在,我不太熟悉Ubuntu使用的init系统,但我想你可以尝试将其改编为Ubuntu。
#5
I believe that Ubuntu's startup scripts already include an "alsactl restore". You should be able to run "alsactl store" with the volume already set to 25% and affect all future reboots.
我相信Ubuntu的启动脚本已经包含了“alsactl restore”。您应该能够运行“alsactl store”,其中卷已设置为25%并影响所有将来的重新启动。
#6
What you can do is to write a script to lower down your volume when you shut down your computer. Something like this:
您可以做的是在关闭计算机时编写一个脚本来降低音量。像这样的东西:
#!/bin/sh
amixer -- sset Master playback -40dB
exit 1
then run this script at shutdown.
然后在关机时运行此脚本。
#7
Create a unit configuration and enable it for startup.
创建单元配置并启用它以进行启动。
Assuming ALSA and systemd (Ubuntu uses systemd version after 14 onwards)
假设ALSA和systemd(Ubuntu在14之后使用systemd版本)
/etc/systemd/system/alsavolume.service
Create a unit file here. You can adjust the command to run /usr/bin/amixer sset PCM -- 97%
. Remember not to use quotations (otherwise systemd will interpret the whole thing as a command).
在此处创建单元文件。您可以调整命令以运行/ usr / bin / amixer sset PCM - 97%。记住不要使用引号(否则systemd会将整个事物解释为命令)。
[Unit]
Description="Set volume level."
After=sound.target
[Service]
Type=simple
ExecStart=/usr/bin/amixer sset PCM -- 97%
[Install]
WantedBy=multi-user.target
Enable it (this means creating a symbolic link to /etc/systemd/system/multi-user.target.wants
to run at startup, but the following commands take care of it for you.)
启用它(这意味着创建一个符号链接到/etc/systemd/system/multi-user.target.wants以在启动时运行,但以下命令会为您处理它。)
-
Reload daemons
systemctl daemon-reload
-
Enable service
systemctl enable alsavolume.service
systemctl enable alsavolume.service
You can add the parameter
--now
to run the unit immediately.您可以添加参数 - 现在立即运行该单元。
重新加载守护进程systemctl守护进程重新加载