一、磁盘分区
(一)概述
原始磁盘需要经过那些操作才能存取数据?
原始磁盘的形态是一个光滑的盘体;
需要将盘体划分出柱面和磁道,然后将磁道划分为多个扇区,称为“低级格式化”;
为了有效组织磁盘和提高i\\o效率,还需要进行“分区”;
此时,磁盘还不能存储数据,还需要对每一分区中的扇区进行逻辑编号,并建立数据结构和磁盘数据的管理方式,称为“高级格式化”,本质上是在分区上确定了文件系统,便可以进行数据存储了。
如果把原始磁盘比作待开发的地块
那么,
“低级格式化”相当于在该地块上修建了道路和房屋;
“分区”相当于根据地理区域划分不同的小区;
“高级格式化”相当于将小区内的房屋进行标记。
windows操作系统,分区、格式化之后,就可以建目录存储文件了。
而linux操作系统则与windows相反,需要先虚拟一个根目录,再将磁盘挂载到根目录。
(二)实践
1. 查看当前分区情况:
工具fdisk:用于linux的磁盘分区表操作
root@linux:~# fdisk -ldisk /dev/vda: 40 gib, 42949672960 bytes, 83886080 sectors# 磁盘大小为 40gunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisklabel type: gptdisk identifier: ec404e4b-bf45-4dee-8d63-3d59fbb9c44edevice start end sectors size type/dev/vda1 227328 41943006 41715679 19.9g linux filesystem /dev/vda14 2048 10239 8192 4m bios boot/dev/vda15 10240 227327 217088 106m efi system# 磁盘分区约为20g,还有20g的空间未使用partition table entries are not in disk order.2. 创建新分区root@linux:~# fdisk /dev/vdawelcome to fdisk (util-linux 2.31.1).changes will remain in memory only, until you decide to write them.be careful before using the write command.command (m for help): p # 列出磁盘分区表 disk /dev/vda: 40 gib, 42949672960 bytes, 83886080 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisklabel type: gptdisk identifier: ec404e4b-bf45-4dee-8d63-3d59fbb9c44edevice start end sectors size type/dev/vda1 227328 41943006 41715679 19.9g linux filesystem/dev/vda14 2048 10239 8192 4m bios boot/dev/vda15 10240 227327 217088 106m efi systempartition table entries are not in disk order.command (m for help): n # 创建新分区partition number (2-13,16-128, default 2): # 默认回车first sector (41943007-83886046, default 41943040): # 默认回车last sector, +sectors or +size{k,m,g,t,p} (41943040-83886046, default 83886046): +10g # 使用size方式定义10g大小created a new partition 2 of type 'linux filesystem' and of size 10 gib.command (m for help): pdisk /dev/vda: 40 gib, 42949672960 bytes, 83886080 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisklabel type: gptdisk identifier: ec404e4b-bf45-4dee-8d63-3d59fbb9c44edevice start end sectors size type/dev/vda1 227328 41943006 41715679 19.9g linux filesystem/dev/vda2 41943040 62914559 20971520 10g linux filesystem/dev/vda14 2048 10239 8192 4m bios boot/dev/vda15 10240 227327 217088 106m efi systempartition table entries are not in disk order.command (m for help): w # 保存、退出the partition table has been altered.syncing disks.3. 查看新创建分区root@linux:~# lsblkname maj:min rm size ro type mountpointvda 252:0 0 40g 0 disk ├─vda1 252:1 0 19.9g 0 part /├─vda2 252:2 0 10g 0 part ├─vda14 252:14 0 4m 0 part └─vda15 252:15 0 106m 0 part /boot/efi4. 格式化命令mkfs(make file system):在特定的分区上建立linux文件系统。root@linux:~# mkfs # 两次键入tab,则可展示支持的文件类型mkfs mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.ntfs mkfs.xfs mkfs.bfs mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.vfat root@linux:~# mkfs.ext3 /dev/vda2 # 在新分区创建ext3的文件系统mke2fs 1.44.1 (24-mar-2018)creating filesystem with 2621440 4k blocks and 655360 inodesfilesystem uuid: 0e6a8449-acbf-4428-a5d7-b67b4535b844superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632allocating group tables: done writing inode tables: done creating journal (16384 blocks): donewriting superblocks and filesystem accounting information: done5. 挂载命令mount:用来挂载文件系统。root@linux:~# mkdir /test2root@linux:~# mount /dev/vda2 /test2/ root@linux:~# ls /test2/lost+found6. 查看分区挂载点及文件类型root@linux:~# df -tfilesystem type 1k-blocks used available use% mounted onudev devtmpfs 1007416 0 1007416 0% /devtmpfs tmpfs 204092 776 203316 1% /run/dev/vda1 ext4 20145724 3279936 16849404 17% /tmpfs tmpfs 1020448 0 1020448 0% /dev/shmtmpfs tmpfs 5120 0 5120 0% /run/locktmpfs tmpfs 1020448 0 1020448 0% /sys/fs/cgroup/dev/vda15 vfat 106858 3668 103190 4% /boot/efitmpfs tmpfs 204088 8 204080 1% /run/user/1001/dev/vda2 ext3 10255672 23096 9708288 1% /test2二、逻辑卷管理(一)概述逻辑卷管理也就是lvm(logical volume manager),位于磁盘和操作系统之间,将一个或多个磁盘分区(pv)虚拟为一个卷组(vg),并在vg上面划分一些逻辑卷(lv)。逻辑卷可再进行格式化、挂载,并且逻辑卷可以动态伸缩。也就是从物理磁盘或分区开始,经过pv--vg--lv(形成逻辑卷)之后,将逻辑卷看成新的磁盘进行分区、格式化并挂载,供主机使用。(二)实践使用lsblk命令查看系统的磁盘使用情况(lsblk--list block);使用fdisk命令进行分区;使用pvcreate创建物理卷,使用vgcreate创建卷组;使用lvcreate创建逻辑卷。1. 创建新分区vda3root@linux:~# fdisk /dev/vdawelcome to fdisk (util-linux 2.31.1).changes will remain in memory only, until you decide to write them.be careful before using the write command.command (m for help): npartition number (3-13,16-128, default 3): first sector (62914560-83886046, default 62914560): last sector, +sectors or +size{k,m,g,t,p} (62914560-83886046, default 83886046): +8gcreated a new partition 3 of type 'linux filesystem' and of size 8 gib.command (m for help): pdisk /dev/vda: 40 gib, 42949672960 bytes, 83886080 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisklabel type: gptdisk identifier: ec404e4b-bf45-4dee-8d63-3d59fbb9c44edevice start end sectors size type/dev/vda1 227328 41943006 41715679 19.9g linux filesystem/dev/vda2 41943040 62914559 20971520 10g linux filesystem/dev/vda3 62914560 79691775 16777216 8g linux filesystem/dev/vda14 2048 10239 8192 4m bios boot/dev/vda15 10240 227327 217088 106m efi systempartition table entries are not in disk order.command (m for help): wthe partition table has been altered.syncing disks.
2. 创建物理卷命令pvcreate:用于将物理硬盘分区初始化为物理卷。root@linux:~# pvcreate /dev/vda3 physical volume /dev/vda3 successfully created.root@linux:~# pvdisplay /dev/vda3 /dev/vda3 is a new physical volume of 8.00 gib --- new physical volume --- pv name /dev/vda3 vg name pv size 8.00 gib allocatable no pe size 0 total pe 0 free pe 0 allocated pe 0 pv uuid ke8k0x-rgzl-fejo-1avo-fppo-hhep-wvb79k3. 创建卷组命令vgcreate:用于创建lvm卷组(volume group),将多个物理卷组织成一个整体,屏蔽底层物理卷细节。root@linux:~# vgcreate vgtest /dev/vda3 volume group vgtest successfully createdroot@linux:~# vgdisplay vg0 volume group vg0 not found cannot process volume group vg0root@linux:~# vgdisplay vgtest --- volume group --- vg name vgtest system id format lvm2 metadata areas 1 metadata sequence no 1 vg access read/write vg status resizable max lv 0 cur lv 0 open lv 0 max pv 0 cur pv 1 act pv 1 vg size <8.00 gib pe size 4.00 mib total pe 2047 alloc pe / size 0 / 0 free pe / size 2047 / <8.00 gib vg uuid 2tm5qm-9fur-xttu-55nq-nyze-atyg-sjqq6y4. 创建逻辑卷命令lvcreate:创建lvm的逻辑卷。root@linux:~# lvcreate -l 200m -n lv0 vgtest logical volume lv0 created.
5. 管理逻辑卷
# 查看物理卷信息root@linux:~# pvs pv vg fmt attr psize pfree /dev/vda3 vgtest lvm2 a-- <8.00g 7.80g# 查看卷组信息root@linux:~# vgs vg #pv #lv #sn attr vsize vfree vgtest 1 1 0 wz--n- <8.00g 7.80g# 增加逻辑卷空间root@linux:~# lvextend -l +100m /dev/vgtest/lv0 size of logical volume vgtest/lv0 changed from 200.00 mib (50 extents) to 300.00 mib (75 extents). logical volume vgtest/lv0 successfully resized.# 查询逻辑卷大小root@linux:~# lvs /dev/vgtest/lv0 lv vg attr lsize pool origin data% meta% move log cpy%sync convert lv0 vgtest -wi-a----- 300.00m root@linux:~#
风吸式杀虫灯的功能特点及技术参数
无人驾驶汽车就要来了,中国你准备好了么?
以FPGA机载为核心的实时视频图形处理系统设计
未动科技与地平线达成战略合作 共推全场景智能驾驶加速落地
OPPOR11什么时候上市最新消息:天王代言OPPOR11手机热销或成定局,OPPOR11配置、价格提前看
什么是磁盘分区与逻辑卷管理
华为海思有望超越联发科,排进全球前15
直流有刷电机原理详解
明年起至2023年期间 全球圆柱形锂离子电池市场将以18.28%的复合年增长率增长
应用笔记 | STM32WB基于Custom Template实现客户定制BLE私有协议
哪款手机音质效果好?魅族pro6,vivox7带你体验完美音质,听音乐就用HIFI音乐手机!
基于TRS-1000温升试验系统提高检测精度与效率的触头温升检测方法
电机制动能量回收原理
新能源汽车电池回收涌动新一股掘金浪潮 环保企业谁会大展拳脚
iPhone最新消息:曾是最保值的苹果,现在是降价最快的iPhone7,史上降价最快苹果手机
赛灵思28nm:点燃设计创新的激情
凌力尔特公司推出一款双通道同步降压型 DC/DC 控制器 LTC3887
小米8青春版评测 性价比家族出了个高颜值
SC23 | 研究人员竞相使用 NVIDIA CUDA Quantum 大力推进研究工作
宝马慕尼黑工厂斥资6.5亿欧元转型生产纯电动汽车