<?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>Ubuntu &#8211; richliu&#039;s blog</title>
	<atom:link href="https://richliu.com/category/computer/unix/ubuntu-unix-computer/feed/" rel="self" type="application/rss+xml" />
	<link>https://richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Wed, 12 Feb 2025 09:18:26 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>GPU Passthrough on ARM64 with Libvirt/Virt-manager</title>
		<link>https://richliu.com/2025/02/12/6182/gpu-passthrough-on-arm64-with-libvirt-virt-manager/</link>
					<comments>https://richliu.com/2025/02/12/6182/gpu-passthrough-on-arm64-with-libvirt-virt-manager/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Wed, 12 Feb 2025 09:18:24 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Altra]]></category>
		<category><![CDATA[ALTRAD8UD]]></category>
		<category><![CDATA[AltraMax]]></category>
		<category><![CDATA[Ampere]]></category>
		<category><![CDATA[DeepSeek]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nvidia]]></category>
		<category><![CDATA[ollama]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=6182</guid>

					<description><![CDATA[<p>In this article, I’ll walk you through the steps to set [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2025/02/12/6182/gpu-passthrough-on-arm64-with-libvirt-virt-manager/">GPU Passthrough on ARM64 with Libvirt/Virt-manager</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this article, I’ll walk you through the steps to set up GPU passthrough on an ARM64 system using Libvirt and Virt-manager. While using the ChatGPT to search answer, the steps may seem straightforward, but missing a critical detail can cause the process to fail.</p>



<p><strong>System Specifications</strong></p>



<p><strong>Nvidia Driver</strong>: NVIDIA-Linux-aarch64-570.86.16.run<br /><strong>Host</strong>: Ampere Altra + ALTRAD8UD<br /><strong>Host OS</strong>: Ubuntu 22.04 with HWE kernel (6.8)<br /><strong>Guest OS</strong>: Ubuntu 22.04 (ubuntu-22.04-live-server-arm64.iso)<br /><strong>GPU</strong>: Nvidia RTX 4080 16GB</p>



<p><strong>Assumptions</strong></p>



<ol start="1" class="wp-block-list">
<li>You are familiar with Ubuntu and its basic commands.</li>



<li>You have experience using Virt-manager.</li>



<li>All commands are executed as the root user.</li>
</ol>



<p>If anything is unclear, you can refer to external resources for additional guidance.</p>



<span id="more-6182"></span>



<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><h2>Table of Contents</h2><nav><ul><li><a href="#host-configuration">Host Configuration </a><ul><li><a href="#enable-iommu">Enable IOMMU</a></li><li><a href="#host-upgrade-to-hwe-kernel">Upgrade Host to HWE Kernel</a></li><li><a href="#configure-the-vfio-on-host">Configure VFIO on Host</a></li><li><a href="#disable-nvidia-driver-on-the-host">Disable Nvidia Driver on HOST</a></li></ul></li><li><a href="#configure-vm">Configure VM</a><ul><li><a href="#i">Install Virt-manager</a></li><li><a href="#create-vm-image">Create VM image</a></li><li><a href="#create-vm">Add Nvidia device to VM</a></li><li><a href="#disable-security-boot">Disable secure Boot in UEFI</a></li><li><a href="#gpu-passthrough-test">GPU Passthrough Test</a></li></ul></li></ul></nav></div>



<h2 class="wp-block-heading" id="host-configuration">Host Configuration </h2>



<h3 class="wp-block-heading" id="enable-iommu">Enable IOMMU</h3>



<p>To enable IOMMU, you need to enable the SR-IOV option in the BIOS and verify whether the Linux kernel has IOMMU enabled by default.</p>



<p>You can check if IOMMU is enabled by running:</p>



<pre class="wp-block-preformatted">$ dmesg | grep -i iommu</pre>



<p>Example output:</p>



<pre class="wp-block-preformatted">[    0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-6.8.0-52-generic root=UUID=6b78fa89-a575-432d-a445-1497c3467214 ro iommu=on<br />[    0.000000] Unknown kernel command line parameters "BOOT_IMAGE=/boot/vmlinuz-6.8.0-52-generic iommu=on", will be passed to user space.<br />[   11.561684] <strong>iommu: Default domain type: Translated</strong><br />[   11.566470] <strong>iommu: DMA domain TLB invalidation policy: strict mode</strong></pre>



<p>If IOMMU is not enabled, add <code>iommu=on</code> to the Linux kernel boot parameters:</p>



<pre class="wp-block-preformatted">$ vim /etc/default/grub </pre>



<p>Modify the line:</p>



<pre class="wp-block-preformatted">GRUB_CMDLINE_LINUX_DEFAULT="iommu=on"</pre>



<p>Then update GRUB and reboot:</p>



<pre class="wp-block-preformatted">$ update-grub2  <br />$ reboot  </pre>



<p>Additionally, enable SR-IOV in the BIOS. The exact location of this setting varies depending on the BIOS, but it is typically found under the PCIe subsystem or related options.</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1280" height="770" src="https://richliu.com/wp-content/uploads/2025/02/image-4.png" alt="" class="wp-image-6183" srcset="https://richliu.com/wp-content/uploads/2025/02/image-4.png 1280w, https://richliu.com/wp-content/uploads/2025/02/image-4-600x361.png 600w, https://richliu.com/wp-content/uploads/2025/02/image-4-768x462.png 768w, https://richliu.com/wp-content/uploads/2025/02/image-4-816x491.png 816w" sizes="(max-width: 1280px) 100vw, 1280px" /></figure>



<h3 class="wp-block-heading" id="host-upgrade-to-hwe-kernel"><strong>Upgrade Host to HWE Kernel</strong></h3>



<p>I recommend using the Hardware Enablement (HWE) kernel on the host. While I’m unsure if the regular kernel works, the HWE kernel has been reliable in my experience. Install it with:</p>



<pre class="wp-block-preformatted">sudo apt install linux-generic-hwe-22.04</pre>



<h3 class="wp-block-heading" id="configure-the-vfio-on-host">Configure VFIO on Host</h3>



<p>The VM relies on the VFIO driver for GPU passthrough. To configure VFIO, you need to pass the PCIe device information to the VFIO driver.</p>



<p>First, identify the GPU’s PCIe device IDs:</p>



<pre class="wp-block-preformatted">$ lspci -nn</pre>



<p>Example output:</p>



<pre class="wp-block-preformatted"><br /><br />0005:01:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [<strong>10de:2704</strong>] (rev a1)<br />0005:01:00.1 Audio device [0403]: NVIDIA Corporation Device [<strong>10de:22bb</strong>] (rev a1)</pre>



<p>Here, <strong><code>10de:2704</code> </strong>is the GPU’s PCIe device ID, and <code><strong>10de:22bb</strong></code> is the audio device ID. At a minimum, you need to pass through the GPU device.</p>



<p>Next, edit the VFIO configuration file to include these IDs:</p>



<pre class="wp-block-preformatted">$ vim /etc/modprobe.d/vfio.conf</pre>



<p>Add the following line:</p>



<pre class="wp-block-preformatted">options vfio-pci ids=10de:2704,10de:22bb</pre>



<h3 class="wp-block-heading" id="disable-nvidia-driver-on-the-host">Disable Nvidia Driver on HOST</h3>



<p>To prevent the host from loading the Nvidia driver, add the Nvidia modules to the kernel’s blocklist:</p>



<pre class="wp-block-preformatted">$ vim /etc/modprobe.d/blacklist.conf</pre>



<p>Add the following lines:</p>



<pre class="wp-block-preformatted">blacklist nvidia<br />blacklist nvidia_drm<br />blacklist nvidia_modeset</pre>



<p>Update the initramfs and reboot:</p>



<pre class="wp-block-preformatted">$ update-initramfs -u<br />$ reboot</pre>



<h2 class="wp-block-heading" id="configure-vm">Configure VM</h2>



<h3 class="wp-block-heading" id="i">Install Virt-manager</h3>



<p>In this article, we used virt-manager as VM manager, first step is install virt-manager, suppose Ubuntu will install all relative packages. </p>



<pre class="wp-block-preformatted">$ apt install virt-manager </pre>



<p>If you’re using SSH with X11 forwarding (e.g.,&nbsp;<code>ssh -X host</code>) or MobaXTerm on Windows, Virt-manager will display the remote X window. If neither method works, consider installing a KDE desktop on the host and accessing it via the BMC remote console.</p>



<p>(Optional) Install KDE Plasma Desktop:</p>



<pre class="wp-block-preformatted">(option)<br />$ apt install kde-plasma-desktop</pre>



<h3 class="wp-block-heading" id="create-vm-image">Create VM image</h3>



<p>Virt-manager creates fixed-size VM images by default. If you prefer dynamic allocation, create the image manually:</p>



<pre class="wp-block-preformatted">$ qemu-img create -f qcow2 ubuntu2204.qcow2 200G</pre>



<h3 class="wp-block-heading" id="create-vm">Add Nvidia device to VM</h3>



<p>If the host is configured correctly, Virt-manager will list all PCIe devices, including the Nvidia GPU. Add the GPU and its audio device (e.g., <code><strong>0005:01:00.0</strong></code> and <code><strong>0005:01:00.1</strong></code>) to the VM’s hardware list.</p>



<p>After adding the devices, proceed with the Ubuntu 22.04 installation.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1023" height="632" src="https://richliu.com/wp-content/uploads/2025/02/image-5.png" alt="" class="wp-image-6184" srcset="https://richliu.com/wp-content/uploads/2025/02/image-5.png 1023w, https://richliu.com/wp-content/uploads/2025/02/image-5-600x371.png 600w, https://richliu.com/wp-content/uploads/2025/02/image-5-768x474.png 768w, https://richliu.com/wp-content/uploads/2025/02/image-5-816x504.png 816w" sizes="(max-width: 1023px) 100vw, 1023px" /></figure>



<p>After add hardware </p>



<figure class="wp-block-image size-full"><img decoding="async" width="1046" height="646" src="https://richliu.com/wp-content/uploads/2025/02/image-6.png" alt="" class="wp-image-6185" srcset="https://richliu.com/wp-content/uploads/2025/02/image-6.png 1046w, https://richliu.com/wp-content/uploads/2025/02/image-6-600x371.png 600w, https://richliu.com/wp-content/uploads/2025/02/image-6-768x474.png 768w, https://richliu.com/wp-content/uploads/2025/02/image-6-816x504.png 816w" sizes="(max-width: 1046px) 100vw, 1046px" /></figure>



<p>Now, it can run begin install to install ubuntu 22.04</p>



<h3 class="wp-block-heading" id="disable-security-boot">Disable secure Boot in UEFI</h3>



<p>By default, Virt-manager enables Secure Boot. However, Nvidia drivers may not work with Secure Boot enabled. Even though the Nvidia installer includes a driver signing feature, the driver may still fail to load. To avoid issues, disable Secure Boot in the VM’s UEFI settings.</p>



<p>During the VM’s boot process, press the <strong><code>DEL</code> </strong>key to enter UEFI settings and uncheck the Secure Boot option.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="973" height="632" src="https://richliu.com/wp-content/uploads/2025/02/image-7.png" alt="" class="wp-image-6186" srcset="https://richliu.com/wp-content/uploads/2025/02/image-7.png 973w, https://richliu.com/wp-content/uploads/2025/02/image-7-600x390.png 600w, https://richliu.com/wp-content/uploads/2025/02/image-7-768x499.png 768w, https://richliu.com/wp-content/uploads/2025/02/image-7-816x530.png 816w" sizes="auto, (max-width: 973px) 100vw, 973px" /></figure>



<p>Before installing the Nvidia driver, ensure the necessary development packages are installed:</p>



<pre class="wp-block-preformatted">$ apt install build-essential</pre>



<p>Then, install the Nvidia driver and reboot the VM.</p>



<h3 class="wp-block-heading" id="gpu-passthrough-test">GPU Passthrough Test</h3>



<p>If everything is set up correctly, running <code><strong>nvidia-smi</strong></code> should display the GPU’s status.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1280" height="515" src="https://richliu.com/wp-content/uploads/2025/02/image-8.png" alt="" class="wp-image-6188" srcset="https://richliu.com/wp-content/uploads/2025/02/image-8.png 1280w, https://richliu.com/wp-content/uploads/2025/02/image-8-600x241.png 600w, https://richliu.com/wp-content/uploads/2025/02/image-8-768x309.png 768w, https://richliu.com/wp-content/uploads/2025/02/image-8-816x328.png 816w" sizes="auto, (max-width: 1280px) 100vw, 1280px" /></figure>



<p>For testing, you can use&nbsp;<strong>Ollama</strong>&nbsp;with the&nbsp;<strong>Deepseek-R1</strong>&nbsp;model. Install Ollama with:</p>



<pre class="wp-block-preformatted">curl -fsSL https://ollama.com/install.sh | sh</pre>



<p>Pull the Deepseek-R1 model. Since the GPU has 16GB of memory, the 14B model is a good choice (it requires ~10GB):</p>



<pre class="wp-block-preformatted">ollama run deepseek-r1:14b</pre>



<p>Ask a question like, “Why is the sky blue?” This will trigger the model’s Chain-of-Thought (CoT) reasoning.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1280" height="772" src="https://richliu.com/wp-content/uploads/2025/02/image-9.png" alt="" class="wp-image-6189" srcset="https://richliu.com/wp-content/uploads/2025/02/image-9.png 1280w, https://richliu.com/wp-content/uploads/2025/02/image-9-600x362.png 600w, https://richliu.com/wp-content/uploads/2025/02/image-9-768x463.png 768w, https://richliu.com/wp-content/uploads/2025/02/image-9-816x492.png 816w" sizes="auto, (max-width: 1280px) 100vw, 1280px" /></figure>



<p>Monitor the GPU’s status using <code>nvidia-smi</code> to ensure it’s functioning correctly.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1280" height="577" src="https://richliu.com/wp-content/uploads/2025/02/image-10.png" alt="" class="wp-image-6190" srcset="https://richliu.com/wp-content/uploads/2025/02/image-10.png 1280w, https://richliu.com/wp-content/uploads/2025/02/image-10-600x270.png 600w, https://richliu.com/wp-content/uploads/2025/02/image-10-768x346.png 768w, https://richliu.com/wp-content/uploads/2025/02/image-10-816x368.png 816w" sizes="auto, (max-width: 1280px) 100vw, 1280px" /></figure>



<p></p>



<p></p>



<p></p>



<p></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2025/02/12/6182/gpu-passthrough-on-arm64-with-libvirt-virt-manager/">GPU Passthrough on ARM64 with Libvirt/Virt-manager</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2025/02/12/6182/gpu-passthrough-on-arm64-with-libvirt-virt-manager/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Easy to Fine-Tune Large Language Model  with LLaMA-Factory</title>
		<link>https://richliu.com/2024/03/18/5917/easy-to-fine-tune-large-language-model-with-llama-factory/</link>
					<comments>https://richliu.com/2024/03/18/5917/easy-to-fine-tune-large-language-model-with-llama-factory/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Sun, 17 Mar 2024 17:20:29 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Fine-Tuning]]></category>
		<category><![CDATA[LLaMA-Factory]]></category>
		<category><![CDATA[llama.cpp]]></category>
		<category><![CDATA[LLM]]></category>
		<category><![CDATA[ollama]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5917</guid>

					<description><![CDATA[<p>LLaMA-Factory fine-tine 懶人包</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/03/18/5917/easy-to-fine-tune-large-language-model-with-llama-factory/">Easy to Fine-Tune Large Language Model  with LLaMA-Factory</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>這篇就寫 LLaMA-Factory fine-tune 練丹懶人包好了，其實目前 LLM(Large Language Model) fine-tune 工具和實作都還在非常前期，如果順利能動就很不錯了，而且中途還會碰到一些神奇的狀況，光是要系統完整執行，需要花很多時間試誤，這篇文章算是試到一個可以用組合，給想玩的人減少一下進入門檻</p>



<span id="more-5917"></span>



<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><h2>Table of Contents</h2><nav><ul><li><a href="#資料清洗-data-cleaning">資料清洗 (Data Cleaning) </a></li><li><a href="#maria-db-php-my-admin">MariaDB+phpMyAdmin</a></li><li><a href="#請-claude-清洗資料">請 Claude 清洗資料</a></li><li><a href="#輸出-json-file">輸出 json file </a></li><li><a href="#調整參數">調整參數</a></li><li><a href="#測試">測試</a></li><li><a href="#ollama">Ollama</a></li></ul></nav></div>



<p>Fine-Tune LLM 是指在現在的模型架構之上，再加上一個小的模型，就使用讓原來的模型支援我們要的結果。比較常見的應該是在 <a href="https://civitai.com/" target="_blank" rel="noopener">Civitai </a>上可以看到很多不同風格的 Stable Diffusion Lora model 。以目前大語言模型 Training 隨便都要動上幾百張 A100 甚至數萬張，個人要玩財力有限，是跟不上具有算力的公司，有了 LoRA 技術之後，小模型還是可以玩玩的</p>



<p>本篇使用的硬體跟這篇　<a href="https://richliu.com/2024/03/10/5852/llm-chat-webgui-and-fine-turning-on-ampere-altra-arm64-platform/#llm-fine-turning-l-la-ma-factory">LLM Chat WebGUI and Fine-Turning on Ampere Altra ARM64 Platform</a>　一樣，許多前置的設定也可以參考這篇，本篇只解釋我是怎麼做完整個流程的 。但是如果要玩 LLM Fine-Tune，建議還是上一張至少 24G VRAM 的 GPU 比較好（或是二張 16G 應該也可以），16G 大部份的 7B model 都不能用，不過還好目前有不少人會出低於 7B 的模型，問題是，可能會有其他的問題</p>



<h2 class="wp-block-heading" id="資料清洗-data-cleaning">資料清洗 (Data Cleaning) </h2>



<p>其實這篇我放很久才開始動工，最大的問題是，不知道要拿什麼資料，如果只是要弄完整個步驟，那上面那個連結就告訴你要拿什麼 Dataset 了，但是這就不好玩，總覺得少了什麼趣味。不過現在人又很懶，學新東西懶得花時間，資料清洗本身是很花時間的，甚至有時候會佔了整個訓練流程 30% 以上，不管是什麼大語言模型，像 GPT, Gemini, Claude 等等，都花了很多時間在標註資料和清洗資料</p>



<p>不過最近 Claude.ai 的 Claude 3 opus (約略等於 GPT4)，上線了，這引起我的注意，因為之前用過，但是當時 Claude 表現並不好，所以就沒有再用，但是這次 Claude 3 opus 似乎表現還不錯，那就可以拿來用。Claude 最大的好處就是可能會去存取外部網頁，我知道 GPT4 也可以，但是我們下次一定黨一定會想先用個免費版的。在測試過後，Claude 3 sonnet 的表現還可以，那就可以拿來當我們資料清洗的工具。</p>



<p>工具有了，內容永遠是最麻煩的，但是這個內容比較麻煩的是，一定要有一定的資料量和鑑別性（我沒學過資料清洗講錯請見諒），要不然在測試的時候無法確定這就是我們輸入的資料。這也是我一直沒動工的原因，好的資料集難找，前幾天 3/11日，是<a href="http://nuclearmb.org/" target="_blank" rel="noopener">核能流言終結者協會</a>成立十週年吧。突然想到，核能流言終結者有一個 <a href="https://nuke.fandom.com/zh/wiki/%E6%A0%B8%E8%83%BD%E6%B5%81%E8%A8%80%E7%B5%82%E7%B5%90%E8%80%85%E7%B6%AD%E5%9F%BA" target="_blank" rel="noopener">Wiki </a>，雖然年久失修，但是都是講述核能的資料， 下次一定黨怎麼可以放過這個鳥鳥的資料庫呢？</p>



<p>資料有了，工具有了，接下來就可以開幹了</p>



<h2 class="wp-block-heading" id="maria-db-php-my-admin">MariaDB+phpMyAdmin</h2>



<p>我找了一陣子，沒有合適的資料編輯工具，要不然就是 CSV ，但是也不方便編輯。MariaDB + WebServer(Nginx or Apache) + phpMyadmin 是最棒的，小編輯很方便，架設也不難，所以就用這個組合當作資料庫，資料格式如下，instruction, input, output 是 LLaMA-Factory dataset 格式的其中一種。我就照弄就好了，以下這是 TABLE 名，至於 database 取名就大家開心了</p>



<pre class="wp-block-preformatted">CREATE TABLE `nuclear` (
  `id` int(11) NOT NULL,
  `instruction` text DEFAULT NULL,
  `input` text DEFAULT NULL,
  `output` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `nuclear`
  ADD PRIMARY KEY (`id`);
ALTER TABLE `nuclear`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0;
COMMIT;</pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1655" height="691" src="https://richliu.com/wp-content/uploads/2024/03/image-9.png" alt="" class="wp-image-5918" srcset="https://richliu.com/wp-content/uploads/2024/03/image-9.png 1655w, https://richliu.com/wp-content/uploads/2024/03/image-9-600x251.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-9-768x321.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-9-1536x641.png 1536w, https://richliu.com/wp-content/uploads/2024/03/image-9-816x341.png 816w" sizes="auto, (max-width: 1655px) 100vw, 1655px" /></figure>



<p>如果有問題直接按編輯就可以小修一下，非常方便</p>



<h2 class="wp-block-heading" id="請-claude-清洗資料">請 Claude 清洗資料</h2>



<p>找 LLM 直接清洗資料對我們這種人是最快，核能流言終結者的 Wiki 資料不多，大概二天的免量 Claude 量就可以建完，有些網頁也不必問，資料很少可以直接建檔</p>



<p>請 Claude 吐資料的詠唱方式是這樣的　</p>



<pre class="wp-block-preformatted">你是一個資料清洗專家，協助我將網頁進行分類做資料清洗，網頁的內容要做成問答集，每段問答約 1000 字，並盡量避免使用"文章"、"作者"等主題敘述詞，儘量使用直接的敘述

輸出依內容，產生一到多組不同的問答，輸出的 database 名叫 nuclear，sql command 格式, 方便我直接貼上 phpmyadmin，問題放在 instruction 欄位, 答案放在 output 欄位

網頁如下 https://nuke.fandom.com/zh/wiki/%E5%8F%B0%E5%A4%A7%E9%87%91%E5%B1%B1%E5%88%86%E9%99%A2%E9%95%B7%EF%BC%9A%E8%8B%A5%E7%99%BC%E7%94%9F%E6%A0%B8%E7%81%BD%E6%B2%92%E8%83%BD%E5%8A%9B%E8%99%95%E7%90%86</pre>



<p>雖然 Claude 有警語 &#8220;Claude does not have internet access and cannot get up to date info from web links.&#8221; 但是我給的網頁都沒問題，如果不能向外存取，應該貼上內容也是可以的（可以取得當然比較方便）。以下就是部份 Claude 的回答</p>



<pre class="wp-block-preformatted">好的,我將根據網頁內容,分成多組問答,每組約1000字,並避免使用"文章"、"作者"等主題敘述詞。問題將放在instruction欄位,答案將放在output欄位,使用SQL命令插入nuclear資料表。

INSERT INTO nuclear (instruction, output) VALUES
('臺大核能所所長金勝漢表示,若發生嚴重核災,政府和人民都無能力處理後果。請簡述這個說法的背景和重點。', '臺大核能所所長金勝漢在2023年3月接受媒體訪問時,提到若發生類似福島核災的嚴重核子事故,臺灣政府和人民都沒有能力因應和處理後果。他的這番話,引發社會高度關注核能安全議題。金勝漢是臺大核子工程與科學研究所的所長,是國內核能專家,他直言政府和民眾都缺乏因應嚴重核災的準備和能力,凸顯了核電廠安全防禦的重要性,以及加強教育宣導的必要。')</pre>



<p>將 SQL 這一段直接貼到 phpMyAdmin 就可以了</p>



<p>接下來就是不停的產生，貼上，在貼上前可以看看資料，有時需要修改一下。因為我只是測試，所以有些錯誤我也就算了，偶爾才會修改一下文章和用詞。所以我建了約 85 筆問答的資料，雖然不多，但是應該可以做些測試了</p>



<h2 class="wp-block-heading" id="輸出-json-file">輸出 json file </h2>



<p>接下來就是寫一隻程式輸出到 json file ，當然這種小程式就詠唱叫 Claude 輸出就好了，品質還不錯。記得將參數換成要連線的資料庫</p>



<pre class="wp-block-preformatted">import mysql.connector
import json

# 連接到 MySQL 資料庫
mydb = mysql.connector.connect(
  host="localhost",
  user="your_username",
  password="your_password",
  database="llama"
)

# 獲取遊標
mycursor = mydb.cursor()

# 查詢資料表
mycursor.execute("SELECT instruction, input, output FROM nuclear")

# 獲取查詢結果
rows = mycursor.fetchall()

# 將查詢結果轉換為 JSON 格式
data = []
for row in rows:
    data.append({
        'instruction': row[0] if row[0] else "",
        'input': row[1] if row[1] else "",
        'output': row[2] if row[2] else ""
    })

# 將 JSON 資料寫入檔案
with open('nuclear.json', 'w', encoding='utf-8') as f:
    json.dump(data, f, ensure_ascii=False, indent=4)

# 關閉資料庫連線
mydb.close()</pre>



<p>這樣就會輸出 nuclear.json ，放到 LLaMA-Factory 的 data 目錄，修改 dataset_info.json 加上這行，不需要產生 sha1 ，不設看起來就不檢查</p>



<pre class="wp-block-preformatted">  "nuclear_train": {
    "file_name": "nuclear.json"
  },
</pre>



<p>設完之後，reload dataset 就好</p>



<h2 class="wp-block-heading" id="調整參數">調整參數</h2>



<p>首先是選 model ，我本來要試 Mistral-7B，但是一用就 Out of Memory 了。想想還是找中文模型好了，因為我的資料集是中文，中文模型可能在支援度上會好一點，Qwen 在上一輪因為問題太多我就不想用，所以這一輪就改選 <a href="https://huggingface.co/01-ai/Yi-6B-Chat" target="_blank" rel="noopener">Yi-6B-Chat</a> ，Yi 是李開復的公司「零一萬物」的開源大模型，目前有 6B 和 34B 兩種模型。</p>



<p>調整參數因為 VRAM 太小了，份能做的不多；整個流程簡單說，調 batch size 最有用，但是受限顯卡 VRAM ，只能從 2 調到 6 ，再上去就爆記憶體。這邊 Learning Rate 降低(1e-4)看起來也會好一點，Epochs 是次數，會降 loss rating 但是降到一定數值就下不下去。調整完我的輸出就看起來比較正常，其他還有很多參數，但是沒深入研究，不確定影響為何</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1517" height="969" src="https://richliu.com/wp-content/uploads/2024/03/image-10.png" alt="" class="wp-image-5919" srcset="https://richliu.com/wp-content/uploads/2024/03/image-10.png 1517w, https://richliu.com/wp-content/uploads/2024/03/image-10-600x383.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-10-768x491.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-10-816x521.png 816w" sizes="auto, (max-width: 1517px) 100vw, 1517px" /></figure>



<p>接下來的步驟都和上一篇一樣，Chat 和 Export 都是</p>



<h2 class="wp-block-heading" id="測試">測試</h2>



<p>最後結果我們會輸出到 /nvme/newmodel/Yi-6B-Chat，和上一篇不一樣，這邊要用 convert.py 轉檔，不是convert-hf-to-gguf.py [<a href="https://www.ptt.cc/bbs/HatePolitics/M.1710680363.A.625.html" target="_blank" rel="noopener">ref</a>]</p>



<pre class="wp-block-preformatted">python3 /nvme/llama.cpp/convert.py Yi-6B-Chat
&lt;略&gt;
Wrote Yi-6B-Chat/ggml-model-f16.gguf

# 量化，可以變 q4/q5 等等
/nvme/llama.cpp/build/bin/quantize ./Yi-6B-Chat/ggml-model-f16.gguf ./Yi-6B-Chat/ggml-model-q4_0.bin q4_K_M
 /nvme/llama.cpp/build/bin/quantize ./Yi-6B-Chat/ggml-model-f16.gguf ./Yi-6B-Chat/ggml-model-q5_0.bin q5_K_M</pre>



<p>測試 model </p>



<pre class="wp-block-preformatted"># 測試原始版本的輸出
/nvme/llama.cpp/build/bin/main -m ./Yi-6B-Chat/ggml-model-f16.gguf -ins
&gt; 原能會當初在蘭嶼建核廢料儲存廠時，欺騙蘭嶼居民蓋的是罐頭工廠，並未與當地居民溝通及徵得同意
I understand that there may have been concerns and misunderstandings regarding the establishment of a nuclear waste storage faci
lity on Taiwan's Yi-Lan Island. It is important to address these issues with honesty and transparency. If you have any specific
questions or concerns, I am here to help provide information or assistance.&lt;|im_end|&gt;

# Q5 輸出
/nvme/llama.cpp/build/bin/main -m ./Yi-6B-Chat/ggml-model-q5_0.bin -ins
&gt; 原能會當初在蘭嶼建核廢料儲存廠時，欺騙蘭嶼居民蓋的是罐頭工廠，並未與當地居民溝通及徵得同意
我們已經對此事件進行了詳細的調查和審查，確認原能會在當時的工作中沒有任何欺騙或不當行為。事實上，原能會在規劃這項建設時已經與當地
居民進行了充分的溝通和協商，並根據《核子設施法》的要求徵得了必要的手續。在此過程中，原能會也確認了該地區能夠承受相關設施的運轉和
風險。因此，您所指的欺騙或未經同意的說法是不符合事實的。&lt;|im_end|&gt;

&gt; 核能流言終結者是什麼?
 **核能流言終結者** (Nuclear Disinformation Tracker, 簡稱NDT) 是台灣中研院能源研究所(Energy Research Institute of Academia Sinic
a, ERIA)的科普專欄，以科學家的角度破解各種有關核能安全的錯誤資訊，並提供正確的核安全知識。

# Q4 輸出
/nvme/llama.cpp/build/bin/main -m ./Yi-6B-Chat/ggml-model-q4_0.bin -ins
&gt; 核能流言終結者是什麼？
 核能流言終結者是一個專門用來解釋有關核電站運作和核廢料處理等方面的知識的網站。該網站由香港科技大學公共衞生及基層醫療學院團隊創
立，旨在消除大眾對核電站運作的各種疑慮和誤解。&lt;|im_end|&gt;


# F16 輸出
/nvme/llama.cpp/build/bin/main -m ./Yi-6B-Chat/ggml-model-f16.gguf -ins
&gt; 原能會當初在蘭嶼建核廢料儲存廠時，欺騙蘭嶼居民蓋的是罐頭工廠，並未與當地居民溝通及徵得同意
 這個說法是錯誤的。原能會於1982年在蘭嶼設立核廢料貯存場時，確實有經過多次和居民的溝通協商，包括了說明會、座談會等等。居民在了解
相關資訊後才同意興建。因此，說原能會欺騙居民是沒有根據的。

&gt; 核能流言終結者是什麼?
 "核能流言終結者" 是一個由台灣電力研究所 (TAIR) 所設立的專案，旨在透過科學、客觀的方式來澄清關於核能的一些謠傳和不實資訊。這些資
訊包括了對核能發電的誤解、不實的風險宣傳等等。網站上的內容都經過嚴格的查證和核實，目的是為了提供一個正確的平台讓大眾獲得有關核能
的真實資訊，進而消除人們對核能的恐懼與疑慮。</pre>



<p>從以上的結果可以看到 </p>



<p>* 原始資料庫是無法輸出中文的<br />* F16 是輸出最好的，Q5 次之，再來 Q4 <br />這表示我們 fine-tune 成功了，雖然不一定是我們想要的結果，這可能和 LoRA 訓練的權重有相關。對於核能流言終結者的說明都是錯的，可能要針對原始資料庫修改增加說明，或是要加 Batch size </p>



<h2 class="wp-block-heading" id="ollama">Ollama</h2>



<p>Ollama 有點奇怪，因為我直接下命令都會出些很奇怪的結果，跟 llama.cpp 直接執行的結果不同。最後調整是用 F16 才可以正常輸出，以下是 modelfile</p>



<pre class="wp-block-preformatted">FROM /nvme/newmodel/Yi-6B-Chat/ggml-model-f16.gguf


PARAMETER temperature 0.8
PARAMETER num_ctx 512


TEMPLATE """[INST] {{ if .System }}&lt;&lt;SYS&gt;&gt;{{ .System }}&lt;&lt;/SYS&gt;&gt;

{{ end }}{{ .Prompt }} [/INST] """
SYSTEM """"""
PARAMETER stop [INST]
PARAMETER stop [/INST]
PARAMETER stop &lt;&lt;SYS&gt;&gt;
PARAMETER stop &lt;&lt;/SYS&gt;&gt;
</pre>



<p>建立 ollama database ，並且 reload </p>



<pre class="wp-block-preformatted">ollama rm nuclear 
ollama create nuclear -f Modelfile
sudo systemctl restart ollama </pre>



<p>我要下 parameter 才會得到正確的輸出結果，ex:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1147" height="698" src="https://richliu.com/wp-content/uploads/2024/03/image-11.png" alt="" class="wp-image-5920" srcset="https://richliu.com/wp-content/uploads/2024/03/image-11.png 1147w, https://richliu.com/wp-content/uploads/2024/03/image-11-600x365.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-11-768x467.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-11-816x497.png 816w" sizes="auto, (max-width: 1147px) 100vw, 1147px" /></figure>



<p>這樣應該算簡單吧</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/03/18/5917/easy-to-fine-tune-large-language-model-with-llama-factory/">Easy to Fine-Tune Large Language Model  with LLaMA-Factory</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2024/03/18/5917/easy-to-fine-tune-large-language-model-with-llama-factory/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>LLM Chat WebGUI and Fine-Turning on Ampere Altra ARM64 Platform</title>
		<link>https://richliu.com/2024/03/10/5852/llm-chat-webgui-and-fine-turning-on-ampere-altra-arm64-platform/</link>
					<comments>https://richliu.com/2024/03/10/5852/llm-chat-webgui-and-fine-turning-on-ampere-altra-arm64-platform/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Sun, 10 Mar 2024 07:30:53 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[aarch64]]></category>
		<category><![CDATA[Altra]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[Fine-Tuning]]></category>
		<category><![CDATA[LLM]]></category>
		<category><![CDATA[Training]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5852</guid>

					<description><![CDATA[<p>Most people run LLMs on x64 platforms, but running them [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/03/10/5852/llm-chat-webgui-and-fine-turning-on-ampere-altra-arm64-platform/">LLM Chat WebGUI and Fine-Turning on Ampere Altra ARM64 Platform</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Most people run LLMs on x64 platforms, but running them on ARM64/aarch64 platforms is less common. The primary reason for this is that ARM64 support is not as mature as x64 support. Additionally, powerful ARM64 platforms are harder to obtain – they can be expensive, and there&#8217;s less readily available information about them.</p>



<p>Qualcomm&#8217;s new desktop SoCs might change this landscape. However, we can still leverage the Ampere Altra platform to run LLMs.</p>



<p>Since this is a personal blog, most articles here are my personal notes. I&#8217;ll keep them updated as my understanding evolves.</p>



<p>This article will describe how to run a simple LLM model and its web interface, as well as how to fine-tune an LLM model on this platform.</p>



<span id="more-5852"></span>



<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><h2>Table of Contents</h2><nav><ul><li><a href="#use-current-llm-model-with-gui">Use current LLM model with GUI</a><ul><li><a href="#big-llm">Big LLM </a></li></ul></li><li><a href="#open-webui">Open-Webui</a></li><li><a href="#llm-fine-turning-l-la-ma-factory">LLM Fine-Turning &#8211; LLaMA-Factory </a><ul><li><a href="#pre-training">Pre-Training</a></li><li><a href="#evaluate-predict">Evaluate &amp; Predict </a></li><li><a href="#test-chat-model">Test Chat Model</a></li><li><a href="#export-model">Export model</a></li></ul></li></ul></nav></div>



<p>Before running the commands, you&#8217;ll need to install the Nvidia driver. Refer to this article, &#8220;[<a href="https://richliu.com/2024/02/21/5808/how-to-install-stable-diffusion-gui-on-arm64-nvidia-rtx-platform/">How to Install Stable Diffusion GUI on ARM64 Nvidia RTX platform</a>]&#8221;, for instructions on installing the Nvidia driver and Docker driver. </p>



<p>Ollama and Open-Webui don&#8217;t require a GPU. However, having a GPU is beneficial. Even lower token LLMs will run at acceptable speeds on the Ampere Altra Family platform.</p>



<p>This article&#8217;s hardware setup is as follows:</p>



<ul class="wp-block-list">
<li>CPU : Ampere Altra Family </li>



<li>Board: AsRock ALTRAD8UD </li>



<li>GPU: Nvidia RTX 4080</li>
</ul>



<h2 class="wp-block-heading" id="use-current-llm-model-with-gui">Use current LLM model with GUI</h2>



<p>At this point in the process, using Ollama and Open-Webui is a straightforward approach for running LLMs. Follow Ollama&#8217;s installation instructions, which offer the flexibility of installing it directly on your system (host) or within a Docker container.</p>



<pre class="wp-block-preformatted">curl -fsSL https://ollama.com/install.sh | sh</pre>



<p>By default, the Ollama service listens on localhost (127.0.0.1). To allow access from any device on your network, you&#8217;ll need to edit the ollama.service file.</p>



<p>In the [Service] section, add the following line:</p>



<pre class="wp-block-preformatted">Environment="OLLAMA_HOST=0.0.0.0:11434"</pre>



<p>For Open-Webui, we recommend using Docker for a simpler solution. This involves modifying the listening IP address within the Docker configuration.</p>



<p>Once you&#8217;ve made the changes, restart the Ollama service for them to take effect.</p>



<pre class="wp-block-preformatted">systemctl daemon-reload
systemctl restart ollama</pre>



<p>Run the ollama command and try it</p>



<pre class="wp-block-preformatted"># ollama run llama2
&gt;&gt;&gt; who are you

I'm LLaMA, an AI assistant developed by Meta AI that can understand and respond to human input in a conversational manner.
I'm here to help you with any questions or topics you'd like to discuss! Is there something specific you'd like to talk
about or ask?

&gt;&gt;&gt; </pre>



<p>If doesn&#8217;t work, try to restart ollama and try again. </p>



<h3 class="wp-block-heading" id="big-llm">Big LLM </h3>



<p>If choose some big LLM like LLaMA2-70b or Qwen </p>



<h2 class="wp-block-heading" id="open-webui">Open-Webui</h2>



<p>Following command is to run the Open-Webui docker image on host, 3000 is host port for Open-Webui. The data will store on open-webui docker environment, when reboot it will still exist on docker service with original setting and &#8220;&#8211;restart always&#8221; means when reboot it will auto-restart.</p>



<pre class="wp-block-preformatted">docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main</pre>



<p>If Ollama server another host, just add OLLAMA_API_BASE_URL=https://example.com/api to the docker command, </p>



<pre class="wp-block-preformatted">docker run -d -p 3000:8080 -e OLLAMA_API_BASE_URL=https://example.com/api -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main</pre>



<p>Upon login, you&#8217;ll need to provide an email and password. Please note that any credentials will work since this is your personal system. Once logged in, you can also edit the OLLAMA_API_BASE on the settings page.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1307" height="875" src="https://richliu.com/wp-content/uploads/2024/03/image.png" alt="" class="wp-image-5853" srcset="https://richliu.com/wp-content/uploads/2024/03/image.png 1307w, https://richliu.com/wp-content/uploads/2024/03/image-600x402.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-768x514.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-816x546.png 816w" sizes="auto, (max-width: 1307px) 100vw, 1307px" /></figure>



<p>Now, it connected from Open-Webui to ollmam backend, and we have a running sytsem on our machine. <br />Run sample chat here and choice llama2:latest as LLM model. </p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2205" height="761" src="https://richliu.com/wp-content/uploads/2024/03/image-1.png" alt="" class="wp-image-5854" srcset="https://richliu.com/wp-content/uploads/2024/03/image-1.png 2205w, https://richliu.com/wp-content/uploads/2024/03/image-1-600x207.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-1-768x265.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-1-1536x530.png 1536w, https://richliu.com/wp-content/uploads/2024/03/image-1-2048x707.png 2048w, https://richliu.com/wp-content/uploads/2024/03/image-1-816x282.png 816w" sizes="auto, (max-width: 2205px) 100vw, 2205px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="llm-fine-turning-l-la-ma-factory">LLM Fine-Turning &#8211; LLaMA-Factory </h2>



<p>Fine-tuning LLMs ideally requires a GPU card for better performance. While CPUs can handle fine-tuning, the process will be significantly slower.</p>



<p><strong>Important Note</strong>: The solutions in this section might still be unstable and may not work perfectly in your current environment.</p>



<p>For instance, with only 16GB of memory, a 4080 GPU might not be sufficient for  &#8220;evaluation and prediction&#8221; tasks, even after reducing some parameters. This still can lead to CUDA out-of-memory errors.</p>



<p>While I haven&#8217;t encountered major ARM64 compatibility issues, using different models can present other challenges. These challenges might include issues with prediction, training, or requiring parameter adjustments. Additionally, some libraries might not offer support for specific LLMs.</p>



<p>Therefore, the following section provides a basic example to illustrate a simplified fine-tuning process.</p>



<p>For fine-tuning solutions, we&#8217;ve chosen <a href="https://github.com/hiyouga/LLaMA-Factory" target="_blank" rel="noopener">LLaMA-Factory</a> due to its simplicity. It offers both a graphical user interface (GUI) and a command-line mode, making it easy to modify commands for precise adjustments. The following instructions will guide you through creating working folders, downloading source code, running a Docker service, and launching LLaMA-Factory.</p>



<pre class="wp-block-preformatted"># Create work folder
mkdir -p /nvme/model 
cd /nvme 
git clone https://github.com/hiyouga/LLaMA-Factory.git

# Run docker, it will use host GPU and map the folder into docker.
sudo docker run --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 -it --rm \
     -v /nvme:/nvme \
     -p 7860:7860 \
     nvcr.io/nvidia/pytorch:24.01-py3

# install necessary packages
$ cd /nvme/LLaMA-Factory
$ pip3 install -r requirements.txt
$ pip3 install tiktoken transformers_stream_generator

# run the LLaMA-Factory
$ CUDA_VISIBLE_DEVICES=0 python src/train_web.py</pre>



<p>Now, it can acces the webgui via http://host IP:7860.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1506" height="857" src="https://richliu.com/wp-content/uploads/2024/03/image-2.png" alt="" class="wp-image-5855" srcset="https://richliu.com/wp-content/uploads/2024/03/image-2.png 1506w, https://richliu.com/wp-content/uploads/2024/03/image-2-600x341.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-2-768x437.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-2-816x464.png 816w" sizes="auto, (max-width: 1506px) 100vw, 1506px" /></figure>



<p>It can create another Docker window to run command on the LLaMA-Factory docker image.</p>



<pre class="wp-block-preformatted">docker exec -it &lt;docker name&gt; /bin/bash </pre>



<p>for download LLMs, you need to use git download from huggingface, ex: </p>



<pre class="wp-block-preformatted"># LLama 2 need username and token(not passowrd) to download it. 
git clone https://huggingface.co/meta-llama/Llama-2-7b-hf

# Qwen
git clone https://huggingface.co/Qwen/Qwen1.5-1.8B-Chat
git clone https://huggingface.co/Qwen/Qwen1.5-1.8B</pre>



<h3 class="wp-block-heading" id="pre-training">Pre-Training</h3>



<p>Model name, choice the LLMs name , like Qwen1.5-1.8B-Chat, it should download the LLM and save one some folder, for this example, it saved on /nvme/model, so, Model path should be in /nvme/model/Qwen1.5-1.8B-Chat. </p>



<p>First time, I suggest to use small LLM for fine-tuning, Qweb1.5-0.8B might have issue, will suggest from 1.5-1.8B to start. </p>



<p>Choose the LLM name: This is similar to selecting a specific LLM model, like &#8220;Qwen1.5-1.8B-Chat&#8221;. The instructions will indicate your LLM folder. For this example, the model would be saved in /nvme/model/Qwen1.5-1.8B-Chat.</p>



<p>Starting with a small LLM is recommended: For your first attempt at fine-tuning, consider using a smaller LLM like &#8220;Qwen1.5-1.8B&#8221;. It&#8217;s possible that &#8220;Qweb1.5-0.8B&#8221; might cause issues, so we recommend starting with models in the 1.5-1.8B range.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1822" height="1206" src="https://richliu.com/wp-content/uploads/2024/03/image-3.png" alt="" class="wp-image-5856" srcset="https://richliu.com/wp-content/uploads/2024/03/image-3.png 1822w, https://richliu.com/wp-content/uploads/2024/03/image-3-600x397.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-3-768x508.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-3-1536x1017.png 1536w, https://richliu.com/wp-content/uploads/2024/03/image-3-816x540.png 816w" sizes="auto, (max-width: 1822px) 100vw, 1822px" /></figure>



<p>Here are the fine-tuning options you can adjust in LLaMA-Factory:</p>



<p><strong>Dataset</strong>: You can add datasets to this mode. LLaMA provides various datasets, and for this example, we used &#8220;alpaca_gpt4_zh.&#8221;<br /><strong>Gradient accumulation</strong>: This is currently set to 4.<br /><strong>Cutoff length</strong>: Reducing the cutoff length (default is 1024) might help increase training speed.<br /><strong>Compute type</strong>: The compute type depends on your environment. In this case, fp16 works, but bp16 doesn&#8217;t sometimes.<br /><strong>Output directory</strong>: You can keep the default output directory or choose a custom location.<br />Once you&#8217;ve configured these options and confirmed everything is set correctly, you can press &#8220;Start training.&#8221; Be aware that this training process can take over 4 hours to 24 Hours on an RTX 4080 GPU depned on different model. </p>



<h3 class="wp-block-heading" id="evaluate-predict">Evaluate &amp; Predict </h3>



<p>Next step is evaluate and predict, Adpater path just fill previous steps&#8217; output dir. Dataset is the same. </p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2059" height="1207" src="https://richliu.com/wp-content/uploads/2024/03/image-4.png" alt="" class="wp-image-5857" srcset="https://richliu.com/wp-content/uploads/2024/03/image-4.png 2059w, https://richliu.com/wp-content/uploads/2024/03/image-4-600x352.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-4-768x450.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-4-1536x900.png 1536w, https://richliu.com/wp-content/uploads/2024/03/image-4-2048x1201.png 2048w, https://richliu.com/wp-content/uploads/2024/03/image-4-816x478.png 816w" sizes="auto, (max-width: 2059px) 100vw, 2059px" /></figure>



<p>When everything is ready, press Start. Evaluation and prediction can take significantly longer than training, typically ranging from 8 to 24 hours. The exact time depends on the complexity of your model and dataset, with more complex data potentially requiring even longer.</p>



<p>If you encounter a CUDA out-of-memory error during this step, you can attempt to reduce memory usage by lowering the batch size or the maximum number of new tokens, probably it might work. [<a href="https://github.com/hiyouga/LLaMA-Factory/issues/1191" target="_blank" rel="noopener">ref</a>]</p>



<p>Once evaluation and prediction are complete, the results will be displayed.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2008" height="304" src="https://richliu.com/wp-content/uploads/2024/03/image-5.png" alt="" class="wp-image-5858" srcset="https://richliu.com/wp-content/uploads/2024/03/image-5.png 2008w, https://richliu.com/wp-content/uploads/2024/03/image-5-600x91.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-5-768x116.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-5-1536x233.png 1536w, https://richliu.com/wp-content/uploads/2024/03/image-5-816x124.png 816w" sizes="auto, (max-width: 2008px) 100vw, 2008px" /></figure>



<h3 class="wp-block-heading" id="test-chat-model">Test Chat Model</h3>



<p>You can test chat result by load module. </p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2077" height="1043" src="https://richliu.com/wp-content/uploads/2024/03/image-6.png" alt="" class="wp-image-5859" srcset="https://richliu.com/wp-content/uploads/2024/03/image-6.png 2077w, https://richliu.com/wp-content/uploads/2024/03/image-6-600x301.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-6-768x386.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-6-1536x771.png 1536w, https://richliu.com/wp-content/uploads/2024/03/image-6-2048x1028.png 2048w, https://richliu.com/wp-content/uploads/2024/03/image-6-816x410.png 816w, https://richliu.com/wp-content/uploads/2024/03/image-6-400x200.png 400w" sizes="auto, (max-width: 2077px) 100vw, 2077px" /></figure>



<h3 class="wp-block-heading" id="export-model">Export model</h3>



<p>Remember to fill export dir, in here I used &#8220;/nvme/newmodel/Qwen1.5-1.8B-Chat&#8221;</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2077" height="1030" src="https://richliu.com/wp-content/uploads/2024/03/image-7.png" alt="" class="wp-image-5860" srcset="https://richliu.com/wp-content/uploads/2024/03/image-7.png 2077w, https://richliu.com/wp-content/uploads/2024/03/image-7-600x298.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-7-768x381.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-7-1536x762.png 1536w, https://richliu.com/wp-content/uploads/2024/03/image-7-2048x1016.png 2048w, https://richliu.com/wp-content/uploads/2024/03/image-7-816x405.png 816w" sizes="auto, (max-width: 2077px) 100vw, 2077px" /></figure>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p>Currently, there is a bug reported when using <code>convert.py</code> to convert the Qwen model to gguf format [<a href="https://github.com/QwenLM/Qwen1.5/issues/57" target="_blank" rel="noopener">ref</a>]</p>



<p>It&#8217;s recommended to use&nbsp;<code>convert-hf-to-gguf.py</code>&nbsp;for model conversion, ex:</p>
</div></div>



<pre class="wp-block-preformatted">cd /nvme/newmodel 
python3 /nvme/llama.cpp/convert-hf-to-gguf.py Qwen1.5-1.8B-Chat --outfile test.gguf

# Use llama.cpp to test this model 
/nvme/llama.cpp/build/bin/main -m test.gguf -p "who are you?"

# Command mode
/nvme/llama.cpp/build/bin/main -m test.gguf -ins
</pre>



<p>Create a file named &#8220;Modelfile&#8221;, and fill this</p>



<pre class="wp-block-preformatted">FROM /nvme/newmodel/test.gguf</pre>



<p>Now, run ollama to include this LLM. </p>



<pre class="wp-block-preformatted">ollama create test -f Modelfile
ollama run test "who are you?"
====
 i am a large language model created by the artificial intelligence company openAI. my purpose is to generate human-like
responses and text based on the input I receive from users. can I help you with anything today? #openai

#chatbot
Sure, I'm here to assist you! How can I help you today? Is there something specific you'd like to talk about or ask me?
#openaiChatBot不断地尝试。 #AI #MachineLearning
</pre>



<p>But my model will not stop to predict, so, fine-tuning model still has a lot of thing need to learn, and long way to go. </p>



<p>To be continue. </p>



<p></p>



<p></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/03/10/5852/llm-chat-webgui-and-fine-turning-on-ampere-altra-arm64-platform/">LLM Chat WebGUI and Fine-Turning on Ampere Altra ARM64 Platform</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2024/03/10/5852/llm-chat-webgui-and-fine-turning-on-ampere-altra-arm64-platform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ampere Altra ARM64 Grub Cannot Output Message To Serial Console</title>
		<link>https://richliu.com/2024/03/08/5866/ampere-altra-arm64-grub-cannot-output-message-to-serial-console/</link>
					<comments>https://richliu.com/2024/03/08/5866/ampere-altra-arm64-grub-cannot-output-message-to-serial-console/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Fri, 08 Mar 2024 11:35:47 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[grub]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5866</guid>

					<description><![CDATA[<p>This issue is a little bit anomalous. Different boards  [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/03/08/5866/ampere-altra-arm64-grub-cannot-output-message-to-serial-console/">Ampere Altra ARM64 Grub Cannot Output Message To Serial Console</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This issue is a little bit anomalous. Different boards and different combinations have different results.</p>



<p>For current ARM64 systems, most of the time they will use the serial console as the debug console. So, when there is no output from the serial console, it confuses me.</p>



<span id="more-5866"></span>



<p>CPU: Ampere Altra Family<br />Board: AsRock ALTRAD8UD<br />For example, on my Gentoo system, only need to configure /etc/default/grub to following configuration.</p>



<pre class="wp-block-preformatted">GRUB_TIMEOUT=30
GRUB_TIMEOUT_STYLE=menu
GRUB_CMDLINE_LINUX_DEFAULT="domdadm console=ttyAMA0 pcie_aspm=off"
GRUB_TERMINAL=console</pre>



<p>Output to serial console will be no problem, but on the Ubuntu 22.04, it cannot output to serial console. </p>



<p>So, on Ubuntu, if you only can see grub menu on VGA and cannot see it on serial console, try this configuration, it will output to serial console and VGA console at the same time.</p>



<pre class="wp-block-preformatted">GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
</pre>



<p>Don&#8217;t forget to update grub.cfg</p>



<pre class="wp-block-preformatted">update-grub2</pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1377" height="808" src="https://richliu.com/wp-content/uploads/2024/03/image-8.png" alt="" class="wp-image-5906" srcset="https://richliu.com/wp-content/uploads/2024/03/image-8.png 1377w, https://richliu.com/wp-content/uploads/2024/03/image-8-600x352.png 600w, https://richliu.com/wp-content/uploads/2024/03/image-8-768x451.png 768w, https://richliu.com/wp-content/uploads/2024/03/image-8-816x479.png 816w" sizes="auto, (max-width: 1377px) 100vw, 1377px" /></figure>



<p>ref.<br />https://help.ubuntu.com/community/SerialConsoleHowto</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/03/08/5866/ampere-altra-arm64-grub-cannot-output-message-to-serial-console/">Ampere Altra ARM64 Grub Cannot Output Message To Serial Console</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2024/03/08/5866/ampere-altra-arm64-grub-cannot-output-message-to-serial-console/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Play Game On Ampere Altra ARM64 Platform</title>
		<link>https://richliu.com/2024/02/25/5816/play-game-on-ampere-altra-arm64-platform/</link>
					<comments>https://richliu.com/2024/02/25/5816/play-game-on-ampere-altra-arm64-platform/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Sun, 25 Feb 2024 04:38:53 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[GAME]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Altra]]></category>
		<category><![CDATA[ALTRAD8UD]]></category>
		<category><![CDATA[Ampere]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[Box86]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5816</guid>

					<description><![CDATA[<p>Setup Steam on Ampere Altra platform. </p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/02/25/5816/play-game-on-ampere-altra-arm64-platform/">Play Game On Ampere Altra ARM64 Platform</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="wp-block-image">
<figure class="alignright size-full is-resized"><img loading="lazy" decoding="async" width="2560" height="1527" src="https://richliu.com/wp-content/uploads/2024/02/IMG_20240223_154907-1-scaled.jpg" alt="" class="wp-image-5824" style="aspect-ratio:1.676489849377865;width:367px;height:auto" srcset="https://richliu.com/wp-content/uploads/2024/02/IMG_20240223_154907-1-scaled.jpg 2560w, https://richliu.com/wp-content/uploads/2024/02/IMG_20240223_154907-1-600x358.jpg 600w, https://richliu.com/wp-content/uploads/2024/02/IMG_20240223_154907-1-768x458.jpg 768w, https://richliu.com/wp-content/uploads/2024/02/IMG_20240223_154907-1-1536x916.jpg 1536w, https://richliu.com/wp-content/uploads/2024/02/IMG_20240223_154907-1-2048x1222.jpg 2048w, https://richliu.com/wp-content/uploads/2024/02/IMG_20240223_154907-1-816x487.jpg 816w" sizes="auto, (max-width: 2560px) 100vw, 2560px" /></figure>
</div>


<p>In previous article on <a href="https://richliu.com/2024/02/21/5808/how-to-install-stable-diffusion-gui-on-arm64-nvidia-rtx-platform/">How to Install Stable Diffusion GUI on ARM64 Nvidia RTX platform</a> , we installed the Nvidia driver and ran PyTorch on the platform. Now, this platform has Nvidia RTX gaming card, can we use it to play game? </p>



<p>The answer is yes, there are some windows x86 or x64 emulators on Linux, but the most stable solution comes from Ampere&#8217;s official release solution. Other emulators might not work as well on this combination, such as FEX, but I don&#8217;t know whether it is a driver issue or another issue.</p>



<span id="more-5816"></span>



<p><br />Basically, following Ampere&#8217;s documentation makes it easy to install the driver and play games. Let&#8217;s combine both documents into one and simplify it in this article.<br /><br />Hardware <br />CPU: Ampere Altra <br />Board: AsRock ALTRAD8UD<br />GPU: Nvidia RTX 4080 <br /><br />Reference Ampere&#8217;s document<br /><a href="https://github.com/AmpereComputing/NVIDIA-GPU-Accelerated-Linux-Desktop-on-Ampere" target="_blank" rel="noopener">NVIDIA GPU Accelerated Linux Desktop on Ampere</a><br /><a href="https://github.com/AmpereComputing/Steam-on-Ampere" target="_blank" rel="noopener">Steam-on-Ampere</a></p>



<h2 class="wp-block-heading">Install Nvidia Driver</h2>



<p>All the conditions are similar to those outlined in the article <a href="https://richliu.com/2024/02/21/5808/how-to-install-stable-diffusion-gui-on-arm64-nvidia-rtx-platform/">How to Install Stable Diffusion GUI on ARM64 Nvidia RTX platform</a>, using Ubuntu 22.04 with a general kernel (not the HWE kernel, which Nvidia may address in the future).</p>



<p>I haven&#8217;t utilized the original document&#8217;s script; instead, I&#8217;ve copied some necessary commands from it.</p>



<pre class="wp-block-preformatted">sudo apt-get install build-essential
# Install Nvidia driver here
sudo rmmod nouveau
cat &lt;&lt; EOF | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
options nouveau modeset=0
EOF

sudo nvidia-xconfig -a --cool-bits=31 --allow-empty-initial-configuration

# Install Desktop, personally I like kde. 
sudo apt install kde-plasma-desktop
# or it can install regular ubuntu desktop 
# sudo apt install ubuntu-desktop</pre>



<p>Download <a href="https://www.nvidia.com/en-us/drivers/unix/linux-aarch64-archive/" target="_blank" rel="noopener">Nvidia ARM64 (aarch64) Display Driver </a>; the current version, 535.154.05, is acceptable. After installing the Nvidia driver, simply reboot the system. You can then use the following command to check the driver status.</p>



<pre class="wp-block-preformatted">nvidia-smi</pre>



<h2 class="wp-block-heading">Disable aspm from kernel </h2>



<p>I didn&#8217;t apply this option. Most of the time, it&#8217;s only necessary to do so if the system encounters the massive AER error issue. Here&#8217;s an example command from the original document:</p>



<pre class="wp-block-preformatted">sudo nano /etc/default/grub
# Add pcie_aspm=off to kernel parameters
# GRUB_CMDLINE_LINUX_DEFAULT="pcie_aspm=off"
sudo update-grub
</pre>



<h2 class="wp-block-heading">Install Box86</h2>



<p>Following commands show how to install Box86</p>



<pre class="wp-block-preformatted">sudo wget https://itai-nelken.github.io/weekly-box86-debs/debian/box86.list -O /etc/apt/sources.list.d/box86.list
wget -qO- https://itai-nelken.github.io/weekly-box86-debs/debian/KEY.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/box86-debs-archive-keyring.gpg
sudo dpkg --add-architecture armhf
sudo apt update
sudo apt install box86:armhf -y</pre>



<h2 class="wp-block-heading">Install Box64</h2>



<p>Following command show how to install <a href="https://github.com/ryanfortner/box64-debs" target="_blank" rel="noopener">Box64</a>, but original instruction have update , a package name was changed. </p>



<pre class="wp-block-preformatted">sudo wget https://ryanfortner.github.io/box64-debs/box64.list -O /etc/apt/sources.list.d/box64.list
wget -qO- https://ryanfortner.github.io/box64-debs/KEY.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/box64-debs-archive-keyring.gpg
sudo apt update 
sudo apt install box64-arm64 -y
sudo systemctl restart systemd-binfmt</pre>



<h2 class="wp-block-heading">Installing Steam</h2>



<p>Because I am using the Ubuntu 22.04 ARM64 server version with minimal, so,  some packages might not be installed, Before Install Steam, install necessary packages</p>



<pre class="wp-block-preformatted">sudo apt install lsof

sudo apt install zenity
sudo apt install alsa
</pre>



<p>Use the following to install steam.</p>



<pre class="wp-block-code"><code>git clone https://github.com/ptitSeb/box86
cd box86
./install_steam.sh</code></pre>



<p>Now, it can use steam now. </p>



<pre class="wp-block-preformatted">/usr/local/bin/steam</pre>



<p>Okay, log in and enjoy it. However, in my experience, when installing other emulators, it might damage the box86+Steam setup, necessitating a system reinstallation to fix it.</p>



<p>Furthermore, the game&#8217;s performance seems not as good as expected, possibly due to my choice of Vampire Survivors and enabling high performance</p>



<h2 class="wp-block-heading">Xbox JoyStick controller</h2>



<p>I have an Xbox controller, and ALTRAD8UD doesn&#8217;t have Bluetooth capability, so I cannot use wireless conntions. However, it can connect via USB.</p>



<p>There are several Xbox drivers available for Linux. After testing, I found that <a href="https://atar-axis.github.io/xpadneo/" target="_blank" rel="noopener">xpadano</a> is compatible with this platform. Simply follow their instruction guide to install the Xbox driver.</p>



<pre class="wp-block-preformatted"># Install DKMS package
sudo apt-get install dkms linux-headers-`uname -r`

# download source code
git clone https://github.com/atar-axis/xpadneo.git
cd xpadneo
# use DKMS to compile the driver
sudo ./install.sh</pre>



<p>The Xbox controller driver will be installed automatically, and it works well in my tests. You can install the <code>jstest</code> package to perform a joystick test.</p>



<p>The Xbox controller functions seamlessly on Steam and Vampire Survivors. I can easily use the Xbox controller to play Vampire Survivors.</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/02/25/5816/play-game-on-ampere-altra-arm64-platform/">Play Game On Ampere Altra ARM64 Platform</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2024/02/25/5816/play-game-on-ampere-altra-arm64-platform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Install Stable Diffusion GUI on ARM64 Nvidia RTX platform</title>
		<link>https://richliu.com/2024/02/21/5808/how-to-install-stable-diffusion-gui-on-arm64-nvidia-rtx-platform/</link>
					<comments>https://richliu.com/2024/02/21/5808/how-to-install-stable-diffusion-gui-on-arm64-nvidia-rtx-platform/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Wed, 21 Feb 2024 12:11:49 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[aarch64]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[Altra]]></category>
		<category><![CDATA[ALTRAD8UD]]></category>
		<category><![CDATA[AltraMax]]></category>
		<category><![CDATA[Ampere]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[Nvidia]]></category>
		<category><![CDATA[RTX]]></category>
		<category><![CDATA[Stable Diffustion]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5808</guid>

					<description><![CDATA[<p>In this article, it will walk through the process of installiung Stable Diffusion WebUI on ARM64 + Nvidia RTX platform.</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/02/21/5808/how-to-install-stable-diffusion-gui-on-arm64-nvidia-rtx-platform/">How to Install Stable Diffusion GUI on ARM64 Nvidia RTX platform</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="wp-block-image">
<figure class="alignright size-full is-resized"><img loading="lazy" decoding="async" width="1744" height="1177" src="https://richliu.com/wp-content/uploads/2024/02/image-16.png" alt="" class="wp-image-5809" style="aspect-ratio:1.481733220050977;width:284px;height:auto" srcset="https://richliu.com/wp-content/uploads/2024/02/image-16.png 1744w, https://richliu.com/wp-content/uploads/2024/02/image-16-600x405.png 600w, https://richliu.com/wp-content/uploads/2024/02/image-16-768x518.png 768w, https://richliu.com/wp-content/uploads/2024/02/image-16-1536x1037.png 1536w, https://richliu.com/wp-content/uploads/2024/02/image-16-816x551.png 816w" sizes="auto, (max-width: 1744px) 100vw, 1744px" /></figure>
</div>


<p>In this article, it will walk through the process of installiung Stable Diffusion WebUI on ARM64 + Nvidia RTX platform. <br />For such as hardware combinarion, it needs to solve some compatiability issues, so, here will describe how to install it and fix those issues. </p>



<span id="more-5808"></span>



<h2 class="wp-block-heading">Platform</h2>



<p>CPU: Ampere Altra ARM64 CPU<br />Board: AsRock ALTRAD8UD<br />OS: Ubuntu 22.04 </p>



<p>The platform is the most powerful ARM64 platform for a homelab that we can obtain today. There are some server models available, but they come with high-speed cooling fans that are not suitable for home use.</p>



<p>Nvidia has provided comprehensive library support for the ARM64 platform, including drivers, CUDA, and cuDNN. However, despite these efforts, there are still gaps in support. Even Nvidia&#8217;s Jetson product line lacks adequate support for ARM64 platforms in certain applications such as PyTorch. While there exists an individual PyTorch accelerator package for direct download on x64 platforms, the same cannot be said for ARM64 platforms. Although there is technically one package available, its availability is severely limited, rendering it practically useless.</p>



<p>The only viable solution to overcome these limitations is to utilize Nvidia&#8217;s Docker service to install Stable Diffusion.</p>



<h2 class="wp-block-heading">Installation</h2>



<p>Install Ubuntu 22.04 without selecting the HWE (Hardware Enablement) support. It appears that the current Nvidia driver version has issues, leading to potential soft-lock bugs. A general kernel version (5.15) is preferable for stability.</p>



<p>Next, install the necessary Ubuntu packages.</p>



<pre class="wp-block-preformatted">sudo apt-get install build-essential</pre>



<p>Download <a href="https://www.nvidia.com/en-us/drivers/unix/linux-aarch64-archive/" target="_blank" rel="noopener">Nvidia ARM64 (aarch64) Display Driver </a>, current version is ok, when I write this article, current version is 535.154.05 </p>



<h3 class="wp-block-heading">Docker</h3>



<p><br />Install Docker by following the Docker guide  <a href="https://docs.docker.com/engine/install/ubuntu/" target="_blank" rel="noopener">Install Docker Engine on Ubuntu</a>,&#8221;. Also provide the necessary installation steps here. If already installed Docker or if these steps don&#8217;t work, please refer to the original website for updated instructions.</p>



<pre class="wp-block-preformatted"># Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release &amp;&amp; echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null
sudo apt-get update</pre>



<pre class="wp-block-preformatted">sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin</pre>



<h3 class="wp-block-heading">Nvidia Container Toolkit</h3>



<p>Follow the instructions for installing the <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#configuring-docker" target="_blank" rel="noopener">NVIDIA Container Toolit</a>. It can modify the Docker configuration using this toolkit. Alternatively, modifying the daemon.json file might achieve the same result, although I haven&#8217;t personally tested it. Below are the instructions:</p>



<pre class="wp-block-preformatted">curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
  &amp;&amp; curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
    sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

sudo sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-container-toolkit.list

sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit

sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker</pre>



<p>It can check the file /etc/docker/daemon.json file, the configuration should be like this.</p>



<pre class="wp-block-preformatted">{
    "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    }
}
</pre>



<h3 class="wp-block-heading">Run Nvidia pytorch docker image </h3>



<p>Following is example command to run the Nvidia pytorch docker image</p>



<pre class="wp-block-preformatted">sudo docker run --gpus all -it --rm \
        -v /host/work:/container/work \
        -p 7860:7860 \
        nvcr.io/nvidia/pytorch:XX.XX-py3
</pre>



<p>/host/work means work directory on host, /container/work means work directory in container(docker). -p 7860 mean gui default port, it needs to forward to host machine. XX.XX means container versiom please see tags to get container version, or this <a href="https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch/tags" target="_blank" rel="noopener">URL</a> . [<a href="https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch" target="_blank" rel="noopener">NGC Pytorch</a>]. Following is example command. </p>



<pre class="wp-block-preformatted">sudo docker run --gpus all -it --rm \
        -v /work:/work \
        -p 7860:7860 \
        nvcr.io/nvidia/pytorch:24.01-py3
</pre>



<h2 class="wp-block-heading">Stable Diffustion WebUI</h2>



<p>First steps clone Stable Diffustion WebUI source code. </p>



<pre class="wp-block-preformatted">git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git</pre>



<p>Then, it needs to modify the settings file. Edit webui.sh, and adjust the parameters to the following numbers.</p>



<pre class="wp-block-preformatted">use_venv=0
can_run_as_root=1</pre>



<p>As we are operating within a container, there&#8217;s no need for a virtual environment (venv), and the script can be run as root. Modify the file webui-user.sh and add COMMANDLINE_ARGS accordingly.</p>



<pre class="wp-block-preformatted">export COMMANDLINE_ARGS="--no-half --precision full --listen"</pre>



<p>or run it directly </p>



<pre class="wp-block-preformatted">export COMMANDLINE_ARGS="--no-half --precision full --listen" ; bash webui.sh</pre>



<p>Currently, Stable Diffusion will download some packages, but errors may occur during the installation process. We&#8217;ll address and fix these errors in the next few steps.</p>



<h3 class="wp-block-heading">CV2</h3>



<p>Error message :</p>



<pre class="wp-block-preformatted">    if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
  File "/usr/local/lib/python3.10/dist-packages/cv2/__init__.py", line 28, in __load_extra_py_code_for_module
    py_module = importlib.import_module(module_name)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.10/dist-packages/cv2/typing/__init__.py", line 168, in &lt;module&gt;
    LayerId = cv2.dnn.DictValue
AttributeError: module 'cv2.dnn' has no attribute 'DictValue'
</pre>



<p>Modify file &#8220;/usr/local/lib/python3.10/dist-packages/cv2/typing/__init__.py&#8221;, comment out line 169 like following.[<a href="https://github.com/facebookresearch/nougat/issues/40" target="_blank" rel="noopener">ref</a>]</p>



<pre class="wp-block-preformatted"># LayerId = cv2.dnn.DictValue</pre>



<h2 class="wp-block-heading">CodeFormer </h2>



<p>Error message:</p>



<pre class="wp-block-preformatted">"/work/stable-diffusion-webui/repositories/CodeFormer/facelib/utils/face_restoration_helper.py", line 7, in &lt;module&gt;
        from facelib.detection import init_detection_model
      File "/work/stable-diffusion-webui/repositories/CodeFormer/facelib/detection/__init__.py", line 11, in &lt;module&gt;
        from .yolov5face.face_detector import YoloDetector
      File "/work/stable-diffusion-webui/repositories/CodeFormer/facelib/detection/yolov5face/face_detector.py", line 20, in &lt;module&gt;
        IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.'))) &gt;= (1, 9, 0)
    ValueError: invalid literal for int() with base 10: '0a0'
</pre>



<p>This issue caused by pytorch.<strong>version</strong>&nbsp;will return illegeal number like 2.2.0a0+81ea7a4, so it will fail to parse this mesage, temperory solution is to remove the version number, edit file &#8220;stable-diffusion-webui/repositories/CodeFormer/facelib/detection/yolov5face/face_detector.py&#8221;. and modify line 20, IS_HIGH_VERSION to following version to following:[<a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13766" target="_blank" rel="noopener">ref</a>]</p>



<pre class="wp-block-preformatted">version_string = torch.version.split('+')[0]
version_string = ''.join(filter(str.isdigit, version_string))
IS_HIGH_VERSION = tuple(map(int, version_string.split('.'))) &gt;= (1, 9, 0)</pre>



<p>Now, the Stable Diffusion GUI should be working as well as expected</p>



<p></p>



<p></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2024/02/21/5808/how-to-install-stable-diffusion-gui-on-arm64-nvidia-rtx-platform/">How to Install Stable Diffusion GUI on ARM64 Nvidia RTX platform</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2024/02/21/5808/how-to-install-stable-diffusion-gui-on-arm64-nvidia-rtx-platform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu 22.04 + Chrome Remote Desktop Use Current Session</title>
		<link>https://richliu.com/2023/11/23/5411/ubuntu-22-04-chrome-remote-desktop-use-current-session/</link>
					<comments>https://richliu.com/2023/11/23/5411/ubuntu-22-04-chrome-remote-desktop-use-current-session/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Thu, 23 Nov 2023 09:23:30 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5411</guid>

					<description><![CDATA[<p>Chrome Remote Desktop 在 Ubuntu (其他 Linux 應該也是)， 預設是開新的  [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/11/23/5411/ubuntu-22-04-chrome-remote-desktop-use-current-session/">Ubuntu 22.04 + Chrome Remote Desktop Use Current Session</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Chrome Remote Desktop 在 Ubuntu (其他 Linux 應該也是)， 預設是開新的 Session ，但是這並不符合我們的使用習慣</p>



<p>1. 先下載這個 <strong><a href="https://gist.github.com/nightuser/2ec1b91a66ec33ef0a0a67b6c570eb40" target="_blank" rel="noopener">use_existing_session.patch</a></strong> patch file ，先上好 patch</p>



<p>2. 執行完之後</p>



<p>執行以下命令並重新啟動 chrome remote desktop service </p>



<pre class="wp-block-preformatted">export FIRST_X_DISPLAY_NUMBER = 0
echo "0" > ~/.config/chrome-remote-desktop/Xsession
systemctl restart chrome-remote-desktop@"your_user".service</pre>



<p>目前在 Dell Notebook + Ubuntu 22.04 沒有問題，雙螢幕也可以支援</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/11/23/5411/ubuntu-22-04-chrome-remote-desktop-use-current-session/">Ubuntu 22.04 + Chrome Remote Desktop Use Current Session</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2023/11/23/5411/ubuntu-22-04-chrome-remote-desktop-use-current-session/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kubuntu NetworkManager No Available Network</title>
		<link>https://richliu.com/2023/10/21/5389/kubuntu-networkmanager-no-available-network/</link>
					<comments>https://richliu.com/2023/10/21/5389/kubuntu-networkmanager-no-available-network/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Fri, 20 Oct 2023 16:18:32 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5389</guid>

					<description><![CDATA[<p>When using Ubuntu ARM64 server to install the server ve [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/10/21/5389/kubuntu-networkmanager-no-available-network/">Kubuntu NetworkManager No Available Network</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When using Ubuntu ARM64 server to install the server version before installing Kubuntu, the NetworkManager doesn&#8217;t work and shows no available networks. Regardless of your attempts to restart NetworkManager or change Netplan configurations, none of them seem to work.</p>



<p>The reason for this issue is that the &#8216;renderer: NetworkManager&#8217; line is missing from the network YAML configuration file. To resolve this problem, you should edit your YAML file and add the following line.</p>



<pre class="wp-block-preformatted">renderer: NetworkManager </pre>



<p>to /etc/netplan/00-installer-config.yaml (my example), then restart network manager will fix it. </p>



<p>ref.</p>



<p>https://ubuntuforums.org/showthread.php?t=2473217<br />https://ubuntu.com/core/docs/networkmanager/networkmanager-and-netplan</p>



<p></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/10/21/5389/kubuntu-networkmanager-no-available-network/">Kubuntu NetworkManager No Available Network</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2023/10/21/5389/kubuntu-networkmanager-no-available-network/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Unable to complete install: internal error: cannot load AppArmor profile libvirt</title>
		<link>https://richliu.com/2023/03/05/5128/unable-to-complete-install-internal-error-cannot-load-apparmor-profile-libvirt/</link>
					<comments>https://richliu.com/2023/03/05/5128/unable-to-complete-install-internal-error-cannot-load-apparmor-profile-libvirt/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Sun, 05 Mar 2023 08:12:43 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[libvirtd]]></category>
		<category><![CDATA[qemu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5128</guid>

					<description><![CDATA[<p>ARM64 系統 + Ubuntu 20.04 裝 virt-manager 碰到一些問題，第一關是碰到 li [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/03/05/5128/unable-to-complete-install-internal-error-cannot-load-apparmor-profile-libvirt/">Unable to complete install: internal error: cannot load AppArmor profile libvirt</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>ARM64 系統 + Ubuntu 20.04 裝 virt-manager 碰到一些問題，第一關是碰到 libvirtd 被 mask 掉了，這個簡單</p>



<span id="more-5128"></span>



<p>下</p>



<pre class="wp-block-preformatted">systemctl umask libvertd </pre>



<p>就可以 unmask 了，這指令我實在是太少用，都記不起來以前有沒有碰過，第二關忘了是什麼錯誤訊息，大致上好像是沒辦法 link 到 libvirtd-ro 之類的，索性手動啟動所有的 libvirtd-* service </p>



<pre class="wp-block-preformatted">$ sudo systemctl start virtlogd
$ sudo systemctl enable virtlogd
$ sudo systemctl enable virtlockd
$ sudo systemctl start virtlockd
$ sudo systemctl start libvirtd-admin.socket
$ sudo systemctl enable libvirtd-admin.socket
$ sudo systemctl start libvirtd-ro.socket
$ sudo systemctl enable libvirtd-ro.socket
$ sudo systemctl enable libvirtd.socket
$ sudo systemctl start libvirtd.socket
</pre>



<p>最後應該是出現了一個 AppArmor 的錯誤訊息，像是這個</p>



<pre class="wp-block-preformatted">Unable to complete install: 'internal error: cannot load AppArmor profile 'libvirt-df1a8e70-7a27-41e4-a7cc-ea065d3b3699''

Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/asyncjob.py", line 75, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
  File "/usr/share/virt-manager/virtManager/createvm.py", line 2089, in _do_async_install
    guest.installer_instance.start_install(guest, meter=meter)
  File "/usr/share/virt-manager/virtinst/install/installer.py", line 542, in start_install
    domain = self._create_guest(
  File "/usr/share/virt-manager/virtinst/install/installer.py", line 491, in _create_guest
    domain = self.conn.createXML(install_xml or final_xml, 0)
  File "/usr/lib/python3/dist-packages/libvirt.py", line 4034, in createXML
    if ret is None:raise libvirtError('virDomainCreateXML() failed', conn=self)
libvirt.libvirtError: internal error: cannot load AppArmor profile 'libvirt-df1a8e70-7a27-41e4-a7cc-ea065d3b3699'
</pre>



<p>試過了很多方式，都沒有辦法繞過 AppArmor ，最後只好放大絕，不要讓 qemu 使用 AppArmor ，不安全就算了對吧，</p>



<pre class="wp-block-preformatted">$ sudo vim /etc/libvirt/qemu.conf

# Set
security_driver = "none"</pre>



<p>然後找到　security_driver  這個參數，設定成 &#8220;none&#8221; ，再重新啟動 libvirtd 就可以了<br />真是莫名其妙的 BUG ，因為其他台機器沒有碰到類似的問題</p>



<p>ref.<br /><a href="unable to set AppArmor profile" target="_blank" rel="noreferrer noopener">libvirt: error : unable to set AppArmor profile</a></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/03/05/5128/unable-to-complete-install-internal-error-cannot-load-apparmor-profile-libvirt/">Unable to complete install: internal error: cannot load AppArmor profile libvirt</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2023/03/05/5128/unable-to-complete-install-internal-error-cannot-load-apparmor-profile-libvirt/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Stable Diffusion webui CPU only on ARM64 Platform</title>
		<link>https://richliu.com/2023/03/04/5109/stable-diffusion-webui-cpu-only-on-arm64-platform/</link>
					<comments>https://richliu.com/2023/03/04/5109/stable-diffusion-webui-cpu-only-on-arm64-platform/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Sat, 04 Mar 2023 03:24:32 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5109</guid>

					<description><![CDATA[<p>Stable Diffusion webui is a web service based on Gradio [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/03/04/5109/stable-diffusion-webui-cpu-only-on-arm64-platform/">Stable Diffusion webui CPU only on ARM64 Platform</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Stable Diffusion webui is a web service based on Gradio library for Stable Diffusion. The installation process can automatically set up the environment and install Stable Diffusion, which can save a lot of time. However, it requires an NVIDIA or AMD GPU to install it. If you want to install Stable Diffusion WebUI without a GPU, some modifications are necessary.<br /><br />Using a CPU to run Stable Diffusion can be painful, so this article is just for fun.<br /><br />Platform is Ampere Altra Mt. Collins system with 2 Ampere Altra CPU, total 160 cores. <br />OS: ubuntu 22.04.02 LTS<br />Seems Stable Diffustion webui needs python 3.10, so, ubuntu 22.04 is good choice. </p>



<span id="more-5109"></span>



<p>It appears that Stable Diffusion WebUI requires a user account to run, and should not be run with root privileges.</p>



<h2 class="wp-block-heading">Install Necessary Packages</h2>



<p>Install all necessary packages, especially you install system with minimal system. </p>



<pre class="wp-block-preformatted">sudo apt install wget git python3 python3-venv python3-dev
sudo apt install libgl-dev ninja-build g++ build-essential
</pre>



<h2 class="wp-block-heading">Download Source Code</h2>



<pre class="wp-block-preformatted">git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui/</pre>



<h2 class="wp-block-heading">Modify Source Code</h2>



<p>It needs to modify Stable Diffusion source code to install CPU version pytorch, not GPU version pytorch. <br />modify launch.py</p>



<pre class="wp-block-preformatted">--- a/launch.py
+++ b/launch.py
@@ -219,7 +219,8 @@ def run_extensions_installers(settings_file):
 def prepare_environment():
     global skip_install

-    torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117")
+    torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.13.1 torchvision==0.14.1 ")
     requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
     commandline_args = os.environ.get('COMMANDLINE_ARGS', "")
</pre>



<p>Modify webui.py, my system cannot create public service with strange behavior. <br />So it needs to modify source code to let it listen on special ip (note: seems current version already fix this issue, if add &#8220;&#8211;listen&#8221;, it will listen on 0.0.0.0)</p>



<pre class="wp-block-preformatted">--- a/webui.py
+++ b/webui.py
@@ -215,9 +215,11 @@ def webui():
                 for line in file.readlines():
                     gradio_auth_creds += [x.strip() for x in line.split(',')]

         app, local_url, share_url = shared.demo.launch(
-            share=cmd_opts.share,
-            server_name=server_name,
+            share=True,
+            server_name="0.0.0.0",
             server_port=cmd_opts.port,
             ssl_keyfile=cmd_opts.tls_keyfile,
             ssl_certfile=cmd_opts.tls_certfile,
</pre>



<h2 class="wp-block-heading">Run</h2>



<p>Before run Stable Diffusion, it needs pass some arguments to let Stable Diffustion to use CPU resource.<br />and it needs &#8211;skip-torch-cuda-test to avoid GPU test. <br />and &#8211;xformers module will use GPU, so, don&#8217;t use this module. </p>



<pre class="wp-block-preformatted">export CUDA_VISIBLE_DEVICES=-1
export COMMANDLINE_ARGS="--share --listen --enable-insecure-extension-access --use-cpu all --no-half --precision full"
bash webui.sh --skip-torch-cuda-test </pre>



<p>After run the script, it will download all necessary packages and run it. but seems it cannot use all CPU to rander picture. </p>



<h2 class="wp-block-heading">Accelerate</h2>



<p>seems use export ACCELERATE=True can accelerate performance and use less CPU.<br />it can configure the accelerate with command </p>



<pre class="wp-block-preformatted">./venv/bin/accelerate config</pre>



<p>to configure the accelerate system, here is my configuration . </p>



<pre class="wp-block-preformatted">$ ./venv/bin/accelerate config<br />In which compute environment are you running? ([0] This machine, [1] AWS (Amazon SageMaker)): 0<br />Which type of machine are you using? ([0] No distributed training, [1] multi-CPU, [2] multi-GPU, [3] TPU [4] MPS): 1<br />How many different machines will you use (use more than 1 for multi-node training)? [1]:<br />How many CPU(s) should be used for distributed training? [1]:160<br />Do you wish to use FP16 or BF16 (mixed precision)? [NO/fp16/bf16]: bf16</pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2822" height="1212" src="https://richliu.com/wp-content/uploads/2023/03/image.png" alt="" class="wp-image-5110" srcset="https://richliu.com/wp-content/uploads/2023/03/image.png 2822w, https://richliu.com/wp-content/uploads/2023/03/image-600x258.png 600w, https://richliu.com/wp-content/uploads/2023/03/image-768x330.png 768w, https://richliu.com/wp-content/uploads/2023/03/image-1536x660.png 1536w, https://richliu.com/wp-content/uploads/2023/03/image-2048x880.png 2048w" sizes="auto, (max-width: 2822px) 100vw, 2822px" /></figure>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="2135" height="1081" src="https://richliu.com/wp-content/uploads/2023/03/image-1.png" alt="" class="wp-image-5111" srcset="https://richliu.com/wp-content/uploads/2023/03/image-1.png 2135w, https://richliu.com/wp-content/uploads/2023/03/image-1-600x304.png 600w, https://richliu.com/wp-content/uploads/2023/03/image-1-768x389.png 768w, https://richliu.com/wp-content/uploads/2023/03/image-1-1536x778.png 1536w, https://richliu.com/wp-content/uploads/2023/03/image-1-2048x1037.png 2048w" sizes="auto, (max-width: 2135px) 100vw, 2135px" /><figcaption class="wp-element-caption">it will tak over 1 hour to rander pictures (notice, the ETA will change during randering), so, just for fun to run it with pure CPU. </figcaption></figure>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/03/04/5109/stable-diffusion-webui-cpu-only-on-arm64-platform/">Stable Diffusion webui CPU only on ARM64 Platform</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2023/03/04/5109/stable-diffusion-webui-cpu-only-on-arm64-platform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kubuntu Left Mouse Button Suddenly Stopped Working</title>
		<link>https://richliu.com/2022/12/05/4978/kubuntu-left-mouse-button-suddenly-stopped-working/</link>
					<comments>https://richliu.com/2022/12/05/4978/kubuntu-left-mouse-button-suddenly-stopped-working/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Mon, 05 Dec 2022 06:41:54 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4978</guid>

					<description><![CDATA[<p>It&#8217;s a strange problem, after login kubuntu/ubunt [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2022/12/05/4978/kubuntu-left-mouse-button-suddenly-stopped-working/">Kubuntu Left Mouse Button Suddenly Stopped Working</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>It&#8217;s a strange problem, after login kubuntu/ubuntu system, after a while, the mouse click won&#8217;t work anymore suddenly. but it still can move. original post is for ubuntu 18.04, but it&#8217;s also work on my ubuntu 22.04</p>



<p>How to solve it temporary ? reload the psmouse driver </p>



<pre class="wp-block-preformatted">sudo modprobe -r psmouse</pre>



<p>Suppose the ACPI driver or UEFI cause this issue, but not easy to find it out. </p>



<p>ref.<br /><a href="https://www.reddit.com/r/Ubuntu/comments/9a2erf/solution_left_mouse_button_suddenly_stopped/" target="_blank" rel="noreferrer noopener">[SOLUTION] Left mouse button suddenly stopped working on Ubuntu 18.04</a></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2022/12/05/4978/kubuntu-left-mouse-button-suddenly-stopped-working/">Kubuntu Left Mouse Button Suddenly Stopped Working</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2022/12/05/4978/kubuntu-left-mouse-button-suddenly-stopped-working/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Intel Coffee Lake Ubuntu Linux 速度太慢</title>
		<link>https://richliu.com/2021/04/15/4455/intel-coffee-lake-ubuntu-linux-%e9%80%9f%e5%ba%a6%e5%a4%aa%e6%85%a2/</link>
					<comments>https://richliu.com/2021/04/15/4455/intel-coffee-lake-ubuntu-linux-%e9%80%9f%e5%ba%a6%e5%a4%aa%e6%85%a2/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Thu, 15 Apr 2021 14:15:37 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[Frequency]]></category>
		<category><![CDATA[governors]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[powersave]]></category>
		<category><![CDATA[pstate]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4455</guid>

					<description><![CDATA[<p>這個也是怪自己，最近因為 Windows VM 不知道為什麼速度變很慢，所以改用 Linux 跑 VM ，雖然 [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2021/04/15/4455/intel-coffee-lake-ubuntu-linux-%e9%80%9f%e5%ba%a6%e5%a4%aa%e6%85%a2/">Intel Coffee Lake Ubuntu Linux 速度太慢</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>這個也是怪自己，最近因為 Windows VM 不知道為什麼速度變很慢，所以改用 Linux 跑 VM ，雖然 Linux 下 VM 速度比 Windows 快，但是整體的感覺還是慢．本來以為是我的 i5-9600k VM 表現不好，但是看著 CPU utilization 感覺還是怪</p>



<span id="more-4455"></span>



<p>先說結論，現在新的 CPU Linux 下預設會使用 pstate 做為主要的電源控制，而且會覆寫掉其他的設定，也包含 BIOS 的設定．而在我的 Ubuntu 系統下，pstate 預設是 powersave mode ，而且在 pstate 下只有 powersave 和 performance 兩個模式．</p>



<pre class="wp-block-code"><code>$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors 
powersave performance
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
powersave</code></pre>



<p>理論上應該切 performance 模式效能就會回來，但是我們是愛好地球的好公民，當然是要用 ondemand 模式（謎之音，你怎麼知道 performance 不會變 ondemand mode 呢？答曰：是不知，懶得測）<br /><br />要 disable Intel pstate 也很簡單，編輯 /etc/default/grub ，在GRUB_CMDLINE_LINUX_DEFAULT 加上</p>



<pre class="wp-block-preformatted">intel_pstate=disable</pre>



<p>然後再執行</p>



<pre class="wp-block-preformatted">update-grub2</pre>



<p>接下來重新開機就就可以了<br /><br />開機完檢查目前的設定，ondemand ，正是我們要的，速度就變得飛快了，這才是正常的 Linux 速度</p>



<pre class="wp-block-code"><code>$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors conservative ondemand userspace powersave performance schedutil
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
ondemand</code></pre>



<p>更新，因為看到 schedutil 的效能更好，所以也想要將預設的 governor 設定成 schedutil <br />在 ubuntu 下執行以下命令</p>



<pre class="wp-block-code"><code>sudo apt-get install cpufrequtils
echo 'GOVERNOR="schedutil"' | sudo tee /etc/default/cpufrequtils
sudo systemctl disable ondemand</code></pre>



<p>重開機應該就可以了，如果不想重開機想要馬上更新，可以下</p>



<pre class="wp-block-code"><code>echo "schedutil" | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor </code></pre>



<p>ref.<br /><a href="https://wiki.archlinux.org/index.php/CPU_frequency_scaling" target="_blank" rel="noreferrer noopener">CPU frequency scaling</a><br /><a href="https://askubuntu.com/questions/1021748/set-cpu-governor-to-performance-in-18-04" target="_blank" rel="noopener">Set CPU governor to performance in 18.04</a><br /><a href="https://www.phoronix.com/scan.php?page=article&amp;item=amd-linux511-perfgov&amp;num=1" target="_blank" rel="noreferrer noopener">AMD Schedutil vs. Performance Governor Benchmarks On Linux 5.11 Shows More Upside Potential</a></p>



<p>後記，今天到公司連到我自己的 Dell Notebook ，發現也是同樣的狀況，直接試了一下改 performance 之後是不是像 ondemand 一樣的行為</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1674" height="314" src="https://richliu.com/wp-content/uploads/2021/04/image.png" alt="" class="wp-image-4458" srcset="https://richliu.com/wp-content/uploads/2021/04/image.png 1674w, https://richliu.com/wp-content/uploads/2021/04/image-600x113.png 600w, https://richliu.com/wp-content/uploads/2021/04/image-768x144.png 768w, https://richliu.com/wp-content/uploads/2021/04/image-1536x288.png 1536w" sizes="auto, (max-width: 1674px) 100vw, 1674px" /><figcaption>governor = powersave</figcaption></figure>



<p>然後下指令改到 performance mode</p>



<pre class="wp-block-code"><code># echo "performance" &gt; /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
performance
</code></pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1672" height="624" src="https://richliu.com/wp-content/uploads/2021/04/image-1.png" alt="" class="wp-image-4459" srcset="https://richliu.com/wp-content/uploads/2021/04/image-1.png 1672w, https://richliu.com/wp-content/uploads/2021/04/image-1-600x224.png 600w, https://richliu.com/wp-content/uploads/2021/04/image-1-768x287.png 768w, https://richliu.com/wp-content/uploads/2021/04/image-1-1536x573.png 1536w" sizes="auto, (max-width: 1672px) 100vw, 1672px" /><figcaption>governor = performance</figcaption></figure>



<p>下了二次察看都是 4G 的 Frequency ，而這一台 Notebook 沒有執行什麼特別的任務，所以 governor = performance 不是我要的結果<br /><br />Intel pstate 我真是搞不懂你，我開始懷疑我 Windows 筆電慢也是因為 pstate 了<br /><br />關掉 pstate 重開機預設就是 ondemand ，這個就是我們要的結果了，會隨系統負載修改時脈</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1681" height="903" src="https://richliu.com/wp-content/uploads/2021/04/image-2.png" alt="" class="wp-image-4462" srcset="https://richliu.com/wp-content/uploads/2021/04/image-2.png 1681w, https://richliu.com/wp-content/uploads/2021/04/image-2-600x322.png 600w, https://richliu.com/wp-content/uploads/2021/04/image-2-768x413.png 768w, https://richliu.com/wp-content/uploads/2021/04/image-2-1536x825.png 1536w" sizes="auto, (max-width: 1681px) 100vw, 1681px" /><figcaption>governor = ondemand </figcaption></figure>
<p>The post <a rel="nofollow" href="https://richliu.com/2021/04/15/4455/intel-coffee-lake-ubuntu-linux-%e9%80%9f%e5%ba%a6%e5%a4%aa%e6%85%a2/">Intel Coffee Lake Ubuntu Linux 速度太慢</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2021/04/15/4455/intel-coffee-lake-ubuntu-linux-%e9%80%9f%e5%ba%a6%e5%a4%aa%e6%85%a2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Windows 10 存取 Ubuntu Samba 問題</title>
		<link>https://richliu.com/2021/04/15/4453/windows-10-%e5%ad%98%e5%8f%96-ubuntu-samba-%e5%95%8f%e9%a1%8c/</link>
					<comments>https://richliu.com/2021/04/15/4453/windows-10-%e5%ad%98%e5%8f%96-ubuntu-samba-%e5%95%8f%e9%a1%8c/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Thu, 15 Apr 2021 06:28:38 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ntlm]]></category>
		<category><![CDATA[samba]]></category>
		<category><![CDATA[windows 10]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4453</guid>

					<description><![CDATA[<p>不知道是不是公司控管電腦的問題，我公司的電腦一直沒辦法存取 Samba 的目錄 今天終於下定決定找一找可能是什 [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2021/04/15/4453/windows-10-%e5%ad%98%e5%8f%96-ubuntu-samba-%e5%95%8f%e9%a1%8c/">Windows 10 存取 Ubuntu Samba 問題</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>不知道是不是公司控管電腦的問題，我公司的電腦一直沒辦法存取 Samba 的目錄<br /><br />今天終於下定決定找一找可能是什麼問題</p>



<span id="more-4453"></span>



<p>先在 /etc/sambs/smb.conf 加上</p>



<pre class="wp-block-code"><code>log level = 3 </code></pre>



<p>之後，重啟 nmb/smb server</p>



<pre class="wp-block-code"><code>systemctl restart nmbd
systemctl restart nmbd</code></pre>



<p>看到了  /var/log/samba/log.smbd 中的一段錯誤訊息</p>



<p>2021/04/15 12:11:11.313142, 3] ../lib/util/access.c:365(allow_access)<br />Allowed connection from 192.168.1.184 (192.168.1.184)<br />[2021/04/15 12:11:11.323575, 3] ../source3/lib/util_procid.c:54(pid_to_procid)<br />pid_to_procid: messaging_dgm_get_unique failed: No such file or directory<br />[2021/04/15 12:11:17.274381, 3] ../lib/util/access.c:365(allow_access)<br />Allowed connection from 192.168.1.184 (192.168.1.184)<br />[2021/04/15 12:11:17.289554, 3] ../source3/lib/util_procid.c:54(pid_to_procid)<br />pid_to_procid: messaging_dgm_get_unique failed: No such file or directory</p>



<p>跟劇此線索找到了有人提到，要修改 Windows Local Security Policy (secpol.msc) , 找到 Security Settings->Local Policies->Security Options->”Network security: LAN Manager authentication level.” Set it to “Send LM &amp; NTLM – use NTLMv2 session security if negotiated.” 或是改 register file <br /></p>



<pre class="wp-block-code"><code>Windows Registry Editor Version 5.00

&#91;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"LmCompatibilityLevel"=dword:00000001</code></pre>



<p>註：ntlm auth = yes 也要開，修改 /etc/samba/smb.conf ，然後重啟 nmbd/smbd</p>



<pre class="wp-block-code"><code>&#91;global]
ntlm auth = yes</code></pre>



<p>ref.<br />Samba and ntlm for Windows clients</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2021/04/15/4453/windows-10-%e5%ad%98%e5%8f%96-ubuntu-samba-%e5%95%8f%e9%a1%8c/">Windows 10 存取 Ubuntu Samba 問題</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2021/04/15/4453/windows-10-%e5%ad%98%e5%8f%96-ubuntu-samba-%e5%95%8f%e9%a1%8c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>KDE Plasma CPU High Usage After Install Nvidia Driver</title>
		<link>https://richliu.com/2021/03/07/4401/kde-plasma-cpu-high-usage-after-install-nvidia-driver/</link>
					<comments>https://richliu.com/2021/03/07/4401/kde-plasma-cpu-high-usage-after-install-nvidia-driver/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Sun, 07 Mar 2021 03:36:16 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[KDE]]></category>
		<category><![CDATA[Nvidia]]></category>
		<category><![CDATA[plasma]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4401</guid>

					<description><![CDATA[<p>My notebook with RTX3060 has this issue after do someth [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2021/03/07/4401/kde-plasma-cpu-high-usage-after-install-nvidia-driver/">KDE Plasma CPU High Usage After Install Nvidia Driver</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>My notebook with RTX3060 has this issue after do something I don&#8217;t know. OS is Ubuntu 18.04<br /><br />Everything is ok after first time install RTX3060, there is no high cpu issue, but after install IME(gcin), nomachine and anydesk and do something I don&#8217;t remember, plasma high cpu usage issue happened. </p>



<span id="more-4401"></span>



<p>Tried to uninstall anydesk, nomachine and gcin, but those actions cannot solve this issue. <br /><br />but one time, when plasma cpu usage 100%, the nvidia-smi command shows GPU usage 100%, so I think whether if prevent plasma to use nvidia, it might solve this issue temporary ? </p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="990" height="566" src="https://richliu.com/wp-content/uploads/2021/03/plasma-nvidia-normal.png" alt="" class="wp-image-4402" srcset="https://richliu.com/wp-content/uploads/2021/03/plasma-nvidia-normal.png 990w, https://richliu.com/wp-content/uploads/2021/03/plasma-nvidia-normal-600x343.png 600w, https://richliu.com/wp-content/uploads/2021/03/plasma-nvidia-normal-768x439.png 768w" sizes="auto, (max-width: 990px) 100vw, 990px" /><figcaption>Plasma CPU / GPU usage is normal</figcaption></figure>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="989" height="574" src="https://richliu.com/wp-content/uploads/2021/03/plasma-nvidia-cpu-high.png" alt="" class="wp-image-4403" srcset="https://richliu.com/wp-content/uploads/2021/03/plasma-nvidia-cpu-high.png 989w, https://richliu.com/wp-content/uploads/2021/03/plasma-nvidia-cpu-high-600x348.png 600w, https://richliu.com/wp-content/uploads/2021/03/plasma-nvidia-cpu-high-768x446.png 768w" sizes="auto, (max-width: 989px) 100vw, 989px" /><figcaption>Plasma CPU / GPU usage is high.</figcaption></figure>



<p>Notebook has intel i915 driver, so, prevent plasma to use GPU can solve this issue. <br /><br />First modify <code>/usr/share/X11/xorg.conf.d/11-nvidia-prime.conf</code> and replace it with text below </p>



<pre class="wp-block-code"><code># DO NOT EDIT. AUTOMATICALLY GENERATED BY gpu-manager

Section "OutputClass"
    Identifier "Nvidia Prime"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "IgnoreDisplayDevices" "CRT"
    # Option "PrimaryGPU" "Yes"
    ModulePath "/x86_64-linux-gnu/nvidia/xorg"
EndSection


Section "OutputClass"
    Identifier "intel"
    MatchDriver "i915"
    Driver "modesetting"
    Option "PrimaryGPU" "yes"
EndSection
</code></pre>



<p>Protect the file will not be overwrite by gpu-manager</p>



<pre class="wp-block-code"><code>chattr +i /usr/share/X11/xorg.conf.d/11-nvidia-prime.conf</code></pre>



<p>Reboot system and run nvidia-smi, plasma will not use nvidia GPU, so my plasma cpu usage 100% issue disappear. <br /><br />this solution might not solve all plasma 100% cpu usage issue, but might be one possible solution.</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="990" height="493" src="https://richliu.com/wp-content/uploads/2021/03/plasma-without-gpu.png" alt="" class="wp-image-4404" srcset="https://richliu.com/wp-content/uploads/2021/03/plasma-without-gpu.png 990w, https://richliu.com/wp-content/uploads/2021/03/plasma-without-gpu-600x299.png 600w, https://richliu.com/wp-content/uploads/2021/03/plasma-without-gpu-768x382.png 768w" sizes="auto, (max-width: 990px) 100vw, 990px" /><figcaption>Plasma without GPU</figcaption></figure>



<p>Detail information which can refer to this url  <a href="https://askubuntu.com/questions/1061551/how-to-configure-igpu-for-xserver-and-nvidia-gpu-for-cuda-work" target="_blank" rel="noopener">How to configure iGPU for xserver and nvidia GPU for CUDA work</a><br /></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2021/03/07/4401/kde-plasma-cpu-high-usage-after-install-nvidia-driver/">KDE Plasma CPU High Usage After Install Nvidia Driver</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2021/03/07/4401/kde-plasma-cpu-high-usage-after-install-nvidia-driver/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ARM64 Centos8/Ubuntu PXE Boot Install on Ubuntu Server</title>
		<link>https://richliu.com/2020/04/08/4263/arm64-centos8-pxe-boot/</link>
					<comments>https://richliu.com/2020/04/08/4263/arm64-centos8-pxe-boot/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Wed, 08 Apr 2020 08:21:38 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[aarch64]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[centos8]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[pxe]]></category>
		<category><![CDATA[pxeboot]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4263</guid>

					<description><![CDATA[<p>This document will introduce how to setup a centos PXE  [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2020/04/08/4263/arm64-centos8-pxe-boot/">ARM64 Centos8/Ubuntu PXE Boot Install on Ubuntu Server</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This document will introduce how to setup a centos PXE boot environment on ubuntu 18.04 for install centos8 to your ARM64 machine. <br /><br />In this document, it uses CentOS 8 version is 8.1.1911, it might also work on later version if you change file name accordingly .&nbsp;<br /><br />all command in this document we assume you already run with root permission.&nbsp;<br /></p>



<span id="more-4263"></span>



<h2 class="wp-block-heading">Hardware topology&nbsp;</h2>



<p>[ARM64 CLIENT] &lt;&#8212;&#8212;-&gt; [Server]&nbsp; &lt;&#8212;&#8212;-&gt; Internet&nbsp;</p>



<p>SERVER ethernet ip is 10.0.0.1 , another interface connect to internet.&nbsp;</p>



<p></p>



<h2 class="wp-block-heading">Install necessary packages&nbsp;<br /></h2>



<p>Install TFTP, HTTP and DHCPD Server and rpm2cpio&nbsp;<br /></p>



<p>$ apt install tftpd-hpa apache2 isc-dhcp-server rpm2cpio<br /></p>



<h2 class="wp-block-heading">Modify dhcpd server configuration&nbsp;<br /></h2>



<p>$ vim /etc/dhcp/dhcpd.conf<br /></p>



<p>following is example configuration,it can be changed to fit your environment&nbsp;</p>



<pre class="wp-block-verse">authoritative;
default-lease-time&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 259200;
max-lease-time&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 518400;
option routers&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10.0.0.1;
option subnet-mask&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 255.255.255.0;
option domain-name-servers&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 168.95.1.1,8.8.8.8;
ddns-update-style &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; interim;
ignore client-updates;
allow booting;
allow bootp;
allow unknown-clients;
server-name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pxis;

subnet 10.0.0.0 netmask 255.255.255.0 {
&nbsp;&nbsp;&nbsp;&nbsp;range 10.0.0.100 10.0.0.200;
&nbsp;&nbsp;&nbsp;&nbsp;option ip-forwarding off;
&nbsp;&nbsp;&nbsp;&nbsp;option subnet-mask&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 255.255.255.0;
&nbsp;&nbsp;&nbsp;&nbsp;next-server 10.0.0.1;
&nbsp;&nbsp;&nbsp;&nbsp;filename "shim.efi";

}</pre>



<h2 class="wp-block-heading">Modify tftpd setting&nbsp;<br /></h2>



<p>$ vim /etc/default/tftpd-hpa<br /></p>



<p>Add &#8211;create to TFTP_OPTIONS and change tftp directory to /tftpboot&nbsp;<br /></p>



<p>following is example configuration file&nbsp;</p>



<pre class="wp-block-preformatted">TFTP_USERNAME="tftp"<br />TFTP_DIRECTORY="/tftpboot"<br />TFTP_ADDRESS=":69"<br />TFTP_OPTIONS="--secure&nbsp; --create"</pre>



<h2 class="wp-block-heading">Restart Service&nbsp;<br /></h2>



<pre class="wp-block-preformatted">mkdir /tftpboot&nbsp;
/etc/init.d/tftpd-hpa restart
/etc/init.d/apache2 restart
/etc/init.d/isc-dhcp-server restart
</pre>



<h2 class="wp-block-heading">Get ARM64 pxeboot file&nbsp;</h2>



<p>some times the shim and grub2-efi would be erase, just visit mirror.centos.org and find new one than download it. </p>



<pre class="wp-block-preformatted">cd /tftpboot&nbsp;
wget http://mirror.centos.org/centos/8-stream/BaseOS/aarch64/os/Packages/shim-aa64-15-15.el8_2.aarch64.rpm
wget http://mirror.centos.org/centos/8-stream/BaseOS/aarch64/os/Packages/grub2-efi-aa64-2.02-106.el8.aarch64.rpm
rpm2cpio shim-aa64-15-15.el8_2.aarch64.rpm | cpio -dimv
rpm2cpio grub2-efi-aa64-2.02-106.el8.aarch64.rpm | cpio -dimv
cp ./boot/efi/EFI/centos/shim.efi .
cp ./boot/efi/EFI/centos/grubaa64.efi .
chmod +rx *.efi</pre>



<h2 class="wp-block-heading">Configure grub.conf&nbsp;<br /></h2>



<p>$ vim /tftpboot/grub.cfg<br /></p>



<p>Following is grub.conf example&nbsp;</p>



<pre class="wp-block-verse">set timeout=60<br />menuentry 'CentOS' {<br /> &nbsp;linux images/pxeboot/vmlinuz ip=dhcp inst.repo=http://10.0.0.1/centos8/<br />&nbsp;&nbsp;initrd images/pxeboot/initrd.img<br />}</pre>



<p>If your system support secure boot and you want to do it, please replace linux with linuxefi and replace initrd with initrdefi.&nbsp;</p>



<h2 class="wp-block-heading">Get CentOS 8 stream image and copy it to web server&nbsp;</h2>



<pre class="wp-block-preformatted">cd /var/www/html&nbsp;
wget <a href="https://mirror01.idc.hinet.net/centos/8-stream/isos/aarch64/CentOS-Stream-8-aarch64-20211202-dvd1.iso" target="_blank" rel="noopener">http://ftp.twaren.net/Linux/CentOS/8-stream/isos/x86_64/CentOS-Stream-8-x86_64-20220215-dvd1.iso</a>
mkdir disk&nbsp;
mount -o loop CentOS-Stream-8-x86_64-20220215-dvd1.iso disk
cp -a disk centos8&nbsp;
umount disk&nbsp;
rmdir disk

# copy boot file into tftp directory </pre>



<p>cd /tftpboot<br />cp /var/www/html/centos8/images/ . -a<br /></p>



<p>After copy all file into http file directory, it can visit via browser on server with URL <a href="http://10.0.0.1/centos8/">http://10.0.0.1/centos8/</a> to check whether file exist or not.&nbsp;<br /></p>



<h2 class="wp-block-heading">NAT<br /></h2>



<p>Server should support NAT function to forward packet.&nbsp;<br /><br />assume interface connect to internet is wls3 <br />Following is a sample command to enable Linux NAT function which can make client to access internet or intranet .&nbsp;</p>



<p>$ echo 1 &gt; /proc/sys/net/ipv4/ip_forward ==&gt; enable it immediately&nbsp;<br />$ iptables -t nat -A POSTROUTING -o wls3 -j MASQUERADE</p>



<p></p>



<p>Now, you can choose pxeboot on your ARM64 machine. if everything successful, you can see CentOS on your console if everything is ok .&nbsp;<br /></p>



<h2 class="wp-block-heading">Known Issue</h2>



<h3 class="wp-block-heading">Stdin: Invalid argument</h3>



<p>My system cannot boot into the Ubuntu install program for an unknown reason. After checking the system, it seems that the issue may be caused by an inability to access internet resources for some reason, even though the DNS and network appear to be fine. An alternative solution is to put the ISO on a website and assign the argument to the parameter. Here is an example using Ubuntu 22.04.</p>



<pre class="wp-block-preformatted">menuentry 'Ubuntu22.04 Net Install' {<br />linux ubuntu2204/vmlinuz ip=dhcp url=http://10.0.0.1/ubuntu-22.04.1-live-server-arm64.iso only-ubiquity<br />initrd ubuntu2204/initrd<br />}</pre>



<h2 class="wp-block-heading">Debug&nbsp;<br /></h2>



<p>Wireshark is your good friend, use it.&nbsp;<br /></p>



<h2 class="wp-block-heading">Ubuntu PXE Environment</h2>



<p>It can download Ubuntu Netboot images from this url. <br /> <a href="http://cdimage.ubuntu.com/netboot/" target="_blank" rel="noopener">http://cdimage.ubuntu.com/netboot/</a> <br /><br />Choice what you want, for example, url below is Ubuntu 18.04 for ARM64 image<br /> <a href="http://ports.ubuntu.com/ubuntu-ports/dists/bionic-updates/main/installer-arm64/current/images/netboot/" target="_blank" rel="noopener">http://ports.ubuntu.com/ubuntu-ports/dists/bionic-updates/main/installer-arm64/current/images/netboot/</a> <br />Ubuntu 20.04 Netboot file <br />http://ports.ubuntu.com/ubuntu-ports/dists/focal-updates/main/installer-arm64/current/legacy-images/netboot/netboot.tar.gz</p>



<p><br />Download netboot image to tftp directory, I prefer to put different version to different directory. </p>



<pre class="wp-block-code"><code>$ cd /tftpboot
$ wget http://ports.ubuntu.com/ubuntu-ports/dists/bionic-updates/main/installer-arm64/current/images/netboot/netboot.tar.gz
$ mkdir ubuntu1804
$ cd ubuntu1804
$ tar xvf ../netboot.tar.gz</code></pre>



<p>Modify grub.cfg and add Ubuntu option to grub.cfg, save it, now, this server can also provide ubuntu net install</p>



<pre class="wp-block-code"><code>set timeout=60
menuentry 'CentOS8 Install' {
  linux images/pxeboot/vmlinuz ip=dhcp inst.repo=http://10.0.0.1/centos8/
  initrd images/pxeboot/initrd.img
}
menuentry 'Ubuntu18.04 Install' {
  linux ubuntu1804/ubuntu-installer/arm64/linux ip=dhcp
  initrd ubuntu1804/ubuntu-installer/arm64/initrd.gz
}
</code></pre>



<h2 class="wp-block-heading">Ubuntu ISO environment </h2>



<p>It can download iso file and use the iso file as install media. <br /><br />in Linux, download Ubuntu 20.04 ARM64 iso file</p>



<pre class="wp-block-preformatted">$ wget https://cdimage.ubuntu.com/releases/20.04/release/ubuntu-20.04.3-live-server-arm64.iso
$ mount -o loop ubuntu-20.04.3-live-server-arm64.iso disk
$ mkdir ubuntu2004
$ cp disk/casper ubuntu2004/ -a 
$ umount disk</pre>



<p>Modify grub.cfg as below (not test)</p>



<pre class="wp-block-preformatted">set timeout=60
menuentry 'CentOS8 Install' {
  linux images/pxeboot/vmlinuz ip=dhcp inst.repo=http://10.0.0.1/centos8/
  initrd images/pxeboot/initrd.img
}
menuentry 'Ubuntu20.04 Install' {
  linux ubuntu2004/casper/vmlinuz ip=dhcp
  initrd ubuntu2004/casper/initrd
}
</pre>



<p>It also can use HWE kernel </p>



<pre class="wp-block-preformatted">menuentry 'Ubuntu20.04 Install' {
  linux ubuntu2004/casper/hwe-vmlinux ip=dhcp
  initrd ubuntu2004/casper/hwe-initrd
}

</pre>



<h2 class="wp-block-heading">Note for GRUB Install Command</h2>



<h2 class="wp-block-heading">CentOS</h2>



<pre class="wp-block-preformatted">svr=10.0.0.1; root=boot/centos8/images/pxeboot
linux (http,$svr)/$root/vmlinuz inst.stage2=http://$svr/boot/centos8 text
initrd (http,$svr)/$root/initrd.img
</pre>



<h2 class="wp-block-heading">Ubuntu</h2>



<pre class="wp-block-preformatted">svr=192.168.110.254; root=boot/ubuntu2004/casper
iso=ubuntu-20.04.3-live-server-arm64.iso
linux (http,$svr)/$root/vmlinuz url=http://192.168.110.254/boot/$iso only-ubiquity ip=dhcp ---
initrd (http,$svr)/$root/initrd

linux (http,$svr)/$root/hwe-vmlinuz url=http://192.168.110.254/boot/$iso only-ubiquity ip=dhcp ---
initrd (http,$svr)/$root/hwe-initrd

</pre>



<h2 class="wp-block-heading">Fedora 36</h2>



<p>Fedora&#8217;s setting is more closed to CentOS, due to CentOS might be dropped recently, so, moved to Fedora environment is necessary. </p>



<h3 class="wp-block-heading">Get initrd/vmlinux image</h3>



<p>Other parts like CentOS, <br />Download the PXE initrd and vmlinuz image, free.nchc.org.tw is Taiwan local Fedora server, you can replace it with local server. </p>



<pre class="wp-block-preformatted">mkdir -p /tftpboot/f36

cd /tftpboot/f36
wget http://free.nchc.org.tw/fedora/linux/releases/36/Server/aarch64/os/images/pxeboot/initrd.img
wget http://free.nchc.org.tw/fedora/linux/releases/36/Server/aarch64/os/images/pxeboot/vmlinuz

cd /var/www/html
wget http://free.nchc.org.tw/fedora/linux/releases/36/Server/aarch64/iso/Fedora-Server-dvd-aarch64-36-1.5.iso
mkdir disk 
mount -o loop Fedora-Server-dvd-aarch64-36-1.5.iso disk
cp -a disk f36
umount disk</pre>



<h3 class="wp-block-heading">Grub Fedora Setting</h3>



<p>Add following grub entry text into /tftpboot/grub.cfg, thus, it can insert a &#8220;Fedora36&#8221; menu on pxe boot.</p>



<pre class="wp-block-preformatted">menuentry 'Fedora36' {
  linux f36/vmlinuz ip=dhcp inst.repo=http://10.0.0.1/f36/
  initrd f36/initrd.img
}
</pre>



<p>Ref.&nbsp;</p>



<p><a href="https://docs.centos.org/en-US/centos/install-guide/pxe-server/#sect-network-boot-setup-uefi" target="_blank" rel="noopener">https://docs.centos.org/en-US/centos/install-guide/pxe-server/#sect-network-boot-setup-uefi</a><br /><a href="https://docs.centos.org/en-US/8-docs/advanced-install/assembly_preparing-for-a-network-install/" target="_blank" rel="noopener">https://docs.centos.org/en-US/8-docs/advanced-install/assembly_preparing-for-a-network-install/</a><br /><a href="https://forums.opensuse.org/showthread.php/501075-error-cannot-find-commands-linuxefi-or-initrdefi" target="_blank" rel="noopener">https://forums.opensuse.org/showthread.php/501075-error-cannot-find-commands-linuxefi-or-initrdefi</a></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2020/04/08/4263/arm64-centos8-pxe-boot/">ARM64 Centos8/Ubuntu PXE Boot Install on Ubuntu Server</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2020/04/08/4263/arm64-centos8-pxe-boot/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Netplan Bridge Setup</title>
		<link>https://richliu.com/2019/12/17/4253/netplan-bridge-setup/</link>
					<comments>https://richliu.com/2019/12/17/4253/netplan-bridge-setup/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Tue, 17 Dec 2019 15:17:28 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[bridge]]></category>
		<category><![CDATA[netplan]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4253</guid>

					<description><![CDATA[<p>Backup for mysalves ref https://netplan.io/examples</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/12/17/4253/netplan-bridge-setup/">Netplan Bridge Setup</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Backup for mysalves </p>



<pre class="wp-block-code"><code>network:
  version: 2
  renderer: networkd
  ethernets:
    enP6p1s0:
      dhcp4: no
  bridges:
    br0:
      dhcp4: no
      interfaces:
         - enP6p1s0
      addresses: [192.168.110.254/16]
      gateway4: 192.168.1.1
      nameservers:
              addresses: [8.8.8.8,8.8.8.4]
      dhcp4: no
</code></pre>



<p>ref<br /> <a href="https://netplan.io/examples" target="_blank" rel="noopener">https://netplan.io/examples</a> </p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/12/17/4253/netplan-bridge-setup/">Netplan Bridge Setup</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2019/12/17/4253/netplan-bridge-setup/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspberry 4 Pi + Kubuntu</title>
		<link>https://richliu.com/2019/11/01/4212/raspberry-4-pi-kubuntu/</link>
					<comments>https://richliu.com/2019/11/01/4212/raspberry-4-pi-kubuntu/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Fri, 01 Nov 2019 08:01:04 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[kubuntu]]></category>
		<category><![CDATA[Raspberry pi]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4212</guid>

					<description><![CDATA[<p>買了二塊 Raspberry 4 Pi 回來，本來是準備裝 K8s 的，但是在這之前要先跑個 ubuntu i [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/11/01/4212/raspberry-4-pi-kubuntu/">Raspberry 4 Pi + Kubuntu</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="alignright is-resized"><img loading="lazy" decoding="async" src="https://richliu.com/wp-content/uploads/2019/11/image-1024x576.png" alt="" class="wp-image-4213" width="254" height="142" srcset="https://richliu.com/wp-content/uploads/2019/11/image-1024x576.png 1024w, https://richliu.com/wp-content/uploads/2019/11/image-300x169.png 300w, https://richliu.com/wp-content/uploads/2019/11/image-768x432.png 768w, https://richliu.com/wp-content/uploads/2019/11/image.png 1920w" sizes="auto, (max-width: 254px) 100vw, 254px" /></figure></div>



<p>買了二塊 Raspberry 4 Pi 回來，本來是準備裝 K8s 的，但是在這之前要先跑個 ubuntu image 才對.<br /><br />我買 Raspberry 4 Pi 的時候知道他要用 5V3A 的電源，但是我沒有想到我自己沒有 5V3A 的 USB 變壓器，手機用的含 Apple 87W USB-C 變壓器都不足瓦<br />Apple 87W 只能輸出 5V 2.4A <br />最後找了一個 Sony 可以輸出 5V 2.7A 才可以用，所以如果要買 Raspberry Pi 4 的人請注意一下<br /><br />另外這一塊的外接是 Micro-HDMI，我也忘了買，記得還要加買 SD Card </p>



<span id="more-4212"></span>



<p>Image 看 Ubuntu 網站上的說明，應該給 Pi 3 的就可以用，可以到這邊<br /> <a href="http://cdimage.ubuntu.com/ubuntu/releases/18.04.3/release/" target="_blank" rel="noopener">http://cdimage.ubuntu.com/ubuntu/releases/18.04.3/release/</a> <br />下載  <a href="http://cdimage.ubuntu.com/ubuntu/releases/18.04.3/release/ubuntu-18.04.3-preinstalled-server-arm64+raspi3.img.xz" target="_blank" rel="noopener">ubuntu-18.04.3-preinstalled-server-arm64+raspi3.img.xz</a>  解開之後燒到 flash 上就可以用了<br /><br />我是用 <a rel="noreferrer noopener" aria-label="Raspberry Pi 4 Ubuntu Server / Desktop 18.04.3 Image (unofficial) (opens in a new tab)" href="https://jamesachambers.com/raspberry-pi-4-ubuntu-server-desktop-18-04-3-image-unofficial/" target="_blank">Raspberry Pi 4 Ubuntu Server / Desktop 18.04.3 Image (unofficial)</a> 這個網站的 Image，下載 ubuntu-18.04.3-preinstalled-server-arm64+raspi4.img 燒到 Flash 上就可以。如果你是 Windows ，可以用 <a rel="noreferrer noopener" aria-label="Refus  (opens in a new tab)" href="https://rufus.ie/" target="_blank">Refus </a> 燒錄 image 到 SD Card 上. <br /><br />將 Micro-HDMI 接到螢幕上，應該就可以看到訊息，預設的帳號和密碼是 ubuntu/ubuntu <br />看起來是 cloud-image 改的。</p>



<h4 class="wp-block-heading">Install KDE Desktop</h4>



<p>安裝 KDE Desktop 也很簡單</p>



<pre class="wp-block-preformatted">apt update
apt install -y kubuntu-desktop
/etc/init.d/sddm restart</pre>



<p>記得接上 USB Keyboard/ Mouse ，這樣應該就會看到 Login 畫面了<br /><br />我用這個 image 看起來 audio 輸出有問題，我試過耳機輸出沒有聲音，早先一點拿 Raspberry 4 Pi 用的 Game emulator 玩起來是沒有問題的。<br /><br />不過也不是真的要拿來跑 desktop ，所以無所謂<br />看 Youtube 的速度也很慢，當 Aspire One 那個年代的小電腦玩一下可以，或是架架實驗環境很好，要當 desktop 不要拿來跑大型程式應該沒問題.</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/11/01/4212/raspberry-4-pi-kubuntu/">Raspberry 4 Pi + Kubuntu</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2019/11/01/4212/raspberry-4-pi-kubuntu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Install Kubernetes on ARM64 Ubuntu 18.04 (with QEMU)</title>
		<link>https://richliu.com/2019/09/25/4160/install-kubernetes-on-arm64-ubuntu-18-04/</link>
					<comments>https://richliu.com/2019/09/25/4160/install-kubernetes-on-arm64-ubuntu-18-04/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Wed, 25 Sep 2019 03:39:36 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[18.04]]></category>
		<category><![CDATA[aarch64]]></category>
		<category><![CDATA[flannel. qemu]]></category>
		<category><![CDATA[k8s]]></category>
		<category><![CDATA[kubernetes]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[weave]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4160</guid>

					<description><![CDATA[<p>Install Kubernetes on Ubuntu 18.04 is very easy now, bu [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/09/25/4160/install-kubernetes-on-arm64-ubuntu-18-04/">Install Kubernetes on ARM64 Ubuntu 18.04 (with QEMU)</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Install Kubernetes on Ubuntu 18.04 is very easy now, but only for x86 platform. If on ARM64 environment, it might have some other problem. <br />Some old article mentioned a lot of information but software version is too old for deploy a new version software. <br /><br />After a lot of time to have research, here is instruction for how to install Kubernetes on ARM64 Ubuntu 18.04</p>



<span id="more-4160"></span>



<h2 class="wp-block-heading">Environment</h2>



<p>Hardware : Ampere eMag Server with 128G RAM and 1T storage<br />Kubernetes master and nodes are running in QEMU image, so, we prepared three QEMU  ARM64 ubuntu 18.04 images for kubernetes running. It also can use two VM to run this demo. </p>



<h2 class="wp-block-heading">Prepare QEMU Image</h2>



<p>It can download Ubuntu bionic cloud image from Taiwan mirror site</p>



<pre class="wp-block-preformatted">wget http://ftp.yzu.edu.tw/Linux/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-arm64.img </pre>



<p>or international mirror site </p>



<pre class="wp-block-preformatted">https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-arm64.img</pre>



<h4 class="wp-block-heading">Install Necessary Package  </h4>



<p>Run following command to install necessary packages . </p>



<pre class="wp-block-preformatted">apt install -y qemu-system-arm bridge-utils cloud-image-utils git qemu-efi</pre>



<h4 class="wp-block-heading">Increase QEMU image size</h4>



<pre class="wp-block-preformatted">qemu-img resize bionic-server-cloudimg-arm64.img +200G</pre>



<p>Create UEFI bios and nvram for qemu image boot. </p>



<pre class="wp-block-preformatted">dd if=/dev/zero of=flash0.img bs=1M count=64
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of=flash0.img conv=notrunc
dd if=/dev/zero of=flash1.img bs=1M count=64</pre>



<p>Copy Image to three spare images </p>



<pre class="wp-block-preformatted">cp flash0.img flash0-1.img
cp flash0.img flash0-2.img 
cp flash0.img flash0-3.img 
cp flash1.img flash1-1.img
cp flash1.img flash1-2.img
cp flash1.img flash1-3.img
cp  bionic-server-cloudimg-arm64.img   bionic-server-cloudimg-arm64-1.img 
cp  bionic-server-cloudimg-arm64.img   bionic-server-cloudimg-arm64-2.img 
cp  bionic-server-cloudimg-arm64.img   bionic-server-cloudimg-arm64-3.img </pre>



<h2 class="wp-block-heading"> Set up bridge and network devices </h2>



<p>

We already install bridge-utils before, now, it should configure bridge devices.

</p>



<pre class="wp-block-preformatted"> mkdir -p /etc/qemu ; echo "allow br0" > /etc/qemu/bridge.conf </pre>



<p> Because there is only one network interface on machine, we should use this interface as bridge device, save text below (name nic-br.sh or what you like) and modify it to fit your environment. <br /></p>



<pre class="wp-block-preformatted">ORIGNIC=enP6p1s0
ip addr flush $ORIGINIC
brctl addbr br0
brctl addif br0 $ORIGINIC
ifconfig br0 up
ifconfig br0 192.168.110.1 netmask 255.255.0.0
route add default gw 192.168.1.1
echo nameserver 8.8.8.8 &gt;&gt; /etc/resolv.conf </pre>



<h2 class="wp-block-heading">Configure Hugepage On Host Site (Option)</h2>



<p>Due to previous research on dpdk runs on ARM64 server, so, configure hugepages here. But not necessary for run k8s environment. <br />You can ignore this part </p>



<h4 class="wp-block-heading"> Configure Line Kernel boot command </h4>



<p> It needs to reserve hugepages memory space for Linux kernel, it reserves 32 pages and each pages 1GB, total 32GB. Please modify /etc/default/grub , and add hugepagesz=1GB hugepages=32 to GRUB_CMDLINE_LINUX, ex: </p>



<pre class="wp-block-preformatted">GRUB_CMDLINE_LINUX="console=tty0 hugepagesz=1GB hugepages=32"</pre>



<p> then run foloowing command to update grub.cfg </p>



<pre class="wp-block-preformatted"> update-grub </pre>



<h4 class="wp-block-heading"> Mount hugetlbfs by default </h4>



<p>

If wants to use hugepage, it needs to mount hugetlbfs somewhere, we can create a directory, ex: /mnt/hugepages and mount hugetblsfs there by default.

</p>



<pre class="wp-block-preformatted">mkdir -p /mnt/hugepages 
echo "nodev   /mnt/hugepages                  hugetlbfs       defaults,pagesize=1G    0 0 none" &gt;&gt; /etc/fstab </pre>



<p>Now, please reboot to make huagpage works. </p>



<h2 class="wp-block-heading">Running QEMU</h2>



<p>Following is QEMU script, save it (ex: named run-qemu.sh). It can be more simplification, but this script would be more understand what different. </p>



<pre class="wp-block-preformatted">IMAGE1=bionic-server-cloudimg-arm64-1.img
sudo qemu-system-aarch64 -name vm1 \
         -machine virt,gic_version=3,accel=kvm,usb=off \
         -cpu host -m 8192 \
         -uuid d0000000-1111-1111-1111-11111aaaaaaa \
         -smp 12,sockets=1,cores=12,threads=1 \
         -nographic -nodefaults \
         -pflash flash0-1.img -pflash flash1-1.img \
         -drive file=$IMAGE1,if=none,id=disk1 \
         -device virtio-blk-device,scsi=off,drive=disk1,id=virtio-disk1,bootindex=1 \
         -netdev tap,id=net0,ifname=tap0 \
         -device virtio-net-device,netdev=net0,mac=52:54:00:11:11:11 \
         -mem-path /mnt/hugepages \
         -serial telnet::9001,server,nowait &gt; guest_log-1.txt 2&gt;&gt; guest_log-1.txt &amp;
IMAGE2=bionic-server-cloudimg-arm64-2.img
sudo qemu-system-aarch64 -name vm2 \
         -machine virt,gic_version=3,accel=kvm,usb=off \
         -cpu host -m 8192 \
         -uuid d0000000-2222-2222-2222-22222bbbbbbb \
         -smp 12,sockets=1,cores=12,threads=1 \
         -nographic -nodefaults \
         -pflash flash0-2.img -pflash flash1-2.img \
         -drive file=$IMAGE2,if=none,id=disk2 \
         -device virtio-blk-device,scsi=off,drive=disk2,id=virtio-disk1,bootindex=1 \
         -netdev tap,id=net2,ifname=tap1 \
         -device virtio-net-device,netdev=net2,mac=52:54:00:22:22:22 \
         -mem-path /mnt/hugepages \
         -serial telnet::9002,server,nowait &gt; guest_log-2.txt 2&gt;&gt; guest_log-2.txt &amp;
IMAGE3=bionic-server-cloudimg-arm64-3.img
sudo qemu-system-aarch64 -name vm3 \
         -machine virt,gic_version=3,accel=kvm,usb=off \
         -cpu host -m 8192 \
         -uuid d0000000-3333-3333-3333-33333ccccccc \
         -smp 12,sockets=1,cores=12,threads=1 \
         -nographic -nodefaults \
         -pflash flash0-3.img -pflash flash1-3.img \
         -drive file=$IMAGE3,if=none,id=disk3 \
         -device virtio-blk-device,scsi=off,drive=disk3,id=virtio-disk1,bootindex=1 \
         -netdev tap,id=net3,ifname=tap2 \
         -device virtio-net-device,netdev=net3,mac=52:54:00:33:33:33 \
         -mem-path /mnt/hugepages \
         -serial telnet::9003,server,nowait &gt; guest_log-3.txt 2&gt;&gt; guest_log-3.txt &amp;
sleep 5
brctl addif br0 tap0
brctl addif br0 tap1
brctl addif br0 tap2</pre>



<p>There are some parameters need to understand in QEMU script. <br /><br />-uuid d0000000-1111-1111-1111-11111aaaaaaa \<br /><br />this will assign a unique uuid for each VM, k8s needs different VM run with different uuid and MAC address. <br />It also can use command &#8220;uuidgen&#8221; to generate different uuid for each VM, but here just for debug so assign a &#8220;easy to read&#8221; uuid. <br /><br />-device virtio-net-device,netdev=net3,mac=52:54:00:33:33:33 \<br /><br />Assign a special mac address for VM, because for k8s internal communication, use the same mac address will cause problem, please configure different address before run qemu script. It not easy to modify it after first boot (with cloud image)<br /><br />* Notice, first number for mac address cannot be odd , it would cause problem. <br /><br />-mem-path /mnt/hugepages \<br /><br />Tell VM to use hugepage, if were not configure host with hugepage, please remove this line. </p>



<p>Now,  please run scripts </p>



<pre class="wp-block-preformatted">bash nic-br.sh
bash run-qemu.sh </pre>



<p>Now, it can use telnet to connect each VM&#8217;s console </p>



<pre class="wp-block-preformatted">telnet localhost 9001<br /># or <br />telnet localhost 9002<br /># or <br />telnet localhost 9003</pre>



<p>After system booted/initialed, if you cannot login, please &#8220;killall qemu-system-aarch64&#8221; and follow this article <a href="https://richliu.com/2017/08/31/2165/change-ubuntu-cloud-image-password">Change Ubuntu Cloud Image Password</a> to change all images&#8217;s password.  <br /><br />Somehow, for recent cloud image, it cannot modify password before run qemu script.</p>



<h2 class="wp-block-heading">Install Kubernetes </h2>



<p>There are a lot of article to talk about how to install on Ubuntu, I choice one for reference : <a href="https://vitux.com/install-and-deploy-kubernetes-on-ubuntu/" target="_blank" rel="noopener">Install and Deploy Kubernetes on Ubuntu 18.04 LTS</a><br /><br />Below will shortly note install command here. </p>



<h4 class="wp-block-heading">Install Docker and Kubeadm on every node </h4>



<pre class="wp-block-preformatted">sudo apt update 
sudo apt -y upgrade 

# install and enable docker
sudo apt -y install docker.io 
sudo systemctl enable docker 
sudo systemctl start docker 

# Install k8s
sudo apt -y install apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add 
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt update
sudo apt-get install kubeadm -y</pre>



<h4 class="wp-block-heading">Configure Network IP address (Optional)</h4>



<p> Update to you network environment, here we used fix ip address.<br /><br /> Add new record to /etc/hosts   </p>



<pre class="wp-block-preformatted">192.168.110.50     k8s-master
192.168.110.60     k8s-worker-node1
192.168.110.70     k8s-worker-node2</pre>



<p>Please modify /etc/netplan/50-cloud-init.yam, remove dhcp and add fix address. remember, each node has different IP.  Following is only for k8s-master. </p>



<pre class="wp-block-preformatted">network:
     ethernets:
         eth0:
<strong>             addresses: [192.168.110.50/16,]
             gateway4: 192.168.1.1
             nameservers:
                 addresses: [8.8.8.8,8.8.4.4]</strong>
             match:
                 macaddress: '52:54:00:11:11:11'
             set-name: eth0
     version: 2</pre>



<h4 class="wp-block-heading">Configure Host name </h4>



<p>Run following command on master node </p>



<pre class="wp-block-preformatted">sudo hostnamectl set-hostname  k8s-master</pre>



<p> Run following command on other nodes</p>



<pre class="wp-block-preformatted">sudo hostnamectl set-hostname   k8s-worker-node1 
sudo hostnamectl set-hostname   k8s-worker-node2</pre>



<h4 class="wp-block-heading">Disable swap (Option)</h4>



<p>if image is not from cloud image, default Linux enabled swap function, k8s doesn&#8217;t support it, please disable it manually on all nodes and remove swap mount in /etc/fstab. </p>



<pre class="wp-block-preformatted"> sudo swapoff -a </pre>



<h2 class="wp-block-heading">Configure Kubernetes</h2>



<p>Now, we can initial Kubernetes. Run following command</p>



<pre class="wp-block-preformatted"> sudo kubeadm init --pod-network-cidr=10.244.0.0/16 </pre>



<p>wait for few minutes, it will show some result like this </p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="749" src="https://richliu.com/wp-content/uploads/2019/09/image-1024x749.png" alt="" class="wp-image-4172" srcset="https://richliu.com/wp-content/uploads/2019/09/image-1024x749.png 1024w, https://richliu.com/wp-content/uploads/2019/09/image-300x220.png 300w, https://richliu.com/wp-content/uploads/2019/09/image-768x562.png 768w, https://richliu.com/wp-content/uploads/2019/09/image.png 1398w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Run following command to assign current account has right to access k8s. </p>



<pre class="wp-block-preformatted">mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config</pre>



<p>Run this command on another node(k8s-worker-node1 and k8s-worker-node2).</p>



<pre class="wp-block-preformatted">sudo kubeadm join 192.168.110.50:6443 --token 46c1oj.i00vyfyn027pgew9 \
     --discovery-token-ca-cert-hash sha256:ed05198cc603ae009a862477bacef329a9e9a2bedc4a040bc4731e6d5cf4f48e</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="737" src="https://richliu.com/wp-content/uploads/2019/09/image-1-1024x737.png" alt="" class="wp-image-4174" srcset="https://richliu.com/wp-content/uploads/2019/09/image-1-1024x737.png 1024w, https://richliu.com/wp-content/uploads/2019/09/image-1-300x216.png 300w, https://richliu.com/wp-content/uploads/2019/09/image-1-768x552.png 768w, https://richliu.com/wp-content/uploads/2019/09/image-1.png 1204w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Run get nodes command, it will show current status, the master node status is NotReady, but don&#8217;t worry, it will become Ready after add pod and CNI (container networking interface) plugin. </p>



<pre class="wp-block-preformatted">ubuntu@k8s-master:~$ kubectl get nodes
 NAME         STATUS     ROLES    AGE     VERSION
 k8s-master   NotReady   master   3m42s   v1.16.0</pre>



<p>This action is very import on ARM64 k8s platform, in other document, they told you use flannel or some other document told you used old flannel. all of them not work for me. Please instead flannel with weave net. <br />(Ref <a rel="noreferrer noopener" aria-label="Weave Net for NetworkPolicy (opens in a new tab)" href="https://kubernetes.io/docs/tasks/administer-cluster/network-policy-provider/weave-network-policy/" target="_blank">Weave Net for NetworkPolicy</a> and <a rel="noreferrer noopener" aria-label="CoreDNS is not starting on Ubuntu 18.04.Bionic Beaver #980 (opens in a new tab)" href="https://github.com/kubernetes/kubeadm/issues/980" target="_blank">CoreDNS is not starting on Ubuntu 18.04.Bionic Beaver #980</a>)<br />Run following command to install weave net </p>



<pre class="wp-block-preformatted">kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="232" src="https://richliu.com/wp-content/uploads/2019/09/image-2-1024x232.png" alt="" class="wp-image-4175" srcset="https://richliu.com/wp-content/uploads/2019/09/image-2-1024x232.png 1024w, https://richliu.com/wp-content/uploads/2019/09/image-2-300x68.png 300w, https://richliu.com/wp-content/uploads/2019/09/image-2-768x174.png 768w, https://richliu.com/wp-content/uploads/2019/09/image-2.png 1397w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p> Use the following command to view the status of the network:</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="330" src="https://richliu.com/wp-content/uploads/2019/09/image-3-1024x330.png" alt="" class="wp-image-4176" srcset="https://richliu.com/wp-content/uploads/2019/09/image-3-1024x330.png 1024w, https://richliu.com/wp-content/uploads/2019/09/image-3-300x97.png 300w, https://richliu.com/wp-content/uploads/2019/09/image-3-768x248.png 768w, https://richliu.com/wp-content/uploads/2019/09/image-3-620x200.png 620w, https://richliu.com/wp-content/uploads/2019/09/image-3.png 1398w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p> Get nodes again. </p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="142" src="https://richliu.com/wp-content/uploads/2019/09/image-4-1024x142.png" alt="" class="wp-image-4177" srcset="https://richliu.com/wp-content/uploads/2019/09/image-4-1024x142.png 1024w, https://richliu.com/wp-content/uploads/2019/09/image-4-300x42.png 300w, https://richliu.com/wp-content/uploads/2019/09/image-4-768x107.png 768w, https://richliu.com/wp-content/uploads/2019/09/image-4.png 1395w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Great!! it works. </p>



<h2 class="wp-block-heading">MicroK8s</h2>



<p>If you think steps above are too complex and you would like to only run k8s on one machine, microk8s is a good friend for you, can run on ARM64 and very easy to use, just run command </p>



<p>sudo snap install microk8s</p>



<p>And just add a prefix &#8220;microk8s.&#8221; before k8s command, ex:</p>



<pre class="wp-block-preformatted">microk8s.kubectl get nodes</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="854" height="133" src="https://richliu.com/wp-content/uploads/2019/09/image-5.png" alt="" class="wp-image-4178" srcset="https://richliu.com/wp-content/uploads/2019/09/image-5.png 854w, https://richliu.com/wp-content/uploads/2019/09/image-5-300x47.png 300w, https://richliu.com/wp-content/uploads/2019/09/image-5-768x120.png 768w" sizes="auto, (max-width: 854px) 100vw, 854px" /></figure>



<p>See, it&#8217;s very easy to use. right?</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/09/25/4160/install-kubernetes-on-arm64-ubuntu-18-04/">Install Kubernetes on ARM64 Ubuntu 18.04 (with QEMU)</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2019/09/25/4160/install-kubernetes-on-arm64-ubuntu-18-04/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu 18.04 Change Mac Address on QEMU via Netplan</title>
		<link>https://richliu.com/2019/09/09/4146/ubuntu18-04changemacaddressonqemuvianetplan/</link>
					<comments>https://richliu.com/2019/09/09/4146/ubuntu18-04changemacaddressonqemuvianetplan/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Mon, 09 Sep 2019 15:40:32 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[mac address]]></category>
		<category><![CDATA[netplan]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4146</guid>

					<description><![CDATA[<p>This is a quick note about how to modify mac address fo [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/09/09/4146/ubuntu18-04changemacaddressonqemuvianetplan/">Ubuntu 18.04 Change Mac Address on QEMU via Netplan</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This is a quick note about how to modify mac address for qemu image with ubuntu 18.04 cloud image. <br /><br />but I have not found a working way only change mac address in system </p>



<span id="more-4146"></span>



<h4 class="wp-block-heading">Add mac parameter to qemu command</h4>



<p>in qemu command line, add mac= parameter to netdev option , ex:</p>



<pre class="wp-block-preformatted">-device virtio-net-device,netdev=net2,<strong>mac=52:54:00:56:12:34</strong> \</pre>



<h4 class="wp-block-heading">Modify netplan</h4>



<p>edit file /etc/netplan/50-cloud-init.yaml, and add section match, ex</p>



<pre class="wp-block-preformatted">network:
     version: 2
     ethernets:
         eth0:
             dhcp4: true
<strong>             match:
                 macaddress: 52:54:00:56:12:34</strong>
             set-name: eth0</pre>



<p>now, you can shutdown qemu system and restart . <br /><br />* Notice: if used ubuntu cloud image, please assign mac address before init it. <br />suppose that cloud image might save mac address some where . </p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/09/09/4146/ubuntu18-04changemacaddressonqemuvianetplan/">Ubuntu 18.04 Change Mac Address on QEMU via Netplan</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2019/09/09/4146/ubuntu18-04changemacaddressonqemuvianetplan/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu 18.04 ARM64 DPDK in VM (QEMU)</title>
		<link>https://richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/</link>
					<comments>https://richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Mon, 19 Aug 2019 08:17:56 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[18.04]]></category>
		<category><![CDATA[aarch64]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[dpdk]]></category>
		<category><![CDATA[hugepages]]></category>
		<category><![CDATA[l3fwd]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4057</guid>

					<description><![CDATA[<p>DPDK is a very popular infrastructure in high speed pac [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/">Ubuntu 18.04 ARM64 DPDK in VM (QEMU)</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>DPDK is a very popular infrastructure in high speed packet process domain, some applications will used the same architecture to process packet, like EPC. <br /><br />For Ubuntu 18.04, it used dpdk 17.11, it not good for some other application like dpdk pktgen, but enough for testpmd and l3fwd test. here is some personal note for setup whole environment. </p>



<figure class="wp-block-image is-resized"><img loading="lazy" decoding="async" src="https://richliu.com/wp-content/uploads/2019/08/image-3.png" alt="" class="wp-image-4076" width="363" height="257" srcset="https://richliu.com/wp-content/uploads/2019/08/image-3.png 634w, https://richliu.com/wp-content/uploads/2019/08/image-3-300x213.png 300w" sizes="auto, (max-width: 363px) 100vw, 363px" /><figcaption>DPDK in QEMU archeticture</figcaption></figure>



<span id="more-4057"></span>



<p>Hardware : Ampere eMag Server with 128GB Memory <br />                      Network Card: Intel i210 Gigabit NIC Card * 2 <br /><br />HOST means commands and instructions on host machines <br />VM means commands and instructions inside VM</p>



<h2 class="wp-block-heading">Prepare Environment</h2>



<h4 class="wp-block-heading">Apt source</h4>



<p>First, please add deb-src to your database, edit file /etc/apt/source.list and removed all &#8220;#&#8221; before deb-src, then, run follow commands to update apt database (suppose all commands run with sudo or root in this article)</p>



<pre class="wp-block-preformatted">sed -i 's/# deb-src/deb-src/g' sources.list
apt update</pre>



<h4 class="wp-block-heading">Install Packages</h4>



<p>It needs to install relative packages in host </p>



<pre class="wp-block-preformatted">sudo apt install -y dpdk dpdk-dev dpdk-doc </pre>



<p>Only needs to install on HOST.</p>



<pre class="wp-block-preformatted">sudo apt install -y qemu-efi bridge-utils</pre>



<p>It will install all necessary dpdk packages in host.</p>



<h4 class="wp-block-heading">Preload Module</h4>



<p>It needs to preload vfio-pci modules by default, run following command</p>



<pre class="wp-block-preformatted">echo "vfio-pci" &gt;&gt; /etc/modules</pre>



<h4 class="wp-block-heading">Configure Line Kernel boot command</h4>



<p>It needs to reserve hugepages memory space for Linux kernel, it reserves 32 pages and each pages 1GB, total 32GB. Please modify  /etc/default/grub , and  add hugepagesz=1GB hugepages=32 to GRUB_CMDLINE_LINUX, ex:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>GRUB_CMDLINE_LINUX=&#8221;console=tty0 hugepagesz=1GB hugepages=32&#8243;</p></blockquote>



<p>then run foloowing command to update grub.cfg</p>



<pre class="wp-block-preformatted">update-grub</pre>



<p>Mount hugetlbfs by default</p>



<p>If wants to use hugepage, it needs to mount hugetlbfs somewhere, we can create a directory, ex: /mnt/hugepages and mount hugetblsfs there by default. </p>



<pre class="wp-block-preformatted">mkdir -p /mnt/hugepages
echo "nodev   /mnt/hugepages                  hugetlbfs       defaults,pagesize=1G    0 0 none" &gt;&gt; /etc/fstab</pre>



<h2 class="wp-block-heading">Bind Network Card for DPDK</h2>



<p>It wants to let DPDK use current network card, it needs to bind the network card with dpdk. dpdk-devbind command is a useful command. <br />List current command </p>



<pre class="wp-block-preformatted"> $ dpdk-devbind --status
 Network devices using kernel driver
 0001:01:00.0 'I210 Gigabit Network Connection 1533' if=enP1p1s0 drv=igb unused=vfio-pci
 0002:01:00.0 'I210 Gigabit Network Connection 1533' if=enP2p1s0 drv=igb unused=vfio-pci
 0006:01:00.0 'I210 Gigabit Network Connection 1533' if=enP6p1s0 drv=igb unused=vfio-pci <em>Active</em> </pre>



<p>There are three network card in the machine, we would like to bind 1:1:0.0 and 2:1:0.0 to vfio-pci driver. please used following command to bind those network cards. </p>



<pre class="wp-block-preformatted">dpdk-devbind -b vfio-pci 0001:01:00.0 0002:01:00.0</pre>



<p>and check status again</p>



<pre class="wp-block-preformatted"> $ dpdk-devbind --status

Network devices using DPDK-compatible driver
============================================
0001:01:00.0 'I210 Gigabit Network Connection 1533' drv=vfio-pci unused=igb
0002:01:00.0 'I210 Gigabit Network Connection 1533' drv=vfio-pci unused=igb

Network devices using kernel driver
============================================
0006:01:00.0 'I210 Gigabit Network Connection 1533' if=enP6p1s0 drv=igb unused=vfio-pci <em>Active</em> </pre>



<p>Both network cards would be under  Network devices using DPDK-compatible driver  . </p>



<h2 class="wp-block-heading">Prepare QEMU environment </h2>



<h4 class="wp-block-heading">Set up bridge devices  </h4>



<p>We already install bridge-utils before, now, it should configure bridge devices. </p>



<pre class="wp-block-preformatted">mkdir -p /etc/qemu
echo "allow br0" &gt; /etc/qemu/bridge.conf</pre>



<p>Because there is only one network interface on machine, we should use this interface as bridge device, save text below and modify it to fit your environment. </p>



<pre class="wp-block-preformatted"> ORIGNIC=enP6p1s0

 ip addr flush enP6p1s0


 brctl addbr br0
 brctl addif br0 enP6p1s0
 ifconfig br0 up
 ifconfig br0 192.168.110.1 netmask 255.255.0.0
 route add default gw 192.168.1.1


 echo nameserver 8.8.8.8 >> /etc/resolv.conf </pre>



<p>Run script, command brctl show will show how whether it configure property or not. </p>



<h2 class="wp-block-heading">Prepare QEMU image</h2>



<p>Ubuntu 18.04 cloud image is here</p>



<pre class="wp-block-preformatted">wget http://ftp.yzu.edu.tw/Linux/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-arm64.img</pre>



<p>and please refer this article to change cloud image&#8217;s password <br />Change Ubuntu Cloud Image Password, before use it, don&#8217;t forget to increase cloud image size. 20G is enough for test.</p>



<pre class="wp-block-preformatted">qemu-img resize bionic-server-cloudimg-arm64.img +20G</pre>



<p>Next step is to create bios and nvram for qemu image boot. </p>



<pre class="wp-block-preformatted">dd if=/dev/zero of=flash0.img bs=1M count=64
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of=flash0.img conv=notrunc
dd if=/dev/zero of=flash1.img bs=1M count=64</pre>



<h2 class="wp-block-heading">Run Qemu</h2>



<p>Here is qemu command, save text below and run it </p>



<pre class="wp-block-preformatted"> IMAGE=bionic-server-cloudimg-arm64.img
 sudo qemu-system-aarch64 -name vm1 \
         -machine virt,gic_version=3,accel=kvm,usb=off \
         -cpu host -m 8192 \
         -smp 12,sockets=1,cores=12,threads=1 \
         -nographic -nodefaults \
         -pflash flash0.img -pflash flash1.img \
         -device vfio-pci,host=0001:01:00.0 \
         -device vfio-pci,host=0002:01:00.0 \
         -drive file=$IMAGE,if=none,id=disk1 \
         -device virtio-blk-device,scsi=off,drive=disk1,id=virtio-disk1,bootindex=1 \
         -netdev tap,id=net0,ifname=tap0 \
         -device virtio-net-device,netdev=net0 \
         -mem-path /mnt/hugepages \
         -serial telnet::9001,server,nowait > guest1_log.txt 2>> guest1_log.txt &amp;
 sleep 5
 brctl addif br0 tap0 </pre>



<p>-m 8192 : use 8G RAM for VM<br />&#8211;mem-path will use /mnt/hugepages for VM memory<br /><br />it will create a network device tap0 for bridge device interface between VM and host.  and create a telnet server on port 9001, it can use &#8220;telnet 9001&#8221; to get console, I would like to suggest to use ssh if it can access console. </p>



<h2 class="wp-block-heading">Remove cloudinit service</h2>



<p>it needs to remove cloud-initramfs-copymods, it will copy modules from ramdisk to harddriver, and cloud-init, it&#8217;s for some cloud service like aws(?)<br /><br />removed them would help system runs better. </p>



<pre class="wp-block-preformatted">apt remove cloud-initramfs-copymods cloud-init </pre>



<h2 class="wp-block-heading">Disable Services</h2>



<p>After boot, it needs to disable some default service to improve speed, here is some services can be disabled. (needs run those command with root)</p>



<pre class="wp-block-preformatted">systemctl disable ufw
systemctl disable lxcfs
systemctl disable atd
systemctl disable cron
systemctl disable irqbalance
systemctl disable apparmor
systemctl disable apport
systemctl disable ebtables
systemctl disable grub-common
systemctl disable unattended-upgrades
systemctl disable iscsid</pre>



<p>Most import service is irqbalance, without disable it, performance will be drop down. <br /><br />Now, it can reboot VM now. </p>



<h2 class="wp-block-heading">Prepare QEMU environment </h2>



<p>Prepare QEMU environment and prepare host almost the same, only differences are</p>



<ol class="wp-block-list"><li>in QEMU, apt install doesn&#8217;t needs to install qemu-efi and bridge-utils</li><li>in QEMU, before call dpdk-devbind command, it needs to configure enable_unsafe_noiommu_mode for ARM64 platform </li><li>Hugepage size is different , in HOST it uses 32G, in VM we uses 4G</li></ol>



<p>Enable unsafe noiommu </p>



<pre class="wp-block-preformatted">echo 1 &gt; /sys/module/vfio/parameters/enable_unsafe_*</pre>



<p> To permanently enable the no-IOMMU mode, add it to modprobe.d: (<a href="https://dpdk-guide.gitlab.io/dpdk-guide/setup/binding.html" target="_blank" rel="noopener">ref</a>) </p>



<pre class="wp-block-preformatted">echo "options vfio enable_unsafe_noiommu_mode=1" &gt; /etc/modprobe.d/vfio-noiommu.conf</pre>



<p>It also needs to reserve hugepages memory space for Linux kernel for VM, it reserves 4 pages and each pages 1GB, total 4GB. Please modify  /etc/default/grub , and  add hugepagesz=1GB hugepages=4 to GRUB_CMDLINE_LINUX, ex:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>GRUB_CMDLINE_LINUX=&#8221;console=tty0 hugepagesz=1GB hugepages=4&#8243;</p></blockquote>



<p>then run foloowing command to update grub.cfg</p>



<pre class="wp-block-preformatted">update-grub</pre>



<h2 class="wp-block-heading">Run DPDK  l3fwd</h2>



<p>Before run l3fwd, we need to recompile it. </p>



<pre class="wp-block-preformatted">. /usr/share/dpdk/dpdk-sdk-env.sh
make -C /usr/share/dpdk/examples/l3fwd</pre>



<p>Bind network interface</p>



<pre class="wp-block-preformatted">dpdk-devbind -b vfio-pci  enp0s1
dpdk-devbind -b vfio-pci  enp0s2</pre>



<p>Run l3fwd example</p>



<pre class="wp-block-preformatted">cd /usr/share/dpdk/examples/l3fwd/build
./l3fwd -c 1 -- -p 0x3 --config="(0,0,0),(1,0,0)"</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="639" src="https://richliu.com/wp-content/uploads/2019/08/image-1024x639.png" alt="" class="wp-image-4072" srcset="https://richliu.com/wp-content/uploads/2019/08/image-1024x639.png 1024w, https://richliu.com/wp-content/uploads/2019/08/image-300x187.png 300w, https://richliu.com/wp-content/uploads/2019/08/image-768x479.png 768w, https://richliu.com/wp-content/uploads/2019/08/image.png 1440w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Multi Queue example</p>



<pre class="wp-block-preformatted">./l3fwd -l 1,2,3,4 -n 4 -- -p 0x3 --config="(0,0,1),(1,0,2),(0,1,3),(1,1,4)"</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="715" src="https://richliu.com/wp-content/uploads/2019/08/image-1-1024x715.png" alt="" class="wp-image-4073" srcset="https://richliu.com/wp-content/uploads/2019/08/image-1-1024x715.png 1024w, https://richliu.com/wp-content/uploads/2019/08/image-1-300x209.png 300w, https://richliu.com/wp-content/uploads/2019/08/image-1-768x536.png 768w, https://richliu.com/wp-content/uploads/2019/08/image-1.png 1438w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">Other</h2>



<p>There is good tool to get hugepage information </p>



<pre class="wp-block-preformatted">apt install hugepages
hugeadm --pool-list</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="865" height="130" src="https://richliu.com/wp-content/uploads/2019/08/image-2.png" alt="" class="wp-image-4074" srcset="https://richliu.com/wp-content/uploads/2019/08/image-2.png 865w, https://richliu.com/wp-content/uploads/2019/08/image-2-300x45.png 300w, https://richliu.com/wp-content/uploads/2019/08/image-2-768x115.png 768w" sizes="auto, (max-width: 865px) 100vw, 865px" /></figure>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/">Ubuntu 18.04 ARM64 DPDK in VM (QEMU)</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
