centos7 挂载新磁盘

一 、挂载新磁盘

查看磁盘

[root@localhost ~]# fdisk -l

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000c81ed

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104857566    52427759+  83  Linux

Disk /dev/vdb: 2199.0 GB, 2199023255552 bytes, 4294967296 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

磁盘/dev/vdb尚有2199GB未分配

查看分区

df -Th 或者lsblk

[root@localhost ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs          tmpfs     7.8G     0  7.8G   0% /dev/shm
tmpfs          tmpfs     7.8G  488K  7.8G   1% /run
tmpfs          tmpfs     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1      ext4       50G  2.0G   45G   5% /
tmpfs          tmpfs     1.6G     0  1.6G   0% /run/user/0

磁盘/dev/vdb实际并没有挂载

磁盘分区

注意:

# 执行"fdisk /dev/vdb"后,出现"Command (m for help)"提示时,依次输入下面指令
n -> p -> 1 -> 回车 -> 回车 -> w

详情:

[root@localhost ~]# 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 0x11e106cf.

WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 
partition table format (GPT).


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-4294967295, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4294967294, default 4294967294): 
Using default value 4294967294
Partition 1 of type Linux and of size 2 TiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

说明:

n:添加新分区

p:设为主分区

1: 分区序号

两个回车指是开始和结束的磁盘大小;

w:写入磁盘

tips: 可以使用partprobe命令刷新分区信息

格式分区

[root@localhost ~]# mkfs.ext4 /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
134217728 inodes, 536870655 blocks
26843532 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
16384 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, 214990848, 512000000

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

挂载磁盘

mkdir /mnt
mount /dev/vdb1 /mnt

确认磁盘

[root@localhost ~]# fdisk -l 

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000c81ed

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104857566    52427759+  83  Linux

Disk /dev/vdb: 2199.0 GB, 2199023255552 bytes, 4294967296 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: 0x11e106cf

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048  4294967294  2147482623+  83  Linux

确认分区

[root@localhost ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs          tmpfs     7.8G     0  7.8G   0% /dev/shm
tmpfs          tmpfs     7.8G  492K  7.8G   1% /run
tmpfs          tmpfs     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1      ext4       50G  2.0G   45G   5% /
tmpfs          tmpfs     1.6G     0  1.6G   0% /run/user/0
/dev/vdb1      ext4      2.0T   81M  1.9T   1% /mnt

开机启动

echo "/dev/vdb1 /mnt ext4 defaults 0 0" >> /etc/fstab

二 、挂载旧目录

如果你要用来挂载的目录里面并不是空的,那么挂载了文件系统之后,原目录下的东西就会暂时的消失。并不是被覆盖掉,而是暂时的隐藏了起来,等到新分割槽被卸除之后,则原目录原本的内容就会再次出来。

如果要永久挂载已有目录,可以在新硬盘创建文件系统后,先挂载到一个临时目录,然后把要扩展的目录复制到这临时目录,然后删除要扩展的目录,再卸载临时挂载点,重新挂载到要扩展的目录上。举例:

# 比如要扩充 /var

# 在创建好文件系统后 新建临时挂载点 mnt
mkdir /mnt

# 将/dev/sdb1挂载到/mnt下
mount /dev/vdb1 /mnt

# 拷贝/var下的所有内容到新的硬盘
cp -pdr /var/* /mnt

# 删除当前/var目录下的内容
rm -rf /var/*

# 卸载磁盘
umount /dev/vdb1

# 重新挂载磁盘到/var目录
mount /dev/vdb1 /var

# 过程中若提示磁盘忙,使用fuser找出将正在使用磁盘的程序并结束掉;
fuser -m -v /var
fuser -m -v -i -k /var

# 开机启动
echo "/dev/vdb1 /var ext4 defaults 0 0" >> /etc/fstab

你可能感兴趣的:(centos7 挂载新磁盘)