当前位置:网站首页>实现新增加硬盘的磁盘分区和文件系统挂载
实现新增加硬盘的磁盘分区和文件系统挂载
2022-07-27 12:48:00 【一直在努力学习的菜鸟】
实现新增加硬盘的磁盘分区和文件系统挂载
1. 查看磁盘设备
[[email protected] ~]#ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
2. 添加硬盘







3. 别名实现新添加硬盘的识别
[[email protected] ~]#alias scandisk='echo - - - > /sys/class/scsi_host/host0/scan;echo - - - > /sys/class/scsi_host/host1/scan;echo - - - > /sys/class/scsi_host/host2/scan'
[[email protected] ~]#alias scandisk
alias scandisk='echo - - - > /sys/class/scsi_host/host0/scan;echo - - - > /sys/class/scsi_host/host1/scan;echo - - - > /sys/class/scsi_host/host2/scan'
[[email protected] ~]#scandisk
[[email protected] ~]#lsblk
[[email protected] ~]#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 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdb 8:16 0 200G 0 disk
sr0 11:0 1 9.5G 0 rom
[[email protected] ~]#ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5 /dev/sdb
4. 创建分区
MBR:Master Boot Record,1982年,使用32位表示扇区数,分区不超过2T
MBR分区中一块硬盘最多有4个主分区,也可以3主分区+1扩展(N个逻辑分区)
MBR分区:主和扩展分区对应的1–4,/dev/sda3,逻辑分区从5开始,/dev/sda5
GPT:GUID(Globals Unique Identifiers) partition table 支持128个分区,使用64位,支持8Z(
512Byte/block )64Z ( 4096Byte/block)
fdisk /dev/sda:管理MBR分区
gdisk /dev/sda:类fdisk的GPT分区工具
子命令:
p:分区列表
t:更改分区类型
n:创建新分区
d:删除分区
v:校验分区
u:转换单位
w:保存并退出
q:不保存并退出
[[email protected] ~]#yum -y install gdisk
[[email protected] ~]#gdisk /dev/sdb
Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-419430366, default = 2048) or {
+-}size{
KMGTP}: 2048
Last sector (2048-419430366, default = 419430366) or {
+-}size{
KMGTP}: +1G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 419430400 sectors, 200.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0351662F-7E98-4CC8-B5D4-8973B19FC01C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 419430366
Partitions will be aligned on 2048-sector boundaries
Total free space is 417333181 sectors (199.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 2099199 1024.0 MiB 8300 Linux filesystem
Command (? for help): n
Partition number (2-128, default 2): 2
First sector (34-419430366, default = 2099200) or {
+-}size{
KMGTP}:
Last sector (2099200-419430366, default = 419430366) or {
+-}size{
KMGTP}: +100G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 419430400 sectors, 200.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0351662F-7E98-4CC8-B5D4-8973B19FC01C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 419430366
Partitions will be aligned on 2048-sector boundaries
Total free space is 207617981 sectors (99.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 2099199 1024.0 MiB 8300 Linux filesystem
2 2099200 211814399 100.0 GiB 8300 Linux filesystem
Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-419430366, default = 211814400) or {
+-}size{
KMGTP}:
Last sector (211814400-419430366, default = 419430366) or {
+-}size{
KMGTP}: +50G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 419430400 sectors, 200.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0351662F-7E98-4CC8-B5D4-8973B19FC01C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 419430366
Partitions will be aligned on 2048-sector boundaries
Total free space is 102760381 sectors (49.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 2099199 1024.0 MiB 8300 Linux filesystem
2 2099200 211814399 100.0 GiB 8300 Linux filesystem
3 211814400 316671999 50.0 GiB 8300 Linux filesystem
Command (? for help): n
Partition number (4-128, default 4): 4
First sector (34-419430366, default = 316672000) or {
+-}size{
KMGTP}:
Last sector (316672000-419430366, default = 419430366) or {
+-}size{
KMGTP}: +1k
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 419430400 sectors, 200.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0351662F-7E98-4CC8-B5D4-8973B19FC01C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 419430366
Partitions will be aligned on 2048-sector boundaries
Total free space is 102760379 sectors (49.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 2099199 1024.0 MiB 8300 Linux filesystem
2 2099200 211814399 100.0 GiB 8300 Linux filesystem
3 211814400 316671999 50.0 GiB 8300 Linux filesystem
4 316672000 316672001 1024 bytes 8300 Linux filesystem
Command (? for help): n
Partition number (5-128, default 5): 5
First sector (34-419430366, default = 316674048) or {
+-}size{
KMGTP}:
Last sector (316674048-419430366, default = 419430366) or {
+-}size{
KMGTP}: +2G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 419430400 sectors, 200.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0351662F-7E98-4CC8-B5D4-8973B19FC01C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 419430366
Partitions will be aligned on 2048-sector boundaries
Total free space is 98566075 sectors (47.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 2099199 1024.0 MiB 8300 Linux filesystem
2 2099200 211814399 100.0 GiB 8300 Linux filesystem
3 211814400 316671999 50.0 GiB 8300 Linux filesystem
4 316672000 316672001 1024 bytes 8300 Linux filesystem
5 316674048 320868351 2.0 GiB 8300 Linux filesystem
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
5. 创建文件系统
[[email protected] ~]#lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs b36add53-d3f4-4ef7-9444-3c69bffb95db /boot
├─sda2 ext4 099f9e4c-8094-4e19-ace1-f99b7f81744b /
├─sda3 xfs 756b01bd-ccee-4563-a492-7368bb57b100 /data
├─sda4
└─sda5 swap 076fc1a8-ac81-4378-8fcf-6968c31519bc [SWAP]
sdb
├─sdb1
├─sdb2
├─sdb3
├─sdb4
└─sdb5
sr0 iso9660 CentOS 7 x86_64 2020-11-02-15-15-23-00
[[email protected] ~]#mkfs.xfs /dev/sdb1
[[email protected] ~]#mkfs.ext4 /dev/sdb2
[[email protected] ~]#mkfs.xfs /dev/sdb3
[[email protected] ~]#mkswap /dev/sdb5
[[email protected] ~]#lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs b36add53-d3f4-4ef7-9444-3c69bffb95db /boot
├─sda2 ext4 099f9e4c-8094-4e19-ace1-f99b7f81744b /
├─sda3 xfs 756b01bd-ccee-4563-a492-7368bb57b100 /data
├─sda4
└─sda5 swap 076fc1a8-ac81-4378-8fcf-6968c31519bc [SWAP]
sdb
├─sdb1 xfs 2a668187-9013-4187-9177-bcbcff8842f0
├─sdb2 ext4 cd43676b-cd3f-409c-8c62-374db8c02ffe
├─sdb3 xfs 1d8d09e7-dd06-4e08-8021-b34f64cf77b1
├─sdb4
└─sdb5 swap 5a4fa393-66c2-4530-a058-f2602130da6a
sr0 iso9660 CentOS 7 x86_64 2020-11-02-15-15-23-00
[[email protected] ~]#partprobe #同步分区表
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
6. 挂载
[[email protected] ~]#vim /etc/fstab
UUID=cd43676b-cd3f-409c-8c62-374db8c02ffe /root ext4 defaults 1 1
UUID=2a668187-9013-4187-9177-bcbcff8842f0 /boot xfs defaults 0 0
UUID=1d8d09e7-dd06-4e08-8021-b34f64cf77b1 /data xfs defaults 0 0
UUID=5a4fa393-66c2-4530-a058-f2602130da6a swap swap defaults 0 0
[[email protected] ~]#mount -a #使添加新的挂载项生效
[[email protected] ~]#swapon -a #激活所有的交换分区
[[email protected] ~]#lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs b36add53-d3f4-4ef7-9444-3c69bffb95db /boot
├─sda2 ext4 099f9e4c-8094-4e19-ace1-f99b7f81744b /
├─sda3 xfs 756b01bd-ccee-4563-a492-7368bb57b100 /data
├─sda4
└─sda5 swap 076fc1a8-ac81-4378-8fcf-6968c31519bc [SWAP]
sdb
├─sdb1 xfs 2a668187-9013-4187-9177-bcbcff8842f0 /boot
├─sdb2 ext4 cd43676b-cd3f-409c-8c62-374db8c02ffe /root
├─sdb3 xfs 1d8d09e7-dd06-4e08-8021-b34f64cf77b1 /data
├─sdb4
└─sdb5 swap 5a4fa393-66c2-4530-a058-f2602130da6a [SWAP]
sr0 iso9660 CentOS 7 x86_64 2020-11-02-15-15-23-00
7. 查看磁盘空间使用情况
[[email protected] ~]#df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 980M 0 980M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda2 99G 2.6G 91G 3% /
/dev/sdb3 50G 33M 50G 1% /data
/dev/sdb1 1014M 33M 982M 4% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb2 99G 61M 94G 1% /root
[[email protected] ~]#free -h
total used free shared buff/cache available
Mem: 1.9G 165M 1.5G 9.5M 317M 1.6G
Swap: 4.0G 0B 4.0G
边栏推荐
- Redis distributed online installation
- Xshell7 can log in to MySQL virtual machine, but not mysql
- 初学者入门:使用WordPress搭建一个专属自己的博客
- feign的动态代理
- Connotative quotations
- 固定定位
- Xianghe meat cake in memory
- Distributed system architecture theory and components
- "Game engine light in light out" 4.1 unity shader and OpenGL shader
- Summary of common methods of ArrayList
猜你喜欢

Will causal learning open the next generation of AI? Chapter 9 Yunji datacanvas officially released the open source project of ylarn causal learning

C program debugging and exception handling (try catch)

Jesd204b debugging notes (practical version)

Detail try catch finally

Security measures for tcp/ip protocol vulnerabilities

Gan: generate adversarial networks

Getting started for beginners: build your own blog with WordPress

GAN:生成对抗网络 Generative Adversarial Networks

Specify the add method of HashSet

Distributed system architecture theory and components
随机推荐
Flinksql synchronizes data from Oracle to Doris, with a total of more than 50 fields and more than 30 million entries in Oracle tables
正则表达式去除两端空格
From the perspective of it, the CIO of B2B industry talks about how to change from "cost center" to "growth center"?
redis分布式在线安装
Firefox 103 发布,更快、更安全
Xposed+FDex2 app脱壳 (黑猫投诉app脱壳)
2022 global Vocational Education Industry Development Report
Getting started for beginners: build your own blog with WordPress
Poj1548 robots [bipartite graph minimum path coverage]
A survey of video game addictive behavior research
[Nuxt 3] (十二) 项目目录结构 2
Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions
Feign的两个调用处理器
Detail throw and throws
Why do you need foreign keys?
CEPH distributed storage performance tuning (6)
Sff1004-mhchxm diode sff1004
轮播图
Security measures for tcp/ip protocol vulnerabilities
PG synchronizes multiple data tables to MySQL. Is there a way to simplify the configuration?