Centos7下对硬盘进行分区并挂载

项目上有几个centos7.2的的云虚拟主机,需要将分配的硬盘格式化并挂载,记录一下挂载的过程。

fdisk -l 查看没有挂载的硬盘

[root@vm-0001 ~]# fdisk -l

Disk /dev/vda: 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
Disk label type: dos
Disk identifier: 0x0005455a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    83886079    41430016   8e  Linux LVM

Disk /dev/vdb: 322.1 GB, 322122547200 bytes, 629145600 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 /dev/mapper/centos-root: 38.1 GB, 38084280320 bytes, 74383360 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 /dev/mapper/centos-swap: 4294 MB, 4294967296 bytes, 8388608 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/vda 已经分了两个区 vda1、vda2,/dev/vdb 还没有分区,我们接下来就将 /dev/vdb 分区并挂载,这里我分成一个区。

使用 fdisk /dev/vdb 对 vdb 进行分区,

[root@vm-0001 ~]# 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 0x5f82c677.

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

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

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

分区后,我们在使用 fdisk -l 确认一下:

[root@vm-0001 ~]# fdisk -l

Disk /dev/vda: 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
Disk label type: dos
Disk identifier: 0x0005455a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    83886079    41430016   8e  Linux LVM

Disk /dev/vdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x5f82c677

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   629145599   314571776   83  Linux

Disk /dev/mapper/centos-root: 38.1 GB, 38084280320 bytes, 74383360 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 /dev/mapper/centos-swap: 4294 MB, 4294967296 bytes, 8388608 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/vdb1

接下来使用 mkfs.ext4 命令对分区进行格式化,我这里是 mkfs.ext4 /dev/vdb1

[root@vm-0001 ~]# 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
19660800 inodes, 78642944 blocks
3932147 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2227175424
2400 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

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

格式化完毕后需要挂载硬盘,这里我挂载到 /data 目录下:

[root@vm-0001 ~]# mkdir /data
[root@vm-0001 ~]# mount /dev/vdb1 /data

挂载完毕后,df -hT 确认一下是否正确:

Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        36G  1.7G   34G   5% /
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs                   tmpfs     3.9G  8.5M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1               xfs       497M  125M  373M  25% /boot
tmpfs                   tmpfs     799M     0  799M   0% /run/user/0
/dev/vdb1               ext4      296G   65M  281G   1% /data

上面显示已经正确挂载到 /data 路径下了。

接下来 vim /etc/fstab 设置开机自动挂载,

vim /etc/fstab

在文件底部增加如下信息:

/dev/vdb1    /data    ext4    defaults    0 0

保存文件即可。

 

版权声明:
作者:Miigua
链接:https://www.miigua.com/article/329.html
来源:米瓜的博客
文章版权归作者所有,未经允许请勿转载。

THE END
二维码
打赏
请在后台主题设置处设置打赏图片
< <上一篇
下一篇>>