convert xrandr commands to xorg.conf settings

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Ramblin

convert xrandr commands to xorg.conf settings

Post by Ramblin »

I am running a headless - no monitor - server running LinuxMint19 with vino-server feeding an UltraVNC client on a Windows 7 PC.

With the initial system settings, when I connect to the server via UltraVNC, I get a screen that is 800x600. That is too small and crowded to be very useful.

I have been able to change the default screen size for the connection to a larger screen (1280x960 instead of 800x600) with xrandr commands and I have put the xrandr commands into a startup application so they are set each time I start or reboot the system.

But ...

Is there a way to put the equivalent settings into an xorg.conf file?

For all I know it cannot be done in xorg.conf files, but if so, could someone please tell me (and save what little hair I have left)?
Is it possible that in a headless environment with no connected monitors you cannot initialize a larger screen size via xorg.conf since there is no "connected monitors" until I connect in (via UltraVNC to vino-server) to manually make the settings?

I hope it is possible, but so far, after numerous attempts and many days of reading man pages and other posts, I cannot get it to work using only the xorg.conf files.

If someone could tell me what I need to put into an xorg.conf file to accomplish the same thing as

Code: Select all

    xrandr --newmode "1280x960_60.00"  101.25  1280 1360 1488 1696  960 963 967 996 -hsync +vsync
    xrandr --addmode VIRTUAL1 "1280x960_60.00"
    xrandr --output VIRTUAL1 --mode 1280x960_60.00
I would appreciate it.

Please do not suggest alternative VNC servers (or other additional applications/packages) as a solution. I know I could use x11vnc or other vnc servers and there may be other additional applications that could work, but since I have it working with vino-server and xrandr commands, I know it will work; I just can't get it to work with xorg.conf settings and would prefer to learn how and do it that way.

I used

Code: Select all

    cvt 1280 960
to get the Modeline settings for the higher screen size and used the xrandr commands above to tell the system to show me a larger screen. Everything works fine, until of course the next reboot.

So I put the xrandr commands into a startup script and it works, giving me the larger screen at every startup and reboot.

I did try the above in .profile and .bashrc but there were issues with each of those so I reverted to the startup script solution and it works.

But I would prefer to use xorg.conf files to accomplish the same thing. Unfortunately, up until now, I can only get the first two xrandr commands "kind of" simulated by putting the code below into /usr/share/X11/xorg.conf.d/80-larger-monitor-for-remote-desktop.conf - but I cannot get the --output command duplicated. I still need to manually (or via startup script) use the xrandr --output command.

Code: Select all

    Section "Monitor"
        Identifier "VIRTUAL1"
        HorizSync 28.0-80.0
        VertRefresh 48.0-75.0
        Modeline "1280x960_60.00"  101.25  1280 1360 1488 1696  960 963 967 996 -hsync +vsync
        Option "PreferredMode" "1280x960_60.00"
        Option "Enable" "true"
    EndSection
I say "kind of simulated" since, after creating the above xorg.conf file and rebooting, I can just run the final xrandr command
xrandr --output VIRTUAL1 --mode 1280x960_60.00
and the correct screen size will be created, but not in exactly the same way. The larger screen will be created but a subsequent xrandr -q command does NOT report the same result as when I use all three xrandr commands above instead of the xorg.conf file.

When I do NOT use the xorg.conf settings and instead use the full set of xrandr commands, the output of xrandr -q is

Code: Select all

    Screen 0: minimum 8 x 8, current 1280 x 960, maximum 32767 x 32767
    DP1 disconnected (normal left inverted right x axis y axis)
    HDMI1 disconnected (normal left inverted right x axis y axis)
    VGA1 disconnected (normal left inverted right x axis y axis)
    VIRTUAL1 connected 1280x960+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
       1280x960_60.00  59.94* 
    VIRTUAL2 disconnected (normal left inverted right x axis y axis)
but when I use the xorg.xonf settings and only use the xrandr --output command, the screen size is changed but the output of xrandr -q shows the VIRTUAL1 monitor as disconnected and there is no VIRTUAL2 monitor added.

So apparently, I do not have the settings quite figured out.

I do NOT want to use the dummy driver solution suggested in other posts, since that creates a software driver and it eliminates any acceleration for the monitor. The performance difference is noticeable.

And the fact that I can successfully do this using all xrandr commands says it is doable without a dummy driver; I just cannot fgure out how to do it via xorg.conf file settings.

In case you were going to suggest a more comprehensive xorg.conf file (please do) you should know that I tried, in /usr/share/X11/xorg.conf.d/80-larger-monitor-for-remote-desktop.conf

Code: Select all

    Section "ServerLayout"
    	Identifier "RC Remote Desktop"
        Screen     0 "RC Screen" 0 0
    EndSection
    
    Section "Monitor"
        Identifier "VIRTUAL1"
        HorizSync 28.0-80.0
        VertRefresh 48.0-75.0
        Modeline "1280x800_60.00"   83.50  1280 1352 1480 1680  800 803 809 831 -hsync +vsync
        Modeline "1280x960_60.00"  101.25  1280 1360 1488 1696  960 963 967 996 -hsync +vsync
        Option "PreferredMode" "1280x960_60.00"
        Option "Enable" "true"
    EndSection
    
    Section "Device"
        Identifier "RC Device"
    	Driver "intel"
    	BusID "PCI:0:2:0"
    EndSection
    
    Section "Screen"
        Identifier "RC Screen"
        Device "RC Device"
        Monitor "VIRTUAL1"
        SubSection "Display"
            Depth 24
            Modes "1280x960_60.00"    
        EndSubSection
    EndSection
but there was no change to the result.

Any ideas?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
AndyMH
Level 21
Level 21
Posts: 13757
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: convert xrandr commands to xorg.conf settings

Post by AndyMH »

Don't know about xorg.conf, but you can put your xrandr commands into .profile (lives in home). Or you can edit the lightdm conf file. See my post:

viewtopic.php?f=46&t=280143
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Ramblin

Re: convert xrandr commands to xorg.conf settings

Post by Ramblin »

AndyMH wrote: Wed Dec 05, 2018 5:25 am ou can put your xrandr commands into .profile (lives in home). Or you can edit the lightdm conf file. See my post:
viewtopic.php?f=46&t=280143
I did not know I could point to scripts from /etc/lightdm/lightdm.conf.d/70-linuxmint.conf

Thanks for the info.

As it turns out, because I am running headless, if I use .profile, the system tries to run the xrandr commands before there is anything connected and it generates startup errors, requiring me to physically go to the server, connect monitor and keyboard/mouse and click OK on the error dialog before the system will finish starting.

So I am assuming a similar issue will occur if I use lightdm to trigger the xrandr commands?

That is why I ended up with a startup application, so it will not try xrandr commands until I have actually signed in / connected.

The error message is one of the reasons I am wondering if it is not possible t do this via xorg.conf, but still hoping I can learn enough about xorg.conf to figure this out using xorg.conf.
User avatar
AndyMH
Level 21
Level 21
Posts: 13757
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: convert xrandr commands to xorg.conf settings

Post by AndyMH »

I did not know I could point to scripts from /etc/lightdm/lightdm.conf.d/70-linuxmint.conf
Might be worth a try?

I did find this https://www.x.org/archive/current/doc/m ... nf.5.xhtml and might have a play myself to see if it is a better way of solving the problems I had in the link I posted.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Ramblin

Re: convert xrandr commands to xorg.conf settings

Post by Ramblin »

AndyMH wrote: Wed Dec 05, 2018 7:35 am
That was a nice layman's language explanation of xorg.conf settings, thank you.

I tried some new xorg.conf settings - and only had to go physically to the server to rescue it :-) - but no change from the situation I am in.

As for the lightdm option, it would allow me to trigger xrandr commands from a new place, and I may use that for another issue, but I already know xrandr commands triggered after startup will give me what I want so I am looking to see if it can be done via xorg.conf.

I am starting to doubt that it can be done via xorg.conf in a headless environment since there is no connected monitor when the system starts, and only when I log in via vino-server and create a "connected" monitor will the system let me change settings.

If you do discover anything different, please do let me know.
User avatar
Spearmint2
Level 16
Level 16
Posts: 6900
Joined: Sat May 04, 2013 1:41 pm
Location: Maryland, USA

