<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Void And Any &#187; LXC</title>
	<atom:link href="http://voidandany.free.fr/index.php/category/informatique/linux/lxc/feed/" rel="self" type="application/rss+xml" />
	<link>http://voidandany.free.fr</link>
	<description>mon bazar...</description>
	<lastBuildDate>Sat, 09 Dec 2017 09:24:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Monter (automatiquement) un périphérique USB (type /dev/ttyUSB0) dans LXC</title>
		<link>http://voidandany.free.fr/index.php/monter-automatiquement-un-peripherique-usb-type-devttyusb0-dans-lxc/</link>
		<comments>http://voidandany.free.fr/index.php/monter-automatiquement-un-peripherique-usb-type-devttyusb0-dans-lxc/#comments</comments>
		<pubDate>Mon, 14 Sep 2015 11:55:29 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[LXC]]></category>
		<category><![CDATA[conteneur]]></category>
		<category><![CDATA[lxc]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=4786</guid>
		<description><![CDATA[Je me suis pas mal battu pour y arriver, alors si ça peut servir à quelqu&#8217;un d&#8217;autre&#8230; Le contexte : Le serveur hôte est sous Ubuntu 14.04 Le conteneur est aussi sous Ubuntu (template download, paramètres &#171;&#160;-d ubuntu  -r trusty &#8230; <a href="http://voidandany.free.fr/index.php/monter-automatiquement-un-peripherique-usb-type-devttyusb0-dans-lxc/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Je me suis pas mal battu pour y arriver, alors si ça peut servir à quelqu&#8217;un d&#8217;autre&#8230;</p>
<p>Le contexte :</p>
<ul>
<li>Le serveur hôte est sous Ubuntu 14.04</li>
<li>Le conteneur est aussi sous Ubuntu (template download, paramètres &laquo;&nbsp;-d ubuntu  -r trusty -a amd64&#8243;)</li>
<li>Un périphérique USB est connecté sur l&#8217;hôte (un <a href="http://www.digitalsmarties.net/products/jeelink">jeelink</a> pour être précis) il apparait en tant que /dev/ttyUSB0</li>
<li>Je veux monter ce périphérique dans le conteneur</li>
</ul>
<p>En premier lieu on doit trouver le numéro majeur et mineur du périphérique USB, pour cela un simple ls suffit sur l&#8217;hôte :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0
crw-rw---- <span style="color: #000000;">1</span> root dialout <span style="color: #000000;">188</span>, <span style="color: #000000;">0</span> sept.  <span style="color: #000000;">1</span> <span style="color: #000000;">16</span>:08 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0</pre></div></div>

<p>Le périphérique a ici le numéro 188,0</p>
<p>&nbsp;</p>
<p>Il faut ensuite autoriser ce périphérique dans le conteneur (cgroups), cela se fait dans le fichier de config de ce dernier (/var/lib/lxc/[conteneur]/config).</p>
<p>On ajoute simplement la ligne suivante :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lxc.cgroup.devices.allow = c <span style="color: #000000;">188</span>:<span style="color: #000000;">0</span> rwm</pre></div></div>

<p>On peut dès lors démarrer le conteneur et monter le périphérique dans le conteneur avec la commande suivante :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> lxc-device <span style="color: #660033;">-n</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>conteneur<span style="color: #7a0874; font-weight: bold;">&#93;</span> add <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0</pre></div></div>

<p>C&#8217;est déjà pas mal mais on peut faire mieux et monter automatiquement le périphérique au démarrage du conteneur, pour cela au fichier de config du dit conteneur on ajoutera :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lxc.autodev = <span style="color: #000000;">1</span>
lxc.hook.autodev=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>lxc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>conteneur<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">/</span>autodev</pre></div></div>

<p>On appelle un script (nommé autodev) en se branchant sur un hook de LXC, ce script contient les commandes nécessaire pour monter le périphérique :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #800000;">${LXC_ROOTFS_MOUNT}</span><span style="color: #000000; font-weight: bold;">/</span>dev
<span style="color: #c20cb9; font-weight: bold;">mknod</span> ttyUSB0 c <span style="color: #000000;">188</span> <span style="color: #000000;">0</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> 0666 ttyUSB0</pre></div></div>

<p>Il faut rendre ce script exécutable :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>lxc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>conteneur<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">/</span>autodev</pre></div></div>

<p>&nbsp;</p>
<p>Et à chaque démarrage le script est joué (au bon moment) et le périphérique monté dans le conteneur.</p>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/monter-automatiquement-un-peripherique-usb-type-devttyusb0-dans-lxc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
