linux磁盘挂载

linux磁盘挂载

一、查看磁盘

查看磁盘挂载和分区情况:fdisk -l

[root@ecm-1e38 ~]# fdisk -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: dos
Disk identifier: 0x47871e76

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886079 83884032  40G 83 Linux


Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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
image-20240719140235843

二、磁盘分区

1. 上一步确定待挂载的磁盘名称/dev/vdb

2. 分区:fdisk /dev/vdb

输入:m

[root@ecm-1e38 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x89a8cce5.

Command (m for help): 

输入:n

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): 

输入:p

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

输入:1(磁盘做1个分区,后边连续两个回车)

Partition number (1-4, default 1): 1
First sector (2048-1048575999, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1048575999, default 1048575999): 

Created a new partition 1 of type 'Linux' and of size 500 GiB.

Command (m for help): 

输入:w(保存然后自动退出)

Created a new partition 1 of type 'Linux' and of size 500 GiB.

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

[root@ecm-1e38 ~]# 

3. 检查是否分区成功

/dev/vdb1就是刚建的分区

[root@ecm-1e38 ~]# fdisk -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: dos
Disk identifier: 0x47871e76

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886079 83884032  40G 83 Linux


Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0x89a8cce5

Device     Boot Start        End    Sectors  Size Id Type
/dev/vdb1        2048 1048575999 1048573952  500G 83 Linux

三、格式化分区

格式化成[ext4]的文件系统

输入:mkfs -t ext4 /dev/vdb1

[root@ecm-1e38 ~]# mkfs -t ext4 /dev/vdb1
mke2fs 1.46.4 (18-Aug-2021)
Creating filesystem with 131071744 4k blocks and 32768000 inodes
Filesystem UUID: c28be586-c293-41b0-bcba-4890db06ea9e
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done     

[root@ecm-1e38 ~]# 

四、挂载磁盘

1. 创建要挂载的目录

2. 将分区挂载到指定目录

[root@ecm-1e38 /]# mkdir ims  创建要挂载的目录
[root@ecm-1e38 /]# mount /dev/vdb1 /ims  将分区挂载到指定目录

3. 查看磁盘信息,确认挂载新磁盘是否成功

挂载成功/dev/vdb1 492G 28K 467G 1% /ims

[root@ecm-1e38 /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs           7.6G     0  7.6G   0% /dev/shm
tmpfs           3.1G   17M  3.1G   1% /run
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/vda1        40G  2.6G   38G   7% /
tmpfs           7.6G  8.0K  7.6G   1% /tmp
/dev/vdb1       492G   28K  467G   1% /ims

五、设置开机启动自动挂载

1. 备份文件

cp /etc/fstab /etc/fstab.bak

[root@ecm-1e38 /]# cp /etc/fstab /etc/fstab.bak
[root@ecm-1e38 /]# 

2. 获取磁盘分区的uuid

blkid /dev/vdb1

[root@ecm-1e38 /]# blkid /dev/vdb1
/dev/vdb1: UUID="c28be586-c293-41b0-bcba-4890db06ea9e" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="89a8cce5-01"
[root@ecm-1e38 /]# 

3. 修改磁盘挂载配置文件

vim /etc/fstab

追加配置UUID=c28be586-c293-41b0-bcba-4890db06ea9e /ims ext4 defaults 0 1

keyvalue
UUIDblkid /dev/vdb1命令获取
/ims挂载的目录
ext4文件系统名称
defaults挂载参数
0指定分区是否被dump备份,0代表不备份,1代表每天备份,2代表不定期备份
1指定分区是否被fsck检测,0代表不检测,其它数字代表检测的优先级,1的优先级比2高
#
# /etc/fstab
# Created by anaconda on Fri Sep  8 06:45:45 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=41adc3cf-2ec7-490a-9d22-a84b74a2860d /                       xfs     defaults        0 0
UUID=c28be586-c293-41b0-bcba-4890db06ea9e /ims                    ext4    defaults        0 1
~                                                                                                                                                                                                                          

4. 重启测试

正常

[root@ecm-1e38 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs           7.6G     0  7.6G   0% /dev/shm
tmpfs           3.1G   17M  3.1G   1% /run
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/vda1        40G  2.6G   38G   7% /
tmpfs           7.6G  8.0K  7.6G   1% /tmp
/dev/vdb1       492G   28K  467G   1% /ims

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值