欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux挂载盘

程序员文章站 2022-05-20 08:52:22
...

一、将盘连接到服务器

物理机就是将硬盘连接到主机,虚拟机则将盘连接到虚拟机

二、挂载命令说明

查看挂载

fdisk -l 查看硬盘信息
/dev/vdb 为挂载盘

[[email protected] ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos
Disk identifier: 0x000ae09f

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20971486    10484719+  83  Linux

Disk /dev/vdb: 42.9 GB, 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

格式化

ext4

mkfs /dev/vdb 格式化 /dev/vdb ,默认 ext2格式

指定文件格式ext4

mkfs.ext4 /dev/vdb

[[email protected] ~]# mkfs.ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485760 blocks
524288 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624

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

xfs格式化

mkfs.xfs -f /dev/vdb
或者 mkfs -t xfs /dev/vdb

[[email protected] ~]# mkfs.xfs -f /dev/vdb
meta-data=/dev/vdb               isize=512    agcount=4, agsize=2621440 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=10485760, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=5120, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

之前已经格式化为ext4,需要格式化为xfs mkfs.xfs -f /dev/vdb

[[email protected] ~]# mkfs.xfs /dev/vdb 
mkfs.xfs: /dev/vdb appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.

挂载

将 /dev/vdb挂载到/data目录下

mount /dev/vdb /data

不挂载

取消目录 /data的挂载盘

umount  /data

实际使用命令

查看挂载信息

fdisk -l

格式化磁盘

mkfs.ext4 /dev/vdb
#使用xfs格式化磁盘 如果已经格式化其他格式可能需要增加 -f选项
mkfs.xfs /dev/vdb

挂载

mount /dev/vdb /data

不挂载

umount /data

查看挂载盘文件系统格式

findmnt -D
#或
findmnt --df

参考

Linux快速格式化磁盘 挂载 https://baijiahao.baidu.com/s?id=1611865194036930153&wfr=spider&for=pc
linux xfs和ext4的区别 https://blog.csdn.net/nuli888/article/details/51870184

ext2 无损升级 ext4

ext2 无损升级 ext3、ext4 https://blog.csdn.net/vinson0526/article/details/51919541
ext4与xfs比有什么优势和劣势 https://zhidao.baidu.com/question/1947438887354462108.html