1
0
Fork 0
isopod.cool/blog/posts/guide_how_to_automount_drives_on_boot_in_linux/index.php
will 9be2f36883 v3.1 - Minor overhaul to the entire site
- Removed some unused files
- Updated the blog post layout to have all the navigation
- Replaced hovertext in blog posts with footnotes
- Seaonal pride captions on homepage
- Updated /etc/quotes/
  - Background color is now actually reminiscent of Discord
- Total overhaul to /uses/
  - Added sub-page for my computer
- New markup for blockquotes that css-tricks.com says is more semantically correct
- More difficult captcha on the guestbook (answer remains unchanged)
- New blog post about DMs on the fediverse
- Blog now has links to each year
- Removed journal. I barely used it and it was redundant anyway
- Removed the TODO list that I wasn't using from /etc/
- CSS overhaul:
  - Cool new hover animation on navigation links
  - Centralized most color definitions to root variables, and a couple other things too
  - Standard font is now B612 mono
  - complies with prefers-reduced-motion
  - Light theme and low contrast mode in the works
  - Made tables more consistent, and the one on /about/ no longer looks like doodoo
  - Accent borders on headings and such-like
  - Main header & caption are now left-aligned instead of center-aligned
  - Isopod letterhead moved from left side of header to right
  - h1 made smaller, h2-6 changed back to default sizes
  - Adjusted a couple background positions to improve readability
  - Got rid of the checkbox-hack dropdown navigation on mobile, because it kind of sucked
  - Regular body text no longer has text-shadow
- probably some other stuff I forgot about
2024-07-08 03:47:39 -06:00

61 lines
5 KiB
PHP

<!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">
<link href="/blog/comment/comments.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/nav.php'); ?>
<h1>guide:</h1>
<h2 id="caption">How to Automount Drives On Boot in Linux</h2>
<?php include("../post_dates.php"); ?>
<h2>Preamble</h2>
<details>
<summary>Show preamble</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<br>
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/user/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>
<?php include("../../comment/form.php"); ?>
</body>
</html>