How to mount a disk in Linux and set it to automatically mount on boot

How to mount a disk in Linux and set it to automatically mount on boot

Knowing that everyone's time is precious, I will write down the process commands directly. You can configure them. If you want to study the principles, just read on.

fdisk -l # View mountable disks df -h # View mounted disks mkfs.ext4 /dev/vdb # Initialize the disk mount /dev/vdb /u01 # Mount the disk to /u01, making sure /u01 is empty blkid # Get the uuid and properties of the disk, and use the uuid to mount it at startup
vim /etc/fstab # Mount at boot, the template is UUID=********** /u01 ext4 defaults 1 1

Because the Linux system sometimes has insufficient disk storage and needs to be expanded, you can choose to mount the disk at this time. This mounted disk can be understood as a USB flash drive.

The first step is to use fdisk -l to check which disks can be mounted.

You can see that there are two disks above. Now use df -h to check which disks have been mounted.

Only one of the small disks is mounted. Now we can mount the large disk /dev/vdb.

mount /dev/vdb /u01

Note that the u01 folder must be empty, otherwise the contents of u01 will not be displayed before mounting. Therefore, a new folder is usually created when mounting. In short, it must be ensured to be empty.

At this time, if the disk has been mounted before, it cannot be mounted and the following error is reported

We want to initialize the disk mkfs.ext4 /dev/vdb

Then mount it mount /dev/vdb /u01

After mounting, you need to set the system to mount automatically at boot, otherwise it will be troublesome if you need to mount again after reboot.

We use uuid to boot mount

Use blkid to get the disk's uuid and attributes

vim /etc/fstab

Configuration template: UUID=************* /u01 ext4 defaults 1 1

If the disk has been expanded before, you need to restart the server first to make the expanded disk take effect, umount the mounted folder (umount dir_name), and execute

e2fsck -f /dev/vdb # Check the data disk and return the disk information resize2fs /dev/vdb # Resize the data disk

Then re-mount as above. Don't worry, the data will not be lost when re-mounting.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Linux mount shared directory
  • Basic usage of mount/umount commands in Linux and how to automatically mount at boot
  • Linux mount and unmount hard disk script sharing
  • How to get all mount points in Linux using Python

<<:  How to install mysql5.7 in windows

>>:  JavaScript uses promise to handle multiple repeated requests

Recommend

Json advantages and disadvantages and usage introduction

Table of contents 1. What is JSON 1.1 Array liter...

Detailed explanation of basic concepts of HTML

What is HTML? HTML is a language used to describe...

An example of how to implement an adaptive square using CSS

The traditional method is to write a square in a ...

React internationalization react-intl usage

How to achieve internationalization in React? The...

Detailed explanation of querying JSON format fields in MySQL

During the work development process, a requiremen...

Using JavaScript in HTML

The <script> tag In HTML5, script has the f...

Solution to forgetting MySQL root password in MACOS

MySQL is a relational database management system ...

MySQL database table and database partitioning strategy

First, let's talk about why we need to divide...

Nexus uses nginx proxy to support HTTPS protocol

background All company websites need to support t...

Front-end AI cutting tips (experience)

AI image cutting needs to be coordinated with PS....

dl, dt, dd list label examples

The dd and dt tags are used for lists. We usually...

MySql common query command operation list

MYSQL commonly used query commands: mysql> sel...

A brief analysis of MySQL's WriteSet parallel replication

【Historical Background】 I have been working as a ...