Home System Tutorial LINUX Getting Started with Linux Mounting: Concepts, Methods, and Commands

Getting Started with Linux Mounting: Concepts, Methods, and Commands

Feb 10, 2024 pm 04:12 PM
linux linux tutorial linux system linux command shell script overflow embeddedlinux Getting started with linux linux learning

Linux系统中,磁盘分区和文件系统是两个重要的概念,它们决定了数据的存储方式和访问方式。但是,要让系统能够识别和使用磁盘分区中的文件系统,还需要一个关键的步骤,那就是挂载。挂载是指将磁盘分区或其他设备与系统中的一个目录关联起来,从而可以通过该目录来访问磁盘分区中的文件和数据。本文将介绍Linux中挂载的基本概念,方法和命令,帮助你更好地管理你的磁盘和文件系统。

需求:需要把系统盘搞到/home 下面。

思考:/home 下面是用户默认的家目录,如果用户家目录有数据是会被覆盖的。找朋友确认是刚安装的系统才开始搞的。更改分区大小首先想到的是lvm,但是看了客户的磁盘信息发现不需要考虑这些,怎么简单怎么来。

查看硬盘信息

[root@localhost /]# fdisk -l            查看硬盘信息

Disk /dev/sda: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00085ef7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    17803263     8388608   82  Linux swap / Solaris
/dev/sda3        17803264   468860927   225528832   83  Linux

Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdc: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0007a974

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   976773119   488385536   8e  Linux LVM

Disk /dev/sdd: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a4688

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1   *        2048     1026047      512000   83  Linux
/dev/sdd2         1026048   468860927   233917440   8e  Linux LVM

数据的操作是需要非常严谨的,看到了这么多的硬盘,有看到了lvm分区。对于新装的系统我第一感觉是:难道要我修复lvm分区吗?经过和朋友确认发现我想多了,只是挂载,磁盘已经拔掉了。

找到对应硬盘分区格式化

磁盘分区

[root@localhost /]# fdisk /dev/sdb              \\针对第二块盘分区
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6511fa23.

Command (m for help): p                   \\查看已有分区

Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6511fa23

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n                    \\创建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p                        \\主分区
Partition number (1-4, default 1): 
First sector (2048-468862127, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-468862127, default 468862127): 
Using default value 468862127
Partition 1 of type Linux and of size 223.6 GiB is set

Command (m for help): p                     \\查看确认分区
 
Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6511fa23

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   468862127   234430040   83  Linux

Command (m for help): w                    \\保存改分区
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

分区格式化

[root@localhost /]# mkfs             \\tab 万能操作
mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs     
[root@localhost /]# mkfs.xfs /dev/sdb1         格式化sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=14651878 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=58607510, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=28616, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

查看检查分区

[root@localhost /]# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 223.6G  0 disk 
├─sda1   8:1    0   500M  0 part /boot
├─sda2   8:2    0     8G  0 part [SWAP]
└─sda3   8:3    0 215.1G  0 part /
sdb      8:16   0 223.6G  0 disk 
└─sdb1   8:17   0 223.6G  0 part 

挂载分区到”/home”

挂载分区,找到uuid,写入fstab

[root@localhost /]# blkid /dev/sdb1             查看sdb1 的uuid   写入fstab uuid 最稳定  /dev/sdb1 也可以
/dev/sdb1: UUID="ffbd4feb-c55e-40ca-86d3-c43919bd9060" TYPE="xfs" 
[root@localhost /]# echo "/dev/sdb1: UUID="ffbd4feb-c55e-40ca-86d3-c43919bd9060" TYPE="xfs" " >> /etc/fstab 
[root@localhost /]# vim /etc/fstab 
-bash: vim: command not found

[root@localhost /]# vi /etc/fstab           写入fstab
[root@localhost /]# tail -n 2 /etc/fstab
ffbd4feb-c55e-40ca-86d3-c43919bd9060  /home xfs defaults 0 0
#/dev/sdb1 /home xfs defaults 0 0         \\uuid 和 /dev/sdb1 区别??
[root@localhost /]# mount -a                 重新读取配置文件

检查挂载成果,挂载成功!!

[root@localhost /]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs       215G  852M  215G   1% /
devtmpfs       devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs          tmpfs     7.8G     0  7.8G   0% /dev/shm
tmpfs          tmpfs     7.8G  8.4M  7.8G   1% /run
tmpfs          tmpfs     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1      xfs       497M  119M  378M  24% /boot
tmpfs          tmpfs     1.6G     0  1.6G   0% /run/user/0
/dev/sdb1      xfs       224G   33M  224G   1% /home

[root@localhost /]# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 223.6G  0 disk 
├─sda1   8:1    0   500M  0 part /boot
├─sda2   8:2    0     8G  0 part [SWAP]
└─sda3   8:3    0 215.1G  0 part /
sdb      8:16   0 223.6G  0 disk 
└─sdb1   8:17   0 223.6G  0 part /home

ok,收工!!

PS:菜鸟级教程,新手复习,老鸟勿喷!如果这些你都看不懂的话,真的要恶补了!!!

Getting Started with Linux Mounting: Concepts, Methods, and Commands

通过本文,你应该对Linux中的挂载有了一个基本的了解,包括挂载的作用,类型,参数和命令。你也应该掌握了如何查看,添加,删除和修改挂载点的方法,以及如何处理挂载出错的情况。挂载是Linux系统中一个重要而常用的操作,它可以让你灵活地使用不同的磁盘分区和文件系统,提高数据的安全性和效率。希望本文能够对你有所帮助,如果你有任何问题或建议,请在评论区留言。

The above is the detailed content of Getting Started with Linux Mounting: Concepts, Methods, and Commands. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1585
276
How to make PHP container support automatic construction? Continuously integrated CI configuration method of PHP environment How to make PHP container support automatic construction? Continuously integrated CI configuration method of PHP environment Jul 25, 2025 pm 08:54 PM

To enable PHP containers to support automatic construction, the core lies in configuring the continuous integration (CI) process. 1. Use Dockerfile to define the PHP environment, including basic image, extension installation, dependency management and permission settings; 2. Configure CI/CD tools such as GitLabCI, and define the build, test and deployment stages through the .gitlab-ci.yml file to achieve automatic construction, testing and deployment; 3. Integrate test frameworks such as PHPUnit to ensure that tests are automatically run after code changes; 4. Use automated deployment strategies such as Kubernetes to define deployment configuration through the deployment.yaml file; 5. Optimize Dockerfile and adopt multi-stage construction

How to build an independent PHP task container environment. How to configure the container for running PHP timed scripts How to build an independent PHP task container environment. How to configure the container for running PHP timed scripts Jul 25, 2025 pm 07:27 PM

Building an independent PHP task container environment can be implemented through Docker. The specific steps are as follows: 1. Install Docker and DockerCompose as the basis; 2. Create an independent directory to store Dockerfile and crontab files; 3. Write Dockerfile to define the PHPCLI environment and install cron and necessary extensions; 4. Write a crontab file to define timing tasks; 5. Write a docker-compose.yml mount script directory and configure environment variables; 6. Start the container and verify the log. Compared with performing timing tasks in web containers, independent containers have the advantages of resource isolation, pure environment, strong stability, and easy expansion. To ensure logging and error capture

How to Securely Erase a Hard Drive on Linux How to Securely Erase a Hard Drive on Linux Jul 24, 2025 am 12:08 AM

Confirm the target hard disk device name (such as /dev/sda) to avoid accidentally deleting the system disk; 2. Use sudoddif=/dev/zeroof=/dev/sdXbs=1Mstatus=progress to overwrite the zero value in full disk, which is suitable for most scenarios; 3. Use sudoshred-v-n3/dev/sdX for three random data overwrites to ensure that it cannot be restored; 4. Optionally execute sudobadblocks-wsv/dev/sdX for destructive write tests; finally use sudohexdump-C/dev/sdX|head to verify whether it is all zero and complete safe erasing.

Linux vs Windows: Which Operating System is Better for You? Linux vs Windows: Which Operating System is Better for You? Jul 29, 2025 am 03:40 AM

Windowsisbetterforbeginnersduetoeaseofuse,seamlesshardwarecompatibility,andsupportformainstreamsoftwarelikeMicrosoftOfficeandAdobeapps.2.LinuxoutperformsWindowsonolderorlow-resourcehardwarewithfasterboottimes,lowersystemrequirements,andlessbloat.3.Li

How to Schedule Tasks on Linux with Cron and anacron How to Schedule Tasks on Linux with Cron and anacron Aug 01, 2025 am 06:11 AM

cronisusedforpreciseschedulingonalways-onsystems,whileanacronensuresperiodictasksrunonsystemsthataren'tcontinuouslypowered,suchaslaptops;1.Usecronforexacttiming(e.g.,3AMdaily)viacrontab-ewithsyntaxMINHOURDOMMONDOWCOMMAND;2.Useanacronfordaily,weekly,o

What to do after installing linux What to do after installing linux Jul 23, 2025 am 02:57 AM

AfterinstallingLinux,thefirststepsincludeupdatingyoursystem,installingessentialsoftware,settingupbackupandsecuritymeasures,andcustomizingtheinterfacetosuityourpreferences.1)Updateyoursystemusingtheappropriatecommandforyourdistro(e.g.,sudoaptupdate&am

How to install software on Linux using the terminal? How to install software on Linux using the terminal? Aug 02, 2025 pm 12:58 PM

There are three main ways to install software on Linux: 1. Use a package manager, such as apt, dnf or pacman, and then execute the install command after updating the source, such as sudoaptininstallcurl; 2. For .deb or .rpm files, use dpkg or rpm commands to install, and repair dependencies when needed; 3. Use snap or flatpak to install applications across platforms, such as sudosnapinstall software name, which is suitable for users who are pursuing version updates. It is recommended to use the system's own package manager for better compatibility and performance.

The Ultimate Guide to High-Performance Gaming on Linux The Ultimate Guide to High-Performance Gaming on Linux Aug 03, 2025 am 05:51 AM

ChoosePop!_OS,Ubuntu,NobaraLinux,orArchLinuxforoptimalgamingperformancewithminimaloverhead.2.InstallofficialNVIDIAproprietarydriversforNVIDIAGPUs,ensureup-to-dateMesaandkernelversionsforAMDandIntelGPUs.3.EnabletheperformanceCPUgovernor,usealow-latenc

See all articles