1
0
Fork 0

new blog post on configuring your fstab

actually added the blog post in this one. how does git commit -a work
main
will 1 year ago
parent cbb6313d2a
commit 4ee3024af3

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Guide - How to Automount Drives On Boot in Linux</title>
<link href="/style.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<h1>guide:</h1>
<h2 id="caption">How to Automount Drives On Boot in Linux</h2>
<nav>
<a href="/">home</a>
<a href="/blog/">blog</a>
</nav>
<details>
<summary><h2 style="display:inline-block;margin:0;">Preamble</h2></summary>
<p>Recently I had to reinstall Linux because of reasons, and I hit a bit of a snag. See, my computer has this setup with three drives where one is the boot drive, and the other has /home on it... it's not important, point is, I wanted some drives to be automatically mounted as specific directories at boot time.</p>
<p>This is pretty easy to do with the manual partitioning tools most graphical installers provide, but I would have also had to manually partition the boot drive and hell if I'm figuring out for the umpteenth time how this particular distro with this particular hardware needs to be partitioned in order to be bootable, so I just selected the automatic partitioning option which assumes you just want everything on the boot drive.</p>
<p>Now the problem is that my system doesn't know my /home directory is on /dev/sda3 and not /dev/nvme0n1p1. So I have to fix that now or just log in as root and mount my shit every time I turn the computer on for the rest of time. Guess which thing sounded like more of a pain in the ass. I googled it so you don't have to!</p>
<h2>Now on to the good stuff</h2>
</details>
<p>I recommend you log out and do this as root in a TTY if you intend to mount something as your home directory.</p>
<h2>Getting partition information</h2>
<p>First, run:</p>
<code>sudo blkid</code>
<p>This will return a list of block devices (partitions) your system sees with some information about each, like this:</p>
<code>
<span class="codetitle">sudo blkid</span>
/dev/sda1: <strong>UUID="YOUR_UUID"</strong> BLOCK_SIZE="4096" <strong>TYPE="YOUR_TYPE"</strong> PARTUUID="30aac87d-21c9-44a9-8033-108eede77f8b"
</code>
<p>You'll probably have more than one though. There should be one per partition your system can see. We're interested in the <code>UUID</code> and <code>TYPE</code> attributes. Find the ones for the partition you want mounted and take note of them. We'll be adding these to your fstab file.</p>
<h2>Editing your fstab</h2>
<p><strong>Make a backup of your fstab file in case you break things!</strong> You can do this by simply copying the file:</p>
<code>sudo cp /etc/fstab /etc/fstab.bak</code>
<p>Now we can edit it. Open <code>/etc/fstab</code> in your favorite text editor, and you should be greeted with a file that looks something like this:</p>
<img src="fstab.png" alt="Screenshot of /etc/fstab on my computer before I did this" />
<p>(This is the fstab file EndeavourOS generated on install. Because I set it to use btrfs, it mounted the same partition like four separate times as subvolumes. Yours will likely be smaller if you didn't do this.)</p>
<p>This information tells your system which partitions should be mounted and at which locations to mount them, as well as some other settings. We don't need to worry about most of it, though. Simply append a line for your partition to the file:</p>
<code>
<span class="codetitle">/etc/fstab</span>
#imagine the contents of your fstab file here
UUID=<strong>YOUR_UUID</strong> /path/to/mountpoint <strong>YOUR_TYPE</strong> defaults 0 0
</code>
<p>For example, here's the entry I added for one of my drives:</p>
<code>
<span class="codetitle">/etc/fstab</span>
UUID=f8c3f1b1-7fef-4a01-bec7-ba3e89e2f8da /home/willem/vault ext4 defaults 0 0
</code>
<p>If you did it right, you should now be able to reboot and see your partitions have been automatically mounted!</p>
<p>One more thing to keep in mind, if you see any lines with a mount point that's the same as the place you're trying to mount to (for example, the system has mounted a btrfs subvolume for /home and you want to put that on your secondary drive) you should probably comment out or delete that.</p>
<h2>The fast way</h2>
<p>Alternatively, you could just paste this into your terminal and then reboot:</p>
<code>
partition="<strong>/dev/yourpartition</strong>"; directory="<strong>/path/to/mountpoint</strong>"; sudo cp /etc/fstab /etc/fstab.$(date +%s).bak; echo "UUID=$(sudo blkid $partition | sed "s/^.* UUID=\"//;s/\".*//") $directory $(sudo blkid $partition | sed "s/^.* TYPE=\"//;s/\".*//") defaults 0 0" | sudo tee -a /etc/fstab
</code>
<p>But don't complain to me if you break your system doing that.</p>
</body>
</html>
Loading…
Cancel
Save