LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 08-31-2021, 07:12 AM   #1
A-Okay
LQ Newbie
 
Registered: Mar 2021
Posts: 22

Rep: Reputation: Disabled
Automate Screen resolution


Hi,

I am running a Linux OS in Virtualbox.

ls /bin/usr/*session shows, that I am using xfce4.

When I reboot the system, I have to change the screen resolution over the settings each time.

How could I set the screen resolution value, fix it, so I don't need to do change it everytime by doing it manually?

Thank you and best regards
 
Old 08-31-2021, 08:26 AM   #2
A-Okay
LQ Newbie
 
Registered: Mar 2021
Posts: 22

Original Poster
Rep: Reputation: Disabled
I had an idea but it doesn't work. What I did:

crontab -e
@reboot /usr/bin/xrandr -s 1600x1200
sudo systemctl enable cron.service
sudo nano /etc/cron.allow (put the user into it)
reboot

But after rebooting the OS it doesn't change.

Anymore ideas or am I doing smth. wrong with cron?
 
Old 08-31-2021, 09:22 AM   #3
enigma9o7
Senior Member
 
Registered: Jul 2018
Location: Silicon Valley
Distribution: Bodhi Linux
Posts: 1,402

Rep: Reputation: 561Reputation: 561Reputation: 561Reputation: 561Reputation: 561Reputation: 561
Two ways. Either put appropriate xrandr command in your autostart actions (for example "xrandr --mode 1600x900"). Test the command to make sure it works before adding it. https://wiki.archlinux.org/title/Xfce#Autostart

Or you could install virtualbox guest extensions, then set resolution from virtualbox menu. To install those, select the 'insert guest additions' cd option, then open the CD and run the VBoxLinux... script.

Last edited by enigma9o7; 08-31-2021 at 01:00 PM.
 
Old 08-31-2021, 12:34 PM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
It works for me without guest additions or convoluted cron/systemd commands (why not just use a systemd timer instead? But I digress....).
Just set up display resolution with common GUI tools in the guest OS, should get applied at login, and that should be enough.
Which distro, which desktop environment?
 
Old 08-31-2021, 02:23 PM   #5
A-Okay
LQ Newbie
 
Registered: Mar 2021
Posts: 22

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by enigma9o7 View Post
Two ways. Either put appropriate xrandr command in your autostart actions (for example "xrandr --mode 1600x900").
xrandr -s 1600x1200 is valid. I tried it in the cli and it worked. Why do you consider this as inappropriate?

Okay. I'll try to do the settings over Virtualbox. Ty for your input.

I did now a little script to speed it up, by doing:

cat > /usr/bin/setscreen
xrandr -s 1600x1200
chmod +x /usr/bin/setscreen

So I've only need to exec. "setscreen" in the cli to speed it up
 
Old 08-31-2021, 02:33 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
To answer your question about cron, since it is not automatically associated with the desktop so its like trying to run a GUI application without a GUI. To associate cron with the desktop you need to specify the display environment variable like:

@reboot DISPLAY=:0 xrandr -s 1600x1200
 
1 members found this post helpful.
Old 08-31-2021, 02:46 PM   #7
A-Okay
LQ Newbie
 
Registered: Mar 2021
Posts: 22

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post

@reboot DISPLAY=:0 xrandr -s 1600x1200
Ty for your input! Unfortunately doesn't work.

I think i'm going to stick with the little script. It's not an elegant way but better then nothing.

 
Old 08-31-2021, 02:52 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
Depending on distribution and cron version I should of added the full path to xrandr but check on your system.

@reboot DISPLAY=:0 /usr/bin/xrandr -s 1600x1200

As suggested above I would add guest additions. Depending on distribution/version you might need to install extra stuff like gcc and the source header files before you can actually install them.
 
1 members found this post helpful.
Old 08-31-2021, 08:09 PM   #9
enigma9o7
Senior Member
 
Registered: Jul 2018
Location: Silicon Valley
Distribution: Bodhi Linux
Posts: 1,402

Rep: Reputation: 561Reputation: 561Reputation: 561Reputation: 561Reputation: 561Reputation: 561
Quote:
Originally Posted by A-Okay View Post
xrandr -s 1600x1200 is valid. I tried it in the cli and it worked. Why do you consider this as inappropriate?
Sorry I didnt mean that it was invalid. I just meant use xfce autostart for any xrandr command that works, using one of those methods I linked earlier...

Quote:
To launch custom applications when Xfce starts up, click the Applications Menu > Settings > Settings Manager and then choose the Session and Startup option and click the tab Application Autostart. You will see a list of programs that get launched on startup. To add an entry, click the Add button and fill out the form, specifying the path to an executable you want to run.

Autostart applications are stored as name.desktop in ~/.config/autostart/.

Alternatively, add the commands you wish to run (including setting environment variables) to xinitrc (or xprofile when a display manager is being used).
Tip: Sometimes it might be useful to delay the startup of an application. Note that specifying under Application > Autostart a command such as sleep 3 && command does not work; a workaround is to use the syntax sh -c "sleep 3 && command"
Quote:
Originally Posted by A-Okay View Post
Okay. I'll try to do the settings over Virtualbox.
If you install the guest additions on guest OS, then you can select resolution from Virtual Box menu under View/Virtual Screen (which it remembers thru shutdowns and reboots, etc) for that machine. If you have hidden your menu bar, hit Ctrl+Home to get popup menu.

Last edited by enigma9o7; 08-31-2021 at 08:17 PM.
 
1 members found this post helpful.
Old 08-31-2021, 08:12 PM   #10
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,384
Blog Entries: 28

Rep: Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164
My experience with VirtualBox has been that, once I set the display in a VMs system settings, the VM has retained the setting.

One thought that comes to me is that, in the VirtualBox display settings for that VM (not the display settings within the VM), perhaps experimenting with the "Graphics Controller" setting might yield some results.
 
Old 09-02-2021, 02:39 PM   #11
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 483

Rep: Reputation: 153Reputation: 153
Quote:
When I reboot the system, I have to change the screen resolution over the settings each time.

How could I set the screen resolution value, fix it, so I don't need to do change it everytime by doing it manually?
This is actually a file persistence issue. It might indicate something else is wrong with the VM.

@frankbell
Quote:
My experience with VirtualBox has been that, once I set the display in a VMs system settings, the VM has retained the setting.
Quote:
I had an idea but it doesn't work. What I did:

crontab -e
@reboot /usr/bin/xrandr -s 1600x1200
sudo systemctl enable cron.service
sudo nano /etc/cron.allow (put the user into it)
reboot

But after rebooting the OS it doesn't change.

Anymore ideas or am I doing smth. wrong with cron?
The cron.service runs before graphical.target has even started X and the GUI. xrandr can't change the resolution of a screen that hasn't been created yet as X itself hasn't been started.

The cron.service runs at multi-user.target (old runlevel 3) while X and the DE are started at graphical.target (old runlevel 5).

It is simplest to use the DE autostart directory.

Last edited by tofino_surfer; 09-03-2021 at 01:39 AM.
 
Old 09-05-2021, 03:03 AM   #12
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,878
Blog Entries: 1

Rep: Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078
Quote:
Originally Posted by A-Okay View Post
/usr/bin/setscreen
This is a poor choice of location for a personally created script. In most distros, /usr/bin/ should be the exclusive domain of the package management system. Anything you place there is subject to being overwritten by package management activity. Scripts you create for global use are better placed in /usr/local/bin/ or /usr/local/sbin/.

Xrandr scripts will be run automatically if you place them in an appropriate location in /etc/X11/. The appropriate location depends on the distro. e.g. in Debian and derivatives, /etc/X11/Xsession.d/ usually works.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to automate starting a process in gnu screen and restart it when it crashes kav Linux - Server 6 09-12-2010 03:26 PM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
default screen resolution smaller than max. resolution ?? Thoddy Linux - General 2 11-10-2005 01:33 AM
Unable to configure screen resolution for 15.2" LCD screen in Fedore Core 1 schu Linux - Newbie 3 01-02-2004 05:39 PM
screen freezes after making changes to the screen resolution with Xconfigurator sharathkv Linux - Newbie 1 08-01-2003 05:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration