北大青鸟小游网:值得大家信赖的游戏下载站!

微信:96kaifa
关注我们
所在位置:首页 > 服务器 > 如何在Linux中使用LVM管理命令

如何在Linux中使用LVM管理命令

发布时间:2021-06-16 11:00:07来源:北大青鸟手游网作者:北大青鸟手游网

in
in
  • 游戏类别:社交聊天
  • 游戏大小:
  • 游戏语言:
  • 游戏版本:
点击查看
扫码查看

这篇文章将为大家详细讲解有关如何在Linux中使用LVM管理命令,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

在 Linux 操作系统中, 设备文件 是一种特殊类型的文件。这些文件绝大多数位于 /dev 目录下,用来表示 Linux 主机检测到的某个具体的硬件设备。

比如 /dev/sda 文件通常用来指代系统中的第一块硬盘。

Linux 操作系统及其应用与服务则通过这些设备文件与对应的硬件设备进行交互。

对于常见的磁盘(ATA、SATA、SCSI、SAS、SSD 等)和优盘等块存储设备,其设备文件主要以 sd* 的形式命名。如 sda 表示第一块硬盘, sdb2 表示第二块硬盘的第二个分区,以此类推。

因此,可直接使用 ls -l /dev/sd* 命令查看系统中的磁盘设备:

$ ls -l /dev/sd*brw-rw---- 1 root disk 8, 0 8月 7 00:47 /dev/sdabrw-rw---- 1 root disk 8, 1 8月 7 00:47 /dev/sda1

即当前系统中只连接了一块硬盘( /dev/sda ),且该硬盘只有一个分区( /dev/sda1 )。

二、分区

分区可以理解为将一整块硬盘划分为一个或多个相互独立的存储区域。

比如可以将系统的第一块硬盘划分为 3 个分区,分别为 sda1、sda2、sda3 。sda1 用于挂载根目录( / ),sda2 挂载 /var ,sda3 挂载 /home 目录。则即使 /var 目录下的日志文件等占用了 sda2 全部的存储空间,也不会影响其他两个分区的使用。

可以使用 fdisk -l 命令查看系统中的磁盘和分区信息:

$ sudo fdisk -lDisk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectorsDisk model: VBOX HARDDISKUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x20985120Device Boot Start End Sectors Size Id Type/dev/sda1 2048 20964824 20962777 10G 83 Linux

创建磁盘分区

fdisk 命令还可以用来对硬盘进行分区操作,包括创建新分区、删除已有的分区、创建分区表等。

我这里通过 VirtualBox 软件为虚拟机中的 Linux 系统添加了一块空白的虚拟硬盘。使用 fdisk -l 命令查看系统检测到的硬盘设备:

$ sudo fdisk -lDisk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectorsDisk model: VBOX HARDDISKUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x20985120Device Boot Start End Sectors Size Id Type/dev/sda1 2048 20964824 20962777 10G 83 LinuxDisk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectorsDisk model: VBOX HARDDISKUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes

此时系统中多了一块不包含任何分区的新硬盘 /dev/sdb 。

使用 fdisk /dev/sdb 命令对新硬盘进行分区操作:

$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.33.1).
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.
Created a new DOS disklabel with disk identifier 0xce119026.

Command (m for help): mHelp:

 DOS (MBR)
 a toggle a bootable flag
 b edit nested BSD disklabel
 c toggle the dos compatibility flag

 Generic
 d delete a partition F list free unpartitioned space l list known partition types
 n add a new partition p print the partition table t change a partition type v verify the partition table i print information about a partition Misc
 m print this menu
 u change display/entry units
 x extra functionality (experts only)

 Script
 I load disk layout from sfdisk script file O dump disk layout to sfdisk script file Save & Exit w write table to disk and exit q quit without saving changes

 Create a new label
 g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table

进入 fdisk 程序界面之后,按下 m 键并回车,即可打印帮助信息,获取该界面下支持的交互式命令。

比如输入 p 可以用来输出当前硬盘的分区信息,输入 n 创建新的分区,输入 d 删除已有的分区。

在对分区进行任何操作之后,最后都需要使用 w 将之前的所有更改写入硬盘。

这里先按下 n 开始新分区的创建,根据提示选择分区类型( p 表示主分区, e 表示扩展分区),进一步选择分区编号和第一个扇区的位置(一般默认即可),最后输入新分区中最后一个扇区的位置(也可以直接指定分区大小),格式为 +/-sectors 或 +/-size 。如输入 +3G 则表示创建大小为 3 GB 的新分区。具体步骤如下:

Command (m for help): nPartition type p primary (0 primary, 0 extended, 4 free)
 e extended (container for logical partitions)Select (default p): pPartition number (1-4, default 1):First sector (2048-10485759, default 2048):Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485759, default 10485759): +3G

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

Command (m for help): nPartition type p primary (1 primary, 0 extended, 3 free)
 e extended (container for logical partitions)Select (default p): pPartition number (2-4, default 2):First sector (6293504-10485759, default 6293504):Last sector, +/-sectors or +/-size{K,M,G,T,P} (6293504-10485759, default 10485759):

Created a new partition 2 of type 'Linux' and of size 2 GiB.

再用同样的步骤将磁盘的剩余空间划分为另一个分区。此时查看分区信息,原本空白的 5GB 新硬盘 sdb 已经被划分为两个分区 sdb1 和 sdb2 :

Command (m for help): p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dos
Disk identifier: 0xce119026Device Boot Start End Sectors Size Id Type/dev/sdb1  2048 6293503 6291456 3G 83 Linux
/dev/sdb2 6293504 10485759 4192256 2G 83 Linux


我要评价

  • 热门资讯
  • 最新资讯
  • 手游排行榜
  • 手游新品榜