Ubuntu 16.04 Display Utility |
When you click on the resolution drop-down control, you will see only one option. For some reason unknown to me the Hyper-V display driver does not support changing the VM's resolution after it has started although it is perfectly capable of booting up in different resolutions.
There is a simple resolution to the problem, if you are satisfied with having only one resolution to work with as long as it is the resolution you desire. That is to modify grub's default configuration to specify the resolution when it boots up into Ubuntu. Benjamin Armstrong describes the change in his article, Changing Ubuntu Screen Resolution in a Hyper-V VM.
What if that is not enough? For example in my case I want to be able to maximize the VM to fill either of two different monitors on the host, and have a smaller size I can use when I want to record a screen demo. For that things are a little more difficult. However, if you can make the change Armstrong outlined, you should be able to do everything described here.
Unfortunately we don't know how to enable multiple resolutions from within the VM, but it is possible to modify grub to support booting in to different resolutions. To do that follow the steps presented below.
Reveal the Grub Menu
We plan add several menu options to grub to support the various resolutions we desire, so it won't do if the menu is hidden during the boot up. To make the menu appear during the boot open /etc/default/grub in your favorite Linux text editor with root privileges. For example:
sudo nano /etc/default/grub
Then look for the following two lines near the top of the file, and comment them by adding "#" at the start of each.
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=false
These lines should look like the following after you have done this.
#GRUB_HIDDEN_TIMEOUT=0
#GRUB_HIDDEN_TIMEOUT_QUIET=false
Optionally, if you are sure you always want to see the menu during the boot you can simply delete the lines.
Optionally Set Grub Memory
If you want grub to remember your last selection for automatic boots make the following changes to /etc/default/grub.
Look for the following line near the top of the file (the rightward side of the equal sign might differ).
GRUB_DEFAULT=0
Change that line by replacing the value on the right of the equal sign with the word "saved." It will look like this, after completing this step.
GRUB_DEFAULT=saved
Now add the following line below GRUB_DEFAULT.
GRUB_SAVEDEFAULT=true
When you are finished with this step you should have two lines near the top of the grub file that look like this.
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
Important: See note below under "Create a Menu Entry Template."
Save You Grub Changes
Now save your changes to /etc/default/grub and exit your editor.
Create a Menu Entry Template
The next step will modify another grub configuration file called 40_custom under the /etc/grub.d directory. Before we can do this we need to extract some code from another file to make a template. Using your favorite editor open /boot/grub/grub.cfg. We don't want to make changes to this file so don't use sudo. For example:
nano /boot/grub/grub.cfg
Now save the contents of this file to your home directory as "me-template" so you can modify its contents. (In nano press control-O and save the file to ~/me-template.) Now search within the file for the default menu entry for Ubuntu. Searching for "menuentry 'Ubuntu'" should find it for you, and add a few blank lines before the line so you can see the beginning of the code easily. After you have done this it will look something like this.
Modified Template |
Use your editor to delete all of the lines above the menu entry including the blank lines you created. Now you should have only the menu entry you found plus everything following it. Your editor may look something like this.
Nano Editor |
Below the menu entry you should see a line that starts with "submenu." You can see this in the illustration above about half way down. Starting with that line delete it and everything below that line to the end of the file. You should be left with nothing but the original default menu entry code.
On the top line delete everything after the 'Ubuntu' except for the last bracket character ("{"). Then at the end of the quoted text add a space and this text, "(AAAxBBB)." The top line of the code should look like then when this step is complete.
menuentry 'Ubuntu (AAAxBBB)'
{Now modify the line that starts with the word "linux" and replace the last word, "$vt_handoff," with the following text.
video=hyperv_fb:AAAxBBB
Note: After writing this article I discovered that making the changes described above under "Optionally Set Grub Memory" are not enough to cause grub to remember choices made using menu entries made with this template. To enable the template entries to be saved add a line after the line that reads "recordfail" and add the command "savedefault." After this step your template should look like this.
Template with savedefault Line Added |
That's it for the template. Be sure to save your changes before exiting your editor.
Modify 40_custom
Now we will use the template to modify the 40_custom file under the /etc/grub.d directory. Use your favorite editor with sudo to open the file. I use nano, so I'll issue the command,
sudo nano /etc/grub.d/40_custom
For each resolution you want to support within Ubuntu add a copy of the template replacing "AAAxBBB" in each with the desired resolution. There are two locations within the template that need to change: one is in the menu entry name at the start of the template, and the other is at the end of the line starting with the word linux. Obviously both instances should be the same in each menu entry to make sense.
My complete 40_custom file looks like this:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'Ubuntu (1280x720)' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5
else
search --no-floppy --fs-uuid --set=root 55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5
fi
linux /boot/vmlinuz-4.4.0-65-generic root=UUID=55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5 ro quiet splash video=hyperv_fb:1280x720 $vt_handoff
initrd /boot/initrd.img-4.4.0-65-generic
}
menuentry 'Ubuntu (1600x900)' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5
else
search --no-floppy --fs-uuid --set=root 55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5
fi
linux /boot/vmlinuz-4.4.0-65-generic root=UUID=55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5 ro quiet splash video=hyperv_fb:1600x900
initrd /boot/initrd.img-4.4.0-65-generic
}
menuentry 'Ubuntu (1920x1080)' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5
else
search --no-floppy --fs-uuid --set=root 55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5
fi
linux /boot/vmlinuz-4.4.0-65-generic root=UUID=55a7670b-1426-46ef-9f6a-d9ed6a6d7ee5 ro quiet splash video=hyperv_fb:1920x1080
initrd /boot/initrd.img-4.4.0-65-generic
}
Generate a New grub.cfg File
If you have followed these steps carefully you are ready to compile your changes into a new grub.cfg file. for this execute the following command.
sudo update-grub
You should see something like this, if everything is okay.
Successful update-grup Output |
If instead error messages appear, use the error messages to track down your mistakes and correct them.
If the update is successful, you should be able now to reboot Ubuntu and select the resolution you desire to use. When I boot up the VM now I see the following boot menu.
New GRUB Menu |
Enjoy!
No comments:
Post a Comment
Comments are welcome but monitored for appropriate content.