Disk mounting and canceling in Linux

Preface

Today I was going to add a disk to a PVE device, but I encountered a small pitfall:磁盘挂载后重启后发现磁盘没有被挂载, so I organized and recorded it.

Disk mount

View partition information

Runfdisk -l command to view the disk partition information available in the system

root@pve:/mnt# fdisk -l
Disk /dev/sda: 59.63 GiB, 64023257088 bytes, 125045424 sectors
Disk model: SanDisk SSD P4 6
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 4CF9B57E-4721-4752-8C97-292DD2E20AC9

Device       Start       End   Sectors  Size Type
/dev/sda1       34      2047      2014 1007K BIOS boot
/dev/sda2     2048   1050623   1048576  512M EFI System
/dev/sda3  1050624 125045390 123994767 59.1G Linux LVM


Disk /dev/mapper/pve-swap: 4 GiB, 4294967296 bytes, 8388608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/pve-root: 55.12 GiB, 59185823744 bytes, 115597312 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdc: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model:  Z700 120GB     
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xc5957d6a

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdc1  *     2048 234440703 234438656 111.8G  7 HPFS/NTFS/exFAT
root@pve:/mnt# 

Information description:

There are 2 disks here: sda disk has 3 partitions and sdc disk has one partition

/dev/sda: 
	/dev/sda1
	/dev/sda2
	/dev/sda3

/dev/sdc:
	/dev/sdc1

Partition settings

The sdc disk device is connected via USB, use thefdisk /dev/sdc command to set the partition

After executing the command, enter the partition interface and follow the prompts:

输入m:查看帮助信息

输入n:创建一个新分区

输入p:显示磁盘分区表的信息,包括分区号、起始扇区、大小等

输入w:写入保存分区设置

Specific execution information is as follows:

root@pve:/mnt# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

Command (m for help): n
All space for primary partitions is in use.

Command (m for help): p
Disk /dev/sdc: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model:  Z700 120GB     
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xc5957d6a

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdc1  *     2048 234440703 234438656 111.8G  7 HPFS/NTFS/exFAT

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

format

Format disk to ext4 format

mkfs -t ext4 /dev/sdc1

Disk mount

Building/mnt/​sdc1Memoji

mkdir -p /mnt/sdc1

General /mnt/​sdc1Bunku 挂载在 /mnt/​sdc1

mount -t ext4 /dev/sdc1 /mnt/sdc1

Persistent mount point configuration

After the disk is mounted and restarted, it is found that the disk is not mounted. This is because the mount point configuration is incorrect or the persistence settings are not performed.

Write/mnt/​sdc1 mount to system startup items

echo /dev/sdc1 /mnt/sdc1 ext4 defaults 1 2 >> /etc/fstab

检查/etc/fstabPlacement text:

/etc/fstabThe file is used to store disk information and mount point settings to be mounted when the system starts.

root@pve:/mnt# vi /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/pve/root / ext4 errors=remount-ro 0 1
UUID=D11C-D304 /boot/efi vfat defaults 0 1
/dev/pve/swap none swap sw 0 0
proc /proc proc defaults 0 0
/dev/sdc1 /mnt/sdc1 ext4 defaults 0 1

Cancel disk mount

To unmount the disk, you can use theumount command.

View mounted disks

Use the following command to view the currently mounted disks and corresponding mount points:

root@pve:/mnt# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1694612k,nr_inodes=423653,mode=755,inode64)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=345664k,mode=755,inode64)
/dev/sda2 on /boot/efi type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/sdc1 on /mnt/sdc1 type ext4 (rw,relatime)

Unmount

Use the umount command to unmount the specified disk. Use the mount point corresponding to the target disk as the parameter of the command.

root@pve:/mnt# umount /mnt/sdc1

Notice:

If the mount fails, it may be because the disk is in use. You can try closing the application or process using the disk and then running the unmount command again.

Guess you like

Origin blog.csdn.net/qq_38628046/article/details/134753766