Re: convert xrandr commands to xorg.conf settings

Post by Spearmint2 »

You put not in .profile, but in .xprofile, which you create with text editor. Put those xrandr commands in it, and into the user profile folder.
All things go better with Mint. Mint julep, mint jelly, mint gum, candy mints, pillow mints, peppermint, chocolate mints, spearmint,....
Ramblin

Re: convert xrandr commands to xorg.conf settings

Post by Ramblin »

Spearmint2 wrote: Thu Dec 06, 2018 5:05 am You put not in .profile, but in .xprofile, which you create with text editor. Put those xrandr commands in it, and into the user profile folder.
I appreciate the clarification and may use that in a future scenario

But in this situation I am trying to find a way to get xorg.conf to work; I already have a solution using xrandr commands - albeit in a startup application not as commands in .xprofile - but the real question is:
How (and is it possible) to accomplish this with xorg.conf settings in a headless environment?
msummerfield

Re: convert xrandr commands to xorg.conf settings

Post by msummerfield »

I have been grappling with a similar problem over the past couple of days. I am using x11vnc server on a Linux Mint 19.1 host, and RealVNC Viewer on a Windows notebook, and trying to get the Linux box to function headless.

There are many supposed solutions using Xorg conf files, but none of them worked for me. The challenge (as you have found) is getting Xorg to associate a nonexistent monitor with a GPU, and set a desired mode. I think the VIRTUAL1 port (which is not supported by all GPUs/drivers) is a bit of a red herring. You have succeeded in defining a mode name ("1280x960_60.00"), but not making any of the other connections, which is why VIRTUAL1 remains disconnected until you connect it with 'xrandr --output ...'.

As far as I can work out, the only thing that really matters in the Xorg conf files is somehow forcing Xorg to identify a GPU. With no real monitors connected, it finds no corresponding GPU (i.e. corresponding to a "Device" in the config files), and therefore does not set up a sensible display mode. In your case, I suspect that identifying VIRTUAL1 in a "Monitor" section was enough to do the trick.

Alternatively, you can simply use a "Device" section to enforce a default when no connected monitors are found. And the most important thing about this seems to be to specify an Xorg device driver, i.e. none of the other settings seem to make any difference. I am just using this, in a file /usr/share/X11/xorg.conf.d/10-device.conf:

Code: Select all

Section "Device"
    Identifier     "Device0"
    Driver         "intel"
    VendorName     "Intel Corporation"
EndSection
From here, I could not for the life of me find a way to specify a default mode via Xorg conf files. I just got 1024x768 no matter what I did! Although Xorg must be getting that default resolution from somewhere, I couldn't find a way to override it, and I ended up (as AndyMH suggested) adding the required xrandr command to the lightdm config directory, e.g. create /etc/lightdm/lightdm.conf.d/75-display-setup.conf containing:

Code: Select all

[SeatDefaults]
display-setup-script=/usr/bin/xrandr --fb 1920x1200
Note that you don't really need a script for a one-line command!

