首页 >> 知识 >> Centos7挂载新磁盘到目录

Centos7挂载新磁盘到目录

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

1.查看当前硬盘使用状况 [root@bigdata003 /]# [root@bigdata003 /]# df -hFilesystem Size Used Avail Use% Mounted on/dev/vda2 84G 45G 40G 53% /devtmpfs 32G 0 32G 0% /devtmpfs 32G 0 32G 0% /dev/shmtmpfs 32G 3.2G 29G 10% /runtmpfs 32G 0 32G 0% /sys/fs/cgrouptmpfs 6.3G 0 6.3G 0% /run/user/0[root@bigdata003 /]# 2.查看新硬盘 [root@bigdata003 /]# [root@bigdata003 /]# fdisk -lDisk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0009f962 Device Boot Start End Blocks Id System/dev/vda1 2048 33556479 16777216 82 Linux swap / Solaris/dev/vda2 * 33556480 209715199 88079360 83 LinuxDisk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes[root@bigdata003 /]#

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

3.硬盘分区 [root@bigdata003 /]# [root@bigdata003 /]# fdisk /dev/vdbWelcome 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 tableBuilding a new DOS disklabel with disk identifier 0x91c761c0.Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): 1First sector (2048-1048575999, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): Using default value 1048575999Partition 1 of type Linux and of size 500 GiB is setCommand (m for help): wThe 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/vdb1mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks32768000 inodes, 131071744 blocks6553587 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=42949672964000 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): doneWriting 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(评论区测试成功) 创建临时目录: mkdir /root/mount_tmp拷贝/opt下的所有内容到临时目录: cp -pdr /opt/* /root/mount_tmp删除当前/opt目录下的内容: rm -rf /opt/*重新挂载硬盘到/opt目录 mount /dev/vdb1 /optcp -pdr /root/mount_tmp/* /optrm /root/mount_tmp -rf

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

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