您当前的位置: 首页 >  centos

Bulut0907

暂无认证

  • 4浏览

    0关注

    346博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Centos7挂载新磁盘到目录

Bulut0907 发布时间:2021-12-30 16:49:46 ,浏览量:4

目录
  • 1.查看当前硬盘使用状况
  • 2.查看新硬盘
  • 3.硬盘分区
  • 4.格式化分区
  • 5. 挂载到新目录
    • 5.1 挂载硬盘
    • 5.2. 设置开机启动自动挂载
  • 6. 挂载到旧目录/opt(评论区测试成功)

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 /]# 

参数说明:

  • m表示寻求帮助
  • n表示新建一个分区
  • p表示分区类型为主分区(一个磁盘的主分区,最多4个。e表示逻辑分区,可以将一个主分区分成多个逻辑分区,所有主分区的逻辑分区个数最多12个)
  • 分区数量为1(范围为1-4个)
  • w表示写入分区表到磁盘并退出
  • q:如果在执行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表示不会使用Kdump进行系统崩溃的异常信息记录,第二个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
关注
打赏
1664501120
查看更多评论
立即登录/注册

微信扫码登录

0.0383s