红帽RHCE之超级详细的磁盘分区方案_redhat磁盘分区

parted /dev/vdb #对/dev/vdb磁盘进行分区
mklabel gpt #设置磁盘标签也是设置分区方案的标识;(msdos是MBR的分区方案,gpt是gpt的分区方案)
print #再次查看磁盘概要信息,查看标签是否写入
mkpart #创建分区
data1 #分区名称
ext4 #选择文件系统(并不是真的创建文件系统,而是占位符的作用,所以可以随便输入文件系统)
2048s #起始扇区对于大多数磁盘而言,起始扇区为 2048 的倍数较为安全。(第二次分区的起始扇区为601M)
600M #结束扇区,分配600M容量给此分区。
qu #退出parted
udevadm settle #等待系统检测新分区并在/dev目录下创建关联的设备文件(同步)
lsblk #查看磁盘块设备
mkfs.ext4 /dev/vdb1 #设置/dev/vdb1的文件系统(具有格式化的作用)
blkid #查看分区文件系统信息以及UID
fdisk -l #查看磁盘分区情况


**命令行分区:** parted /dev/vdb mkpart data1 ext4 2048s 600M  
 **交互式分区详解:**



[root@boyu ~]# lsblk #查看磁盘块设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 159.1M 0 rom
vda 253:0 0 50G 0 disk
└─vda1 253:1 0 50G 0 part /
vdb 253:16 0 10G 0 disk

[root@boyu ~]# parted /dev/vdb print #打印/dev/vdb磁盘概要信息,(刚开始磁盘是没有标签的,打上什么标签就用什么分区方案
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: loop #此时磁盘还没有标签,需要打上msdos或gpt否则会报错从而不能进行分区
Disk Flags:

Number Start End Size File system Flags
1 0.00B 10.7GB 10.7GB ext4

[root@boyu ~]# parted /dev/vdb #对/dev/vdb磁盘进行分区
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
Yes/No? yes
(parted) print #再次查看磁盘概要信息,查看标签是否写入
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt #设置磁盘标签也是设置分区方案的标识;(msdos是MBR的分区方案,gpt是gpt的分区方案)
Disk Flags:

Number Start End Size File system Name Flags

(parted) mkpart #创建分区
Partition name? []? data1 #分区名称
File system type? [ext2]? ext4 #选择文件系统(并不是真的创建文件系统,而是占位符的作用,所以可以随便输入文件系统)
Start? 2048s #起始扇区对于大多数磁盘而言,起始扇区为 2048 的倍数较为安全。(第二次分区的起始扇区为601M
End? 600M #结束扇区,分配600M容量给此分区。
(parted) qu #退出parted
Information: You may need to update /etc/fstab.

[root@boyu ~]# udevadm settle #等待系统检测新分区并在/dev目录下创建关联的设备文件(同步)
[root@boyu ~]# lsblk #查看磁盘块设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 159.1M 0 rom
vda 253:0 0 50G 0 disk
└─vda1 253:1 0 50G 0 part /
vdb 253:16 0 10G 0 disk
└─vdb1 253:17 0 571M 0 part
[root@boyu ~]# mkfs.ext4 /dev/vdb1 #设置/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
36560 inodes, 146176 blocks
7308 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=150994944
5 block groups
32768 blocks per group, 32768 fragments per group
7312 inodes per group
Superblock backups stored on blocks:
32768, 98304

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

[root@boyu ~]# blkid #查看分区文件系统信息以及UID
/dev/sr0: UUID=“2022-04-01-19-16-54-00” LABEL=“config-2” TYPE=“iso9660”
/dev/vda1: UUID=“4b499d76-769a-40a0-93dc-4a31a59add28” TYPE=“ext4”
/dev/vdb1: UUID=“1a256214-2a01-4935-a26e-5fe36223455c” TYPE=“ext4” PARTLABEL=“data1” PARTUUID=“8b155f85-2d4e-43a7-8494-31db6bd986d4”
[root@boyu ~]# fdisk -l #查看磁盘分区情况

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x0009ac89

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 104857566 52427759+ 83 Linux
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: gpt
Disk identifier: 3F23313C-76B0-4AD1-B81B-CE3D3CE46FCD

