博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
实验:新增硬盘、MBR分区、制作文件系统并挂载使用
阅读量:5746 次
发布时间:2019-06-18

本文共 7225 字,大约阅读时间需要 24 分钟。

前期准备: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

附加内容:[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 10G 0 disk
├─sdb1 8:17 0 1G 0 part
└─sdb2 8:18 0 2G 0 part
sdc 8:32 0 10G 0 disk
sr0 11:0 1 10G 0 rom
此处我们新创建了sdb和sdc两个硬盘,并且将sdb分了sdb1和sdb2两个分区,若想将sdc的分区与sdb一样,我们将sdb的分区表克隆至sdc即可,我们要做如下操作:
[root@centos7 ~]# hexdump -C -n 512 /dev/sdb
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001b0 00 00 00 00 00 00 00 00 ae bb 79 e2 00 00 00 20 |..........y.... |
000001c0 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 15 |!...(....... ...|
000001d0 51 05 83 2a a0 0a 00 00 40 00 00 00 40 00 00 00 |Q..
....@...@...|
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
00000200
[root@centos7 ~]# hexdump -C -n 512 /dev/sdc
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000200
我们看到sdb有数据。sdc是空的,
[root@centos7 ~]# dd if=/dev/sdb of=/dev/sdc bs=1 count=66 skip=446 seek=446 (注:count=66,是因为中间的64位字节还要加上55 aa 两个标记位!)
66+0 records in
66+0 records out
66 bytes (66 B) copied, 0.00506342 s, 13.0 kB/s
[root@centos7 ~]# hexdump -C -n 512 /dev/sdc
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 |............... |
000001c0 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 15 |!...(....... ...|
000001d0 51 05 83 2a a0 0a 00 00 40 00 00 00 40 00 00 00 |Q..*....@...@...|
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
00000200
[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 10G 0 disk
├─sdb1 8:17 0 1G 0 part
└─sdb2 8:18 0 2G 0 part
sdc 8:32 0 10G 0 disk
├─sdc1 8:33 0 1G 0 part
└─sdc2 8:34 0 2G 0 part
sr0 11:0 1 10G 0 rom
此时的sdc与sdb已然同步。
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 /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

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

转载于:https://blog.51cto.com/14128387/2348574

你可能感兴趣的文章
sql server 触发器
查看>>
[工具]前端自动化工具grunt+bower+yoman
查看>>
自动化测试之WatiN(2)
查看>>
关于完成生鲜电商项目后的一点总结
查看>>
noip2012 普及组
查看>>
第二阶段 铁大Facebook——十天冲刺(10)
查看>>
Java判断是否为垃圾_Java GC如何判断对象是否为垃圾
查看>>
多项式前k项和java_多项式朴素贝叶斯softmax改变
查看>>
java数组只能交换0下标和n_编程练习-只用0交换排序数组
查看>>
centos7安装mysql视频教程_centos7安装mysql(完整)
查看>>
php图片赋值,php如何优雅地赋值
查看>>
【探索HTML5第二弹01】HTML5的前世今生以及来世
查看>>
Failed to connect to remote VM. Connection refused. Connection refused: connect
查看>>
freeze
查看>>
JS时间转时间戳,时间戳转时间。时间显示模式。
查看>>
SAP HANA存储过程结果视图调用
查看>>
设计模式 ( 十八 ):State状态模式 -- 行为型
查看>>
OracleLinux安装说明
查看>>
nova分析(7)—— nova-scheduler
查看>>
Entity Framework 实体框架的形成之旅--Code First模式中使用 Fluent API 配置(6)
查看>>