[Linux]VMware 无重启添加scsi硬盘实现LVM动态扩容(上)

本文介绍了如何在不重启Linux系统的情况下添加SCSI硬盘并将其格式化为逻辑卷,以解决文件系统空间不足的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



注:本实验在VMware 7.1.2 环境中完成,RHEL5.5,磁盘采用逻辑卷(LVM)的管理方式。

安装了一些软件过后发现虚拟机Linux的文件系统空间不够了,

[root@server01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      3.9G  3.7G     0 100% /       <==使用率已经高达100%
/dev/sda1              31M  7.8M   22M  27% /boot
tmpfs                 252M     0  252M   0% /dev/shm

于是想重新从物理硬盘上创建一块虚拟硬盘添加上去,将新的硬盘格式化成逻辑卷,对磁盘进行扩容。


1.添加新硬盘

[1]在VMware中添加一块虚拟硬盘是很简单的: 选中你的虚拟机系统->设置,

[2]在弹出的 “虚拟机设置”中选择最下方的添加,然后添加硬件类型 硬盘-> 下一步 ->创建一个新的虚拟磁盘 -> 选择磁盘类型为SCSI

[这里一定要选SCSI(Small Computer System Interface),即小型计算机系统接口。目前主流SCSI硬盘有两种,一种是支持热插拔的,还有一种数据接口和电源接口排列和普通IDE硬盘相似的不能热插拔。]

最后根据提示做相应的设置,直至完成新硬盘的建立。

[3] 硬盘添加完成后,重启后内核会自动探测到这个新的设备,并添加到系统中。你可以用 fdisk -l 命令查看到这块硬盘,一般是以 /dev/sd[a,b,c,.....] 命名的设备。

[4] 但是在实际应用中,我们会选择尽可能地不去重启系统和服务,现在我们就来探讨一种无重启添加scsi硬盘的方法。

在第[2]步完成后,跳过第三步,我们先 cat /proc/scsi/scsi 这个文件,会看到系统中已经包含了一块scsi硬盘


这时我们以root权限执行 echo "scsi add-single-device 0 0 1 0" > /proc/scsi/scsi  添加scsi设备

[*

解释一下 scsi add-single-device a b c d 这个指令中的参数:                        # 相反  scsi remove-single-device a b c d 是用来移除设备的

a ------- Host 是硬盘所在的SCSI控制器的编号,这里只有一个控制器,所以为0

b ------- Channel 硬盘所在SCSI通道的编号,这里是单通道,为0

c ------- Id 硬盘的SCSI ID号,就是插入的硬盘插槽编号,

              这里我最开始安装虚拟Linux系统的时候虚拟了一个SCSI硬盘(SCSI ID为0),

              现在再虚拟一块出来的话,SCSI ID为1

d ------- Lun ,硬盘的lun号[logical unit number]即逻辑单元号,指的是一个用于SCSI总线的唯一的识别号,

          总线使它能区别其他八个设备(它们每个都是一个逻辑单元)。

*]

这时再 cat /proc/scsi/scsi 就会发现新的scsi的相关信息已经加载到内核中去了。

检测一下 fdisk -l : 已经有两块硬盘设备了: /dev/sda 和 /dev/sdb ,但是/dev/sdb上却还没有分区表,接下来我们将格式化这块新的硬盘:



2.格式化成逻辑卷

[root@server01 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


Command (m for help): n                      # n是新建一个分区
Command action
   e   extended                                           # e代表扩展分区
   p   primary partition (1-4)                     # p代表主分区
p                                                                  # 这里我们选择p,每个分区表最多可以有4个主分区
Partition number (1-4): 3                        # 可以选择1-4,这里我选3
First cylinder (1-522, default 1):            # 选择首个柱面,默认的就好
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522):      # 这里如果选择默认值的话就会使用整块硬盘,你可以自定义大小如 +500M
Using default value 522


Command (m for help): p                      # p代表打印当前的分区表


Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb3               1         522     4192933+  83  Linux          # 这里的文件系统为Linux,我想要Linux LVM的文件系统,那么我需要转换


Command (m for help): t                     #  t代表转换文件系统
Selected partition 3                               # 当前分区表只有一个分区,默认选择了分区3
Hex code (type L to list codes): 8e     # 8e代表LVM的文件系统标志,你也可以输入 L 了解具体更多文件系统标志
Changed system type of partition 3 to 8e (Linux LVM)


Command (m for help): w                   # 这里一定要记得保存,否则前功尽弃
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@server01 ~]# 

本篇暂时讲到这里,先歇歇手。磁盘已经格式化好了,下篇我们将一起来对原有的文件系统进行扩容。

### Python 3.8 on Linux Installation and Configuration #### Installing Python 3.8 from Source Code For users who require a specific version of Python that is not available through the default package manager, installing directly from source code can be an effective method. To install Python 3.8 on Debian-based systems such as Ubuntu or Debian itself: Firstly, ensure all necessary dependencies are installed by executing `sudo apt-get update` followed by `sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ xz-utils tk-dev libffi-dev liblzma-dev python-openssl git`. After preparing the environment, download the desired Python release tarball using `wget https://www.python.org/ftp/python/3.8.x/Python-3.8.x.tgz`, replacing "x" with the latest minor version number[^1]. Unpack this archive via `tar xf Python-3.8.x.tgz`. Navigate into the extracted directory (`cd Python-3.8.x`) where compilation will take place after running configure script: `./configure --enable-optimizations`. Compilation starts once configured successfully: `make altinstall`. Note here to use `altinstall` instead of `install` command to prevent overwriting existing system-wide Python binaries. #### Setting Up Pip for Python 3.8 Once Python 3.8 has been properly set up, setting up pip becomes straightforward. One approach involves downloading the official bootstrap script provided by PyPA (Python Packaging Authority). Execute these commands sequentially within terminal session: ```bash curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3.8 get-pip.py ``` This process installs both pip along with its associated tools like setuptools which facilitate managing packages efficiently under Python environments specifically targeting Python 3.8 interpreter instance[^2]. #### Configuring Environment Variables Environment variables play crucial roles when it comes down to configuring software applications including interpreters like Python. For example, adding custom library paths ensures proper linking during runtime operations without causing conflicts between different versions residing simultaneously across filesystem hierarchies. Appending lines similar below at end part inside `.bashrc` file helps achieve seamless integration while avoiding potential issues caused by missing libraries or mismatched ABI interfaces: ```bash export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" source ~/.bashrc ``` Such configurations allow dynamically loaded modules access additional directories beyond standard locations defined originally upon installation phase thus enhancing flexibility significantly especially concerning third-party extensions requiring non-standard dependencies outside conventional search scope established initially[^3]. --related questions-- 1. What steps should one follow if encountering dependency errors during Python setup? 2. How does altering PATH variable influence execution priority among multiple Python installations coexisting side-by-side? 3. Can you explain how virtualenv works alongside global site-packages management strategies effectively? 4. In what scenarios would someone prefer compiling Python rather than utilizing precompiled binary distributions offered officially?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值