记一次 centos7 下磁盘分区、格式化、挂载全过程(步骤详细!!!)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24871519/article/details/85862090

前情提要

由于测试环境需要,需准备一个大于400G的磁盘空间

具体步骤

查看磁盘使用情况

没有看到大点的磁盘空间,相信还有很多的未挂载磁盘空间。

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   14G  978M   13G   8% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.9M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M  14% /boot
tmpfs                    783M     0  783M   0% /run/user/0

查看硬盘挂载情况

可以看到sda 有500G,其下有两个分区sda1, sda2

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0  500G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   15G  0 part
  ├─centos-root 253:0    0 13.4G  0 lvm  /
  └─centos-swap 253:1    0  1.6G  0 lvm  [SWAP]
sr0              11:0    1 1024M  0 rom

磁盘分区

输入n 开始新增分区,以下都是回车,就是选择的默认将其余空间全分到sda3。

别忘了partprobe 命令。

[root@localhost ~]# fdisk /dev/sda
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.

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (33554432-1048575999, default 33554432):
Using default value 33554432
Last sector, +sectors or +size{K,M,G} (33554432-1048575999, default 1048575999):
Using default value 1048575999
Partition 3 of type Linux and of size 484 GiB is set

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@localhost ~]# partprobe
[root@localhost ~]#

磁盘格式化

[root@localhost ~]# mkfs -t ext4 /dev/sda3
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
31719424 inodes, 126877696 blocks
6343884 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2275409920
3872 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

进行挂载

我将此块空间挂在/home/data 目录下。

[root@localhost ~]# mkdir /home/data
[root@localhost ~]# mount /dev/sda3 /home/data
[root@localhost ~]#

检查是否正常

可以看到sda3 已经挂载上去了。

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   14G  978M   13G   8% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.9M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M  14% /boot
tmpfs                    783M     0  783M   0% /run/user/0
/dev/sda3                477G   73M  452G   1% /home/data

设置开机挂载

到 /etc/fstab 下配置挂载信息,添加一条记录。

/dev/sda3 /home/data ext4 defaults 0 0

测试一下fstab 文件是否正常运行:

[root@localhost ~]# mount -a

参考内容

猜你喜欢

转载自blog.csdn.net/qq_24871519/article/details/85862090