Daily Archives: 8 February 2017

Fedora: Start a Virtual Machine using a physical hard disk

Recently, we wanted to start a Virtual Machine running a Windows installation from a physical hard disk.

We could not find a way for GNOME Boxes to achieve this, so we installed qemu to do so.

We installed qemu using:

sudo dnf install qemu -y;

Configuring our command to start the Virtual Machine from the physical hard drive:

  • Our hard disk was identified on the physical machine as /dev/sda so we set the -hda parameter to that value.
  • Then we added the parameter -boot c to instruct the virtual machine to boot from the first hard disk.
  • The default guest start-up RAM size was 128 MiB, so we set the parameter -m to 4096 to give to the virtual machine 4GB of RAM.
  • Finally we added the -snapshot parameter which instructed the system to write to temporary files instead of the disk image files (all disk images are considered as read only).
    In this case, the raw disk image used are not written back. When sectors are written, they are written in a temporary file created in /tmp.
    You can however force the write back to the raw disk images by using the commit monitor command (or C-a s in the serial console).

In the end our command was as follows:

sudo qemu-kvm -snapshot -m 4096 -boot c -hda /dev/sda;

Start CLion as root on Fedora 1


Execute the following as a normal user

xhost +si:localuser:root;
sudo ./clion.sh;

Background Story and More Information

Recently we needed to start CLion as root on Fedora to allow the application we were developing to bind the DHCP service of the system.
When we tried to start CLion as root we got the following error:

java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.

Specifically, the whole error log was as follows:

[[email protected] bin]$ sudo ./clion.sh 
[sudo] password for george: 
No protocol specified

Start Failed: Failed to initialize graphics environment

