<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://dev1galaxy.org/extern.php?action=feed&amp;tid=4180&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / Copy Installation to USB with encryption using the f2fs filesystem.]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=4180</link>
		<description><![CDATA[The most recent posts in Copy Installation to USB with encryption using the f2fs filesystem..]]></description>
		<lastBuildDate>Tue, 09 Mar 2021 10:30:14 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Copy Installation to USB with encryption using the f2fs filesystem.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=27970#p27970</link>
			<description><![CDATA[<p>Hope that subject heading sounds correct?</p><p>Doing this cause of boredom and just to see if i could <img src="https://dev1galaxy.org/img/smilies/wink.png" width="15" height="15" alt="wink" />. This is how i made a copy onto a usb3.0 drive of my devuan beowulf installation using f2fs as the filesystem.<br />Note this tutorial is only for legacy-bios not uefi. For this i opted to just have 1 boot partition and 1 encrypted root partition, no encrypted lvm, no home partitions etc etc...<br />The reason for the f2fs filesystem is that it is better suited to flash drives hence the name flash friendly file system, <a href="https://www.kernel.org/doc/html/v5.7/filesystems/f2fs.html" rel="nofollow">https://www.kernel.org/doc/html/v5.7/fi … /f2fs.html</a><br />Ive opted to create plain encrypted root partition but you can leave this out if you want, just skip the encryption steps and in point 4. ignore mkfs.f2fs /dev/mapper/usb and use mkfs.f2fs /dev/sdX2.</p><p>1. make sure to install these before moving forward.</p><div class="codebox"><pre><code># apt install f2fs-tools
# apt install cryptsetup
# apt install arch-install-scripts
# apt install rsync</code></pre></div><p>2. get the boot and root partition ready<br />i use cfdisk for this, just create 2 partitions, the first atleast 500MB and make it bootable and the second the rest of the drive.<br />Use what ever disk utility you like though, just make sure their is a boot partition and a root partition nothing more as it is out of the scope of this tutorial.<br />Make sure that the usb has enough space for your operating system, im using a 128GB usb3.0 stick and my system is only around 20GB in total.</p><p>3. create the encryption and take note of what the usb device partions are for, /dev/sdX2 in my case is /dev/sdb2 the root partition.</p><div class="codebox"><pre><code># cryptsetup luksFormat /dev/sdX2</code></pre></div><p>answer YES in capitals, then input a password.</p><p>Now open the the encrypted partition.</p><div class="codebox"><pre><code># cryptsetup open /dev/sdX2 usb</code></pre></div><p>4. create the filesystems for boot and root, if you have no other usb devices plugged in these should be sdb1 for boot and sdb2 for root. </p><div class="codebox"><pre><code># mkfs.ext2 /dev/sdX1 
# mkfs.f2fs /dev/mapper/usb</code></pre></div><p>5. now lets just mount the root then the boot partition.</p><div class="codebox"><pre><code># mount /dev/mapper/usb /mnt 
# mount /dev/sdX1 /mnt/boot</code></pre></div><p>6. now lets rsync the root filesystem to the /mnt</p><div class="codebox"><pre><code># rsync -aAXHv --exclude={&quot;/dev/*&quot;,&quot;/proc/*&quot;,&quot;/sys/*&quot;,&quot;/tmp/*&quot;,&quot;/run/*&quot;,&quot;/mnt/*&quot;,&quot;/media/*&quot;,&quot;/lost+found&quot;} / /mnt</code></pre></div><p>7. after the rsync has completed successfully lets chroot into the usb filesystem and edit a few things.</p><div class="codebox"><pre><code># arch-chroot /mnt</code></pre></div><p>lets get the uuids of the usb device to edit /etc/fstab and /etc/crypttab with the blkid command, (blkid - locate/print block device attributes).</p><div class="codebox"><pre><code># blkid
/dev/sdX1: UUID=&quot;&lt;this is your boot partition UUID&gt;&quot; TYPE=&quot;ext2&quot; PARTUUID=&quot;0000000-01&quot; 
/dev/sdX2: UUID=&quot;&lt;this is the crypto_luks partition UUID&gt;&quot; TYPE=&quot;crypto_LUKS&quot; PARTUUID=&quot;00000000-02&quot; 
/dev/mapper/usb: UUID=&quot;&lt;this the unencrypted filesystem UUID&gt;&quot; TYPE=&quot;f2fs&quot;</code></pre></div><p>lets edit /etc/fstab first so it looks like below. </p><div class="codebox"><pre><code># /etc/fstab: static file system information.
#
# Use &#039;blkid&#039; to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# &lt;file system&gt; &lt;mount point&gt;   &lt;type&gt;  &lt;options&gt;       &lt;dump&gt;  &lt;pass&gt;
/dev/mapper/usb /               f2fs    rw,defaults      0       1
# /boot was on /dev/sda1 during installation
UUID=&lt;this is your boot partition UUID&gt; /boot           ext2    noatime         0       2</code></pre></div><p>now edit /etc/crypttab and insert the /dev/sdX2 uuid...</p><div class="codebox"><pre><code>usb UUID=&lt;this is the crypto_luks partition UUID&gt; none luks,discard</code></pre></div><p>8. now lets remove grub.cfg then install and update-grub </p><div class="codebox"><pre><code># rm /boot/grub/grub.cfg
# grub-install /dev/sdX # this should be your usb device, mine was /dev/sdb
# update-grub</code></pre></div><p>9.now we need some modules added to the initramfs, ive read that debian stable should have the f2fs module in grub to make root file systems work, this might not be the case for devuan ?<br />But without adding these to /etc/initramfs-tools/modules the usb failed to boot for me.</p><div class="codebox"><pre><code># List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax:  module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod

f2fs
fscrypto
crc32-pclmul
crc32c_generic
crc32c-intel
crc32_generic
libcrc32c</code></pre></div><p>now update the initramfs</p><div class="codebox"><pre><code># update-initramfs -u</code></pre></div><p>lets update grub just in case.</p><div class="codebox"><pre><code># update-grub</code></pre></div><p>---</p><p>Now just ...</p><div class="codebox"><pre><code># exit 
# unmount -R /mnt
# cryptsetup close usb
# reboot into the usb</code></pre></div><p>This should be enough to boot the usb stick via the bios boot menu into a grub screen. This is working for me as im typing all this out from it.<br />please let me know if ive made any mistake or this guide needs improvement. </p><p>happy hacking!</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Tue, 09 Mar 2021 10:30:14 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=27970#p27970</guid>
		</item>
	</channel>
</rss>
