[ubuntu] Mount the disk to a specified directory and set it to automatically mount when booting

Recently, I plan to automatically mount the data disk when it is turned on, so as not to have to mount it manually every time. The summary steps are as follows:

  • Enter the following command to list all partitions in the system:

    sudo  fdisk -l
    

    insert image description here

    Find the partition you want to mount, and you can distinguish it by its capacity. Of course, it may not be easy to distinguish. You can directly 其他位置(other locations)see the relevant information in the directory.
    insert image description here

  • Enter the following command to view the mounted points

    lsblk
    

    or

    df -h
    

    insert image description here
    You can also see the corresponding mount point. For example, here I need to automatically mount /media/chh3213/MECHREVOthe directory when booting up. You can see that its partition is nvme0n1p1.

  • Use sudo blkidthe command to query the UUID and file system format of the corresponding disk partition, which will be used later.
    For example, if I plan to boot and mount nvme0n1p1a partition, then query the partition information:

    sudo blkid /dev/nvme0n1p1
    

    You can view nvme0n1p1the relevant information of the partition (very important, will be used later)

    insert image description here

  • config /etc/fstabfile
    via

    sudo gedit /etc/fstab
    

    Open the fstab file and add the following content in it:

    UUID=84B03D67B03D60BA    /media/chh3213/MECHREVO       ntfs     defaults        0       2
    

    The parameters are described as follows:

    • The first column is UUID, fill in the disk partitions queried before UUID.
    • The second column is the disk partition 挂载目录, which is the path you want to mount.
    • The third column is the file system format of the disk partition, which is displayed in the partition information TYPE.
    • The fourth column is the mount option of the disk partition, which is usually set here defaults.
    • Column 5 is Linux dumpthe backup option.
      0: Indicates that Linux dump is not used for backup. Dump backup is usually not used now, it 0can be set here .
      1: Indicates to use Linux dump backup.
    • Column 6 is fsckan option, that is, whether to use fsck to check the disk when booting.
      0: Indicates no inspection;
      1: Fill in the partition whose mount point is ( /) the root directory 1;
      for other partitions 2, the system will check the numbers in ascending order from the beginning.
  • Restart the system to take effect

Guess you like

Origin blog.csdn.net/weixin_42301220/article/details/130078734