0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

什么是磁盤分區(qū)與邏輯卷管理

汽車電子技術(shù) ? 來源:碼農(nóng)與軟件時(shí)代 ? 作者:碼農(nóng)與軟件時(shí)代 ? 2023-02-20 15:48 ? 次閱讀
一、磁盤分區(qū)

(一)概述

原始磁盤需要經(jīng)過那些操作才能存取數(shù)據(jù)?

原始磁盤的形態(tài)是一個(gè)光滑的盤體;
需要將盤體劃分出柱面和磁道,然后將磁道劃分為多個(gè)扇區(qū),稱為“低級格式化”;
為了有效組織磁盤和提高I\\O效率,還需要進(jìn)行“分區(qū)”;
此時(shí),磁盤還不能存儲數(shù)據(jù),還需要對每一分區(qū)中的扇區(qū)進(jìn)行邏輯編號,并建立數(shù)據(jù)結(jié)構(gòu)和磁盤數(shù)據(jù)的管理方式,稱為“高級格式化”,本質(zhì)上是在分區(qū)上確定了文件系統(tǒng),便可以進(jìn)行數(shù)據(jù)存儲了。

如果把原始磁盤比作待開發(fā)的地塊
那么,
“低級格式化”相當(dāng)于在該地塊上修建了道路和房屋;
“分區(qū)”相當(dāng)于根據(jù)地理區(qū)域劃分不同的小區(qū);
“高級格式化”相當(dāng)于將小區(qū)內(nèi)的房屋進(jìn)行標(biāo)記。

Windows操作系統(tǒng),分區(qū)、格式化之后,就可以建目錄存儲文件了。
Linux操作系統(tǒng)則與Windows相反,需要先虛擬一個(gè)根目錄,再將磁盤掛載到根目錄。

(二)實(shí)踐

1. 查看當(dāng)前分區(qū)情況:

工具fdisk:用于Linux的磁盤分區(qū)表操作
root@linux:~# fdisk -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
# 磁盤大小為 40G
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: EC404E4B-BF45-4DEE-8D63-3D59FBB9C44E


Device      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
# 磁盤分區(qū)約為20G,還有20G的空間未使用
Partition table entries are not in disk order.
2. 創(chuàng)建新分區(qū)
root@linux:~# fdisk /dev/vda
Welcome 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 # 列出磁盤分區(qū)表 
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: gpt
Disk identifier: EC404E4B-BF45-4DEE-8D63-3D59FBB9C44E


Device      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


Partition table entries are not in disk order.


Command (m for help): n # 創(chuàng)建新分區(qū)
Partition number (2-13,16-128, default 2): # 默認(rèn)回車
First sector (41943007-83886046, default 41943040): # 默認(rèn)回車
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): p
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: gpt
Disk identifier: EC404E4B-BF45-4DEE-8D63-3D59FBB9C44E


Device        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 System


Partition table entries are not in disk order.


Command (m for help): w # 保存、退出
The partition table has been altered.
Syncing disks.
3. 查看新創(chuàng)建分區(qū)
root@linux:~# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda     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/efi
4. 格式化

命令mkfs(make file system):在特定的分區(qū)上建立linux文件系統(tǒng)。
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 # 在新分區(qū)創(chuàng)建ext3的文件系統(tǒng)
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: 0e6a8449-acbf-4428-a5d7-b67b4535b844
Superblock backups stored on blocks: 
  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632


Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
5. 掛載

命令mount:用來掛載文件系統(tǒng)。
root@linux:~# mkdir /test2
root@linux:~# mount /dev/vda2 /test2/ 
root@linux:~# ls /test2/
lost+found
6. 查看分區(qū)掛載點(diǎn)及文件類型
root@linux:~# df -T
Filesystem     Type     1K-blocks    Used Available Use% Mounted on
udev           devtmpfs   1007416       0   1007416   0% /dev
tmpfs          tmpfs       204092     776    203316   1% /run
/dev/vda1      ext4      20145724 3279936  16849404  17% /
tmpfs          tmpfs      1020448       0   1020448   0% /dev/shm
tmpfs          tmpfs         5120       0      5120   0% /run/lock
tmpfs          tmpfs      1020448       0   1020448   0% /sys/fs/cgroup
/dev/vda15     vfat        106858    3668    103190   4% /boot/efi
tmpfs          tmpfs       204088       8    204080   1% /run/user/1001
/dev/vda2      ext3      10255672   23096   9708288   1% /test2
二、邏輯卷管理

(一)概述

