Linux mounts new disks, partitions and auto-mounts at boot

Today, a new disk was added to the Alibaba Cloud virtual host, which needs to be mounted to centos7 separately.

Many problems were encountered during the mounting process, which are recorded as follows:

 

View partitions

[php]  view plain copy  
 
  1. fdisk -l  

 

The first and second boxes are partitioned disks, and the third hard disk has no partitions.

start partition

 

[html]  view plain copy
 
 
 
  1. fdisk /dev/sdc  


 

Enter m to see what operations are available

Enter p to view the current hard disk partition, there is currently no partition.

Enter n to create a new partition, enter p to create a partition, enter the partition number 1

Then it will let you set the start sector (I don't know if it is explained like this): The default carriage return is 1 to start from the beginning         

Then the end sector is set to 1000. This value seems to determine the size of the partition. I am not very familiar with the hardware. Install the above method and create a second partition

Then print the number of partitions and enter p, the red box is the partition that has been established

Finally save the partition and enter w

Finally, check if the partition has been created! If a red area appears, it means it has been established.

 

In fact, at this time, the created partition cannot be used, and it needs to be mounted before it can be used. But before mounting, it must be formatted. . .

2. Format the partition

 

Formatting command: mkfs.ext3 /dev/sdb1 is formatted into ext3

                     mkfs.ext2 /dev/sdb1 is formatted as ext2

I used mkfs.ext3 here.

 

[html]  view plain copy
 
 
 
  1. mkfs.ext3 /dev/sdc1   
  2. mkfs.ext3 /dev/sdc2  

Here is one of the pictures:

 

It cannot be used after formatting, it must be mounted.

3. Mount the partition

After formatting, you can mount the partition.

 

[html]  view plain copy
 
 
 
  1. mkdir /d1  
  2. mkdir /d2  
  3. mount /dev/sdc1 /d1  
  4. mount /dev/sdc2 /d2  

 

This mounts successfully and can be used normally.

 

4. Unmount the partition

 

[html]  view plain copy
 
 
 
  1. umount /dev/sdc2  

 

Uninstalled, in fact, it can still be mounted, and the data will still be there

5, delete the partition

[html]  view plain copy
 
 
 
  1. fdisk /dev/sdc  
  2. m  
  3. d  
  4. 1  
  5. d  

Enter w to save. At this time, the partition is deleted and can be recreated.

 

Auto mount at boot

 

4. Directly mount
and edit the /etc/fstab file at boot and
add: /dev/sda1 /test ext3 defaults 0 0 

After restarting, the selection has been mounted.

0, 0 means do not check the disk when booting.

Can also be mounted by disk UUID

 

If you tried sda5 and it doesn't work, you can try to mount it with UUID and check the UUID:
ls -l /dev/disk/by-uuid/
You can see the corresponding UUID number.
 
If changing the UUID still does not work, there is another way:
You can mount it manually, then you write the manual mount command into a script, and it is also possible to set the script to start automatically at boot:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326183738&siteId=291194637
Recommended