Start End Size Type Name

1 2048 1171455 571M Microsoft basic data1


#### 2.2.fdisk的使用(MBR分区)



lsblk #查看磁盘块设备
fdisk /dev/vdb #使用fdisk对/dev/vdb分区
partprobe /dev/vdb1 #将划分的分区从内存同步到磁盘
lsblk #查看磁盘块设备
mkfs.ext4 /dev/vdb1 #设置/dev/vdb1的文件系统(也相当于格式化分区)
blkid #查看分区文件系统信息
fdisk -l #查看磁盘分区情况



[root@boyu ~]# lsblk #查看磁盘块设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 159.1M 0 rom
vda 253:0 0 50G 0 disk
└─vda1 253:1 0 50G 0 part /
vdb 253:16 0 10G 0 disk

[root@boyu ~]# fdisk /dev/vdb #使用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 0x7f5667a2.

Command (m for help): n #创建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #创建主分区(p:主分区,e:扩展分区)
Partition number (1-4, default 1): 1 #主分区序号
First sector (2048-20971519, default 2048): #最开始的扇区,直接回车,默认值是2048开始
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G #最后的扇区,输入想分区的容量,默认是最大容量
Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): p #查看分区表,可以看到目前的分区信息

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x7f5667a2

Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 83 Linux

Command (m for help): w #保存分区信息
The partition table has been altered!

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

[root@boyu ~]# partprobe /dev/vdb1 #将划分的分区从内存同步到磁盘

[root@boyu ~]# lsblk #查看磁盘块设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 159.1M 0 rom
vda 253:0 0 50G 0 disk
└─vda1 253:1 0 50G 0 part /
vdb 253:16 0 10G 0 disk
└─vdb1 253:17 0 1G 0 part

[root@boyu ~]# mkfs.ext4 /dev/vdb1 #设置/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
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

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

[root@boyu ~]# blkid #查看分区文件系统信息
/dev/sr0: UUID=“2022-04-01-19-16-54-00” LABEL=“config-2” TYPE=“iso9660”
/dev/vda1: UUID=“4b499d76-769a-40a0-93dc-4a31a59add28” TYPE=“ext4”
/dev/vdb1: UUID=“ed825353-5d70-4e29-a442-e675ee553406” TYPE=“ext4”

[root@boyu ~]# fdisk -l #查看磁盘分区情况

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x0009ac89

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 104857566 52427759+ 83 Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xf2a70c68

Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 83 Linux


#### 2.3.gdisk的使用(GPT分区)



lsblk #查看磁盘块设备
gdisk /dev/vdb #使用gdisk对/dev/vdb分区
partprobe /dev/vdb1 #将划分的分区从内存同步到磁盘
lsblk #查看磁盘块设备
mkfs.ext4 /dev/vdb1 #设置/dev/vdb1的文件系统
blkid #查看分区文件系统信息
gdisk -l /dev/vdb1 #查看磁盘分区情况



[root@boyu ~]# lsblk #查看磁盘块设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 159.1M 0 rom
vda 253:0 0 50G 0 disk
└─vda1 253:1 0 50G 0 part /
vdb 253:16 0 10G 0 disk

[root@boyu ~]# gdisk /dev/vdb #使用gdisk对/dev/vdb分区
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present

Creating new GPT entries.

Command (? for help): n #创建分区
Partition number (1-128, default 1): #主分区序号
First sector (34-20971486, default = 2048) or {±}size{KMGTP}: #最开始的扇区,默认是2048,直接回车选择默认
Last sector (2048-20971486, default = 20971486) or {±}size{KMGTP}: +500M #最后的扇区,输入想分区的容量,默认是磁盘最大容量
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/vdb: 20971520 sectors, 10.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): A16A075F-FADE-4865-8F93-93A98B89654D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 19947453 sectors (9.5 GiB)

