Difference between pages "Compiling Xen" and "Using Grub2"

From Wikislax
(Difference between pages)
Jump to: navigation, search
(Created page with "{{RightTOC}} == What is Xen ? == [http://wiki.xen.org/wiki/Xen_Overview Xen] is an hypervisor, a thin software layer executing multiple virtual machines, each running its ow...")
 
(Created page with "{{RightTOC}} == What is Grub2 ? == [http://www.gnu.org/software/grub/ GNU Grub2] is a bootloader. A bootloader is the first software program that runs when a computer starts...")
 
Line 1: Line 1:
 
{{RightTOC}}
 
{{RightTOC}}
  
== What is Xen ? ==
+
== What is Grub2 ? ==
  
[http://wiki.xen.org/wiki/Xen_Overview Xen] is an hypervisor, a thin software layer executing multiple virtual machines, each running its own operating system. Xen is normally used as a server virtualization platform, running on headless servers without graphical console and controlled through the network. However it is also possible to run Xen on graphical desktops, and with proper hardware virtualization, to dedicate the primary graphics card (and keyboard / mouse) to a virtual machine, making it possible to have high performance full 3D and video acceleration in a virtual machine (see [http://wiki.xen.org/wiki/Xen_VGA_Passthrough Xen VGA Passthru]). Xen is otherwise free and open source.
+
[http://www.gnu.org/software/grub/ GNU Grub2] is a bootloader. A bootloader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the operating system kernel software. For Xen we'll use Grub2 over Lilo. The reason is that Grub2 affords booting Xen alongside Domain-0, which Slackware's default Lilo cannot do. Last, we'll use Grub2 over Grub legacy, because the latter is not 64-bits compatible.
  
== A few quirks ==
+
== Compiling Grub2 ? ==
  
The '''dev86-0.16.21-x86_64-1.txz''' package included with Slackware 14.2 does not afford compiling '''xen-4.9.0''' properly, and must be replaced by '''[{{SERVER}}/wikislax/download/dev86-0.16.17-x86_64-2.txz dev86-0.16.17-x86_64-2.txz]''', that can be found on the Slackware 13.37, 14.0, or 14.1 distribution disks, in directory '''slackware64/d'''. Trying to compile dev86 [http://v3.sk/~lkundrak/dev86/ from source] is not an alternative : dev86 source versions 0.16.18 to 0.16.21 have the same issue compiling xen-4.9.0, and older 0.16.17 does not compile on Slackware 14.2.
+
Compiling Grub2 is usually unnecessary as it is included with the Slackware distribution. However the '''grub-2.00''' version included with Slackware 14.2 does not afford booting Xen so we'll compile '''grub-2.02''' from source instead :
  
# removepkg /var/log/packages/dev86-0.16.21-x86_64-1.txz
+
[ftp://ftp.gnu.org/gnu/grub/ Download] from the GNU page then untar to /usr/local and install as below :
# installpkg dev86-0.16.17-x86_64-2.txz
 
  
Also, the '''grub-2.00''' included with Slackware 14.2 does not afford booting xen. However, getting the latest version '''grub-2.02''' from source does work.
+
# tar -C /usr/local -xvf grub-2.02.tar.gz
 +
# cd /usr/local/
 +
# chown -R root:root grub-2.02.tar.gz
 +
# cd grub-2.02
 +
# ./configure --libdir=/usr/local/lib64
 +
# make
 +
# make install
 +
# make clean
  
== Hardware requirements ==
+
== Configuring Grub2 ==
  
Xen runs on Intel X86 hardware and requires a processor and motherboard supporting VT-x and optionally VT-d for hardware virtualization. See this [http://www.intel.com/support/motherboards/desktop/sb/cs-030922.htm page] for a list of Intel compatible motherboards and chipsets and this [http://ark.intel.com/ page] for a list of compatible processors. Our system running Xen successfully at the time of this writing (and since June 2012) is based on a DZ77GA70K Intel motherboard, an Intel® Core™ i7-3770 Processor (the overclockable i7-3770 "K" model does not afford virtualization), 32 Gb of PC12800 memory and an MSI GeForce G210 graphics board.
+
The Grub2 configuration is described in the [http://www.gnu.org/software/grub/manual/grub.html Grub2 documentation]. As it is quite massive we will just edit what we need.
  
== Documentation difficulties ==
+
<u>Note</u> : if using the Grub2 included with the Slackware distribution, the configuration files are '''/etc/default/grub''' and the files in '''/etc/grub.d'''. If using a Grub2 compiled by yourself then the configuration files are '''/usr/local/etc/default/grub''' and the files in '''/usr/local/etc/grub.d'''.
  
Although the software itself works well and is pretty straighforward, good quality Internet information is missing. The volume of information on the Xen wiki is plethoric, but mostly irrelevant as pertaining to old versions of everything. Building the big picture requires interpretation of tiny bits in forum messages, a pretty painful process, although I have to recognize that it worked for me in the end. An alternative is to use one of these old-style information repositories named "books". Yes it is pretty old-fashionned ;) but actually there are good ones on the topic. Here is [http://www.amazon.co.uk/The-Book-Xen-Practical-Administrator/dp/1593271867/ref=sr_1_1?s=books&ie=UTF8&qid=1341037874&sr=1-1 the most recent I found], it is a good value but of course you can find more on [http://www.amazon.co.uk/s/ref=nb_sb_noss_2?url=search-alias%3Dstripbooks&field-keywords=xen&x=0&y=0 amazon(.co.uk)].
+
Let's go to the actual config now. Let's start with general options in file '''default/grub''' that we create.
  
== Software constraints ==
+
# If you change this file, run grub-mkconfig -o /boot/grub/grub.cfg
 +
# afterwards to update /boot/grub/grub.cfg.
 +
 +
GRUB_DEFAULT=0
 +
#GRUB_HIDDEN_TIMEOUT=0
 +
GRUB_HIDDEN_TIMEOUT_QUIET=false
 +
GRUB_TIMEOUT=4
 +
GRUB_DISTRIBUTOR=$( sed 's/Slackware /Slackware-/' /etc/slackware-version )
 +
GRUB_CMDLINE_LINUX_DEFAULT=""
 +
GRUB_CMDLINE_LINUX=""
 +
 +
# Uncomment to disable graphical terminal (grub-pc only)
 +
GRUB_TERMINAL=console
 +
 +
# The resolution used on graphical terminal
 +
# note that you can use only modes which your graphic card supports via VBE
 +
# you can see them in real GRUB with the command `vbeinfo'
 +
#GRUB_GFXMODE=640x480
 +
#GRUB_GFXMODE=1024x768x32
 +
 +
# Font used on the graphical terminal:
 +
#GRUB_FONT=/usr/share/grub/dejavusansmono.pf2
 +
 +
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
 +
#GRUB_DISABLE_LINUX_UUID=true
 +
 +
# Uncomment to disable generation of recovery mode menu entries
 +
#GRUB_DISABLE_LINUX_RECOVERY="true"
  
To make a long story short, at the time of this writing (and since June 2012) working with nVidia graphic boards on Xen and X11 requires the "nouveau" driver. Other drivers like nv or the nVidia proprietary driver do not support Xen and switch off the screen when launched or do not display properly. "Nouveau" requires a fairly recent version of X11. Slackware 13.37 or newer is required. "Nouveau" is available in kernel 3.4.2 upstream and was previously included as a staging driver. Xen dom0 support was included in kernel 3.0. To benefit from both Xen and "Nouveau", the best is to use kernel 3.4.2 upstream.
+
We now need to organize the files under '''grub.d'''. Keep only '''00_header''' untouched, rename and make all the other files not executable, then add menu entries as executable files '''11_xen-4.9.0-kernel-4.4.88-dom0''' and '''12_kernel-4.4.88-dom0'''. It will be wise to add yet another entry '''13_slack-4.4.88''' as a backup kernel. set root=(hd0,2) means the second partition on the disk. The other options is what we have kept after trying and failing many times to see anything on the console :
  
== Compiling acpica ==
+
#! /bin/sh -e
 +
echo "Adding Xen 4.9.0 / Slackware 14.2 (kernel 4.4.88-dom0)"
 +
cat << EOF
 +
menuentry "Xen 4.9.0 / Slackware 14.2 (kernel 4.4.88-dom0)" {
 +
        set root=(hd0,2)
 +
        multiboot /boot/xen-4.9.0.gz dom0_mem=max:16GB console=vga vga=gfx-1024x768x8 noreboot
 +
        module /boot/vmlinuz-4.4.88-dom0 console=vga earlyprintk=xen root=/dev/sda2 ro vga=gfx-1024x768x8
 +
        }
 +
EOF
  
Xen requires acpica. [https://www.acpica.org/downloads Download] then install as below :
+
#! /bin/sh -e
 +
echo "Adding Slackware 14.2 (kernel 4.4.88-dom0)"
 +
cat << EOF
 +
menuentry "Slackware 14.2 (kernel 4.4.88-dom0)" {
 +
        set root=(hd0,2)
 +
        linux /boot/vmlinuz-4.4.88-dom0 root=/dev/sda2 ro vga=773
 +
        }
 +
EOF
  
  # tar -C /usr/local -xvf acpica-unix-yyyymmdd.tar.gz
+
  #! /bin/sh -e
  # cd /usr/local
+
echo "Adding Slackware 14.2 (kernel 4.4.88)"
  # chown -R root:root acpica-unix-yyyymmdd
+
  cat << EOF
# cd acpica-unix-yyyymmdd
+
  menuentry "Slackware 14.2 (kernel 4.4.88)" {
# make
+
        set root=(hd0,2)
  # make install
+
        linux /boot/vmlinuz root=/dev/sda2 ro vga=773
# cd ..
+
        }
# rm -r acpica-unix-yyyymmdd
+
  EOF
  
== Compiling yajl ==
+
Update '''/boot/grub/grub.cfg''' accordingly :
  
Xen requires yajl. [http://lloyd.github.io/yajl/ Download] then install as below. <u>Note</u> : there is no option to specify the target library directory so the files need to be moved manually.
+
# grub-mkconfig -o /boot/grub/grub.cfg
  
# tar -C /usr/local -xvf lloyd-yajl-x.y.z.66cb08c.tar.gz
+
== Installing the bootloader ==
# cd /usr/local
 
# chown -R root:root lloyd-yajl-66cb08c
 
# cd lloyd-yajl-66cb08c
 
# ./configure
 
# make
 
# make install
 
# cd ../lib
 
# mv libyajl* ../lib64
 
# ldconfig
 
# cd ..
 
# rm -r lloyd-yajl-66cb08c
 
  
== Compiling Xen ==
+
Last step is to create boot record in first sector of disk partition. If not using Master Boot Record in /dev/sda, then the --force option must be used :
  
[http://xen.org/products/xen_source.html Download Xen] from the official [http://www.xen.org xen.org] site. <u>Note</u> : File stubs-32.h is missing in the compiler includes so we add a link to the existing stubs-64.h. Also, some Xen Python scripts are installed in /usr/local/lib64/python-2.7/site-packages which python cannot find so we add links from the standard library as well.
+
  # grub-install --force /dev/sda2
 
+
  # dd if=/dev/sda2 of=/mnt/win7/Boot/Slack14.mbr bs=512 count=1
  # cd /usr/include/gnu
 
# ln -s stubs-64.h stubs-32.h
 
# cd
 
# tar -C /usr/local -xvf xen-x.y.z.tar.gz
 
  # cd /usr/local
 
# chown -R root:root xen-x.y.z
 
# cd xen-x.y.z
 
# ./configure --libdir=/usr/local/lib64 --with-initddir=/etc/rc.d
 
# make world
 
# make install
 
# make clean
 
# cd ../lib64/python2.7/site-packages
 
# ln -s xen /usr/lib64/python2.7/site-packages
 
# ln -s xen-3.0-py2.7.egg-info /usr/lib64/python2.7/site-packages
 
 
 
== Adjusting rc.local* ==
 
 
 
Xen needs a couple of daemons to run to ensure VM management. Add these lines to rc.local and rc.local_shutdown :
 
 
 
PATH=/usr/local/sbin:/usr/local/bin:$PATH
 
export PATH
 
 
# start xencommons
 
if [ -x /etc/rc.d/xencommons ]; then
 
    /etc/rc.d/xencommons start
 
fi
 
 
# stop xencommons
 
if [ -x /etc/rc.d/xencommons ]; then
 
    /etc/rc.d/xencommons stop
 
fi
 
 
 
== Compiling a dom0 Kernel ==
 
 
 
Domain-0 (dom0 for short) is a special guest (virtual machine) that the Xen hypervisor always loads on host startup. Dom0 is used to control and manage the Xen hypervisor, and provides virtual disks and networks for other unprivileged guests (=domUs). Dom0 support was introduced in Linux kernel 3.0. The kernel generated must include the .config file domU and [http://wiki.xen.org/wiki/Mainline_Linux_Kernel_Configs#Configuring_the_kernel dom0 options]. Here is a minimal example of such a [{{SERVER}}/slax/download/config-dom0 .config dom0] file. Feel free to use it as a base, replacing device drivers as required. The rest of the kernel compilation is nominal :
 
 
 
# tar -C /usr/src -xvf linux-4.4.88.tar.bz2
 
# cd /usr/local
 
# rm linux
 
# ln -s linux-4.4.88 linux
 
# cd linux
 
# make menuconfig
 
# make
 
# make modules_install
 
# cp arch/x86_64/boot/bzImage /boot/vmlinuz-4.4.88-dom0
 
# cp System.map /boot/System.map-4.4.88-dom0
 
# cp .config /boot/config-4.4.88-dom0
 
  
We're now all set up, Xen is ready to be booted by grub2 !
+
You can now cross fingers and reboot ! If everything goes right you should be able to see the [{{SERVER}}/slax/download/xl.dmesg.log xl dmesg log] being displayed during Xen bootup, then the screen will be cleared and Xen will proceed with Linux (dom0) bootup as usual.
  
 
<br/>
 
<br/>
  
{{ pFoot |[[Compiling from Source]]|[[Main Page]]|[[Using Grub2]]}}
+
{{pFoot|[[Compiling Xen]]|[[Main Page]]|[[Creating VMs]]}}

Revision as of 23:26, 6 December 2017

What is Grub2 ?

GNU Grub2 is a bootloader. A bootloader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the operating system kernel software. For Xen we'll use Grub2 over Lilo. The reason is that Grub2 affords booting Xen alongside Domain-0, which Slackware's default Lilo cannot do. Last, we'll use Grub2 over Grub legacy, because the latter is not 64-bits compatible.

Compiling Grub2 ?

Compiling Grub2 is usually unnecessary as it is included with the Slackware distribution. However the grub-2.00 version included with Slackware 14.2 does not afford booting Xen so we'll compile grub-2.02 from source instead :

Download from the GNU page then untar to /usr/local and install as below :

# tar -C /usr/local -xvf grub-2.02.tar.gz
# cd /usr/local/
# chown -R root:root grub-2.02.tar.gz
# cd grub-2.02
# ./configure --libdir=/usr/local/lib64
# make
# make install
# make clean

Configuring Grub2

The Grub2 configuration is described in the Grub2 documentation. As it is quite massive we will just edit what we need.

Note : if using the Grub2 included with the Slackware distribution, the configuration files are /etc/default/grub and the files in /etc/grub.d. If using a Grub2 compiled by yourself then the configuration files are /usr/local/etc/default/grub and the files in /usr/local/etc/grub.d.

Let's go to the actual config now. Let's start with general options in file default/grub that we create.

# If you change this file, run grub-mkconfig -o /boot/grub/grub.cfg
# afterwards to update /boot/grub/grub.cfg.

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=false
GRUB_TIMEOUT=4
GRUB_DISTRIBUTOR=$( sed 's/Slackware /Slackware-/' /etc/slackware-version )
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""

# Uncomment to disable graphical terminal (grub-pc only)
GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
#GRUB_GFXMODE=1024x768x32

# Font used on the graphical terminal:
#GRUB_FONT=/usr/share/grub/dejavusansmono.pf2

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_LINUX_RECOVERY="true"

We now need to organize the files under grub.d. Keep only 00_header untouched, rename and make all the other files not executable, then add menu entries as executable files 11_xen-4.9.0-kernel-4.4.88-dom0 and 12_kernel-4.4.88-dom0. It will be wise to add yet another entry 13_slack-4.4.88 as a backup kernel. set root=(hd0,2) means the second partition on the disk. The other options is what we have kept after trying and failing many times to see anything on the console :

#! /bin/sh -e
echo "Adding Xen 4.9.0 / Slackware 14.2 (kernel 4.4.88-dom0)"
cat << EOF
menuentry "Xen 4.9.0 / Slackware 14.2 (kernel 4.4.88-dom0)" {
       set root=(hd0,2)
       multiboot /boot/xen-4.9.0.gz dom0_mem=max:16GB console=vga vga=gfx-1024x768x8 noreboot
       module /boot/vmlinuz-4.4.88-dom0 console=vga earlyprintk=xen root=/dev/sda2 ro vga=gfx-1024x768x8
       }
EOF
#! /bin/sh -e
echo "Adding Slackware 14.2 (kernel 4.4.88-dom0)"
cat << EOF
menuentry "Slackware 14.2 (kernel 4.4.88-dom0)" {
        set root=(hd0,2)
        linux /boot/vmlinuz-4.4.88-dom0 root=/dev/sda2 ro vga=773
        }
EOF
#! /bin/sh -e
echo "Adding Slackware 14.2 (kernel 4.4.88)"
cat << EOF
menuentry "Slackware 14.2 (kernel 4.4.88)" {
       set root=(hd0,2)
       linux /boot/vmlinuz root=/dev/sda2 ro vga=773
       }
EOF

Update /boot/grub/grub.cfg accordingly :

# grub-mkconfig -o /boot/grub/grub.cfg

Installing the bootloader

Last step is to create boot record in first sector of disk partition. If not using Master Boot Record in /dev/sda, then the --force option must be used :

# grub-install --force /dev/sda2
# dd if=/dev/sda2 of=/mnt/win7/Boot/Slack14.mbr bs=512 count=1

You can now cross fingers and reboot ! If everything goes right you should be able to see the xl dmesg log being displayed during Xen bootup, then the screen will be cleared and Xen will proceed with Linux (dom0) bootup as usual.


Compiling Xen Main Page Creating VMs