邏輯卷管理也就是LVM(Logical Volume  Manager),位于磁盤和操作系統(tǒng)之間,將一個(gè)或多個(gè)磁盤分區(qū)(PV)虛擬為一個(gè)卷組(VG),并在VG上面劃分一些邏輯卷(LV)。邏輯卷可再進(jìn)行格式化、掛載,并且邏輯卷可以動態(tài)伸縮。

也就是從物理磁盤或分區(qū)開始,經(jīng)過PV--VG--LV(形成邏輯卷)之后,將邏輯卷看成新的磁盤進(jìn)行分區(qū)、格式化并掛載,供主機(jī)使用。


(二)實(shí)踐

使用lsblk命令查看系統(tǒng)的磁盤使用情況(lsblk--list block);
使用fdisk命令進(jìn)行分區(qū);
使用pvcreate創(chuàng)建物理卷,
使用vgcreate創(chuàng)建卷組;
使用lvcreate創(chuàng)建邏輯卷。

1. 創(chuàng)建新分區(qū)vda3
root@linux:~# fdisk /dev/vda


Welcome 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): n
Partition 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): +8G


Created a new partition 3 of type 'Linux filesystem' and of size 8 GiB.


Command (m for help): p
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: gpt
Disk identifier: EC404E4B-BF45-4DEE-8D63-3D59FBB9C44E


Device        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 System


Partition table entries are not in disk order.


Command (m for help): w
The partition table has been altered.


Syncing disks.


2. 創(chuàng)建物理卷

命令pvcreate:用于將物理硬盤分區(qū)初始化為物理卷。
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-WVb79K
3. 創(chuàng)建卷組

命令vgcreate:用于創(chuàng)建LVM卷組(Volume Group),將多個(gè)物理卷組織成一個(gè)整體,屏蔽底層物理卷細(xì)節(jié)。
root@linux:~# vgcreate vgtest /dev/vda3
  Volume group "vgtest" successfully created
root@linux:~# vgdisplay vg0
  Volume group "vg0" not found
  Cannot process volume group vg0
root@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-SjQQ6y
4. 創(chuàng)建邏輯卷

命令lvcreate:創(chuàng)建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:~#
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • 格式化
    +關(guān)注

    關(guān)注

    2

    文章

    37

    瀏覽量

    9087
  • 磁盤
    +關(guān)注

    關(guān)注

    1

    文章

    355

    瀏覽量

    25092
