Linux Practical Chapter - Disk Mounting

disk mount

first step:

query existing disk

lsblk

[ysf@localhost lesson]$ lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   20G  0 disk 

├─sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   19G  0 part 

  ├─centos-root 253:0    0   17G  0 lvm  /

  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]

sdb               8:16   0    5G  0 disk 

sr0 11: 0 1 1024M 0 rom

 

sdb system initial partition

sdb newly added disk (not mounted, not formatted)

 

Step 2:

fdisk /dev/sdb to partition the disk

m show a list of commands

n add a partition

Select the primary partition or extended partition according to the prompts (usually select the default)

Select the partition number according to the prompt (usually select the default)

Select the start and end positions of the partition according to the prompts (usually select the default)

w write changes to disk

third step:

View a list of partitions

lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   20G  0 disk 

├─sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   19G  0 part 

  ├─centos-root 253:0    0   17G  0 lvm  /

  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]

sdb               8:16   0    5G  0 disk 

└─sdb1            8:17   0    5G  0 part 

sr0 11: 0 1 1024M 0 rom

 

The partition sdb1 has been created and formatted below.

mkfs -t ext4 /dev/sdb1

Format the sdb1 partition as an ext4 type filesystem

the fourth step:

Choose a directory to mount

For example, mount it in the ~/newdisk directory

mount /dev/sdb1 ~/newdisk

lsblk to view the list of partitions

[ysf@localhost ~]$ lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   20G  0 disk 

├─sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   19G  0 part 

  ├─centos-root 253:0    0   17G  0 lvm  /

  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]

sdb               8:16   0    5G  0 disk 

└─sdb1            8:17   0    5G  0 part /home/ysf/newdisk

At this point you can see that the mount is complete

Note: After restarting at this time, the mounted disk will disappear

Execute shutdown -r now

After reconnecting, lsblk view the list of partitions

[ysf@localhost ~]$ lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   20G  0 disk 

├─sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   19G  0 part 

  ├─centos-root 253:0    0   17G  0 lvm  /

  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]

sdb               8:16   0    5G  0 disk 

└─sdb1            8:17   0    5G  0 part 

sr0 11: 0 1 1024M 0 rom 

At this point, it is found that the mounted disk has disappeared. To mount it permanently, you need to modify the configuration file.

the fifth step:

Modify the configuration file

vi /etc/fstab

Add the following line

/dev/sdb1 (partition directory) /home/ysf/newdisk (mount directory) ext4 defaluts 0 0

source /etc/fstab

shutdown -r now

lsblk

[ysf@localhost ~]$ lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   20G  0 disk 

├─sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   19G  0 part 

  ├─centos-root 253:0    0   17G  0 lvm  /

  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]

sdb               8:16   0    5G  0 disk 

└─sdb1            8:17   0    5G  0 part /home/ysf/newdisk

sr0 11: 0 1 1024M 0 rom  

At this point, it is found that the partition mounted to the directory does not fail after restarting

Mounting completed here

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324131842&siteId=291194637