Centos7挂载新磁盘到目录

无情 阅读:176 2022-06-06 14:11:57 评论:0

1.查看当前硬盘使用状况

[root@bigdata003 /]#  
[root@bigdata003 /]# df -h 
Filesystem      Size  Used Avail Use% Mounted on 
/dev/vda2        84G   45G   40G  53% / 
devtmpfs         32G     0   32G   0% /dev 
tmpfs            32G     0   32G   0% /dev/shm 
tmpfs            32G  3.2G   29G  10% /run 
tmpfs            32G     0   32G   0% /sys/fs/cgroup 
tmpfs           6.3G     0  6.3G   0% /run/user/0 
[root@bigdata003 /]#  

2.查看新硬盘

[root@bigdata003 /]#  
[root@bigdata003 /]# fdisk -l 
 
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009f962 
 
   Device Boot      Start         End      Blocks   Id  System 
/dev/vda1            2048    33556479    16777216   82  Linux swap / Solaris 
/dev/vda2   *    33556480   209715199    88079360   83  Linux 
 
Disk /dev/vdb: 536.9 GB, 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 
 
[root@bigdata003 /]#  

可以看到磁盘/dev/vdb并没有挂载。对于虚拟机扩展磁盘空间,看到的是磁盘有剩余空间未挂载

3.硬盘分区

[root@bigdata003 /]#  
[root@bigdata003 /]# fdisk /dev/vdb 
Welcome to fdisk (util-linux 2.23.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 
Building a new DOS disklabel with disk identifier 0x91c761c0. 
 
Command (m for help): n 
Partition type: 
   p   primary (0 primary, 0 extended, 4 free) 
   e   extended 
Select (default p): p 
Partition number (1-4, default 1): 1 
First sector (2048-1048575999, default 2048):  
Using default value 2048 
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999):  
Using default value 1048575999 
Partition 1 of type Linux and of size 500 GiB is set 
 
Command (m for help): w 
The partition table has been altered! 
 
Calling ioctl() to re-read partition table. 
Syncing disks. 
[root@bigdata003 /]#  

参数说明:

  • n表示新建一个分区
  • p表示分区类型为主分区(e表示逻辑分区)
  • 分区数量为1(范围为1-4个)
  • w表示写入分区表

对于虚拟机扩展磁盘空间,新增分区后,需要reboot服务器

4.格式化分区

[root@bigdata003 /]# 
[root@bigdata003 /]# mkfs -t ext3 /dev/vdb1 
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 
32768000 inodes, 131071744 blocks 
6553587 blocks (5.00%) reserved for the super user 
First data block=0 
Maximum filesystem blocks=4294967296 
4000 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, 11239424, 20480000, 23887872, 71663616, 78675968,  
	102400000 
 
Allocating group tables: done                             
Writing inode tables: done                             
Creating journal (32768 blocks): done 
Writing superblocks and filesystem accounting information: done      
 
[root@bigdata003 /]#  

5. 挂载到新目录

5.1 挂载硬盘

[root@bigdata003 /]# 
[root@bigdata003 /]# mkdir data 
[root@bigdata003 /]# 
[root@bigdata003 /]# mount /dev/vdb1 /data 
[root@bigdata003 /]#  

5.2. 设置开机启动自动挂载

编辑/etc/fstab,在最后添加/dev/vdb1 /data ext3 defaults 0 0

其中第一个0表示不会备份此文件系统,第二个0表示fsck不会检查此文件系统

6. 挂载到旧目录/opt(未测试)

  1. 创建临时目录: mkdir /root/mount_tmp
  2. 拷贝/opt下的所有内容到临时目录: cp -pdr /opt/* /root/mount_tmp
  3. 删除当前/opt目录下的内容: rm -rf /opt/*
  4. 重新挂载硬盘到/opt目录
mount /dev/vdb1 /opt 
cp -pdr /root/mount_tmp/* /opt 
rm /root/mount_tmp -rf 

挂载到/opt,可能只是将/opt的挂载分区换成/dev/vdb1,/opt目录大小并没有改变

  1. 设置开机启动自动挂载, 编辑/etc/fstab,在最后添加/dev/vdb1 /opt ext3 defaults 0 0

标签:linux
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

搜索
排行榜
关注我们

一个IT知识分享的公众号