2024-08-15 11:35:51 +08:00

211 lines
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Dich&#x27;blog</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<meta name="robots" content="noodp"/>
<link rel="stylesheet" href="https://blog.dich.bid/style.css">
<link rel="stylesheet" href="https://blog.dich.bid/color/blue.css">
<link rel="stylesheet" href="https://blog.dich.bid/color/background_dark.css">
<link rel="stylesheet" href="https://blog.dich.bid/font-hack-subset.css">
<meta name="description" content="">
<meta property="og:description" content="">
<meta property="og:title" content="Dich'blog">
<meta property="og:type" content="article">
<meta property="og:url" content="https://blog.dich.bid/linux-for-pc-2/">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:description" content="">
<meta name="twitter:title" content="Dich'blog">
<meta property="twitter:domain" content="blog.dich.bid">
<meta property="twitter:url" content="https://blog.dich.bid/linux-for-pc-2/">
<link rel="alternate" type="application/atom+xml" title="Dich&#x27;blog Atom Feed" href="https://blog.dich.bid/atom.xml" />
</head>
<body class="">
<div class="container">
<header class="header">
<div class="header__inner">
<div class="header__logo">
<a href="https://blog.dich.bid" style="text-decoration: none;">
<div class="logo">
Dich&#x27;blog
</div>
</a>
</div>
</div>
<nav class="menu">
<ul class="menu__inner">
<li class="active"><a href="https://blog.dich.bid">blog</a></li>
<li><a href="https://blog.dich.bid/tags">tags</a></li>
<li><a href="https://blog.dich.bid/archive">archive</a></li>
<li><a href="https://blog.dich.bid/about">about me</a></li>
<li><a href="https://blog.dich.bid/links">links</a></li>
<li><a href="https://blog.dich.bid/search">search</a></li>
<li><a href="https://github.com/Dichgrem" target="_blank" rel="noopener noreferrer">github</a></li>
</ul>
</nav>
</header>
<div class="content">
<div class="post">
<h1 class="post-title"><a href="https://blog.dich.bid/linux-for-pc-2/">Linux-For-PC(二):FHS与目录结构</a></h1>
<div class="post-meta-inline">
<span class="post-date">
2023-07-21
</span>
</div>
<span class="post-tags-inline">
:: tags:&nbsp;
<a class="post-tag" href="https://blog.dich.bid/tags/linux/">#Linux</a></span>
<div class="post-content">
<p>前言 在Linux世界中Filesystem Hierarchy StandardFHS是一座引导我们进入系统核心的桥梁它定义了Linux系统中目录结构的规范与作用为我们提供了一张清晰的地图指引我们轻松管理和理解系统。本文将深入探讨FHS规范与Linux系统目录结构解释各个目录的用途与功能帮助我们更好地理解和利用Linux系统。</p>
<span id="continue-reading"></span><h2 id="yi-ren-shi-fhs">一.认识FHS</h2>
<p>FHS是Filesystem Hierarchy Standard文件系统层次结构标准的缩写。它是一个定义了Linux系统中目录结构和各个目录作用的规范。FHS规定了Linux系统中各个目录的用途和预期内容以便确保不同Linux发行版之间的兼容性并使得用户能够更轻松地理解和管理系统。</p>
<p>FHS规范最初由Linux基金会Linux Foundation和自由软件基金会Free Software Foundation共同发布并经过多次修订和更新。该规范不仅对Linux系统本身有用也适用于其他类UNIX操作系统。</p>
<p>FHS规范定义了一些基本的目录如/bin、/boot、/dev等并规定了每个目录的作用和预期内容。这样做有助于系统管理员和开发人员更好地组织和管理文件系统并使得用户能够更轻松地找到所需的文件和数据。</p>
<h2 id="er-chang-jian-mu-lu-jie-gou">二.常见目录结构</h2>
<p>在刚刚由Windows切换至Linux时往往会对目录感到不解不知道安装的软件放在哪个目录之下</p>
<p>以下是对Linux系统目录结构的详细说明</p>
<ul>
<li><strong>/(根目录)</strong>
根目录是整个文件系统的起点包含了系统中所有其他目录和文件。在Linux系统中根目录被表示为/。</li>
<li><strong>/bin二进制文件</strong>
/bin目录存放着一些最基本的系统命令如ls、cp、mv等这些命令通常被所有用户使用。</li>
<li><strong>/boot引导文件</strong>
/boot目录存放着启动Linux系统所需的引导文件如内核映像vmlinuz、引导加载程序boot loader配置文件如GRUB配置文件等。</li>
<li><strong>/dev设备文件</strong>
/dev目录包含了系统中所有设备的特殊文件如硬盘、键盘、鼠标等。在Linux中一切皆文件设备被抽象为文件通过/dev目录中的特殊文件来表示。</li>
<li><strong>/etc配置文件</strong>
/etc目录包含了系统的配置文件如网络配置、用户账户信息、服务配置等。这些配置文件通常以纯文本的形式存在可以由系统管理员进行编辑和修改。</li>
<li><strong>/home用户主目录</strong>
/home目录是系统中所有普通用户的主目录所在地每个用户通常都有一个对应的子目录用于存放用户的个人文件和数据。</li>
<li><strong>/lib库文件</strong>
/lib目录存放着系统所需的共享库文件这些库文件包含了一些程序运行所需的函数和数据为程序提供了基本的支持。</li>
<li><strong>/mnt挂载点</strong>
/mnt目录用于挂载临时文件系统如光盘、移动硬盘等。系统管理员可以将其他设备或文件系统挂载到/mnt目录下以便访问其中的文件和数据。</li>
<li><strong>/opt可选软件包</strong>
/opt目录用于存放一些可选的软件包和应用程序这些软件包通常不属于Linux发行版的默认安装范围但可以被用户自行安装和管理。</li>
<li><strong>/proc进程信息</strong>
/proc目录是一个虚拟的文件系统包含了系统运行时的各种进程信息和系统状态信息。用户可以通过读取/proc目录中的特殊文件来获取系统信息。</li>
<li><strong>/sbin系统命令</strong>
/sbin目录存放着一些系统管理和维护命令这些命令通常只能由超级用户root执行用于系统的管理和维护。</li>
<li><strong>/srv服务数据</strong>
/srv目录用于存放一些服务相关的数据文件如Web服务器的网站数据、FTP服务器的文件等。每个服务通常都会有一个对应的子目录。</li>
<li><strong>/tmp临时文件</strong>
/tmp目录用于存放临时文件和临时数据这些文件通常在系统重启时会被删除。任何用户都可以在/tmp目录下创建临时文件。</li>
<li><strong>/usr用户程序</strong>
/usr目录包含了系统中大部分用户可用的程序和文件如用户应用程序、共享库文件、文档等。它通常是系统的二级目录类似于Windows系统中的Program Files目录。</li>
<li><strong>/var可变数据</strong>
/var目录用于存放系统运行时产生的可变数据如日志文件、邮件、缓存文件等。这些数据通常会随着系统的运行而不断变化。</li>
</ul>
<blockquote>
<p>注意NixOS不符合FHS标准</p>
</blockquote>
<h2 id="san-fen-qu-da-xiao">三.分区大小</h2>
<p>对各个分区进行容量分配时,需要根据系统的实际需求和用途来进行规划。一般而言在安装引导时可以选择让程序自动分区。</p>
<ul>
<li><strong>根目录(/</strong>根目录是整个文件系统的起点通常会分配较大的空间以确保系统和应用程序有足够的空间运行。建议分配至少20GB的空间给根目录。</li>
<li><strong>/home目录</strong>/home目录用于存放用户的个人文件和数据因此需要根据用户数量和存储需求来进行容量分配。一般情况下建议为每个用户分配至少10GB的空间。</li>
<li><strong>/var目录</strong>/var目录用于存放系统运行时产生的可变数据如日志文件、邮件、缓存文件等。根据系统的运行情况和日志文件的大小来进行容量分配一般建议分配10-20GB的空间。</li>
<li><strong>/tmp目录</strong>/tmp目录用于存放临时文件和临时数据通常不需要分配太大的空间。建议分配至少1-2GB的空间给/tmp目录。</li>
<li><strong>/boot目录</strong>/boot目录存放着启动Linux系统所需的引导文件通常只需要分配几百MB的空间即可。</li>
<li><strong>Swap分区</strong>Swap分区是一种虚拟内存用于暂时存放不常用的内存数据。当系统内存不足时Linux会将一部分内存数据移动到Swap分区中以避免内存耗尽导致系统崩溃。Swap分区的大小通常与系统内存大小有关一般建议为系统内存的1.5-2倍。例如如果系统内存为4GB则建议设置Swap分区大小为6-8GB。</li>
</ul>
<blockquote>
<p>这里特别讲讲Swap分区</p>
</blockquote>
<p>Swap分区可以通过以下几种方式实现</p>
<ul>
<li>交换分区Swap Partition创建一个独立的交换分区通常是一个专门的分区用于存放Swap数据。</li>
<li>交换文件Swap File创建一个专门的文件用于存放Swap数据而不是创建独立的分区。这种方式更加灵活可以根据需要动态调整Swap的大小。</li>
<li>Swap大小Swap的大小应该根据系统的内存大小和使用情况来确定一般建议为系统内存的1.5-2倍。</li>
<li>Swap分区/文件的位置Swap分区/文件应该位于较快的存储介质上,以确保交换操作的效率。
Swap的优先级如果同时存在多个Swap分区/文件可以通过设置优先级来指定系统使用的Swap空间。</li>
</ul>
</div>
<div class="pagination">
<div class="pagination__title">
<span class="pagination__title-h">Thanks for reading! Read other posts?</span>
<hr />
</div>
<div class="pagination__buttons">
<span class="button previous">
<a href="https://blog.dich.bid/linux-for-pc-1/">
<span class="button__icon"></span>&nbsp;
<span class="button__text">Linux-For-PC(一):构成与发行版</span>
</a>
</span>
<span class="button next">
<a href="https://blog.dich.bid/linux-for-pc-3/">
<span class="button__text">Linux-For-PC(三):内核&#x2F;shell&#x2F;包管理&#x2F;文件系统&#x2F;桌面环境</span>&nbsp;
<span class="button__icon"></span>
</a>
</span>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="footer__inner">
<div class="copyright">
<span>©
2024
Dichgrem</span>
<span class="copyright-theme">
<span class="copyright-theme-sep">:: </span>
Theme: <a href="https://github.com/pawroman/zola-theme-terminimal/">Terminimal</a> by pawroman
</span>
</div>
</div>
</footer>
</div>
</body>
</html>