Linux(ubuntu) mount disk

foreword

Many blogs have written about formatting disks, partitions, etc., which is confusing with the concept of mounting disks. The purpose of partitioning is to install the system. We must have installed the Ubuntu system by mounting the disk. What are the partitions for?

In addition, formatting the disk is not a necessary option for mounting the disk. If you want to keep the disk data, can I not mount it without formatting? Of course it is impossible. If you are not clear about this concept, it means that you need to supplement the knowledge about the operating system.

There are a lot of information on the Internet, but there are very few really useful articles. Especially under the condition of not being able to climb over the wall. We need to have a good foundation to judge whether these tutorials are right or not.

In addition, it is recommended to prepare the system disk, in case the system fails to start, reinstall the system at any time. Remember to back up your data.

Mount disk with UUID

view UUID

Here I use UUID to mount the disk, because UUID is unique, so that there will be no problems.

blkid

insert image description here
The problem here is that I have three disks, two old mechanical HDDs, and one SSD. If I view it with blkid, I can only see the UUID of the current system disk.
Baidu, using

ls -l /dev/disk/by-uuid/

insert image description here

I can see all the disks. It turns out that there are four disks, and the one with 500mb, efi starts and boots, regardless of him.

In fact, the df -h display is also UUID, and the disk also has a chip. You should record your own UUID. If you have not configured the fstab file, you will use UUID as the mount node.
With the UUID, you can mount the disk, but here you need to do a pre-work, manually create the mount point, that is, the directory, if the directory does not exist, the mount will fail, as prompted below.

insert image description here

Create a directory

The next critical step is that I now have four hard drives and one efi, no matter what. One of the other three is the system disk, 500G, then your other two disks need to be mounted to the directory of this system disk, that is, under your current home folder, to create a new folder. I don't know if I made it clear, df -h checks the current file system.
insert image description hereThe system disk is /dev/nvme0n1p3 and the mount point is /
, so if you want to have a disk folder under the path, you have to create the mount folder under the directory of the system disk.
It's a bit long-winded.

insert image description here

mkdir data
mkdir ssd

Modify the fstab file and mount it permanently

sudo vim /etc/fstab

Replace the UUID below with your own.

UUID=269cfb7f-d7eb-4b1c-b33a-8bf26b878bd7 /home/mi/data   ext4    defaults          0       0
UUID=caa7d4db-82d1-40a5-8df6-0f77818b393e /home/mi/ssd    ext4    defaults          0       0

mi is my username, you need to change it to yours.

Mount it first to see if it has taken effect. If you are very confident, you can also restart directly to see if it takes effect.

sudo mount -a

Then restart the system, you can boot normally, and see my two directories (disk mount points). No problem.
insert image description here

Of course, if it is not normal, don’t panic, reinstall the system!


In addition, you can directly replace your home/(username) path with the disk, just change the path in fstab.


postscript

Directories cannot be created directly under the disk folder.

sudo chmod 777 data/

Guess you like

Origin blog.csdn.net/weixin_40557160/article/details/130424108
Recommended