java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
    at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
    at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:126)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at java.awt.Toolkit$2.run(Toolkit.java:860)
    at java.awt.Toolkit$2.run(Toolkit.java:855)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
    at java.awt.Toolkit.getEventQueue(Toolkit.java:1734)
    at java.awt.EventQueue.isDispatchThread(EventQueue.java:1043)
    at javax.swing.SwingUtilities.isEventDispatchThread(SwingUtilities.java:1361)
    at javax.swing.text.StyleContext.reclaim(StyleContext.java:454)
    at javax.swing.text.StyleContext.addAttribute(StyleContext.java:311)
    at javax.swing.text.html.StyleSheet.addAttribute(StyleSheet.java:578)
    at javax.swing.text.StyleContext$NamedStyle.addAttribute(StyleContext.java:1501)
    at javax.swing.text.StyleContext$NamedStyle.setName(StyleContext.java:1312)
    at javax.swing.text.StyleContext$NamedStyle.<init>(StyleContext.java:1259)
    at javax.swing.text.StyleContext.addStyle(StyleContext.java:107)
    at javax.swing.text.StyleContext.<init>(StyleContext.java:87)
    at javax.swing.text.html.StyleSheet.<init>(StyleSheet.java:166)
    at javax.swing.text.html.HTMLEditorKit.getStyleSheet(HTMLEditorKit.java:391)
    at com.intellij.util.ui.UIUtil.<clinit>(UIUtil.java:102)
    at com.intellij.ide.plugins.PluginManager.start(PluginManager.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.ide.Bootstrap.main(Bootstrap.java:39)
    at com.intellij.idea.Main.main(Main.java:81)

This error occurred because the default configuration of the X server permissions did not allow the root to connect to it.
To verify this, we used xhost X server access control program to check the permissions.
Executing xhost with no command line arguments gave us a message indicating whether or not access control was currently enabled, followed by the list of those users allowed to connect.
For example in our case the output was as follows:

[[email protected] bin]$ xhost
access control enabled, only authorized clients can connect

To add root to the list of users that was allowed to start an X application we executed the following command:

[[email protected] bin]$ xhost +si:localuser:root
localuser:root being added to access control list

Executing xhost again, we got the updated list which included the root

[[email protected] bin]$ xhost
access control enabled, only authorized clients can connect

After this, we were able to start CLion using sudo with no problems.

[[email protected] bin]$ sudo ./clion.sh

Note: This patch is not permanent, we actually execute it once at every restart of the machine.

g++ not found on Fedora 25

On a Fedora 25 (64bit) we got the error g++ not found.

We could have installed g++ using:

sudo dnf install gcc-c++ -y;

But we wanted to install all common additional development tools that we might need for C/C++ development in the future without going over the list of available packages to find which ones.
To do so, we installed all the packages of the group that is marked to be used for C development using dnf as follows:

sudo dnf group install "C Development Tools and Libraries" -y;

A couple of notes on moving a VirtualBox ‘.vdi’ disk image to a GNOME Boxes virtual machine

Recently we had a CentOS virtual machine on VirtualBox which we wanted to use in GNOME Boxes.
We copied the .vdi disk image and we used it to create a new virtual machine in Boxes.

Note A:

By doing this we realized that the system did not reuse the .vdi image.
It merely created a copy at ~/.local/share/gnome-boxes/images/ that was suitable for GNOME Boxes.
So, be sure to have enough space when doing an import like this.
You will need at least twice the space of the .vdi image to complete the migration.

Note B:

When the guest OS started the window manager crashed and it did not allow us to login.
We assumed that this issue occurred due to the VirtualBox Guest Additions that were installed on the guest OS.
As we could not login with the graphical interface, we could not verify this claim.

Fortunately, CentOS (and many other Linux distributions) allow you to switch to a console login using the key combination alt + ctrl + F3.
(There are more than one valid key combinations to do this. In some systems alt + ctrl + F4 is also valid or alt + ctrl + F1 etc).
We hoped that by trying to login via a console login, the Guest Additions would not start and the system would not crash, which luckily this was the case, and we managed to login through the console!

After we logged in, we had to remove the Guest additions. To do so we had to execute the uninstall script that was located at /opt/VBoxGuestAdditions-X.Y.Z/uninstall.sh
(X.Y.Z is the version number of the installed VirtualBox Guest Additions).

When the removal was complete, we executed sudo reboot to restart the system and unload any VirtualBox services that could be executing at the time.
Once the system completed the restart we were able to login properly from the GUI of GNOME and use our virtual machine properly.

Really rough notes on compiling source code on Fedora 25 for STM32F767 Nucleo-144 (Nucleo-F767ZI)

#eclipse with support for C/C++
sudo dnf install -y eclipse-cdt;
#cross-compiler for arm
sudo dnf install -y arm-none-eabi-gcc arm-none-eabi-gdb arm-none-eabi-binutils arm-none-eabi-newlib arm-none-eabi-gcc-cs-c++;
#manually installing openocd from the repository as the version in the repositories does not support our board (STM32F767 Nucleo-144 (Nucleo-F767ZI))
git clone http://openocd.zylin.com/openocd;
cd openocd/;
sudo make install;

#download eclipse plugin from https://my.st.com/content/my_st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stsw-stm32095.license%3d1491636351998.html
#install using from menu “Help” > “Install New Software…” > “Add…” > “Archive…”. Find “en.stsw-stm32095.zip” and press OK. Tick new repo and click next.

#add http://gnuarmeclipse.sourceforge.net/updates as a repository in eclipse.  menu “Help” > “Install New Software…” > “Add…”. Type name “GNU arm eclipse” and type address “http://gnuarmeclipse.sourceforge.net/updates”. Press ok. Tick new repo and click next.

# st_nucleo_f7.cfg copy it with the rest of the configuration files e.g. /usr/local/share/openocd/scripts/board/
sudo cp st_nucleo_f7.cfg /usr/local/share/openocd/scripts/board/

Create a new st 7x project and add 2048 of memory

create a C/C++ run application run

create new openosd run to run the elf created by above run and add parameter

-f /usr/local/share/openocd/scripts/board/st_nucleo_f7.cfg

to config options in debugger tab

sudo usermod -a -G root george;
#if you get error on opening the usb device (really ugly hack)


Needed packages:

  • sudo dnf install -y arm-none-eabi-gcc arm-none-eabi-gdb arm-none-eabi-binutils arm-none-eabi-newlib
  • Do not install openocd from the repositories, clone the git server as it has a later version which supports our board.
    git clone http://openocd.zylin.com/openocd
    then build it

stm32f7x.cfg (compressed) (431 downloads) copy it where you have the rest of the target files
e.g. /usr/share/openocd/scripts/board/st_nucleo_f7.cfg

st_nucleo_f7.cfg (compressed) (415 downloads)   copy it with the rest of the configuration files
e.g. /usr/share/openocd/scripts/target/stm32f7x.cfg

The locations for the above files depend on your configuration

You need to download the STM32CubeF7 (https://my.st.com/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef7.license%3d1487716364634.html) ~634MB
Extract it.

Navigate to a ready project like the GPIO_IOToggle in STM32Cube_FW_F7_V1.6.0/Projects/STM32F767ZI-Nucleo/Examples/GPIO/GPIO_IOToggle

Compile each .c file using the following command, but fix the paths !!! You also might need ton include the Inc directory of the project
arm-none-eabi-gcc -Wall -mcpu=cortex-m7 -mlittle-endian -mthumb -ISTM32Cube_FW_F7_V1.6.0/Drivers/CMSIS/Device/ST/STM32F7xx/Include -ISTM32Cube_FW_F7_V1.6.0/Drivers/CMSIS/Include -ISTM32Cube_FW_F7_V1.6.0/Drivers/STM32F7xx_HAL_Driver/Inc -I. -ISTM32Cube_FW_F7_V1.6.0/Drivers/BSP/STM32F7xx_Nucleo_144 -DSTM32F767xx -Os -c system_stm32f7xx.c -o system_stm32f7xx.o

Merge all .o files into an .elf file

arm-none-eabi-gcc -mcpu=cortex-m7 -mlittle-endian -mthumb -DSTM32F767xx -TSTM32Cube_FW_F7_V1.6.0/Projects/STM32F767ZI-Nucleo/Templates/SW4STM32/STM32F767ZI_Nucleo_AXIM_FLASH/STM32F767ZITx_FLASH.ld -Wl,–gc-sections system_stm32f7xx.o main.o stm32f7xx_it.o -o main.elf

Convert the .elf file to a .hex

arm-none-eabi-objcopy -Oihex main.elf main.hex
Start openocd to attach to the board

sudo ../src/openocd -f /usr/share/openocd/scripts/board/st_nucleo_f7.cfg

Use telnet to control the board

telnet localhost 4444

Flash the board

reset halt
flash write_image erase /home/xeirwn/Downloads/ST/GPIO_IOToggle/Src/main.hex
reset run





sudo dnf install eclipse-cdt-sdk;

download plugin from here https://my.st.com/content/my_st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stsw-stm32095.license%3d1491636351998.html


add http://gnuarmeclipse.sourceforge.net/updates as a repository in eclipse

sudo dnf install -y arm-none-eabi-gcc-cs-c++;

create new openosd run and add parameter

-f /usr/share/openocd/scripts/board/st_nucleo_f7.cfg

to config options in debugger tab

add   RCC_OscInitStruct.PLL.PLLR = 7; to _initialize_hardware.c


I hope I did not forget anything

Anyhow, this post will be updated soon