一、磁盤分區(qū)
(一)概述
原始磁盤需要經(jīng)過那些操作才能存取數(shù)據(jù)?
原始磁盤的形態(tài)是一個光滑的盤體;
需要將盤體劃分出柱面和磁道,然后將磁道劃分為多個扇區(qū),稱為“低級格式化”;
為了有效組織磁盤和提高I\\O效率,還需要進行“分區(qū)”;
此時,磁盤還不能存儲數(shù)據(jù),還需要對每一分區(qū)中的扇區(qū)進行邏輯編號,并建立數(shù)據(jù)結(jié)構(gòu)和磁盤數(shù)據(jù)的管理方式,稱為“高級格式化”,本質(zhì)上是在分區(qū)上確定了文件系統(tǒng),便可以進行數(shù)據(jù)存儲了。
如果把原始磁盤比作待開發(fā)的地塊
那么,
“低級格式化”相當于在該地塊上修建了道路和房屋;
“分區(qū)”相當于根據(jù)地理區(qū)域劃分不同的小區(qū);
“高級格式化”相當于將小區(qū)內(nèi)的房屋進行標記。
Windows操作系統(tǒng),分區(qū)、格式化之后,就可以建目錄存儲文件了。
而Linux操作系統(tǒng)則與Windows相反,需要先虛擬一個根目錄,再將磁盤掛載到根目錄。
(二)實踐
1. 查看當前分區(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): # 默認回車
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): 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ū)掛載點及文件類型
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)之間,將一個或多個磁盤分區(qū)(PV)虛擬為一個卷組(VG),并在VG上面劃分一些邏輯卷(LV)。邏輯卷可再進行格式化、掛載,并且邏輯卷可以動態(tài)伸縮。
也就是從物理磁盤或分區(qū)開始,經(jīng)過PV--VG--LV(形成邏輯卷)之后,將邏輯卷看成新的磁盤進行分區(qū)、格式化并掛載,供主機使用。
(二)實踐
使用lsblk命令查看系統(tǒng)的磁盤使用情況(lsblk--list block);
使用fdisk命令進行分區(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),將多個物理卷組織成一個整體,屏蔽底層物理卷細節(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)站授權轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報投訴
-
格式化
+關注
關注
2文章
39瀏覽量
9335 -
磁盤
+關注
關注
1文章
390瀏覽量
25735
發(fā)布評論請先 登錄
相關推薦
熱點推薦
【雨林木風系統(tǒng)下載教程】利用XP系統(tǒng)磁盤分區(qū)來提升讀寫...
與合并磁盤分區(qū) 如果硬盤中最好了的xp系統(tǒng)的某個分區(qū)容量過大,可將其拆分為兩個分區(qū)。首先將該磁盤分區(qū)中的所有文件保存到其它分區(qū)中。之后在“
發(fā)表于 07-19 10:44
linux的三種磁盤分區(qū)
硬盤分區(qū)有三種,主磁盤分區(qū)(83)、擴展磁盤分區(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
?1198次閱讀
Linux環(huán)境下對磁盤分區(qū)進行管理的一種機制
物理卷就是指硬盤分區(qū)或從邏輯上與磁盤分區(qū)具有同樣功能的設備(如RAID),是LVM的基本存儲邏輯塊,但和基本的物理存儲介質(zhì)(如
Linux磁盤如何劃分 淺談邏輯卷管理(LVM)相關知識
邏輯卷管理LVM是一個多才多藝的硬盤系統(tǒng)工具。無論在Linux或者其他類似的系統(tǒng),都是非常的好用。傳統(tǒng)分區(qū)使用固定大小分區(qū),重新調(diào)整大小十分
Linux系統(tǒng)教程之磁盤分區(qū)和LVM系統(tǒng)的詳細資料概述
本文檔的主要內(nèi)容詳細介紹的是Linux系統(tǒng)教程之磁盤分區(qū)和LVM系統(tǒng)的詳細資料概述主要內(nèi)容包括了:1.磁盤相關概念2.磁盤分區(qū)工具3.創(chuàng)建 LVM 系統(tǒng)4.維護 LVM 系統(tǒng)
發(fā)表于 10-30 16:11
?14次下載

微軟Windows 10研究新的方法管理現(xiàn)代磁盤分區(qū)
如果要刪除舊磁盤并創(chuàng)建新分區(qū)或擴展特定磁盤的空間,則需要依賴Windows 10的磁盤管理工具。在Windows 10上
預裝Win7系統(tǒng)劃分更多的磁盤分區(qū)的方法
硬盤分區(qū)有三種:主磁盤分區(qū)、擴展磁盤分區(qū)、邏輯分區(qū)。一個硬盤主分區(qū)至少有1個,最多4個,擴展
發(fā)表于 07-08 10:50
?0次下載

獲取磁盤分區(qū)UUID的方法介紹
UUID(通用唯一標識符,Universally Unique Identifiers)是磁盤分區(qū)的屬性,在管理具有數(shù)百個驅(qū)動器的服務器時至關重要。

linux系統(tǒng)如何進行磁盤分區(qū)?
linux系統(tǒng)如何進行磁盤分區(qū)? 磁盤分區(qū)是在Linux系統(tǒng)中進行硬盤劃分的一種方法,它可以將一個物理硬盤劃分為多個邏輯分區(qū),每個分區(qū)可獨立
磁盤分區(qū)工具parted的使用方法
傳統(tǒng)的MBR分區(qū)表格式,僅支持最大四個主分區(qū),而且不可以格式化2TB以上的磁盤,因此,大磁盤更適合使用parted工具進行GPT的分區(qū)格式。
評論