<?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>linux Archives - Albert Nogués</title>
	<atom:link href="https://www.albertnogues.com/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.albertnogues.com/tag/linux/</link>
	<description>Data and Cloud Freelancer</description>
	<lastBuildDate>Sun, 12 May 2024 16:01:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.albertnogues.com/wp-content/uploads/2020/12/cropped-cropped-AlbertLogo2-32x32.png</url>
	<title>linux Archives - Albert Nogués</title>
	<link>https://www.albertnogues.com/tag/linux/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Centos 8/9 Stream and AlmaLinux images for WSL</title>
		<link>https://www.albertnogues.com/centos-8-9-stream-and-almalinux-images-for-wsl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=centos-8-9-stream-and-almalinux-images-for-wsl</link>
		
		<dc:creator><![CDATA[Albert]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 11:21:51 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[wsl]]></category>
		<guid isPermaLink="false">https://www.albertnogues.com/?p=1389</guid>

					<description><![CDATA[<p>For the ones like me, interested in running Linux systems on windows for many automation or administration tasks, I am sharing here the images i&#8217;ve found: Centos7/8/9 Stream: https://github.com/mishamosher/CentOS-WSL AlmaLinux (Centos Replacement equivalent to RHEL): https://www.microsoft.com/en-us/p/almalinux-8-wsl/9nmd96xjj19f#activetab=pivot:overviewtab The latest one is a direct link to the microsoft store.</p>
<p>The post <a href="https://www.albertnogues.com/centos-8-9-stream-and-almalinux-images-for-wsl/">Centos 8/9 Stream and AlmaLinux images for WSL</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>For the ones like me, interested in running Linux systems on windows for many automation or administration tasks, I am sharing here the images i&#8217;ve found:</p>



<p>Centos7/8/9 Stream: <a href="https://github.com/mishamosher/CentOS-WSL" target="_blank" rel="noreferrer noopener">https://github.com/mishamosher/CentOS-WSL</a> </p>



<p>AlmaLinux (Centos Replacement equivalent to RHEL): <a href="https://www.microsoft.com/en-us/p/almalinux-8-wsl/9nmd96xjj19f#activetab=pivot:overviewtab" target="_blank" rel="noreferrer noopener">https://www.microsoft.com/en-us/p/almalinux-8-wsl/9nmd96xjj19f#activetab=pivot:overviewtab</a></p>



<p>The latest one is a direct link to the microsoft store.</p>
<p>The post <a href="https://www.albertnogues.com/centos-8-9-stream-and-almalinux-images-for-wsl/">Centos 8/9 Stream and AlmaLinux images for WSL</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ansible playbook to configure Azure Red Hat VM&#8217;s</title>
		<link>https://www.albertnogues.com/ansible-playbook-to-configure-azure-red-hat-vms/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ansible-playbook-to-configure-azure-red-hat-vms</link>
		
		<dc:creator><![CDATA[Albert]]></dc:creator>
		<pubDate>Wed, 21 Apr 2021 10:43:36 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ansible]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lun]]></category>
		<category><![CDATA[machine]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[redhat]]></category>
		<category><![CDATA[ulimit]]></category>
		<category><![CDATA[vm]]></category>
		<guid isPermaLink="false">https://www.albertnogues.com/?p=1067</guid>

					<description><![CDATA[<p>In todays post I am going to share an ansible playbook to configure a new VM recently launched. This playbook contains the following: Change Admin password Create linux Group Add user to several groups Create a new user with specific salted password (Check point 3 for generating the hashed salt) Find all the mounted disks &#8230; </p>
<p>The post <a href="https://www.albertnogues.com/ansible-playbook-to-configure-azure-red-hat-vms/">Ansible playbook to configure Azure Red Hat VM&#8217;s</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In todays post I am going to share an ansible playbook to configure a new VM recently launched. This playbook contains the following:</p>



<ul class="wp-block-list"><li>Change Admin password</li><li>Create linux Group</li><li>Add user to several groups</li><li>Create a new user with specific salted password (Check point 3 for generating the hashed salt)</li><li>Find all the mounted disks in any LUN and format them (create a xfs filesystem)</li><li>Create a mountpoint (in /opt)</li><li>Mount the disk formatted in LUN 0 PART 1 in the specified mountoint in fstab, so it will be persistent across reboots</li><li>Register the OS into RHEL Satellite so yum is usable</li><li>Disable some local repo in an external /mnt drive that crashes yum in the image</li><li>Install Telnet and other packages</li><li>Modify some Ulimits</li><li>Register Machine in a domain (TO BE DONE)</li></ul>



<p>To Start, lets create first the ansible inventory file and call it inventory.yaml (Or use init format if you want). The format of the file should be something like the folowing:</p>



<pre class="wp-block-code"><code>all:
  children:
    myservers:
      hosts:
        SERVER001:
          ansible_host: 10.10.1.1
        SERVER002:
          ansible_host: 10.10.1.2
        SERVER003:
          ansible_host: 10.10.1.3
        SERVER004:
          ansible_host: 10.10.1.4
        SERVER005:
          ansible_host: 10.10.1.5
    alberttest:
      hosts:
        testalbert001:
          ansible_host: 10.10.1.6</code></pre>



<p>Then we can create our playbook file (I will comment it below). This will be another yaml file with the following content:</p>



<pre class="wp-block-code"><code>---
- hosts: myservers
  collections:
    - ansible.posix
  tasks:
  - name: Ping the Server
    ping:

  - name: Change Password of the Admin user.
    user:
      name: Admin
      # python3 -c 'import crypt; print (crypt.crypt("Passw0rd", "$1$SomeSalt$"))'
      password: $1$SomeSalt$C7s11A7tyf8OKOg0JoCYp/

  - name: Create anogues group
    group:
      name: anogues
      state: present

  - name: Create anogues user
    user:
      name: anogues
      password: $1$SomeSalt$C7s11A7tyf8OKOg0JoCYp/
      shell: /bin/bash
      groups: infaedc, wheel
      append: yes

  - name: Create mountpoint
    file: path=/opt/data state=directory

  - name: Find all Luns
    find:
      paths: /dev/disk/azure/scsi1/
      file_type: link
      recurse: No
      patterns: "lun?"
    register: files_matched

  - name: Partition Disk to Max
    shell: "parted {{ item.path }} --script mklabel gpt mkpart xfspart xfs 0% 100%"
    args:
      executable: /bin/bash
    loop: "{{ files_matched.files|flatten(levels=1) }}"

  - name: Inform OS of partition table changes
    command: partprobe

  - name: find UUID of sdX1
    shell: |
      blkid -s UUID -o value $(readlink -f /dev/disk/azure/scsi1/lun0-part1)
    register: uuid

  - name: show real uuid
    debug:
      msg: "{{ uuid.stdout }}"

  - name: Mount disk drive in fstab
    mount:
      path: /opt/data
      src: 'UUID={{uuid.stdout}}'
      fstype: xfs
      opts: defaults,nofail
      dump: 1
      passno: 2
      state: mounted

  - name: Check disk Status
    shell: df -h | grep /dev/sd
    register: df2_status

  - name: Show mounted FS
    debug:
      msg: "{{ df2_status.stdout_lines }}"

  - name: Register RHEL
    redhat_subscription:
      state: present
      username: {{ lookup('env', 'RHEL_USER') }}
      password: {{ lookup('env', 'RHEL_PASSWORD') }}
      autosubscribe: yes

  - name: Disable Media Repo
    ini_file:
      dest: /etc/yum.repos.d/media.repo
      section: "{{item}}"
      option: enabled
      value: 0
    with_items:
      - LocalRepo_BaseOS
      - LocalRepo_AppStream

  - name: Install Telnet and other packags
    yum:
      name:
        - telnet
        - curl
        - zip
        - unzip
        - tar
        - wget
        - libcurl
      state: present

  - name: Add or modify nproc hard limit for the user anogues. Set 65k value.
    pam_limits:
      domain: anogues
      limit_type: hard
      limit_item: nproc
      value: 65000
    become: yes
    become_method: sudo
    become_user: root

  - name: Add or modify nproc soft limit for the user anogues. Set 65k value.
    pam_limits:
      domain: anogues
      limit_type: soft
      limit_item: nproc
      value: 65000
    become: yes
    become_method: sudo
    become_user: root</code></pre>



<p>Let&#8217;s have a look at how it works:</p>



<p>One of the playbook steps is to register RHEL into Satellite. To avoid hardcoding the user and password in the playbooy these values will be taken from your env vars, so please export them before</p>



<p>export RHEL_USER=<br>export RHEL_PASSWORD=</p>



<p>You need to install ansible-posix first (Tested with 1.2.0.). Download it from here: https://galaxy.ansible.com/ansible/posix<br>ansible-galaxy install ansible-posix-1.2.0.tar.gz</p>



<p>To create a crypted user with a salt you can do the following<br>python3 -c &#8216;import crypt; print (crypt.crypt(&#8220;YOUR_UNHASHED_PASSWORD&#8221;, &#8220;$1$SomeSalt$&#8221;))&#8217;<br>And copy the hashed salt into the playbook area for the user you want to set the password</p>



<p>Azure Mounts the Disk Drives by Luns. By default it starts in Lun0, So i am using the softlink to /dev/disk/azure to check the disks added. This playbook will only automount the first disk. If you need more simply modify the playbook and add as many luns as you need</p>



<p># tree /dev/disk/azure<br>/dev/disk/azure<br>├── resource -&gt; ../../sdb<br>├── resource-part1 -&gt; ../../sdb1<br>├── root -&gt; ../../sda<br>├── root-part1 -&gt; ../../sda1<br>├── root-part14 -&gt; ../../sda14<br>├── root-part15 -&gt; ../../sda15<br>├── root-part2 -&gt; ../../sda2<br>└── scsi1<br>├── lun0 -&gt; ../../../sdc<br>└── lun1 -&gt; ../../../sdd</p>



<p>Here there are two disks mounted in two luns, 0 and 1. No disk has been formatted yet as we only see sdc and sdd drives with no partition. Once the first one is formatted, you will see a difference:</p>



<p>/dev/disk/azure<br>├── resource -&gt; ../../sdb<br>├── resource-part1 -&gt; ../../sdb1<br>├── root -&gt; ../../sda<br>├── root-part1 -&gt; ../../sda1<br>├── root-part14 -&gt; ../../sda14<br>├── root-part15 -&gt; ../../sda15<br>├── root-part2 -&gt; ../../sda2<br>└── scsi1<br>├── lun0 -&gt; ../../../sdc<br>├── lun0-part1 -&gt; ../../../sdc1<br>└── lun1 -&gt; ../../../sdd</p>



<p>To run it (make sure you have installed ansible 2.9 from RHEL repo):</p>



<pre class="wp-block-code"><code>ansible-playbook -i inventory.yaml -k playbook.yaml</code></pre>



<p>The playbook also formats all drives found in any luns (All disks mounted in the VM), bout only mounts the first one as we only defined one mount point.</p>



<p>If we need to modify it, we can include all the tasks that ar enecessary (read the blkid, add entry in fstab into another loop block but previously we have to create as many directories for the mountpoints as necessay and feed them in the loop block, so they are assigned concurrently.</p>



<p>Links of interest:</p>



<p><a href="https://stackoverflow.com/questions/19292899/creating-a-new-user-and-password-with-ansible">https://stackoverflow.com/questions/19292899/creating-a-new-user-and-password-with-ansible</a></p>



<p><a href="https://stackoverflow.com/questions/49424967/how-to-create-azure-vm-with-data-disk-and-then-format-it-via-ansible">https://stackoverflow.com/questions/49424967/how-to-create-azure-vm-with-data-disk-and-then-format-it-via-ansible</a></p>
<p>The post <a href="https://www.albertnogues.com/ansible-playbook-to-configure-azure-red-hat-vms/">Ansible playbook to configure Azure Red Hat VM&#8217;s</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>HowTo run (Any Linux) Centos8 inside windows 10</title>
		<link>https://www.albertnogues.com/howto-run-any-linux-centos8-inside-windows-10/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=howto-run-any-linux-centos8-inside-windows-10</link>
		
		<dc:creator><![CDATA[Albert]]></dc:creator>
		<pubDate>Thu, 24 Dec 2020 17:38:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[wsl]]></category>
		<guid isPermaLink="false">http://192.168.1.40/?p=953</guid>

					<description><![CDATA[<p>Since some time ago, windows ships with something called WSL or Windows subsystem for linux. This allows windows users to run linux images withouth having to physically install linux, running cygwin or running vm&#8217;s or docker containers with linux. So it&#8217;s quite practical. And the good part is that from within the linux shell you &#8230; </p>
<p>The post <a href="https://www.albertnogues.com/howto-run-any-linux-centos8-inside-windows-10/">HowTo run (Any Linux) Centos8 inside windows 10</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Since some time ago, windows ships with something called WSL or Windows subsystem for linux. This allows windows users to run linux images withouth having to physically install linux, running cygwin or running vm&#8217;s or docker containers with linux. So it&#8217;s quite practical. And the good part is that from within the linux shell you can see all your attached disks in windows, including the OS disk, so you can for example use a gui or a code editor in windows and interact with linux command line tools inside the shell.</p>



<p>If you want to read more about it you can read <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/windows/wsl/install-win10" data-type="URL" data-id="https://docs.microsoft.com/en-us/windows/wsl/install-win10" target="_blank">Microsoft post on their website</a>.</p>



<p>Basically there are two versions, version 1, and version 2. You can see the differences between both in this <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/windows/wsl/compare-versions" data-type="URL" data-id="https://docs.microsoft.com/en-us/windows/wsl/compare-versions" target="_blank">post</a>. I recommend using version 2 when possible as it&#8217;s more performant. As started on Microsoft website:</p>



<p><em>The primary difference and reasons for updating the Windows Subsystem for Linux from WSL 1 to WSL 2 are to:</em></p>



<ul class="wp-block-list">
<li><em><strong>increase file system performance</strong>,</em></li>



<li><em><strong>support full system call compatibility</strong>.</em></li>
</ul>



<p><em>WSL 2 uses the latest and greatest in virtualization technology to run a Linux kernel inside of a lightweight utility virtual machine (VM). However, WSL 2 is not a traditional VM experience.</em></p>



<p>So, let&#8217;s see the steps to make all this work. First of all we need to enable wsl in windows optional features. For this we can go through the control Panel or the windows search and make a few clicks to enable it or we can run some command from powershell. Make sure you run them as administrator (Right click to Powershell, run as Admin&#8230;)</p>



<p>The commands are either one of these two:</p>



<pre class="wp-block-code"><code>dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart</code></pre>



<p>or</p>



<pre class="wp-block-code"><code>Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux</code></pre>



<p>Any of the two will do the work. After it, restart your computer. </p>



<p><strong>(OPTIONAL)</strong> If optionally you want to upgrade to wsl v2, you need to make sure you are running one of the newer windows 10 releases:</p>



<ul class="wp-block-list">
<li>For x64 systems: <strong>Version 1903</strong> or higher, with <strong>Build 18362</strong> or higher.</li>



<li>For ARM64 systems: <strong>Version 2004</strong> or higher, with <strong>Build 19041</strong> or higher.</li>



<li>Builds lower than 18362 do not support WSL 2. Use the <a href="https://www.microsoft.com/software-download/windows10">Windows Update Assistant</a> to update your version of Windows.</li>
</ul>



<p>If this is the case, you can simply then upgrade it to wsl v2 by running the following to enavle the Virtual Machine Platform support:</p>



<pre class="wp-block-code"><code>dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart</code></pre>



<p>Download and install the v2 kernel package from <a rel="noreferrer noopener" href="https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" data-type="URL" data-id="https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" target="_blank">here</a>.</p>



<p>And set wsl v2 as the default mode with the following command:</p>



<pre class="wp-block-code"><code>wsl --set-default-version 2</code></pre>



<p>Then we are good, we can open now the <a rel="noreferrer noopener" href="https://aka.ms/wslstore" data-type="URL" data-id="https://aka.ms/wslstore" target="_blank">microsoft store</a> and download any of the supported images there, like Ubuntu, Suse, Debian, Fedora, Alpine&#8230; But if you want to use Centos8, we need some extra work.</p>



<p>There is a Github project that now has been archived due to the Centos / Centos Stream controversy but is still working for our purpose. We can use it as long as we are in Windows 10 version 2004, otherwise upgrade your windows 10.</p>



<p>We go to the <a rel="noreferrer noopener" href="https://github.com/wsldl-pg/CentWSL/releases" data-type="URL" data-id="https://github.com/wsldl-pg/CentWSL/releases" target="_blank">release page of the github repo</a> and download the zip file. Another option is to go to the new github repo continuing the work of the original one with the new Centos versions (including CentOs stream and CentOs 8.3 <a rel="noreferrer noopener" href="https://github.com/mishamosher/CentOS-WSL/releases/" data-type="URL" data-id="https://github.com/mishamosher/CentOS-WSL/releases/" target="_blank">here</a>), the procedure will be the same.</p>



<p>Once downloaded, we extract the zip file and we run the exe file inside. This will unpack all the content of the root filesystem inside the tar.gz file and will make everything ready to be run. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="347" height="96" src="https://www.albertnogues.com/wp-content/uploads/2020/12/CentosInstall.png" alt="" class="wp-image-956" srcset="https://www.albertnogues.com/wp-content/uploads/2020/12/CentosInstall.png 347w, https://www.albertnogues.com/wp-content/uploads/2020/12/CentosInstall-300x83.png 300w, https://www.albertnogues.com/wp-content/uploads/2020/12/CentosInstall-217x60.png 217w" sizes="(max-width: 347px) 100vw, 347px" /></figure>



<p>To enter into the bash shell we simply click again into the exe file once it has been installed and voilà!. Another way is to write the bash command in the cmd, which will open bash inside our cmd window.</p>



<p>Then we can update our system to the latest version by running dnf update:</p>



<pre class="wp-block-code"><code>&#91;root@DESKTOP-JONAOMM ~]# cat /etc/redhat-release
CentOS Stream release 8
&#91;root@DESKTOP-JONAOMM ~]# dnf update
CentOS Stream 8 - AppStream                                                             3.2 MB/s | 6.4 MB     00:02
CentOS Stream 8 - BaseOS                                                                2.5 MB/s | 2.4 MB     00:00
CentOS Stream 8 - Extras                                                                 10 kB/s | 7.0 kB     00:00
Dependencies resolved.
========================================================================================================================
 Package                                    Arch       Version                                      Repository     Size
========================================================================================================================
Installing:
 kernel                                     x86_64     4.18.0-259.el8                               baseos        5.0 M                     baseos         31 M
...
Installing weak dependencies:
 dconf                                      x86_64     0.28.0-4.el8                                 appstream     108 k

Transaction Summary
========================================================================================================================
Install   53 Packages
Upgrade  138 Packages

Total download size: 326 M
Is this ok &#91;y/N]:</code></pre>



<p>At the same time I recommend you to <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/windows/terminal/get-started" data-type="URL" data-id="https://docs.microsoft.com/en-us/windows/terminal/get-started" target="_blank">install windows terminal</a> as well to get better experience (tab support, search, custom themes&#8230;)</p>



<p>If we look around we can see our local volumes &#8220;mounted&#8221; inside</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="480" height="154" src="https://www.albertnogues.com/wp-content/uploads/2020/12/WSLMount.png" alt="" class="wp-image-957" srcset="https://www.albertnogues.com/wp-content/uploads/2020/12/WSLMount.png 480w, https://www.albertnogues.com/wp-content/uploads/2020/12/WSLMount-300x96.png 300w, https://www.albertnogues.com/wp-content/uploads/2020/12/WSLMount-187x60.png 187w" sizes="(max-width: 480px) 100vw, 480px" /></figure>



<p>We can also share our image with others (friends, coworkers) if we customized it or installed some software which is great for people like me that have many friends, which I met in sites like <a href="https://chatempanada.com">https://chatempanada.com</a> online. </p>



<p>. We can export it with:</p>



<pre class="wp-block-code"><code>wsl --export ImageName FileName</code></pre>



<p>with Image Name the name of the linux flavour we want to export. We can check all the available ones with the following command:</p>



<pre class="wp-block-code"><code>wsl --list
Distribuciones del subsistema de Windows para Linux:
CentOS8 (predet.)
CentOS8-stream</code></pre>



<p>And then pack the tar file inside a compressed file and send it to whom we want.</p>



<p>Another useful trick is that if we dont want to log in as root (which is what wsl by default does), we can run the following:</p>



<pre class="wp-block-code"><code>wsl -d ImageName -u username</code></pre>



<p>Happy Linuxing!</p>
<p>The post <a href="https://www.albertnogues.com/howto-run-any-linux-centos8-inside-windows-10/">HowTo run (Any Linux) Centos8 inside windows 10</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