If you are ever going to attach a real monitor, however, it might be nice to bypass this when there is really a monitor connected, because Xorg will probably detect the most appropriate (and safe) settings. A script containing something along the following lines should do the trick (but I haven't actually tried it):

Code: Select all

#! /bin/sh
if xrandr | grep -q ' connected'    # Space is necessary, because unconnected ports say 'disconnected'
then 
    echo Real monitor connected
    # Do nothing
else 
    echo No monitor connected
    xrandr --fb 1920x1200
fi
I hope my experience can be of some assistance to someone. And if anybody can make that final step to do everything in the Xorg conf files, I'd love to know how.
Ramblin

Re: convert xrandr commands to xorg.conf settings

Post by Ramblin »

Thank you for your reply; I figured I was not the only one who wanted to do this but it sure is not an easy thing - maybe not even possible - to accomplish it all via xorg.conf files.

I did try adding Device sections to my xorg.conf files, but it has been a while and I cannot remember exactly what I entered. The server is not with me so before I try this, I want to ask a question (see below for details): If I use the lightdm,conf setup to run a script, will it wait until I actually login to run the script?

The reason I ask? When I tried putting the xrandr commands into any one of the /home/{user}/.profile or /home/{user}/.bash_aliases or /home/{user}/.bashrc files, it generated an error message about no device connected which needed to be acknowledged before boot would continue. So this meant I had to go to the server, physically connect monitor, keyboard and mouse, acknowledge the error and then continue my experiments.

The server is not with me right now, so if I try something that gives me this result again, I have a little trip in my future - which I'd like to avoid :-)

I did get to the point where I could have the first two xrandr commands "emulated" in xorg-conf:

Code: Select all

xrandr --newmode .....
xrandr --addmode VIRTUAL1 ....
I say "emulated" since when I manually (or via script) used the last xrandr command

Code: Select all

xrandr --output VIRTUAL1 ....
after handling the first two xrandr commands in xorg.conf settings, it did work, but when I used the xrandr command to see what output devices were there, it showed VIRTUAL1 as having the new resolution and it was working but VIRTUAL1 was shown as disconnected (even though it was working). When this was done with all xrandr commands via script (or manually) after logging in (and apparently "connecting"VIRTUAL1), VIRTUAL1 was shown as connected.
msummerfield wrote: Fri Dec 28, 2018 3:04 am Alternatively, you can simply use a "Device" section to enforce a default when no connected monitors are found. And the most important thing about this seems to be to specify an Xorg device driver, i.e. none of the other settings seem to make any difference. I am just using this, in a file /usr/share/X11/xorg.conf.d/10-device.conf:

Code: Select all

Section "Device"
    Identifier     "Device0"
    Driver         "intel"
    VendorName     "Intel Corporation"
EndSection
I noticed that the number preceding your filename (10-) is smaller than the numbers preceding the other files in /usr/share/X11/xorg.conf.d/ , which means your file is read and used early. If another file in that directory, with a larger number prefixing your file name, redefines Device0 , your settings would be overridden. Is that your intent?
msummerfield wrote: Fri Dec 28, 2018 3:04 am I ended up (as AndyMH suggested) adding the required xrandr command to the lightdm config directory, e.g. create /etc/lightdm/lightdm.conf.d/75-display-setup.conf containing:

Code: Select all

[SeatDefaults]
display-setup-script=/usr/bin/xrandr --fb 1920x1200
I was wondering if I could just use the command in the lightdm.conf file; thanks for showing how.
Questions: Why did you use

Code: Select all

xrandr -fb 1920x1200
instead of

Code: Select all

xrandr --output VIRTUAL1 --mode 1920x1200_60.00
(or whatever the modeline was for your 1920x1200 setting)


msummerfield wrote: Fri Dec 28, 2018 3:04 am

Code: Select all

#! /bin/sh
if xrandr | grep -q ' connected'    # Space is necessary, because unconnected ports say 'disconnected'
then 
    echo Real monitor connected
    # Do nothing
else 
    echo No monitor connected
    xrandr --fb 1920x1200
fi
I hope my experience can be of some assistance to someone. And if anybody can make that final step to do everything in the Xorg conf files, I'd love to know how.
As explained above, when the setup is all via xrandr commands (script or manual), the VIRTUAL monitor shows as "connected" so I'd modify the above script to check if monitors OTHER than VIRTUAL1 were connected but that is a relatively simple modification and you've given me a good idea. Thank you.

So, back to my real question: If I use the lightdm,conf setup to run a script, will it wait until I actually login to run the script?
msummerfield

Re: convert xrandr commands to xorg.conf settings

Post by msummerfield »

As I understand it, lightdm will read the config files in the directory /etc/lightdm/lightdm.conf.d in sequence according to the number at the start of each file name. By starting my added config file with 75- I ensure that it is run after the other existing config file (70-linuxmint.conf). If instead you have a single lightdm.conf file, you should be able to achieve the same effect by adding the lines at the end.

All this happens when the display manager starts up, i.e. after Xorg start, but before any user logs in.

As I said, I think that connecting VIRTUAL1 is a red herring. No monitor, either real or virtual, needs to be connected for x11vnc to work. The requirement is for there to be a framebuffer (i.e. display memory), which x11vnc monitors and sends to the remote VNC client using the VNC protocols. The output of xrandr -q on my Linux box is:

Code: Select all

Screen 0: minimum 8 x 8, current 1920 x 1200, maximum 32767 x 32767
DP1 disconnected primary (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
HDMI3 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
Note that none of the outputs is connected. Screen 0 is nonetheless associated with a framebuffer. Furthermore, since I told Xorg to use the Intel integrated GPU with the "Device" section this framebuffer is handled by the GPU and gets all the benefits of hardware acceleration, despite no monitor being connected.

This should answer why I used xrandr --fb 1920x1200 - all I need to do is set the desired resolution of the frame buffer. I do not need to connect any of the outputs, nor do I need to set up any of the timing parameters associated with a 'real' monitor mode. It is also why I do not need to worry about "Device0" being overridden - if there is a real monitor connected, Xorg detects it and correctly associates the current Screen with the corresponding output and graphics device. All I am doing is ensuring that Xorg is forced to recognise a device even if no monitor is connected. If that would have happened anyway, because there is a "Device" section in a subsequent config file in the sequence, then no harm done.

As for whether you should risk attempting this remotely given your concerns about maybe needing to be present to connect a real monitor, keyboard and mouse, all I can say is that this is all working for me, and I cannot see how this setup could prevent the machine from booting cleanly. The sequence of events is (1) machine boots, (2) Xorg starts, (3) lightdm starts. So even if the Xorg or lightdm config causes an error, you should still be able to log in via SSH to fix it. But, of course, you may have other things going on in your system configuration, so I can't possibly guarantee this!
Ramblin

Re: convert xrandr commands to xorg.conf settings

Post by Ramblin »

msummerfield wrote: Thu Jan 03, 2019 9:40 am... As for whether you should risk attempting this remotely ...
Thank you for the detailed response

I am blocked out for the next week on a new project but will give this a shot and let you know how it goes.

Thanks again.
Ramblin

Re: convert xrandr commands to xorg.conf settings

Post by Ramblin »

msummerfield wrote: Thu Jan 03, 2019 9:40 amI cannot see how this setup could prevent the machine from booting cleanly.
Thank you

I finally got back to this and did test it out.

It works.

A few things I had to do differently:
  • I do not have an integrated intel driver since my motherboard does not have onboard graphics, so when I (without thinking) put in the intel driver instead of the vesa driver, I had a panic moment when even my console would not work, but a recovery boot and file edit took the heart attack away :-)
  • I was actually trying to reduce the resolution since the default vesa output is the max resolution of 1280x768 and as much as I would have like that, the lag was noticeable so I reduced it to a native 1024x768 and the lag is less (still noticeable but less). Because of that, I could not use the --fb xrandr command since I would have been asking for a frame buffer that was less than my output and it generated an error (I did it manually to see why it was not working), but all I had to do was specify the default output using the xrandr command and it was better
One (of many lessons) thing I learned
  • When you said to use the file name 75-display-setup.conf and use display-setup-script in your file entry, I thought it was like most other xorg.conf files where you could name it whatever you wanted as long as you had the prefix number correct. That is not the case. you need to actually use that file name and script entry for it to work. who knew (other than you ... :-))
So, Thank you for your help and here is what I ended up doing:

Into /usr/share/X11/xorg.conf.d/80-rc-vesa-driver.conf I put

Code: Select all

Section "Device"
    Identifier   "Device0"
    Driver   "vesa"   
EndSection
Into /etc/lightdm/lightdm.conf.d/75-display-setup.conf I put

Code: Select all

[SeatDefaults]
display-setup-script=/usr/bin/xrandr --output default --mode 1024x768
restart light dm with

Code: Select all

sudo systemctl restart lightdm
and life is good

Thanks again
incanuskafre

Re: convert xrandr commands to xorg.conf settings

Post by incanuskafre »

This worked perfectly! thanx!
Just left one thing, this works perfect if you have the monitor plugged before starting the pc, but if yo don't, yo have to manually configure it after doing it, or simply restart. Is there any configuration file where I can put the script to be executed on plug?
Locked

Return to “Graphics Cards & Monitors”