Number Start (sector) End (sector) Size Code Name
1 2048 1026047 500.0 MiB 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 #选择yes,覆盖原有分区表
OK; writing new GUID partition table (GPT) to /dev/vdb.
The operation has completed successfully.

[root@boyu ~]# partprobe /dev/vdb1 #将划分的分区从内存同步到磁盘

[root@boyu ~]# lsblk #查看磁盘块设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 159.1M 0 rom
vda 253:0 0 50G 0 disk
└─vda1 253:1 0 50G 0 part /
vdb 253:16 0 10G 0 disk
└─vdb1 253:17 0 500M 0 part

[root@boyu ~]# mkfs.ext4 /dev/vdb1 #设置/dev/vdb1的文件系统
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

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

[root@boyu ~]# blkid #查看分区文件系统信息
/dev/sr0: UUID=“2022-04-01-19-16-54-00” LABEL=“config-2” TYPE=“iso9660”
/dev/vda1: UUID=“4b499d76-769a-40a0-93dc-4a31a59add28” TYPE=“ext4”
/dev/vdb1: UUID=“3056fc77-8467-4866-9c04-2b2eb9e68bcf” TYPE=“ext4” PARTLABEL=“Linux filesystem” PARTUUID=“75bde7da-ad2e-4bca-9d74-78353f78115e”

[root@boyu ~]# gdisk -l /dev/vdb1 #查看磁盘分区情况
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present

Creating new GPT entries.
Disk /dev/vdb1: 1024000 sectors, 500.0 MiB
Logical sector size: 512 bytes
Disk identifier (GUID): 447F9BA2-3832-407D-85CD-867113057477
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1023966
Partitions will be aligned on 2048-sector boundaries
Total free space is 1023933 sectors (500.0 MiB)


### 3、挂载文件系统


* 添加完文件系统后,最后一步是将文件系统挂载到目录结构中的目录上。
* 将文件系统挂载到目录层次结构上后,用户空间实用程序可以访问设备上的文件或  
 在设备上写入文件。


#### 3.1 手动挂载文件系统


* 手动挂载可用于验证,但是当系统重启,挂载将丢失。



[root@boyu ~]# mkdir /mnt/data1
[root@boyu ~]# mount /dev/vdb1 /mnt/data1
[root@boyu ~]# mount |grep vdb1
/dev/vdb1 on /mnt/data1 type ext4 (rw,relatime,seclabel,data=ordered)


#### 3.2 自动挂载文件系统


* 为确保系统在启动时自动挂载文件系统,需要编辑/etc/fstab文件。
* 在/etc/fstab文件中添加或删除条目后,需要运行 systemctl daemon-reload  
 命令或重启服务器,让systemd注册新配置。



[root@boyu ~]# mkdir /mnt/data1

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

/etc/fstab

Created by anaconda on Thu Mar 7 06:38:37 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=4b499d76-769a-40a0-93dc-4a31a59add28 / ext4 defaults 1 1
① ② ③ ④ ⑤
/dev/vdb1 /mnt/data1 ext4 defaults 0 0

(1)Python所有方向的学习路线(新版)

这是我花了几天的时间去把Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。

最近我才对这些路线做了一下新的更新,知识体系更全面了。

在这里插入图片描述

(2)Python学习视频

包含了Python入门、爬虫、数据分析和web开发的学习视频,总共100多个,虽然没有那么全面,但是对于入门来说是没问题的,学完这些之后,你可以按照我上面的学习路线去网上找其他的知识资源进行进阶。

在这里插入图片描述

(3)100多个练手项目

我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了,只是里面的项目比较多,水平也是参差不齐,大家可以挑自己能做的项目去练练。

在这里插入图片描述

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里无偿获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 21
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值