收藏 人收藏

    評論

    相關(guān)推薦

    LVM邏輯管理器簡介和參考實(shí)例

    LVM(Logical Volume Manager,邏輯管理器)是Linux系統(tǒng)用于對硬盤分區(qū)進(jìn)行管理的一種機(jī)制,其創(chuàng)建初衷是為了解決硬
    的頭像 發(fā)表于 01-02 10:53 ?836次閱讀

    一步一步學(xué):教你在Windows下對硬盤分區(qū)

    之外的所有分區(qū)全部刪除之后,原本的多個(gè)邏輯驅(qū)動器就剩下了一個(gè)“可用空間”: 這時(shí)候繼續(xù)在其上面點(diǎn)擊鼠標(biāo)右鍵,選擇“刪除磁盤分區(qū)”,這時(shí)候整個(gè)擴(kuò)展分區(qū)就成為了“未指派”狀態(tài): 最后,刪除
    發(fā)表于 02-27 16:44

    【雨林木風(fēng)系統(tǒng)下載教程】利用XP系統(tǒng)磁盤分區(qū)來提升讀寫...

    與合并磁盤分區(qū)  如果硬盤中最好了的xp系統(tǒng)的某個(gè)分區(qū)容量過大,可將其拆分為兩個(gè)分區(qū)。首先將該磁盤分區(qū)中的所有文件保存到其它分區(qū)中。之后在“
    發(fā)表于 07-19 10:44

    linux的三種磁盤分區(qū)

    硬盤分區(qū)有三種,主磁盤分區(qū)(83)、擴(kuò)展磁盤分區(qū)(5)、邏輯分區(qū)(包括swap交換分區(qū)82)。一
    發(fā)表于 07-12 06:56

    Linux下的邏輯管理

    邏輯管理(Logic Volume Manager),簡稱LVM,是與傳統(tǒng)的靜態(tài)分區(qū)完全不同的磁盤管理
    發(fā)表于 01-06 17:02 ?1026次閱讀

    Linux環(huán)境下對磁盤分區(qū)進(jìn)行管理的一種機(jī)制

    物理就是指硬盤分區(qū)或從邏輯上與磁盤分區(qū)具有同樣功能的設(shè)備(如RAID),是LVM的基本存儲邏輯塊,但和基本的物理存儲介質(zhì)(如
    的頭像 發(fā)表于 08-10 17:58 ?3655次閱讀

    Linux磁盤如何劃分 淺談邏輯管理(LVM)相關(guān)知識

    邏輯管理LVM是一個(gè)多才多藝的硬盤系統(tǒng)工具。無論在Linux或者其他類似的系統(tǒng),都是非常的好用。傳統(tǒng)分區(qū)使用固定大小分區(qū),重新調(diào)整大小十分
    的頭像 發(fā)表于 09-08 09:50 ?3135次閱讀

    Linux系統(tǒng)教程之磁盤分區(qū)和LVM系統(tǒng)的詳細(xì)資料概述

    本文檔的主要內(nèi)容詳細(xì)介紹的是Linux系統(tǒng)教程之磁盤分區(qū)和LVM系統(tǒng)的詳細(xì)資料概述主要內(nèi)容包括了:1.磁盤相關(guān)概念2.磁盤分區(qū)工具3.創(chuàng)建 LVM 系統(tǒng)4.維護(hù) LVM 系統(tǒng)
    發(fā)表于 10-30 16:11 ?14次下載
    Linux系統(tǒng)教程之<b class='flag-5'>磁盤分區(qū)</b>和LVM系統(tǒng)的詳細(xì)資料概述

    微軟Windows 10研究新的方法管理現(xiàn)代磁盤分區(qū)

    如果要刪除舊磁盤并創(chuàng)建新分區(qū)或擴(kuò)展特定磁盤的空間,則需要依賴Windows 10的磁盤管理工具。在Windows 10上
    的頭像 發(fā)表于 03-19 15:06 ?2025次閱讀

    預(yù)裝Win7系統(tǒng)劃分更多的磁盤分區(qū)的方法

      硬盤分區(qū)有三種:主磁盤分區(qū)、擴(kuò)展磁盤分區(qū)、邏輯分區(qū)。一個(gè)硬盤主分區(qū)至少有1個(gè),最多4個(gè),擴(kuò)展
    發(fā)表于 07-08 10:50 ?0次下載
    預(yù)裝Win7系統(tǒng)劃分更多的<b class='flag-5'>磁盤分區(qū)</b>的方法

    獲取磁盤分區(qū)UUID的方法介紹

    UUID(通用唯一標(biāo)識符,Universally Unique Identifiers)是磁盤分區(qū)的屬性,在管理具有數(shù)百個(gè)驅(qū)動器的服務(wù)器時(shí)至關(guān)重要。
    的頭像 發(fā)表于 01-31 17:45 ?1.2w次閱讀
    獲取<b class='flag-5'>磁盤分區(qū)</b>UUID的方法介紹

    Linux磁盤分區(qū)和掛載

    1.Linux 來說 wulun 有幾個(gè)分區(qū),分給哪一目錄使用,他歸根結(jié)底只有一個(gè)根目錄,一個(gè)獨(dú)立且唯一的文件結(jié)構(gòu),Linux 中每個(gè)分區(qū)都是用來組成整個(gè)文件系統(tǒng)的一部分。
    的頭像 發(fā)表于 03-26 10:14 ?1097次閱讀

    linux系統(tǒng)如何進(jìn)行磁盤分區(qū)?

    linux系統(tǒng)如何進(jìn)行磁盤分區(qū)? 磁盤分區(qū)是在Linux系統(tǒng)中進(jìn)行硬盤劃分的一種方法,它可以將一個(gè)物理硬盤劃分為多個(gè)邏輯分區(qū),每個(gè)分區(qū)可獨(dú)立
    的頭像 發(fā)表于 12-19 11:35 ?891次閱讀

    Linux系統(tǒng)中LVM磁盤管理的應(yīng)用與實(shí)踐

    邏輯管理提供了比傳統(tǒng)的磁盤分區(qū)視圖更高級別的計(jì)算機(jī)系統(tǒng)上磁盤存儲的視圖。這使得系統(tǒng)
    發(fā)表于 04-09 14:39 ?630次閱讀

    鴻蒙開發(fā)文件管理:【@ohos.volumeManager (管理)】

    該模塊提供、磁盤查詢和管理的相關(guān)功能:包括查詢信息,對的掛載卸載、對磁盤分區(qū)以及
    的頭像 發(fā)表于 06-14 10:12 ?242次閱讀
    鴻蒙開發(fā)文件<b class='flag-5'>管理</b>:【@ohos.volumeManager (<b class='flag-5'>卷</b><b class='flag-5'>管理</b>)】