站长资讯网
最全最丰富的资讯网站

实验:新增硬盘、MBR分区、制作文件系统并挂载使用

前期准备:Vmware workstaton虚拟机软件及可用的Centos7系统

1、在虚拟机中新添一块120G的硬盘,已备分区使用,重启系统即可进行分区操作。

2、查看系统上是否识别出的新增的硬盘:

[root@centos7 ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 200G 0 disk

├─sda1 8:1 0 1G 0 part /boot

├─sda2 8:2 0 50G 0 part /

├─sda3 8:3 0 2G 0 part [SWAP]

├─sda4 8:4 0 1K 0 part

└─sda5 8:5 0 10G 0 part /data

sdb 8:16 0 120G 0 disk

sr0 11:0 1 10G 0 rom

3、下面对/dev/sdb硬盘进行分区,硬盘一共120G要求分3个分区,第一个分区为40G,第二个分区为50G,第三个分区为30G:

[root@centos7 ~]# fdisk /dev/sdb

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 0x15c20061.

Command (m for help): n

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p):

Using default response p

Partition number (1-4, default 1):

First sector (2048-251658239, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-251658239, default 251658239): +40G

Partition 1 of type Linux and of size 40 GiB is set

Command (m for help): N

Partition type:

p primary (1 primary, 0 extended, 3 free)

e extended

Select (default p):

Using default response p

Partition number (2-4, default 2):

First sector (83888128-251658239, default 83888128):

Using default value 83888128

Last sector, +sectors or +size{K,M,G} (83888128-251658239, default 251658239): +50G

Partition 2 of type Linux and of size 50 GiB is set

Command (m for help): n

Partition type:

p primary (2 primary, 0 extended, 2 free)

e extended

Select (default p):

Using default response p

Partition number (3,4, default 3):

First sector (188745728-251658239, default 188745728):

Using default value 188745728

Last sector, +sectors or +size{K,M,G} (188745728-251658239, default 251658239):

Using default value 251658239

Partition 3 of type Linux and of size 30 GiB is set

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

4、查看分区效果:

[root@centos7 ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 200G 0 disk

├─sda1 8:1 0 1G 0 part /boot

├─sda2 8:2 0 50G 0 part /

├─sda3 8:3 0 2G 0 part [SWAP]

├─sda4 8:4 0 1K 0 part

└─sda5 8:5 0 10G 0 part /data

sdb 8:16 0 120G 0 disk

├─sdb1 8:17 0 40G 0 part

├─sdb2 8:18 0 50G 0 part

└─sdb3 8:19 0 30G 0 part

sr0 11:0 1 10G 0 rom

5、通知内核读取更新的分区表:

查看分区表是否更新:

[root@centos7 ~]# partprobe /dev/sdb

[root@centos7 ~]# cat /proc/partitions

major minor #blocks name

8 0 209715200 sda

8 1 1048576 sda1

8 2 52428800 sda2

8 3 2097152 sda3

8 4 1 sda4

8 5 10485760 sda5

8 16 125829120 sdb

8 17 41943040 sdb1

8 18 52428800 sdb2

8 19 31456256 sdb3

11 0 10491904 sr0

成功分区后即可制作文件系统了。

6、对新硬盘分区创建文件系统

新增磁盘分区完成后,开始制作文件系统。对sdb1分区进行制做xfs文件系统为例,以演示创建文件系统,其它分区方法一样。

[root@centos7 ~]# mkfs.xfs /dev/sdb1

meta-data=/dev/sdb1 isize=512 agcount=4, agsize=2621440 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=10485760, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal log bsize=4096 blocks=5120, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

查看/dev/sdb1的分区类型:

[root@centos7 ~]# blkid

/dev/sda1: UUID="bfb9c261-33b4-4602-91ea-a71995a8ef96" TYPE="xfs"

/dev/sda2: UUID="4f823650-e522-46fa-9904-c1e7476f89ad" TYPE="xfs"

/dev/sda3: UUID="8cc37a26-d321-4331-a020-05f3a08af552" TYPE="swap"

/dev/sda5: UUID="0f16b61c-d601-4783-8e3d-0a6452aad27d" TYPE="xfs"

/dev/sdb1: UUID="fd61aaf0-bc8e-4da4-8e66-d29d5696b2d5" TYPE="xfs"

/dev/sr0: UUID="2018-11-26-14-22-58-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"

可见sdb1分区已经创建完成,下面就可以挂载分区后正常使用了。

7、挂载新硬盘分区:挂载/dev/sdb1分区:

创建/dev/sdb1分区的挂载点:

[root@centos7 ~]# mkdir /madedu_data

[root@centos7 ~]# mount /dev/sdb1 /magedu_data

mount: mount point /magedu_data does not exist

[root@centos7 ~]# mount /dev/sdb1 /madedu_data

[root@centos7 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda2 50G 3.9G 47G 8% /

devtmpfs 1.2G 0 1.2G 0% /dev

tmpfs 1.2G 0 1.2G 0% /dev/shm

tmpfs 1.2G 11M 1.2G 1% /run

tmpfs 1.2G 0 1.2G 0% /sys/fs/cgroup

/dev/sda5 10G 33M 10G 1% /data

/dev/sda1 1014M 174M 841M 18% /boot

tmpfs 233M 0 233M 0% /run/user/0

tmpfs 233M 12K 233M 1% /run/user/42

/dev/sdb1 40G 33M 40G 1% /madedu_data

8、配置开机自动挂载

挂载完成后,记住要写在/etc/fstab配置文件里,使其新增磁盘分区在开机后能自动挂载。

[root@centos7 ~]# vim /etc/fstab

#

/etc/fstab

Created by anaconda on Thu Jan 3 22:00:10 2019

#

Accessible filesystems, by reference, are maintained under '/dev/disk'

See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=4f823650-e522-46fa-9904-c1e7476f89ad / xfs defaults 0 0

UUID=bfb9c261-33b4-4602-91ea-a71995a8ef96 /boot xfs defaults 0 0

UUID=0f16b61c-d601-4783-8e3d-0a6452aad27d /data xfs defaults 0 0

UUID=8cc37a26-d321-4331-a020-05f3a08af552 swap swap defaults 0 0

/dev/sdb1 /madedu_data xfs

defaults 0 0

将此内容添加其中:/dev/sdb1 /magedu_data xfs defaults 0 0

检查配置文件的语法:

[root@Magedu ~]# mount -a

执行该命令后,没有报错,说明配置文件正确,能开机自动挂载,到此整个新增硬盘、分区、制作文件系统以及自动挂载配置全过程完成结束。

赞(0)
分享到: 更多 (0)
网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号