<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>FileSystem on Rishav's Digital Garden</title><link>https://blog.rishavs.in/tags/filesystem/</link><description>Recent content in FileSystem on Rishav's Digital Garden</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 20 May 2025 10:13:00 +0000</lastBuildDate><atom:link href="https://blog.rishavs.in/tags/filesystem/index.xml" rel="self" type="application/rss+xml"/><item><title>Generating Package Patch for Buildroot</title><link>https://blog.rishavs.in/posts/generating-package-patch-for-buildroot/</link><pubDate>Tue, 20 May 2025 10:13:00 +0000</pubDate><guid>https://blog.rishavs.in/posts/generating-package-patch-for-buildroot/</guid><description>&lt;h2 id="generating-a-patch-using-diff">Generating a Patch Using &lt;code>diff&lt;/code>&lt;/h2>
&lt;h3 id="1-extract-the-original-source">1. Extract the Original Source&lt;/h3>
&lt;p>Ensure you have a pristine copy of the original source for comparison. You can extract it from the tarball in the &lt;code>dl&lt;/code> directory:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>tar -xf dl/&amp;lt;package&amp;gt;-&amp;lt;version&amp;gt;.tar.gz -C /tmp/
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This will create a directory like &lt;code>/tmp/&amp;lt;package&amp;gt;-&amp;lt;version&amp;gt;/&lt;/code>.&lt;/p>
&lt;h4 id="using-buildroots-mechanism">Using buildroot&amp;rsquo;s mechanism&lt;/h4>
&lt;p>Clean the build directory and apply current patches of buildroot&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>make &amp;lt;pkg&amp;gt;-dirclean &lt;span style="color:#75715e"># Remove &amp;lt;pkg&amp;gt; build directory&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>make &amp;lt;pkg&amp;gt;-extract &lt;span style="color:#75715e"># Extract &amp;lt;pkg&amp;gt; sources&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>make &amp;lt;pkg&amp;gt;-patch &lt;span style="color:#75715e"># Apply patches to &amp;lt;pkg&amp;gt; (Optional)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cp -r output/build/&amp;lt;package&amp;gt; /tmp/
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-generate-the-patch">2. Generate the Patch&lt;/h3>
&lt;p>Use the &lt;code>diff&lt;/code> command to create a unified diff between the original and modified sources:&lt;/p></description></item><item><title>Boot to recovery filesystem</title><link>https://blog.rishavs.in/posts/boot-to-recovery-filesystem/</link><pubDate>Thu, 15 May 2025 14:59:00 +0000</pubDate><guid>https://blog.rishavs.in/posts/boot-to-recovery-filesystem/</guid><description>&lt;h2 id="process">Process&lt;/h2>
&lt;ol>
&lt;li>Mount recovery partition into temporary location&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>mkdir -p /mnt/recovery
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mount /dev/mmcblk0p6 /mnt/recovery
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol start="2">
&lt;li>Prepare &lt;code>old_root&lt;/code> directory&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>mkdir -p /mnt/recovery/mnt/old_root
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol start="3">
&lt;li>Switch root using &lt;code>pivot_root&lt;/code>&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>cd /mnt/recovery
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>pivot_root . mnt/old_root
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now:&lt;/p>
&lt;ul>
&lt;li>New root is /mnt/recovery (i.e., /)&lt;/li>
&lt;li>The previous root (e.g., initramfs or mainfs) is now mounted at /mnt/old_root&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>Note: The chroot must be available under the old root and under the new root(recovery)&lt;/p>&lt;/blockquote>
&lt;ol start="4">
&lt;li>Remount &lt;code>/proc&lt;/code>, &lt;code>/sys&lt;/code>, &lt;code>/dev&lt;/code>, etc&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>mount -t proc proc /proc
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mount -t sysfs sysfs /sys
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mount -o bind /mnt/old_root/dev /dev
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mount -o bind /mnt/old_root/tmp /tmp
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mount -o bind /mnt/old_root/run /run
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol start="5">
&lt;li>Start a shell inside of new root&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>exec /bin/sh
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="mount-root-filesystem-from-nfs">Mount root filesystem from NFS&lt;/h2>
&lt;ol>
&lt;li>Setup nfs-service on host machine (refer &lt;a href="../nfs/">this&lt;/a>)&lt;/li>
&lt;li>Mount NFS filesystem into the board&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>mount -t nfs -o nolock 192.168.1.27:/home/rishav/Public /mnt/nfsroot
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol start="3">
&lt;li>Mount ext image as a loopback device&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>mkdir -p /mnt/local
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cp /mnt/nfs/rootfs.ext4 /tmp/rootfs.ext4
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mount -o loop /tmp/rootfs.ext4 /mnt/local
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>Manual page of &lt;code>pivot_root&lt;/code>&lt;/li>
&lt;li>Also see difference between &lt;code>pivot_root&lt;/code> and &lt;code>chroot&lt;/code>&lt;/li>
&lt;/ul></description></item><item><title>Kernel Space vs User Space</title><link>https://blog.rishavs.in/posts/kernel-space-vs-user-space/</link><pubDate>Tue, 04 Feb 2025 17:23:00 +0000</pubDate><guid>https://blog.rishavs.in/posts/kernel-space-vs-user-space/</guid><description>&lt;h2 id="overview">Overview&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Kernel Space&lt;/strong>: This is where the Linux kernel executes and provides low-level access to hardware, system memory management, process scheduling, and device drivers. Kernel space has privileged access to system resources and is protected from direct user interference. For example, when a user requests data from a hardware sensor, the kernel driver handles communication with the hardware, processes the request, and returns the data to user space through system calls.&lt;/li>
&lt;li>&lt;strong>User Space&lt;/strong>: This is where applications and system utilities run. User-space processes operate with restricted privileges and interact with the kernel via system calls, libraries, and IPC mechanisms. For example, a user-space daemon may monitor the watchdog status by writing to &lt;code>/dev/watchdog&lt;/code>, or a mobile app may read light intensity from &lt;code>/sys/bus/i2c/devices/1-0039/lux&lt;/code>.&lt;/li>
&lt;/ul>
&lt;h2 id="communication-methods-between-kernel-and-user-space">Communication Methods between Kernel and User Space&lt;/h2>
&lt;p>There are several ways to facilitate communication between user space and kernel space in an embedded Linux environment:&lt;/p></description></item><item><title>Making File System</title><link>https://blog.rishavs.in/posts/making-file-system/</link><pubDate>Mon, 11 Nov 2024 19:14:00 +0000</pubDate><guid>https://blog.rishavs.in/posts/making-file-system/</guid><description>&lt;h2 id="overview">Overview&lt;/h2>
&lt;ol>
&lt;li>Get the final files into a directory eg. &lt;code>target&lt;/code> and treat it as root(&lt;code>/&lt;/code>) directory of target board/system.&lt;/li>
&lt;li>Generate users eg. &lt;code>root&lt;/code>, &lt;code>admin&lt;/code>, &lt;code>ssh&lt;/code>, etc&lt;/li>
&lt;li>Generate device lists&lt;/li>
&lt;li>Clean few files&lt;/li>
&lt;li>Generate ext image using &lt;code>mkfs&lt;/code>&lt;/li>
&lt;/ol>
&lt;p>Taking reference from buildroot &lt;code>common.mk&lt;/code> and &lt;code>ext2.mk&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>scripts/makedevs -d output/build/buildroot-fs/full_devices_table.txt output/build/buildroot-fs/ext2/target
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mkfs.ext4 -d output/build/buildroot-fs/ext2/target -r &lt;span style="color:#ae81ff">1&lt;/span> -N &lt;span style="color:#ae81ff">0&lt;/span> -m &lt;span style="color:#ae81ff">5&lt;/span> -L rootfs -O ^64bit output/images/rootfs.ext2 2G
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Fakeroot execution complete&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/opt/rk3588_nvrx/host/sbin/resize2fs -M output/images/rootfs.ext2
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/opt/rk3588_nvrx/host/sbin/e2fsck -fy /output/images/rootfs.ext2
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/opt/rk3588_nvrx/host/sbin/resize2fs -M /output/images/rootfs.ext2
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="fakeroot-script">Fakeroot Script&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#!/bin/sh
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>set -ex
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>chown -h -R 0:0 &lt;span style="color:#66d9ef">$(&lt;/span>TARGET&lt;span style="color:#66d9ef">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">$(&lt;/span>HOST_DIR&lt;span style="color:#66d9ef">)&lt;/span>/bin/makedevs -d full_devices_table.txt &lt;span style="color:#66d9ef">$(&lt;/span>TARGET&lt;span style="color:#66d9ef">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">$(&lt;/span>HOST_DIR&lt;span style="color:#66d9ef">)&lt;/span>/sbin/mkfs.ext4 -d &lt;span style="color:#66d9ef">$(&lt;/span>TARGET&lt;span style="color:#66d9ef">)&lt;/span> -r &lt;span style="color:#ae81ff">1&lt;/span> -N &lt;span style="color:#ae81ff">0&lt;/span> -m &lt;span style="color:#ae81ff">5&lt;/span> -L &lt;span style="color:#e6db74">&amp;#34;rootfs&amp;#34;&lt;/span> -O ^64bit rootfs.ext2 &lt;span style="color:#e6db74">&amp;#34;2G&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="post-ext4">Post EXT4&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">$(&lt;/span>HOST_DIR&lt;span style="color:#66d9ef">)&lt;/span>/sbin/resize2fs -M rootfs.ext2
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">$(&lt;/span>HOST_DIR&lt;span style="color:#66d9ef">)&lt;/span>/sbin/e2fsck -fy rootfs.ext2
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">$(&lt;/span>HOST_DIR&lt;span style="color:#66d9ef">)&lt;/span>/sbin/tune2fs -m &lt;span style="color:#ae81ff">5&lt;/span> rootfs.ext2
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">$(&lt;/span>HOST_DIR&lt;span style="color:#66d9ef">)&lt;/span>/sbin/resize2fs -M rootfs.ext2
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="testing-on-host">Testing on Host&lt;/h2>
&lt;pre tabindex="0">&lt;code>sudo mount -o loop path/to/rootfs.ext4 /tmp/fs_path
&lt;/code>&lt;/pre>&lt;h3 id="makedevs">Makedevs&lt;/h3>
&lt;p>Creates a batch of special files as specified in a device table.&lt;/p></description></item></channel></rss>