https://wiki.archlinux.org/api.php?action=feedcontributions&user=Dshub&feedformat=atomArchWiki - User contributions [en]2024-03-29T01:00:01ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=MATLAB&diff=324047MATLAB2014-07-08T14:34:57Z<p>Dshub: /* Configuration */ Added information about the help browser</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an iso file called {{ic|matlab-$RELEASE.iso}}. Once the iso file and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between r2010b and r2011a the contents of the iso file must include: {{ic|./archives/}}, {{ic|./bin/}}, {{ic|./etc/}}, {{ic|./help/}}, {{ic|./java/}}, {{ic|./activate.ini}}, {{ic|./install}}, and {{ic|./installer_input.txt}}. If the MATLAB download agent is used to download the installation software, then the iso file can be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory.<br />
<br />
For MATLAB releases including and after r2011b the contents of the iso file must include: {{ic|./archives/}}, {{ic|./bin/}}, {{ic|./etc/}}, {{ic|./help/}}, {{ic|./java/}}, {{ic|./activate.ini}}, {{ic|./install}}, and {{ic|./installer_input.txt}}. For version before r2014a, the MATLAB download agent could download all the required files and the iso file could be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory. For MATLAB releases including and after r2014a the MATLAB download agent only downloads the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this iso file with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required iso file can be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. <br />
<br />
=== R2013b and earlier ===<br />
Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -nosplash -r "version -java, exit" | grep Java</nowiki>}}<br />
<br />
=== OpenGL acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is likely a problem with your system configuration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null</nowiki>}}<br />
<br />
This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to confirm that the correct the bitmap font package (either {{Pkg|xorg-fonts-100dpi}} or {{Pkg|xorg-fonts-75dpi}} from the [[official repositories]]) is installed on your system.<br />
<br />
=== Sound ===<br />
To confirm that MATLAB is able to use the default soundcard to present sounds run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "load handel; sound(y, Fs); pause(length(y)/Fs); exit" > /dev/null</nowiki>}}<br />
<br />
This should play an except from Handel's "Hallelujah Chorus." If this fails make sure [[ALSA]] is properly configured. This can be done with the {{ic|speaker-test}} program from the {{Pkg|alsa-progs}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ speaker-test</nowiki>}}<br />
<br />
If you do not hear anything, then there is likely a problem with your system configuration.<br />
<br />
=== GPU computing ===<br />
MATLAB can take advantage of [http://www.mathworks.co.uk/discovery/matlab-gpu.html CUDA enabled GPUs] to speed up applications. In order to take advantage of a supported GPU install the {{Pkg|nvidia}}, {{Pkg|nvidia-utils}}, {{Pkg|libcl}}, {{Pkg|opencl-nvidia}}, and {{Pkg|cuda}} packages from the [[official repositories]]. To check if MATLAB is able to utilize the GPU run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "x=rand(10, 'single'); g=gpuArray(x); Success=isequal(gather(g), x), exit" | sed -ne '/Success =/,$p'</nowiki>}}<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Help browser ===<br />
The help browser uses valuable slots in the dynamic thread vector and causes competition with core functionality provided by libraries like the BLAS that also depend on the dynamic thread vector. The help browser can be configured to use fewer slots in the dynamic thread vector with<br />
<br />
>> webutils.htmlrenderer('basic');<br />
<br />
This is a persistent change and to reverse it use<br />
<br />
>> webutils.htmlrenderer('default');<br />
<br />
== Troubleshooting ==<br />
<br />
=== Static TLS errors ===<br />
<br />
MATLAB has a number of libraries that have been compiled with static thread local storage (TLS) including the help broswer {{ic|doc}} and the BLAS libraries. For example,<br />
<br />
>> doc('help');<br />
>> ones(10)*randn(10);<br />
<span style="color:red"><br />
Error using * <br />
BLAS loading error:<br />
dlopen: cannot load any more object with static TLS<br />
</span><br />
<br />
is related to bugs [http://www.mathworks.de/support/bugreports/961964 961964] and [http://www.mathworks.com/support/bugreports/1003952 1003952]. In some cases (e.g., bug [http://www.mathworks.de/support/bugreports/961964 961964]) patched libraries are available from [http://www.mathworks.de/support/bugreports/license/accept_license/5730?fname=attachment_961964_12b_13a_13b_14a_glnxa64_2014-01-30.zip&geck_id=961964 The MathWorks], while in others (e.g., bug [http://www.mathworks.com/support/bugreports/1003952 1003952]) work arounds exist. A more general solution of recompiling {{ic|glibc}} has also been [http://stackoverflow.com/a/19468365/2787723 suggested].<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D<br />
<br />
=== Installaltion ===<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=324046MATLAB2014-07-08T14:25:43Z<p>Dshub: /* Troubleshooting */ Added info about TLS libraries</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an iso file called {{ic|matlab-$RELEASE.iso}}. Once the iso file and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between r2010b and r2011a the contents of the iso file must include: {{ic|./archives/}}, {{ic|./bin/}}, {{ic|./etc/}}, {{ic|./help/}}, {{ic|./java/}}, {{ic|./activate.ini}}, {{ic|./install}}, and {{ic|./installer_input.txt}}. If the MATLAB download agent is used to download the installation software, then the iso file can be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory.<br />
<br />
For MATLAB releases including and after r2011b the contents of the iso file must include: {{ic|./archives/}}, {{ic|./bin/}}, {{ic|./etc/}}, {{ic|./help/}}, {{ic|./java/}}, {{ic|./activate.ini}}, {{ic|./install}}, and {{ic|./installer_input.txt}}. For version before r2014a, the MATLAB download agent could download all the required files and the iso file could be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory. For MATLAB releases including and after r2014a the MATLAB download agent only downloads the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this iso file with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required iso file can be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. <br />
<br />
=== R2013b and earlier ===<br />
Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -nosplash -r "version -java, exit" | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is likely a problem with your system configuration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null</nowiki>}}<br />
<br />
This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to confirm that the correct the bitmap font package (either {{Pkg|xorg-fonts-100dpi}} or {{Pkg|xorg-fonts-75dpi}} from the [[official repositories]]) is installed on your system.<br />
<br />
=== Sound ===<br />
To confirm that MATLAB is able to use the default soundcard to present sounds run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "load handel; sound(y, Fs); pause(length(y)/Fs); exit" > /dev/null</nowiki>}}<br />
<br />
This should play an except from Handel's "Hallelujah Chorus." If this fails make sure [[ALSA]] is properly configured. This can be done with the {{ic|speaker-test}} program from the {{Pkg|alsa-progs}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ speaker-test</nowiki>}}<br />
<br />
If you do not hear anything, then there is likely a problem with your system configuration.<br />
<br />
=== GPU Computing ===<br />
MATLAB can take advantage of [http://www.mathworks.co.uk/discovery/matlab-gpu.html CUDA enabled GPUs] to speed up applications. In order to take advantage of a supported GPU install the {{Pkg|nvidia}}, {{Pkg|nvidia-utils}}, {{Pkg|libcl}}, {{Pkg|opencl-nvidia}}, and {{Pkg|cuda}} packages from the [[official repositories]]. To check if MATLAB is able to utilize the GPU run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "x=rand(10, 'single'); g=gpuArray(x); Success=isequal(gather(g), x), exit" | sed -ne '/Success =/,$p'</nowiki>}}<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Static TLS errors ===<br />
<br />
MATLAB has a number of libraries that have been compiled with static thread local storage (TLS) including the help broswer {{ic|doc}} and the BLAS libraries. For example,<br />
<br />
>> doc('help');<br />
>> ones(10)*randn(10);<br />
<span style="color:red"><br />
Error using * <br />
BLAS loading error:<br />
dlopen: cannot load any more object with static TLS<br />
</span><br />
<br />
is related to bugs [http://www.mathworks.de/support/bugreports/961964 961964] and [http://www.mathworks.com/support/bugreports/1003952 1003952]. In some cases (e.g., bug [http://www.mathworks.de/support/bugreports/961964 961964]) patched libraries are available from [http://www.mathworks.de/support/bugreports/license/accept_license/5730?fname=attachment_961964_12b_13a_13b_14a_glnxa64_2014-01-30.zip&geck_id=961964 The MathWorks], while in others (e.g., bug [http://www.mathworks.com/support/bugreports/1003952 1003952]) work arounds exist. A more general solution of recompiling {{ic|glibc}} has also been [http://stackoverflow.com/a/19468365/2787723 suggested].<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D<br />
<br />
=== Installaltion ===<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=324041MATLAB2014-07-08T13:55:09Z<p>Dshub: /* Installing from the AUR package */ update to use iso file with the AUR submission</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an iso file called {{ic|matlab-$RELEASE.iso}}. Once the iso file and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between r2010b and r2011a the contents of the iso file must include: {{ic|./archives/}}, {{ic|./bin/}}, {{ic|./etc/}}, {{ic|./help/}}, {{ic|./java/}}, {{ic|./activate.ini}}, {{ic|./install}}, and {{ic|./installer_input.txt}}. If the MATLAB download agent is used to download the installation software, then the iso file can be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory.<br />
<br />
For MATLAB releases including and after r2011b the contents of the iso file must include: {{ic|./archives/}}, {{ic|./bin/}}, {{ic|./etc/}}, {{ic|./help/}}, {{ic|./java/}}, {{ic|./activate.ini}}, {{ic|./install}}, and {{ic|./installer_input.txt}}. For version before r2014a, the MATLAB download agent could download all the required files and the iso file could be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory. For MATLAB releases including and after r2014a the MATLAB download agent only downloads the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this iso file with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required iso file can be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. <br />
<br />
=== R2013b and earlier ===<br />
Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -nosplash -r "version -java, exit" | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is likely a problem with your system configuration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null</nowiki>}}<br />
<br />
This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to confirm that the correct the bitmap font package (either {{Pkg|xorg-fonts-100dpi}} or {{Pkg|xorg-fonts-75dpi}} from the [[official repositories]]) is installed on your system.<br />
<br />
=== Sound ===<br />
To confirm that MATLAB is able to use the default soundcard to present sounds run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "load handel; sound(y, Fs); pause(length(y)/Fs); exit" > /dev/null</nowiki>}}<br />
<br />
This should play an except from Handel's "Hallelujah Chorus." If this fails make sure [[ALSA]] is properly configured. This can be done with the {{ic|speaker-test}} program from the {{Pkg|alsa-progs}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ speaker-test</nowiki>}}<br />
<br />
If you do not hear anything, then there is likely a problem with your system configuration.<br />
<br />
=== GPU Computing ===<br />
MATLAB can take advantage of [http://www.mathworks.co.uk/discovery/matlab-gpu.html CUDA enabled GPUs] to speed up applications. In order to take advantage of a supported GPU install the {{Pkg|nvidia}}, {{Pkg|nvidia-utils}}, {{Pkg|libcl}}, {{Pkg|opencl-nvidia}}, and {{Pkg|cuda}} packages from the [[official repositories]]. To check if MATLAB is able to utilize the GPU run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "x=rand(10, 'single'); g=gpuArray(x); Success=isequal(gather(g), x), exit" | sed -ne '/Success =/,$p'</nowiki>}}<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=320814MATLAB2014-06-20T10:25:55Z<p>Dshub: Moved desktop installation file creation to the installation section</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. <br />
<br />
=== R2013b and earlier ===<br />
Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -nosplash -r "version -java, exit" | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is likely a problem with your system configuration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null</nowiki>}}<br />
<br />
This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to confirm that the correct the bitmap font package (either {{Pkg|xorg-fonts-100dpi}} or {{Pkg|xorg-fonts-75dpi}} from the [[official repositories]]) is installed on your system.<br />
<br />
=== Sound ===<br />
To confirm that MATLAB is able to use the default soundcard to present sounds run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "load handel; sound(y, Fs); pause(length(y)/Fs); exit" > /dev/null</nowiki>}}<br />
<br />
This should play an except from Handel's "Hallelujah Chorus." If this fails make sure [[ALSA]] is properly configured. This can be done with the {{ic|speaker-test}} program from the {{Pkg|alsa-progs}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ speaker-test</nowiki>}}<br />
<br />
If you do not hear anything, then there is likely a problem with your system configuration.<br />
<br />
=== GPU Computing ===<br />
MATLAB can take advantage of [http://www.mathworks.co.uk/discovery/matlab-gpu.html CUDA enabled GPUs] to speed up applications. In order to take advantage of a supported GPU install the {{Pkg|nvidia}}, {{Pkg|nvidia-utils}}, {{Pkg|libcl}}, {{Pkg|opencl-nvidia}}, and {{Pkg|cuda}} packages from the [[official repositories]]. To check if MATLAB is able to utilize the GPU run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "x=rand(10, 'single'); g=gpuArray(x); Success=isequal(gather(g), x), exit" | sed -ne '/Success =/,$p'</nowiki>}}<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=320813MATLAB2014-06-20T10:19:31Z<p>Dshub: /* Configuration */</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. <br />
<br />
=== R2013b and earlier ===<br />
Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -nosplash -r "version -java, exit" | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is likely a problem with your system configuration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null</nowiki>}}<br />
<br />
This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to confirm that the correct the bitmap font package (either {{Pkg|xorg-fonts-100dpi}} or {{Pkg|xorg-fonts-75dpi}} from the [[official repositories]]) is installed on your system.<br />
<br />
=== Sound ===<br />
To confirm that MATLAB is able to use the default soundcard to present sounds run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "load handel; sound(y, Fs); pause(length(y)/Fs); exit" > /dev/null</nowiki>}}<br />
<br />
This should play an except from Handel's "Hallelujah Chorus." If this fails make sure [[ALSA]] is properly configured. This can be done with the {{ic|speaker-test}} program from the {{Pkg|alsa-progs}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ speaker-test</nowiki>}}<br />
<br />
If you do not hear anything, then there is likely a problem with your system configuration.<br />
<br />
=== GPU Computing ===<br />
MATLAB can take advantage of [http://www.mathworks.co.uk/discovery/matlab-gpu.html CUDA enabled GPUs] to speed up applications. In order to take advantage of a supported GPU install the {{Pkg|nvidia}}, {{Pkg|nvidia-utils}}, {{Pkg|libcl}}, {{Pkg|opencl-nvidia}}, and {{Pkg|cuda}} packages from the [[official repositories]]. To check if MATLAB is able to utilize the GPU run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "x=rand(10, 'single'); g=gpuArray(x); Success=isequal(gather(g), x), exit" | sed -ne '/Success =/,$p'</nowiki>}}<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=320810MATLAB2014-06-20T10:03:18Z<p>Dshub: /* Configuration */ markup</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your system configuration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null</nowiki>}}<br />
<br />
This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to confirm that the correct the bitmap font package (either {{Pkg|xorg-fonts-100dpi}} or {{Pkg|xorg-fonts-75dpi}} from the [[official repositories]]) is installed on your system.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=320809MATLAB2014-06-20T09:55:42Z<p>Dshub: /* Fonts for figures */ Added a test</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your system configuration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null</nowiki>}}<br />
<br />
This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to confirm that the correct the bitmap font package (either {{Pkg|xorg-fonts-100dpi}} or {{Pkg|xorg-fonts-75dpi}} from the official repository) is installed on your system.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=320807MATLAB2014-06-20T09:48:07Z<p>Dshub: /* OpenGL Acceleration */ reworded the testing of OpenGL</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your system configuration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. When using MATLAB with [[Xorg]], bitmap fonts from either the {{Pkg|xorg-fonts-100dpi}} package or the {{Pkg|xorg-fonts-75dpi}} package must be installed so that fonts in figures can be properly scaled. Refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to determine which package is needed for your system.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=320806MATLAB2014-06-20T09:42:57Z<p>Dshub: /* Installing from the AUR package */</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. When using MATLAB with [[Xorg]], bitmap fonts from either the {{Pkg|xorg-fonts-100dpi}} package or the {{Pkg|xorg-fonts-75dpi}} package must be installed so that fonts in figures can be properly scaled. Refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to determine which package is needed for your system.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=320805MATLAB2014-06-20T09:39:37Z<p>Dshub: /* Installation */</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MAthWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. When using MATLAB with [[Xorg]], bitmap fonts from either the {{Pkg|xorg-fonts-100dpi}} package or the {{Pkg|xorg-fonts-75dpi}} package must be installed so that fonts in figures can be properly scaled. Refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to determine which package is needed for your system.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317194MATLAB2014-05-29T17:35:51Z<p>Dshub: /* Java */ Added a configuration section</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [[http://www.mathworks.com The MathWorks website]]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MAthWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
== Configuration ==<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. When using MATLAB with [[Xorg]], bitmap fonts from either the {{Pkg|xorg-fonts-100dpi}} package or the {{Pkg|xorg-fonts-75dpi}} package must be installed so that fonts in figures can be properly scaled. Refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to determine which package is needed for your system.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317193MATLAB2014-05-29T17:35:09Z<p>Dshub: /* Activation */ made a section instead of subsection</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [[http://www.mathworks.com The MathWorks website]]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MAthWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
== Activation ==<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. When using MATLAB with [[Xorg]], bitmap fonts from either the {{Pkg|xorg-fonts-100dpi}} package or the {{Pkg|xorg-fonts-75dpi}} package must be installed so that fonts in figures can be properly scaled. Refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to determine which package is needed for your system.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317192MATLAB2014-05-29T17:34:11Z<p>Dshub: /* Installation */ added subsection on installing from the AUR package</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
A complete copy of the MATLAB software must be obtained before it can in installed. The MATLAB software is available to licenses holders on both a DVD and through the [[http://www.mathworks.com The MathWorks website]]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).<br />
<br />
=== Installing from the MATLAB installation software ===<br />
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
=== Installing from the AUR package ===<br />
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA. The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MAthWorks. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called {{ic|matlab-$RELEASE.fik}} where {{ic|$RELEASE}} is the release to be installed with a lowercase ''r'' (e.g., r2014a). The installation software must be in an uncompressed tarball called {{ic|matlab-$RELEASE.tar}}. Compression is not needed since the MATLAB installation software is already compressed. Once the tarball and file installation key are created, the MATLAB package can be created and install as usual.<br />
<br />
For MATLAB releases between R2010b and R2013b the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./utils/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./matlab_R2010b_glnxa64_installer.zip}} and {{ic|./readme.txt}}. If the MATLAB download agent is used to download the installation software, then this tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
For MATLAB releases including and after r2014a the contents of the tarball must include: {{ic|./archives/}} {{ic|./bin/}} {{ic|./etc/}} {{ic|./help/}} {{ic|./java/}} {{ic|./sys/}} {{ic|./activate.ini}} {{ic|./install}} {{ic|./install_guide.pdf}} {{ic|./installer_input.txt}} {{ic|./license.txt}} {{ic|./patents.txt}} {{ic|./readme.txt}} and {{ic|./trademarks.txt}}. Unlike in earlier versions, the MATLAB download agent only download the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this tarball with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes. It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required tarball can be trivially created by simply running {{ic|tar -c}} on the download directory.<br />
<br />
=== Activation ===<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Fonts for figures ===<br />
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. When using MATLAB with [[Xorg]], bitmap fonts from either the {{Pkg|xorg-fonts-100dpi}} package or the {{Pkg|xorg-fonts-75dpi}} package must be installed so that fonts in figures can be properly scaled. Refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22| Xorg fonts]] to determine which package is needed for your system.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=Talk:MATLAB&diff=317190Talk:MATLAB2014-05-29T16:51:06Z<p>Dshub: Added info about fonts</p>
<hr />
<div>== Compatibility with Java 7 ==<br />
<br />
Whereas this page claims that versions of MATLAB earlier than R2013a are not compatible with Java 7, I have installed and am running R2012a (the last version available for 32-bit Linux) on current 32-bit Arch Linux while having only {{Pkg|jre7-openjdk}} installed without problem. It might be the case that this section needs a qualifier "on 64-bit" I presume or perhaps one that points out (in-)compatibility between MATLAB programs and to MATLAB external Java 7 software on the system, but it's not generally true that one needs to install anything else simply to run MATLAB R2012a.<br />
<br />
In fact, [http://www.mathworks.com/matlabcentral/answers/103056-how-do-i-change-the-java-virtual-machine-jvm-that-matlab-is-using except for R2013a and earlier on Mac OS X], MATLAB uses the JVM that it itself provides and which it installs in {{ic|$MATLAB/sys/java/jre}}. For R2012a on 32-bit Linux, this is:<br />
<br />
<code><br />
>> version -java<br />
<br />
ans =<br />
<br />
Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode<br />
</code><br />
<br />
and I have yet to uncover any issue with this. Both while installing and running MATLAB I suppose one might need to be careful to not have any environment variables set that would tell the installer and/or MATLAB to not in fact use its own JVM (such as, from the above link, MATLAB_JAVA) but that's about it.<br />
<br />
(I have moreover not encountered the need to install the here mentioned font packages {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}} and {{Pkg|xorg-fonts-type1}}; text within figures displays fine for me without them).<br />
<br />
[[User:Rene|Rene]] ([[User talk:Rene|talk]]) 01:34, 4 May 2014 (UTC)<br />
<br />
:I use 64-bit MATLAB and have no idea what the issues with Java are. I can either use or not use the supplied java or my systems java-7-openjdk with all releases of 64-bit MATLAB between R2010b and R2014a.<br />
<br />
:I cannot resize the fonts in a figure, {{ic|xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12);}} gives the same size font, in all 64-bit releases without {{Pkg|xorg-fonts-100dpi}} installed on the X11 server. My system is running at 96 DPI according to {{ic|<nowiki>xdpyinfo|grep resolution</nowiki>}}, so potentially/presumably {{Pkg|xorg-fonts-75dpi}} might be needed on other systems<br />
<br />
:[[User:Dshub|Dshub]] ([[User talk:Dshub|talk]]) 13:06, 29 May 2014 (UTC)<br />
<br />
:: Given that we now have confirmation from both 32 and 64-bit (*) the best thing might be to simply do away with that Java warning; I also have no idea what it's about. When googling, I did find people running into install time errors which they orginally blamed on a Java version mismatch, but which turned out to be no more than having a tmpfs on /tmp of insufficient size to host MATLAB's native JVM, which the installer copies to /tmp and runs from there -- at least for version R2012a. <br />
<br />
:: As to the font issue; you're right: also no scaling with your example command for me... but in my case even without having any fixed fonts installed (system-wide). I know little about X11 font-issues other than not WANTING the old core fonts installed, and willl not try to comment on that issue further. Can't say I plot a lot anyway :-/<br />
<br />
::Would've been sort of good though if the original author of that section had been a bit more verbose about what exact problems he or she encountered...<br />
<br />
:: (*) Well, I haven't tried running MATLAB with the system-native java-7-openjdk; if you want me to test, I can do so tommorow or day after.<br />
::[[User:Rene|Rene]] ([[User talk:Rene|talk]]) 13:33, 29 May 2014 (UTC)<br />
<br />
::: I am heavily updating the wiki now. I also created a {{AUR|matlab}} PKGBUILD on the [[AUR]] that hopefully will take care of some of the issues. As for the xorg stuff. I think I originated the solution a couple of years ago (i.e., I found the packages that I needed) at [http://www.mathworks.co.uk/matlabcentral/answers/1238#answer_39697 MATLAB answers], but never really tried to document it.<br />
<br />
::: [[User:Dshub|Dshub]] ([[User talk:Dshub|talk]]) 16:51, 29 May 2014 (UTC)</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317174MATLAB2014-05-29T16:09:55Z<p>Dshub: /* Activation */ Added a prompt to the code snippet</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Activation ===<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317173MATLAB2014-05-29T16:09:22Z<p>Dshub: /* Install supported compiler */ fixed grammer</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Activation ===<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Install supported compilers ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317171MATLAB2014-05-29T16:08:09Z<p>Dshub: Added a section on installing Java</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.<br />
<br />
== Installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Activation ===<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== Java ===<br />
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:<br />
<br />
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -r 'version -java, exit' | grep Java</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Install supported compiler ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317169MATLAB2014-05-29T15:46:25Z<p>Dshub: /* Install supported compiler */ Running setup needs to be done on a per user basis so is not really part of the installation</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward. The MATLAB installation software includes its own JVM, although the version lags behind the standard JVMs packaged for Arch. It is sometimes possible, although not required, to use newer versions of the JVM than those supplied by MATLAB.<br />
<br />
== Installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Activation ===<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Install supported compiler ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317168MATLAB2014-05-29T15:35:41Z<p>Dshub: /* Install supported compiler */ Expanded to include jdk and Fortran compilers</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward. The MATLAB installation software includes its own JVM, although the version lags behind the standard JVMs packaged for Arch. It is sometimes possible, although not required, to use newer versions of the JVM than those supplied by MATLAB.<br />
<br />
== Installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Activation ===<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Install supported compiler ===<br />
<br />
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.<br />
<br />
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release. Afterwards run {{ic|mex -setup}} from within MATLAB and select the {{ic|mexopts.sh}} file.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=Talk:MATLAB&diff=317140Talk:MATLAB2014-05-29T13:06:34Z<p>Dshub: /* Compatibility with Java 7 */</p>
<hr />
<div>== Compatibility with Java 7 ==<br />
<br />
Whereas this page claims that versions of MATLAB earlier than R2013a are not compatible with Java 7, I have installed and am running R2012a (the last version available for 32-bit Linux) on current 32-bit Arch Linux while having only {{Pkg|jre7-openjdk}} installed without problem. It might be the case that this section needs a qualifier "on 64-bit" I presume or perhaps one that points out (in-)compatibility between MATLAB programs and to MATLAB external Java 7 software on the system, but it's not generally true that one needs to install anything else simply to run MATLAB R2012a.<br />
<br />
In fact, [http://www.mathworks.com/matlabcentral/answers/103056-how-do-i-change-the-java-virtual-machine-jvm-that-matlab-is-using except for R2013a and earlier on Mac OS X], MATLAB uses the JVM that it itself provides and which it installs in {{ic|$MATLAB/sys/java/jre}}. For R2012a on 32-bit Linux, this is:<br />
<br />
<code><br />
>> version -java<br />
<br />
ans =<br />
<br />
Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode<br />
</code><br />
<br />
and I have yet to uncover any issue with this. Both while installing and running MATLAB I suppose one might need to be careful to not have any environment variables set that would tell the installer and/or MATLAB to not in fact use its own JVM (such as, from the above link, MATLAB_JAVA) but that's about it.<br />
<br />
(I have moreover not encountered the need to install the here mentioned font packages {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}} and {{Pkg|xorg-fonts-type1}}; text within figures displays fine for me without them).<br />
<br />
[[User:Rene|Rene]] ([[User talk:Rene|talk]]) 01:34, 4 May 2014 (UTC)<br />
<br />
:I use 64-bit MATLAB and have no idea what the issues with Java are. I can either use or not use the supplied java or my systems java-7-openjdk with all releases of 64-bit MATLAB between R2010b and R2014a.<br />
<br />
:I cannot resize the fonts in a figure, {{ic|xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12);}} gives the same size font, in all 64-bit releases without {{Pkg|xorg-fonts-100dpi}} installed on the X11 server. My system is running at 96 DPI according to {{ic|<nowiki>xdpyinfo|grep resolution</nowiki>}}, so potentially/presumably {{Pkg|xorg-fonts-75dpi}} might be needed on other systems<br />
<br />
:[[User:Dshub|Dshub]] ([[User talk:Dshub|talk]]) 13:06, 29 May 2014 (UTC)</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317131MATLAB2014-05-29T12:04:12Z<p>Dshub: Moved some of the troubleshooting subsections into the installation section</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward. The MATLAB installation software includes its own JVM, although the version lags behind the standard JVMs packaged for Arch. It is sometimes possible, although not required, to use newer versions of the JVM than those supplied by MATLAB.<br />
<br />
== Installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Activation ===<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== OpenGL Acceleration ===<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.<br />
<br />
=== Install supported compiler ===<br />
<br />
In order for Matlab to work with C code (needed for simulink) it is necessary to install a [http://www.mathworks.ch/support/compilers/?sec=glnxa64 supported compiler]. For example, if using Matlab r2013a, install {{AUR|gcc44}} from the AUR.<br />
<br />
Then edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurances of CC='gcc' with CC='gcc-4.4' and CXX='g++' with CXX='g++-4.4'. Afterwards run <br />
mex -setup<br />
in Matlab and select the {{ic|mexopts.sh}} file.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317130MATLAB2014-05-29T11:59:17Z<p>Dshub: /* License: invalid machine id */ Added alternate methods and information that it is no longer a problem</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward. The MATLAB installation software includes its own JVM, although the version lags behind the standard JVMs packaged for Arch. It is sometimes possible, although not required, to use newer versions of the JVM than those supplied by MATLAB.<br />
<br />
== General installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
=== Install supported compiler ===<br />
<br />
In order for Matlab to work with C code (needed for simulink) it is necessary to install a [http://www.mathworks.ch/support/compilers/?sec=glnxa64 supported compiler]. For example, if using Matlab r2013a, install {{AUR|gcc44}} from the AUR.<br />
<br />
Then edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurances of CC='gcc' with CC='gcc-4.4' and CXX='g++' with CXX='g++-4.4'. Afterwards run <br />
mex -setup<br />
in Matlab and select the {{ic|mexopts.sh}} file.<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== Activation ===<br />
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly. Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file<br />
<br />
{{bc|ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}<br />
<br />
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D<br />
<br />
== OpenGL Acceleration ==<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317118MATLAB2014-05-29T11:21:00Z<p>Dshub: /* OpenGL Acceleration */ OpenGL acceleration is not really a MATLAB issue</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward. The MATLAB installation software includes its own JVM, although the version lags behind the standard JVMs packaged for Arch. It is sometimes possible, although not required, to use newer versions of the JVM than those supplied by MATLAB.<br />
<br />
== General installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
=== Install supported compiler ===<br />
<br />
In order for Matlab to work with C code (needed for simulink) it is necessary to install a [http://www.mathworks.ch/support/compilers/?sec=glnxa64 supported compiler]. For example, if using Matlab r2013a, install {{AUR|gcc44}} from the AUR.<br />
<br />
Then edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurances of CC='gcc' with CC='gcc-4.4' and CXX='g++' with CXX='g++-4.4'. Afterwards run <br />
mex -setup<br />
in Matlab and select the {{ic|mexopts.sh}} file.<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== License: invalid machine id ===<br />
{{Note|This seems to be fixed in r2014a.}}<br />
The installer may complain about an invalid machine id, because it is looking for a network interface named eth0 to get a MAC address for activation, while new Arch Linux setups do not have a network interface called eth0 (systemd uses [http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames Predictable Network Interface Names]). <br />
<br />
The optimal solution is to create a dummy network interface named eth0 with the MAC address of the network device in use (wireless or wired) when you activated MATLAB. First, get that MAC address using {{ic|ip link}} Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with your MAC address.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki><br />
}}<br />
<br />
==== Rename Interfaces ====<br />
<br />
A less preferable option is to [[rename network interfaces|change the name of the interface]].<br />
<br />
The machine id should now be different than 000000000000 and you should be able to install and activate MATLAB without problems.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D<br />
<br />
== OpenGL Acceleration ==<br />
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[Xorg#Driver_installation|video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package from the [[official repositories]]. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. Proper OpenGL configuration can be checked with the {{ic|glxinfo}} from the {{Pkg|mesa}} package from the [[official repositories]]:<br />
<br />
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}<br />
<br />
If "direct rendering" is not "yes", then there is a problem with your hardware acceleration. From within MATLAB is is also possible to check if hardware based OpenGL acceleration is being used:<br />
<br />
{{bc|<nowiki>$ matlab -nodesktop -r 'opengl info; exit' | grep 'Software'</nowiki>}}<br />
<br />
If "software rendering" is not "false", then there is a problem with your hardware acceleration.</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=317105MATLAB2014-05-29T09:53:01Z<p>Dshub: Added an overview section</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Related articles start}}<br />
{{Related|Octave}}<br />
{{Related|Sage-mathematics}}<br />
{{Related|Mathematica}}<br />
{{Related articles end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== Overview ==<br />
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only be available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward. The MATLAB installation software includes its own JVM, although the version lags behind the standard JVMs packaged for Arch. It is sometimes possible, although not required, to use newer versions of the JVM than those supplied by MATLAB.<br />
<br />
== General installation ==<br />
{{Note|Versions earlier than MATLAB R2013a are not compatible with Java 7. When installing an older version, first install {{Pkg|libxp}} and {{AUR|jre6}}.}}<br />
<br />
{{Accuracy|MATLAB R2012a installs and works fine with openjdk 7}}<br />
<br />
MATLAB 2013a+ should install fine with the {{ic|./install}} script provided by MATLAB, without any additional packages. You can run the script as root to install MATLAB system-wide, or run it as your user to install it only for you.<br />
<br />
To install from an iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# curl http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png<br />
<br />
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=env -u _JAVA_OPTIONS matlab -desktop -nosplash -r "cd('%d'); edit '%f'"<br />
Categories=Development;<br />
MimeType=text/x-matlab;<br />
</nowiki>}}<br />
<br />
The {{ic|Exec}} command line is composed as follows:<br />
<br />
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.<br />
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.<br />
* {{ic|env -u _JAVA_OPTIONS}} prevents the creation of a .java.log-file in your home directory by unsetting {{ic|$_JAVA_OPTIONS}}. Java prints all options set this way to stdout, and Matlab treats everything in stdout as an error worth logging.<br />
* {{ic|-r '...'}} executes Matlab code on startup:<br />
*# {{ic|cd('%d')}} This changes the working directory of Matlab to the opened file’s directory.<br />
*# {{ic|edit '%f'}} This spawns an editor tab for the file.<br />
<br />
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
=== Install supported compiler ===<br />
<br />
In order for Matlab to work with C code (needed for simulink) it is necessary to install a [http://www.mathworks.ch/support/compilers/?sec=glnxa64 supported compiler]. For example, if using Matlab r2013a, install {{AUR|gcc44}} from the AUR.<br />
<br />
Then edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurances of CC='gcc' with CC='gcc-4.4' and CXX='g++' with CXX='g++-4.4'. Afterwards run <br />
mex -setup<br />
in Matlab and select the {{ic|mexopts.sh}} file.<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
=== Install-Time Library Errors ===<br />
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').<br />
<br />
* Make sure the device you're installing from is not mounted as {{ic|noexec}}<br />
<br />
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.<br />
<br />
=== License: invalid machine id ===<br />
{{Note|This seems to be fixed in r2014a.}}<br />
The installer may complain about an invalid machine id, because it is looking for a network interface named eth0 to get a MAC address for activation, while new Arch Linux setups do not have a network interface called eth0 (systemd uses [http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames Predictable Network Interface Names]). <br />
<br />
The optimal solution is to create a dummy network interface named eth0 with the MAC address of the network device in use (wireless or wired) when you activated MATLAB. First, get that MAC address using {{ic|ip link}} Next, create the following file:<br />
<br />
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki><br />
[Unit]<br />
Description=Dummy network interface for MATLAB<br />
Requires=systemd-modules-load.service<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/sbin/ip link set dev dummy0 name eth0<br />
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
Replace 00:00:00:00:00:00 with your MAC address.<br />
<br />
Then make the script run on boot:<br />
<br />
# systemctl enable matlab.licensing<br />
<br />
Finally, set the dummy module to load on boot by creating the following file:<br />
<br />
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki><br />
}}<br />
<br />
==== Rename Interfaces ====<br />
<br />
A less preferable option is to [[rename network interfaces|change the name of the interface]].<br />
<br />
The machine id should now be different than 000000000000 and you should be able to install and activate MATLAB without problems.<br />
<br />
=== Resolving start warnings/errors ===<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
=== MATLAB crashes when displaying graphics ===<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
=== Blank/grey UI when using DWM/Awesome ===<br />
<br />
wmname LG3D<br />
<br />
== OpenGL Acceleration ==<br />
<br />
Once Matlab is installed type the following in the interpreter:<br />
<br />
>> opengl info<br />
<br />
The output should be similar to the following:<br />
<br />
{{bc|<nowiki><br />
Version = 2.0 Mesa 7.8.2<br />
Vendor = Advanced Micro Devices, Inc.<br />
Renderer = Mesa DRI R600 (RV710 9552) 20090101 x86/MMX/SSE2 TCL DRI2<br />
MaxTextureSize = 4096<br />
Visual = 0xcb (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff)<br />
Software = false<br />
# of Extensions = 107<br />
<br />
Driver Bug Workarounds:<br />
OpenGLBitmapZbufferBug = 0<br />
OpenGLWobbleTesselatorBug = 0<br />
OpenGLLineSmoothingBug = 0<br />
OpenGLClippedImageBug = 0<br />
OpenGLEraseModeBug = 0<br />
</nowiki>}}<br />
This will vary with card you are using, but the important part is "Software = false". If it's not "false" for you, then there is a problem with your hardware acceleration.<br />
<br />
=== NVIDIA ===<br />
<br />
With an [[Nvidia|NVIDIA]] card, the output should be similar to this:<br />
{{bc|<nowiki><br />
>> opengl info<br />
Version = 2.1.2 NVIDIA 177.82<br />
Vendor = NVIDIA Corporation<br />
Renderer = Quadro NVS 140M/PCI/SSE2<br />
MaxTextureSize = 8192<br />
Visual = 0x21 (TrueColor, depth 16, RGB mask 0xf800 0x07e0 0x001f)<br />
Software = false<br />
# of Extensions = 144<br />
<br />
Driver Bug Workarounds:<br />
OpenGLBitmapZbufferBug = 0<br />
OpenGLWobbleTesselatorBug = 0<br />
OpenGLLineSmoothingBug = 0<br />
OpenGLClippedImageBug = 1<br />
OpenGLEraseModeBug = 0<br />
</nowiki>}}<br />
<br />
With the NVIDIA card all it required to start working was to copy the {{ic|libGLU.so}} from the Matlab installed library {{ic|${MATLAB}/sys/opengl/lib/glnx86/libGLU.so}} to {{ic|/usr/lib directory}}. Note that in x86_64 this might be a different directory.<br />
<br />
{{Note|Although, not thoroughly tested, using {{Pkg|lib32-nvidia-utils}} seems to work as well.}}</div>Dshubhttps://wiki.archlinux.org/index.php?title=Talk:Pam_mount&diff=315322Talk:Pam mount2014-05-16T12:11:55Z<p>Dshub: </p>
<hr />
<div>I think this page is out of date. On my system the /etc/pam.d/system-auth file did not match the template. Further, I had problems with the ordering caused by pam_systemd.so in /etc/pam.d/system-login. I had to load pam_mount after that in order to get volumes to mount and unmount properly. Finally, just modifying /etc/pam.d/system-login worked fine with KDE/KDM so I wonder if any display managers actually need customization. I don't know enough about PAM or pam_mount to make changes. [[User:Dshub|Dshub]] ([[User talk:Dshub|talk]]) 12:11, 16 May 2014 (UTC)</div>Dshubhttps://wiki.archlinux.org/index.php?title=Talk:Pam_mount&diff=315320Talk:Pam mount2014-05-16T12:11:27Z<p>Dshub: Created page with "I think this page is out of date. On my system the /etc/pam.d/system-auth file did not match the template. Further, I had problems with the ordering caused by pam_systemd.so i..."</p>
<hr />
<div>I think this page is out of date. On my system the /etc/pam.d/system-auth file did not match the template. Further, I had problems with the ordering caused by pam_systemd.so in /etc/pam.d/system-login. I had to load pam_mount after that in order to get volumes to mount and unmount properly. Finally, just modifying /etc/pam.d/system-login worked fine with KDE/KDM so I wonder if any display managers actually need customization. I don't know enough about PAM or pam_mount to make changes.</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=262016Xen2013-06-09T18:39:39Z<p>Dshub: added required packge</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
$ grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository needs to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to /etc/netctl/xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
# netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well: {{hc|# brctl show|<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
}}<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
# netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
{{hc|# xl list|<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9}}<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} and {{Pkg|bluez-libs}} packages.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
== Configuring a paravirtualized (PV) Arch domU ==<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260959Xen2013-06-03T17:29:10Z<p>Dshub: Added command prompt</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
$ grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository needs to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to /etc/netctl/xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
# netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well: {{hc|# brctl show|<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
}}<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
# netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
{{hc|# xl list|<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9}}<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
== Configuring a paravirtualized (PV) Arch domU ==<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260958Xen2013-06-03T17:27:43Z<p>Dshub: Added command prompt</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
$ grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository needs to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to /etc/netctl/xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
# netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well: {{hc|# brctl show|<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
}}<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
# netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
== Configuring a paravirtualized (PV) Arch domU ==<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260956Xen2013-06-03T17:22:43Z<p>Dshub: Added command prompt</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
$ grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository needs to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
== Configuring a paravirtualized (PV) Arch domU ==<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260955Xen2013-06-03T17:21:37Z<p>Dshub: Added command prompt</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
$ grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository needs to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
$ grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
== Configuring a paravirtualized (PV) Arch domU ==<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260954Xen2013-06-03T17:21:19Z<p>Dshub: Added command prompt</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
$ grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository needs to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
== Configuring a paravirtualized (PV) Arch domU ==<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260952Xen2013-06-03T17:13:59Z<p>Dshub: added missing word</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository needs to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
== Configuring a paravirtualized (PV) Arch domU ==<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260881Xen2013-06-03T11:54:56Z<p>Dshub: Changed the sectioning level</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
== Configuring a paravirtualized (PV) Arch domU ==<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260880Xen2013-06-03T11:54:38Z<p>Dshub: Changed the sectioning level</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Configuring a hardware virtualized (HVM) Arch domU ==<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260879Xen2013-06-03T11:52:09Z<p>Dshub: /* Using Xen */</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of operating systems including microsot Windows. To use HVM domUs the dom0 hardware must have virtualization support. Paravirtualized domUs do not require virtualization support, but instead require modifications to the guest operating system making the installation procedure different for each operating system (see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions). Some operating systems (e.g., Microsoft Windows) cannot be installed as a PV domU. In general, HVM domUs often run slower than PV domUs since HVMs run on emulated hardware. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, for each domU, a "hard disk" will need to be created and a configuration file needs to be written. Additionally, for installation each domU will need access to a copy of the installation ISO stored on the dom0 (see the [https://www.archlinux.org/download/ Download Page] to obtain the Arch Linux ISO).<br />
<br />
=== Create a domU "hard disk" ===<br />
Xen supports a number of different types of "hard disks" including [[LVM| Logical Volumes]], [[Partitioning|raw partitions]], and image files. To create a [[Wikipedia: Sparse file|sparse file]], that will grow to a maximum of 10GiB, called domU.img, use:<br />
truncate -s 10G domU.img<br />
If file IO speed is of greater importance than domain portability, using [[LVM|Logical Volumes]] or [[Partitioning|raw partitions]] may be a better choice.<br />
<br />
=== Create a domU configuration ===<br />
Each domU requires a separate configuration file that is used to create the virtual machine. Full details about the configuration files can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "file:/path/to/ISO,sdb,r", "phy:/path/to/partition,sda1,w" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|disk&#61;}} includes information about both the the installation media ({{ic|file:}}) and the partition created for the domU {{ic|phy}}. If an image file is being used instead of a physical partition, the {{ic|phy:}} needs to be changed to {{ic|file:}}. The {{ic|vif&#61;}} defines a network controller. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
=== Managing a domU ===<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly. Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260876Xen2013-06-03T11:35:38Z<p>Dshub: Added link for documentation</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository to be enabled to install Xen (See [[Pacman#Repositories]] for details). Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] for the man pages and documentation.<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [https://www.archlinux.org/download/ Download Page] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260870Xen2013-06-03T10:14:57Z<p>Dshub: fixed section markup</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository to be enabled to install Xen (See [[Pacman#Repositories]] for details).<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [https://www.archlinux.org/download/ Download Page] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260869Xen2013-06-03T10:13:31Z<p>Dshub: Added subsections</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Installation of Xen systemd services<br />
<br />
=== Installation of the Xen hypervisor ===<br />
To install the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services. The multilib repository to be enabled to install Xen (See [[Pacman#Repositories]] for details).<br />
<br />
=== Modification of the bootloader ===<br />
The boot loader must be modified to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
=== Creation of a network bridge ===<br />
Xen requires that network communications between domUs and the dom0 (and beyond) be set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by the network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domU is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
=== Installation of Xen systemd services ===<br />
The Xen dom0 requires the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
=== Confirming successful installation<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [https://www.archlinux.org/download/ Download Page] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260865Xen2013-06-03T10:01:37Z<p>Dshub: Cleaned up the language</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
The Xen hypervisor requires kernel level support which is included in recent Linux kernels and is built into the {{Pkg|linux}} and {{Pkg|linux-lts}} Arch kernel packages. To run run HVM domUs the physical hardware must have either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [https://www.archlinux.org/download/ Download Page] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260857Xen2013-06-03T09:48:50Z<p>Dshub: Cleaned up the language</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture allowing multiple operating systems to run simultaneously. The hypervisor is started by the boot loader of the computer it is installed on. Once the hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host or privileged domain) which in our case runs Arch Linux. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from the dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. See [http://wiki.xen.org/wiki/Xen_Overview Xen.org] for a full overview.<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVMs run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
To use the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [https://www.archlinux.org/download/ Download Page] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260854Xen2013-06-03T09:25:14Z<p>Dshub: Fixed download link</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture. It is started by the boot loader of the computer it is installed on, and allows multiple operating systems to run simultaneously on top of it. Once the Xen hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host), or privileged domain, which in our case runs a Linux kernel (other possible dom0 operating systems are NetBSD and OpenSolaris). The physical hardware must, of course, be supported by this kernel to run Xen. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs.<br />
<br />
[http://wiki.xen.org/wiki/Xen_Overview Xen.org] provides a full overview<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVMs run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
To use the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [https://www.archlinux.org/download/ Download Page] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260707Xen2013-06-02T20:04:29Z<p>Dshub: fixed bridge file name consistency</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture. It is started by the boot loader of the computer it is installed on, and allows multiple operating systems to run simultaneously on top of it. Once the Xen hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host), or privileged domain, which in our case runs a Linux kernel (other possible dom0 operating systems are NetBSD and OpenSolaris). The physical hardware must, of course, be supported by this kernel to run Xen. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs.<br />
<br />
[http://wiki.xen.org/wiki/Xen_Overview Xen.org] provides a full overview<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVMs run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
To use the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xenbridge-dhcp:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [[Dowload page]] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260705Xen2013-06-02T20:00:58Z<p>Dshub: Minor language clean up</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture. It is started by the boot loader of the computer it is installed on, and allows multiple operating systems to run simultaneously on top of it. Once the Xen hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host), or privileged domain, which in our case runs a Linux kernel (other possible dom0 operating systems are NetBSD and OpenSolaris). The physical hardware must, of course, be supported by this kernel to run Xen. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs.<br />
<br />
[http://wiki.xen.org/wiki/Xen_Overview Xen.org] provides a full overview<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVMs run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
To use the Xen hypervisor install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xen-bridge:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [[Dowload page]] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260701Xen2013-06-02T19:54:00Z<p>Dshub: /* Configuring a hardware virtualized (HVM) Arch domU */</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture. It is started by the boot loader of the computer it is installed on, and allows multiple operating systems to run simultaneously on top of it. Once the Xen hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host), or privileged domain, which in our case runs a Linux kernel (other possible dom0 operating systems are NetBSD and OpenSolaris). The physical hardware must, of course, be supported by this kernel to run Xen. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs.<br />
<br />
[http://wiki.xen.org/wiki/Xen_Overview Xen.org] provides a full overview<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVM run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xen-bridge:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [[Dowload page]] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the {{Pkg|mesa-libgl}} package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260699Xen2013-06-02T19:47:09Z<p>Dshub: Major rewrite of the domU configuration</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture. It is started by the boot loader of the computer it is installed on, and allows multiple operating systems to run simultaneously on top of it. Once the Xen hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host), or privileged domain, which in our case runs a Linux kernel (other possible dom0 operating systems are NetBSD and OpenSolaris). The physical hardware must, of course, be supported by this kernel to run Xen. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs.<br />
<br />
[http://wiki.xen.org/wiki/Xen_Overview Xen.org] provides a full overview<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVM run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xen-bridge:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
This is how to install Arch as a domU on an already-running Xen dom0. To install Arch Linux ''as'' the Xen dom0, see the previous section. Once the dom0 is fully operational, domUs may be created/imported. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs. While there are some common steps involved in setting up PV and HVM domUs, the processes are substantially different. In both cases, a copy of the Arch Linux ISO will be needed on the dom0. This cane be downloaded from the [[Dowload page]] and a "hard disk" will be needed for the domU. Xen supports a number of different types of "hard disks". For example a [[LVM| Logical Volume]], [[Partitioning|raw partition]], or an image file(s) can be used. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. Each domU requires a separate configuration file that is used to create the virtual machine. The following examples use minimal examples, but full details can be found at the [http://wiki.xensource.com/xenwiki/XenConfigurationFileOptions| Xen Wiki] or the xl.cfg man page. Install the {{AUR|xen-docs}} package from the [[Arch User Repository]] to access the man pages.<br />
<br />
In the following sections the steps for creating HVM and PV domUs running Arch Linux are described. In general, the steps for creating an HVM domU are independent of the domU OS and HVM domUs support a wide range of OSs including microsot Windows. Paravirtualized domUs, on the other hand require modifications to the guest OS making the installation procedure different for each OS. See the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions. Some OSs (e.g., Microsoft Windows) cannot be installed as a PV domU.<br />
<br />
Both HVM and PV domUs share some components of the configuration file. These include<br />
<nowiki><br />
name = "domU"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
The {{ic|name&#61;}} is the name by which the xl tools manage the domU and needs to be unique across all domUs. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, so the last three digits of the {{ic|mac&#61;}} must be randomly filled in (hex values 0-9 and a-f only).<br />
<br />
Some useful commands for managing domUs are:<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
If a domU should be started on boot, create a symlink to the configuration file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Configuring a hardware virtualized (HVM) Arch domU ===<br />
In order to use HVM domUs install the [[mesa-libgl]] package.<br />
<br />
A minimal configuration file for a HVM Arch domU is:<br />
<nowiki><br />
name = 'HVM_domU'<br />
builder = 'hvm'<br />
memory = 256<br />
vcpus = 2<br />
disk = [ 'phy:/dev/mapper/vg0-hvm_arch,xvda,w', 'file:/path/to/ISO,hdc:cdrom,r' ]<br />
vif = [ 'mac=00:16:3e:00:00:00,bridge=xenbr0' ]<br />
vnc = 1<br />
vnclisten = '0.0.0.0'<br />
vncdisplay = 1<br />
</nowiki><br />
Since HVM machines do not have a console, they can only be connected to via a [[Vncserver|vncviewer]]. The configuration file allows for unauthenticated remote access of the domU vncserver and is not suitable for unsecured networks. The vncserver will be available on port 590X, where X is the value of {{ic|vncdisplay}}, of the dom0. The domU can be created with:<br />
<br />
# xl create /path/to/config/file<br />
<br />
and its status can be checked with<br />
<br />
# xl list<br />
<br />
Once the domU is created, connect to it via the vncserver and install Arch Linux as described in the [[Installation Guide]].<br />
<br />
=== Configuring a paravirtualized (PV) Arch domU ===<br />
A minimal configuration file for a PV Arch domU is:<br />
<nowiki><br />
name = "PV_domU"<br />
kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:XX:XX:XX,bridge=xenbr0' ]<br />
</nowiki><br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/.<br />
<br />
Before creating the domU, the installation ISO must be loop-mounted. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Once the ISO is mounted, the domU can be created with:<br />
<br />
# xl create -c /path/to/config/file<br />
<br />
The -c option will enter the domU's console when successfully created and install Arch Linux as described in the [[Installation Guide]]. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the xen-blkfront xen-fbfront xen-netfront xen-kbdfront modules must be added to [[Mkinitcpio]]. Without these modules, the domU will not boot correctly. For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260637Xen2013-06-02T17:21:20Z<p>Dshub: /* Configuring dom0 */ rewording of best practices sentence</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture. It is started by the boot loader of the computer it is installed on, and allows multiple operating systems to run simultaneously on top of it. Once the Xen hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host), or privileged domain, which in our case runs a Linux kernel (other possible dom0 operating systems are NetBSD and OpenSolaris). The physical hardware must, of course, be supported by this kernel to run Xen. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs.<br />
<br />
[http://wiki.xen.org/wiki/Xen_Overview Xen.org] provides a full overview<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVM run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xen-bridge:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, see [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen] which includes information on allocating a fixed amount of memory and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Once the dom0 is fully operational, domUs may be created / imported. Each OS has a slightly different method of installation, see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions.<br />
<br />
=== Creating a Paravirtualized (PV) Arch domU ===<br />
This is how to install Arch as a user domain (or VM) on an already-running Xen host. To install Arch ''as'' the Xen host (dom0), see the previous section.<br />
<br />
To begin, download the latest install ISO from the nearest mirror: [https://www.archlinux.org/download/ Dowload page]. Place the ISO file on the dom0 host. (it is recommended that its checksum be verified, too)<br />
<br />
Create the hard disks for the new domU. This can be done with [[LVM]], raw hard disk partitions or image files. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. <br />
<br />
Next, loop-mount the installation ISO. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Create the bootstrap domU configuration file:<br />
{{hc|/etc/xen/archdomu.cfg|<nowiki>kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
name = "archdomu"<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:__random_three_mac_bytes__,bridge=xenbr0' ]</nowiki>}}<br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, do the last three digits may be randomly filled in (hex values 0-9 and a-f only). See the xl.cfg man page for more information on what the .cfg file lines do. The AUR package [https://aur.archlinux.org/packages/xen-docs/ xen-docs] will need to be installed to access the man pages.<br />
<br />
Create the new domU:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
The -c option will enter the new domain's console when successfully created. At this point, Arch should be installed as usual. The [[Installation Guide]] should be followed. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the following modules must be added to {{ic|/etc/mkinitcpio.conf}}:<br />
MODULES="xen-blkfront xen-fbfront xen-netfront xen-kbdfront"<br />
Without these modules, the domU will not boot correctly. After saving the edit, rebuild the initramfs with the following command:<br />
mkinitcpio -p linux<br />
For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
If the domU should be started on boot, create a symlink to the cfg file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Useful xl command examples ===<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=260635Xen2013-06-02T17:16:00Z<p>Dshub: Major rewrite of the dom0 configuration</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture. It is started by the boot loader of the computer it is installed on, and allows multiple operating systems to run simultaneously on top of it. Once the Xen hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host), or privileged domain, which in our case runs a Linux kernel (other possible dom0 operating systems are NetBSD and OpenSolaris). The physical hardware must, of course, be supported by this kernel to run Xen. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs.<br />
<br />
[http://wiki.xen.org/wiki/Xen_Overview Xen.org] provides a full overview<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVM run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring dom0 ==<br />
The Xen hypervisor relies on a full install of the base operating system. Before attempting to install the Xen hypevisor, the host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a [[Desktop Environment]] or even [[Xorg]]. If you are building a new host from scratch, see the [[Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to convert a standard installation into a working dom0 running on top of the Xen hypevisor:<br />
<br />
* Installation of the Xen hypervisor<br />
* Modification of the bootloader to boot the Xen hypervisor<br />
* Creation of a network bridge<br />
* Enable systemd services<br />
<br />
The first step is to install the Xen hypervisor. Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both of these packages require the multilib repository to be enabled.<br />
<br />
The second step is to modify the boot loader to load a special Xen kernel (xen.gz) which is then used to boot the normal kernel. To do this a new bootloader entry is needed.<br />
<br />
For grub users, the Xen package provides the ''/etc/grub.d/09_xen'' generator file. This file can be edited to customize the Xen boot commands, and will add the required bootloader when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
More information is available at [[Grub]].<br />
<br />
The third step is to create a network bridge. Xen requires that network communications between the guest, the host (and beyond) is set up manually. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. Complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details and ''/etc/xen/scripts'' for scripts for various networking configurations. A basic bridged network, in which a virtual switch is created in dom0 that every domu is attached to, can be setup by modifying the example configuration files provided by [[Netctl]] in ''etc/netctl/examples''. By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xen-bridge:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing network connection is called eth0. <br />
<br />
Start the network bridge with:<br />
netctl start xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
If the bridge is working it can be set to start automatically after rebooting with:<br />
netctl enable xenbridge-dhcp<br />
<br />
The final step is to enable the xenstored, xenconsoled, and xendomains system services (see [[Systemd]] for details).<br />
<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
In addition to the required steps above, the current xen.org wiki has a section regarding [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen.] It includes information on allocating a fixed amount of memory dom0 and how to dedicate (pin) a CPU core for dom0 use. It also may be beneficial to create a xenfs filesystem mount point by including in ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
== Using Xen ==<br />
Once the dom0 is fully operational, domUs may be created / imported. Each OS has a slightly different method of installation, see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions.<br />
<br />
=== Creating a Paravirtualized (PV) Arch domU ===<br />
This is how to install Arch as a user domain (or VM) on an already-running Xen host. To install Arch ''as'' the Xen host (dom0), see the previous section.<br />
<br />
To begin, download the latest install ISO from the nearest mirror: [https://www.archlinux.org/download/ Dowload page]. Place the ISO file on the dom0 host. (it is recommended that its checksum be verified, too)<br />
<br />
Create the hard disks for the new domU. This can be done with [[LVM]], raw hard disk partitions or image files. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. <br />
<br />
Next, loop-mount the installation ISO. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Create the bootstrap domU configuration file:<br />
{{hc|/etc/xen/archdomu.cfg|<nowiki>kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
name = "archdomu"<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:__random_three_mac_bytes__,bridge=xenbr0' ]</nowiki>}}<br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, do the last three digits may be randomly filled in (hex values 0-9 and a-f only). See the xl.cfg man page for more information on what the .cfg file lines do. The AUR package [https://aur.archlinux.org/packages/xen-docs/ xen-docs] will need to be installed to access the man pages.<br />
<br />
Create the new domU:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
The -c option will enter the new domain's console when successfully created. At this point, Arch should be installed as usual. The [[Installation Guide]] should be followed. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the following modules must be added to {{ic|/etc/mkinitcpio.conf}}:<br />
MODULES="xen-blkfront xen-fbfront xen-netfront xen-kbdfront"<br />
Without these modules, the domU will not boot correctly. After saving the edit, rebuild the initramfs with the following command:<br />
mkinitcpio -p linux<br />
For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
If the domU should be started on boot, create a symlink to the cfg file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Useful xl command examples ===<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshubhttps://wiki.archlinux.org/index.php?title=MATLAB&diff=259606MATLAB2013-05-30T13:51:08Z<p>Dshub: Added summary and overview</p>
<hr />
<div>[[Category:Mathematics and science]]<br />
{{Article summary start}}<br />
{{Article summary text|This article contains information about the installation, configuration and use of MATLAB.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Octave}}<br />
{{Article summary wiki|Sage-mathematics}}<br />
{{Article summary wiki|Mathematica}}<br />
{{Article summary end}}<br />
From the [http://www.mathworks.com/products/matlab/ official website]:<br />
<br />
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''<br />
<br />
== General installation ==<br />
{{Warning|This should not be necessary for MATLAB R2013a+, which is compliant with Java 7 and does not require extra packages. Installation should be done with the install script provided by matlab.}}<br />
Use the following commands to mount and install Matlab. Note that the path to the install script should contain no spaces, or the install will fail. For graphical install and interface {{Pkg|libxp}} is needed. You may need to [[Pacman|install]] {{Pkg|libxp}} from the [[official repositories]] first. Note also that Matlab is not compliant with Java 7, so you may need to install, for example, {{Pkg|openjdk6}}.<br />
Install from iso file:<br />
# modprobe loop<br />
# mount -o loop matlab.iso /mnt/<br />
# /mnt/install<br />
<br />
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.<br />
<br />
=== Create Desktop and Menu Shortcuts ===<br />
If you choose Custom in Installation Type, the symlink will be created automatically. Otherwise, you may need to manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:<br />
<br />
# ln -s /{MATLAB}/bin/matlab /usr/local/bin<br />
<br />
To create a menu item, we need to get a icon first:<br />
<br />
# wget http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -O /usr/share/icons/matlab.png<br />
<br />
Then create a new .desktop file in {{ic|/usr/share/applications}} with following lines:<br />
<br />
{{hc|/usr/share/applications/matlab.desktop|<nowiki><br />
#!/usr/bin/env xdg-open<br />
[Desktop Entry]<br />
Type=Application<br />
Icon=/usr/share/icons/matlab.png<br />
Name=MATLAB<br />
Comment=Start MATLAB - The Language of Technical Computing<br />
Exec=matlab -desktop<br />
Categories=Development;<br />
</nowiki><br />
}}<br />
<br />
You can also put this .desktop file in the Desktop folder to create a shortcut.<br />
<br />
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]<br />
<br />
=== Install 32-bit Matlab on 64-bit system ===<br />
{{Note|Follow this section only if you have a student version. All other releases since R2012b are 64-bit only.}}<br />
Unfortunately, there is no 64-bit version of the student version. These instructions have been updated for R2012a student version. To start off we need to install a bunch of packages from the [[multilib]] repository (this list may be out of date): <br />
{{Pkg|lib32-mesa}}, {{Pkg|lib32-glu}}, {{Pkg|lib32-glibc}}, {{Pkg|lib32-libxmu}}, {{Pkg|lib32-zlib}}, {{Pkg|lib32-ncurses}}, {{Pkg|lib32-libxtst}}, {{Pkg|lib32-libxi}}, {{Pkg|lib32-libxrender}}, {{Pkg|lib32-libxfixes}}, {{Pkg|lib32-freetype2}}, {{Pkg|lib32-fontconfig}}, {{Pkg|lib32-libxdamage}}.<br />
A few packages from the [[AUR]] might also be needed: <br />
{{AUR|lib32-libxpm}}, {{AUR|lib32-libxp}}, {{AUR|bin32-openjdk6}} ({{Pkg|openjdk7}} might also work).<br />
<br />
Once they are installed: <br />
<br />
$ ./install -glnx86<br />
<br />
After fixing any library dependency problems, you will be able to guide the installer through the install process. If activation doesn't work in the installer you'll need to login to Wolfram's site and download a license file which you'll put in {{ic|${MATLAB}/licenses}}. After the install process, you'll need to create a symbolic link because the installer oddly thinks it's installing the 64-bit version of Matlab:<br />
<br />
$ cd ${MATLAB}/sys/java/jre<br />
$ ln -s glnx86 glnxa64<br />
<br />
In the above, ${MATLAB} should be replaced by the root directory you chose for your installation.<br />
<br />
You'll also need to put another link in Matlab's {{ic|bin}} folder because despite asking Matlab to install the 32bit version, it still thinks you want to use the 64bit one:<br />
<br />
$ cd ${MATLAB}/bin<br />
$ ln -s glnx86 glnxa64<br />
<br />
After that you'll need to edit the {{ic|${MATLAB}/bin/matlab}} script to get the java settings correct. After the comments at the top of the file, you'll need the line:<br />
<br />
export MATLAB_JAVA=/path/to/jre<br />
<br />
Where {{ic|/path/to/jre}} will be {{ic|/opt/java/jre}} if you're using Sun's JRE. The path is one level up from where {{ic|rt.jar}} is located. That is, {{ic|rt.jar}} should be in {{ic|/opt/java/jre/libs}} if you used {{ic|/opt/java/jre}} for {{ic|MATLAB_JAVA}}. In Matlab R2010a it works pretty well, if you use the internal JRE with:<br />
<br />
export MATLAB_JAVA=${MATLAB}/sys/java/jre/glnx86/jre<br />
<br />
If using {{AUR|bin32-openjdk6}}, use<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre/<br />
<br />
To run it, you'll need to:<br />
<br />
$ ${MATLAB}/bin/matlab -glnx86 -desktop<br />
<br />
At this point you may have to resolve more library dependencies or troubleshoot [[Java]]. Your version of Matlab may need a specific version of Sun's JRE installed.<br />
<br />
=== Install supported compiler ===<br />
<br />
In order for Matlab to work with C code (needed for simulink) it is necessarry to install a supported compiler. Install {{AUR|gcc44}} from the AUR.<br />
<br />
Then edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurances of CC='gcc' with CC='gcc-4.4' and CXX='g++' with CXX='g++-4.4'. Afterwards run <br />
mex -setup<br />
in Matlab and select the {{ic|mexopts.sh}} file.<br />
<br />
== Troubleshooting ==<br />
As one installs Matlab, it might complain that it can't find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].<br />
<br />
==== License: invalid machine id ====<br />
The installer may complain about an invalid machine id, because it is looking for a network interface named eth0 to get a MAC address for activation, while new Arch Linux setups do not have a network interface called eth0 (systemd uses [http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames Predictable Network Interface Names]). Just [[rename network interfaces|change the name of the interface]].<br />
<br />
In a nutshell: install {{Pkg|wireless_tools}} and execute the following:<br />
# systemctl stop NetworkManager<br />
# ifrename -i enp2s0f0 -n eth0<br />
# systemctl start NetworkManager<br />
<br />
This will be needed after each reboot. To make it permanent:<br />
# ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules<br />
<br />
The machine id should now be different than 000000000000 and you should be able to install and activate MATLAB without problems. <br />
<br />
==== Resolving start warnings/errors ====<br />
<br />
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:<br />
<br />
# ln -s /lib/libc.so.6 /lib64<br />
<br />
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):<br />
<br />
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre<br />
<br />
==== MATLAB crashes when displaying graphics ====<br />
<br />
To identify this error, start MATLAB with<br />
<br />
LIBGL_DEBUG=verbose matlab<br />
<br />
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like <br />
<br />
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed <br />
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: <br />
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))<br />
<br />
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by<br />
<br />
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64<br />
sudo unlink libstdc++.so.6<br />
sudo ln -s /usr/lib/libstdc++.so.6<br />
<br />
==== Blank/grey UI when using DWM/Awesome ====<br />
<br />
wmname LG3D<br />
<br />
== OpenGL Acceleration ==<br />
<br />
Once Matlab is installed type the following in the interpreter:<br />
<br />
>> opengl info<br />
<br />
The output should be similar to the following:<br />
<br />
{{bc|<nowiki><br />
Version = 2.0 Mesa 7.8.2<br />
Vendor = Advanced Micro Devices, Inc.<br />
Renderer = Mesa DRI R600 (RV710 9552) 20090101 x86/MMX/SSE2 TCL DRI2<br />
MaxTextureSize = 4096<br />
Visual = 0xcb (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff)<br />
Software = false<br />
# of Extensions = 107<br />
<br />
Driver Bug Workarounds:<br />
OpenGLBitmapZbufferBug = 0<br />
OpenGLWobbleTesselatorBug = 0<br />
OpenGLLineSmoothingBug = 0<br />
OpenGLClippedImageBug = 0<br />
OpenGLEraseModeBug = 0<br />
</nowiki>}}<br />
This will vary with card you are using, but the important part is "Software = false". If it's not "false" for you, then there is a problem with your hardware acceleration.<br />
<br />
=== NVIDIA ===<br />
<br />
With an [[Nvidia|NVIDIA]] card, the output should be similar to this:<br />
{{bc|<nowiki><br />
>> opengl info<br />
Version = 2.1.2 NVIDIA 177.82<br />
Vendor = NVIDIA Corporation<br />
Renderer = Quadro NVS 140M/PCI/SSE2<br />
MaxTextureSize = 8192<br />
Visual = 0x21 (TrueColor, depth 16, RGB mask 0xf800 0x07e0 0x001f)<br />
Software = false<br />
# of Extensions = 144<br />
<br />
Driver Bug Workarounds:<br />
OpenGLBitmapZbufferBug = 0<br />
OpenGLWobbleTesselatorBug = 0<br />
OpenGLLineSmoothingBug = 0<br />
OpenGLClippedImageBug = 1<br />
OpenGLEraseModeBug = 0<br />
</nowiki>}}<br />
<br />
With the NVIDIA card all it required to start working was to copy the {{ic|libGLU.so}} from the Matlab installed library {{ic|${MATLAB}/sys/opengl/lib/glnx86/libGLU.so}} to {{ic|/usr/lib directory}}. Note that in x86_64 this might be a different directory.<br />
<br />
{{Note|Although, not thoroughly tested, using {{Pkg|lib32-nvidia-utils}} seems to work as well.}}</div>Dshubhttps://wiki.archlinux.org/index.php?title=Xen&diff=259560Xen2013-05-30T10:30:21Z<p>Dshub: Major rewrite of overview and introduction</p>
<hr />
<div><br />
[[Category:Virtualization]]<br />
[[Category:Kernel]]<br />
[[de:Xen]]<br />
[[es:Xen]]<br />
[[ru:Xen]]<br />
{{Article summary start}}<br />
{{Article summary text|This article is about basic usage of Xen, including running Arch as both a Xen dom0 ''host'' and as a domU ''guest''.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Xen|http://www.xen.org/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|KVM}}<br />
{{Article summary wiki|QEMU}}<br />
{{Article summary wiki|VirtualBox}}<br />
{{Article summary wiki|VMware}}<br />
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}<br />
{{Article summary end}}<br />
<br />
From [http://wiki.xen.org/wiki/Xen_Overview Xen Overview]:<br />
<br />
:''Xen is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). Xen is the only type-1 hypervisor that is available as open source. Xen is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances.''<br />
<br />
==Introduction==<br />
<br />
The Xen hypervisor is a thin layer of software which emulates a computer architecture. It is started by the boot loader of the computer it is installed on, and allows multiple operating systems to run simultaneously on top of it. Once the Xen hypervisor is loaded, it starts the "dom0" (short for "domain 0", sometimes called the host), or privileged domain, which in our case runs a Linux kernel (other possible dom0 operating systems are NetBSD and OpenSolaris). The physical hardware must, of course, be supported by this kernel to run Xen. Once the dom0 has started, one or more "domUs" (short for user domains, sometimes called VMs or guests) can be started and controlled from dom0. Xen supports both paravirtualized (PV) and hardware virtualized (HVM) domUs.<br />
<br />
[http://wiki.xen.org/wiki/Xen_Overview Xen.org] provides a full overview<br />
<br />
==System requirements==<br />
Paravirtualized domUs require a kernel with support for Xen built in. Recent Linux kernels and some other Unix-like systems provide this support, but Microsoft Windows does not. Hardware virtualized domUs do not require kernel level support, but often run slower than PV domUs since HVM run on emulated hardware. To use HVM domUs, the dom0 must include either Intel VT-x or AMD-V (SVM) virtualization support. In order to verify this, run the following command when the Xen hypervisor is not running:<br />
grep -E "(vmx|svm)" --color=always /proc/cpuinfo<br />
If the above command does not produce output, then hardware virtualization support is unavailable and your hardware is unable to run HVM domUs. If you believe the CPU supports one of these features you should access the host system's BIOS configuration menu during the boot process and look if options related to virtualization support have been disabled. If such an option exists and is disabled, then enable it, boot the system and repeat the above command. The Xen hypervisor also supports PCI passthrough where PCI devices can be passed directly to the domU even in the absence of dom0 support for the device. In order to use PCI passthrough the CPU must support IOMMU/VT-d.<br />
<br />
Install either the current stable {{AUR|xen}} or the bleeding edge unstable {{AUR|xen-hg-unstable}} packages available in the [[Arch User Repository]]. Both packages provide the Xen hypervisor, current xl interface and all configuration and support files, including systemd services.<br />
<br />
== Configuring Xen ==<br />
Xen, unlike certain other virtualization systems, relies on a full install of the base operating system. Before attempting to install Xen, your host machine should have a fully operational and up-to-date install of Arch Linux. This installation can be a minimal install with only the base package and does not require a desktop environment or even X11. If you are building a new host from scratch, see the [[Installation_Guide|Installation Guide]] for instructions on installing Arch Linux. The following configuration steps are required to create a working dom0.<br />
<br />
* installation of the xen package<br />
* an entry in the bootloader configuration file<br />
* systemd services to be started at boot time<br />
* a xenfs filesystem mount point<br />
* bridged networking configuration<br />
<br />
In addition to these required steps, the current xen.org wiki has a section regarding [http://wiki.xen.org/wiki/Xen_Best_Practices best practices for running Xen.] It includes information on allocating a fixed amount of memory dom0 and how to dedicate (pin) a CPU core for dom0 use.<br />
<br />
=== Bootloader Configuration ===<br />
Xen requires that you boot a special xen kernel (xen.gz) which in turn boots your system's normal kernel. A new bootloader entry is needed. To boot into the Xen system, we need a new menuentry in grub.cfg. The Xen package provides a grub2 generator file: ''/etc/grub.d/09_xen''. This file can be edited to customize the Xen boot commands, and will add a menuentry to your grub.cfg when the following command is run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
Example non-xen menuentry for LVM with gpt partition table<br />
menuentry 'Arch ' {<br />
insmod part_gpt<br />
insmod lvm<br />
insmod ext2<br />
set root='lvm/vg0-arch'<br />
linux /boot/vmlinuz-linux root=/dev/mapper/vg0-arch ro init=/usr/lib/systemd/systemd quiet<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
The menuentry to boot the same arch system after Xen has been installed. Get the UUID for ''lvm/vg0-arch'' by using ''blkid''.<br />
<br />
menuentry 'Arch Xen 4.2' {<br />
insmod lvm<br />
insmod part_gpt<br />
insmod ext2<br />
set root='lvm/vg0-arch'<br />
search --no-floppy --fs-uuid --set=root 346de8aa-6150-4d7b-a8c2-1c43f5929f99<br />
multiboot /boot/xen.gz placeholder dom0_mem=1024M<br />
module /boot/vmlinuz-linux placeholder root=/dev/mapper/vg0-arch ro init=/usr/lib/systemd/systemd quiet<br />
module /boot/initramfs-linux.img<br />
}<br />
<br />
Example for a physical partition<br />
Arch Linux(XEN)<br />
menuentry "Arch Linux(XEN)" {<br />
set root=(hd0,X)<br />
search --no-floppy --fs-uuid --set=root 346de8aa-6150-4d7b-a8c2-1c43f5929f99<br />
multiboot /boot/xen.gz dom0_mem=1024M<br />
module /boot/vmlinuz-linux-xen-dom0 root=/dev/sda ro<br />
module /boot/initramfs-linux-xen-dom0.img<br />
}<br />
More at [https://wiki.archlinux.org/index.php/Grub2 Grub2]<br />
<br />
=== Systemd Services ===<br />
Issue the following commands as root so that the services are started at bootup:<br />
# systemctl enable xenstored.service<br />
# systemctl enable xenconsoled.service<br />
# systemctl enable xendomains.service<br />
<br />
=== Xenfs Mountpoint ===<br />
Include in your ''/etc/fstab''<br />
none /proc/xen xenfs defaults 0 0<br />
<br />
=== Bridged Networking ===<br />
Previous versions of Xen provided a bridge connection whereas Xen 4.2 requires that network communications between the guest, the host (and beyond) is set up separately. The use of both DHCP and static addressing is possible, and the choice should be determined by your network topology. With basic bridged networking, a virtual switch is created in dom0 that every domu is attached to. More complex setups are possible, see the [http://wiki.xen.org/wiki/Xen_Networking Networking] article on the Xen wiki for details.<br />
<br />
Netctl greatly simplifies network configuration and is now included as standard in the ''base'' package. Example configuration files are provided in ''etc/netctl/examples'' and Xen 4.2 provides scripts for various networking configurations in ''/etc/xen/scripts''. <br />
<br />
By default, Xen expects a bridge to exist named xenbr0. To set this up with netctl, do the following:<br />
<br />
# cd /etc/netctl<br />
# cp examples/bridge xenbridge-dhcp<br />
<br />
make the following changes to xen-bridge:<br />
Description="Xen bridge connection"<br />
Interface=xenbr0<br />
Connection=bridge<br />
BindsToInterface=(eth0) # Use the name of the external interface found with the 'ip link' command<br />
IP=dhcp<br />
assuming your existing eth0 connection is called eth0-dhcp, <br />
<br />
restart the network:<br />
netctl enable xenbridge-dhcp<br />
<br />
when the prompt returns, check all is well<br />
brctl show<br />
<br />
bridge name bridge id STP enabled interfaces<br />
xenbr0 8000.001a9206c0c0 no eth0<br />
<br />
=== Final Steps ===<br />
Reboot your dom0 host and ensure that the Xen kernel boots correctly and that all settings survive a reboot. A properly set up dom0 should report show the following when you run xl list (as root):<br />
# xl list<br />
Name ID Mem VCPUs State Time(s)<br />
Domain-0 0 511 2 r----- 41652.9<br />
Of course, the Mem, VCPUs and Time columns will be different depending on machine configuration and uptime. The important thing is that dom0 is listed.<br />
<br />
== Using Xen ==<br />
Once the dom0 is fully operational, domUs may be created / imported. Each OS has a slightly different method of installation, see the [http://wiki.xen.org/wiki/Category:Guest_Install Guest Install] page of the Xen wiki for links to instructions.<br />
<br />
=== Creating a Paravirtualized (PV) Arch domU ===<br />
This is how to install Arch as a user domain (or VM) on an already-running Xen host. To install Arch ''as'' the Xen host (dom0), see the previous section.<br />
<br />
To begin, download the latest install ISO from the nearest mirror: [https://www.archlinux.org/download/ Dowload page]. Place the ISO file on the dom0 host. (it is recommended that its checksum be verified, too)<br />
<br />
Create the hard disks for the new domU. This can be done with [[LVM]], raw hard disk partitions or image files. To create a 10GiB blank hard disk file, the following command can be used:<br />
truncate -s 10G sda.img<br />
This creates a sparse file, which grows (to a maximum of 10GiB) only when data is added to the image. If file IO speed is of greater importance than domain portability, using a [[LVM|Logical Volume]] or [[Partitioning|raw partition]] may be a better choice. <br />
<br />
Next, loop-mount the installation ISO. To do this, ensure the directory /mnt exists and is empty, then run the following command (being sure to fill in the correct ISO path):<br />
# mount -o loop /path/to/iso /mnt<br />
<br />
Create the bootstrap domU configuration file:<br />
{{hc|/etc/xen/archdomu.cfg|<nowiki>kernel = "/mnt/arch/boot/x86_64/vmlinuz"<br />
ramdisk = "/mnt/arch/boot/x86_64/archiso.img"<br />
extra = "archisobasedir=arch archisolabel=ARCH_201301"<br />
memory = 256<br />
name = "archdomu"<br />
disk = [ "phy:/path/to/partition,sda1,w", "file:/path/to/ISO,sdb,r" ]<br />
vif = [ 'mac=00:16:3e:__random_three_mac_bytes__,bridge=xenbr0' ]</nowiki>}}<br />
This file needs to tweaked for your specific use. Most importantly, the {{ic|1=archisolabel=ARCH_201301}} line must be edited to use the release year/month of the ISO being used. If you want to install 32-bit Arch, change the kernel and ramdisk paths from /x86_64/ to /i686/. The {{ic|"phy:/path/to/partition,sda1,w"}} line must be edited to point to the partition created for the domU. If an image file is being used, the {{ic|phy:}} needs to be changed to {{ic|file:}}. Finally, a MAC address must be assigned. The 00:16:3e MAC block is reserved for Xen domains, do the last three digits may be randomly filled in (hex values 0-9 and a-f only). See the xl.cfg man page for more information on what the .cfg file lines do. The AUR package [https://aur.archlinux.org/packages/xen-docs/ xen-docs] will need to be installed to access the man pages.<br />
<br />
Create the new domU:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
The -c option will enter the new domain's console when successfully created. At this point, Arch should be installed as usual. The [[Installation Guide]] should be followed. There will be a few deviations, however. The block devices listed in the disks line of the cfg file will show up as {{ic|/dev/xvd*}}. Use these devices when partitioning the domU. After installation and before the domU is rebooted, the following modules must be added to {{ic|/etc/mkinitcpio.conf}}:<br />
MODULES="xen-blkfront xen-fbfront xen-netfront xen-kbdfront"<br />
Without these modules, the domU will not boot correctly. After saving the edit, rebuild the initramfs with the following command:<br />
mkinitcpio -p linux<br />
For booting, it is not necessary to install Grub. Xen has a Python-based grub emulator, so all that is needed to boot is a grub.cfg file: (It may be necessary to create the /boot/grub directory)<br />
{{hc|/boot/grub/grub.cfg|<nowiki>menuentry 'Arch GNU/Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-__UUID__' {<br />
insmod gzio<br />
insmod part_msdos<br />
insmod ext2<br />
set root='hd0,msdos1'<br />
if [ x$feature_platform_search_hint = xy ]; then<br />
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 __UUID__<br />
else<br />
search --no-floppy --fs-uuid --set=root __UUID__<br />
fi<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=UUID=__UUID__ ro<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}</nowiki>}}<br />
This file must be edited to match the UUID of the root partition. From within the domU, run the following command:<br />
# blkid<br />
Replace all instances of __UUID__ with the real UUID of the root partition (the one that mounts as "/").<br />
<br />
Shutdown the domU with the {{ic|poweroff}} command. The console will be returned to the hypervisor when the domain is fully shut down, and the domain will no longer appear in the xl domains list. Now the ISO file may be unmounted:<br />
# umount /mnt<br />
The domU cfg file should now be edited. Delete the "kernel = ", "ramdisk = ", and "extra = " lines and replace them with the following line:<br />
bootloader = "pygrub"<br />
Also remove the ISO disk from the "disk = " line.<br />
<br />
The Arch domU is now set up. It may be started with the same line as before:<br />
# xl create -c /etc/xen/archdomu.cfg<br />
If the domU should be started on boot, create a symlink to the cfg file in /etc/xen/auto and ensure the xendomains service is set up correctly.<br />
<br />
=== Useful xl command examples ===<br />
# xl top<br />
# xl list<br />
# xl console domUname<br />
# xl shutdown domUname<br />
# xl destroy domUname<br />
<br />
== Common Errors ==<br />
* 'xl list' complains about libxl<br />
- Either you have not booted into the Xen system, or xen modules listed in ''xencommons'' script are not installed<br />
<br />
* ''xl create'' fails<br />
- check the guest's kernel is located correctly, check the pv-xxx.cfg file for spelling mistakes (like using ''initrd'' instead of ''ramdisk'')<br />
<br />
* Arch linux guest hangs with a ctrl-d message<br />
- press ctrl-d until you get back to a prompt, rebuild its initramfs described <br />
<br />
* Error message "''failed to execute '/usr/lib/udev/socket:/org/xen/xend/udev_event' 'socket:/org/xen/xend/udev_event': No such file or directory''"<br />
- caused by ''/etc/udev/rules.d/xend.rules''; xend is (a) deprecated and (b) not used, so it is safe to remove xend.rules<br />
<br />
==Resources==<br />
* [http://www.xen.org/ The homepage at xen.org]<br />
* [http://wiki.xen.org/wiki/Main_Page The wiki at xen.org ]</div>Dshub