mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
翻译完成
This commit is contained in:
parent
396991efd3
commit
a0a37c0fba
@ -1,174 +0,0 @@
|
||||
(翻译中 by runningwater)
|
||||
How to Add New Disk in Linux CentOS 7 Without Rebooting
|
||||
================================================================================
|
||||
|
||||
Increasing disk spaces on the Linux servers is a daily routine work for very system administrator. So, in this article we are going to show you some simple simple steps that you can use to increase your disk spaces on Linux CentOS 7 without rebooting to your production server using Linux commands. We will cover multiple methods and possibilities to increase and add new disks to the Linux systems, so that you can follow the one that you feel comfortable while using according to your requirements.
|
||||
|
||||
### 1. Increasing Disk of VM Guest: ###
|
||||
|
||||
Before increasing the disk volume inside your Linux system, you need to add a new disk or increase the one its has already attached with the system by editing its settings from your VMware vShere, Workstation or any other infrastructure environment that you are using.
|
||||
|
||||
![Increase disk](http://blog.linoxide.com/wp-content/uploads/2016/02/1.png)
|
||||
|
||||
### 2. Check Disk Space: ###
|
||||
|
||||
Run the following command to check the current size of your disk space.
|
||||
|
||||
# df -h
|
||||
# fdisk -l
|
||||
|
||||
![Fdisk check](http://blog.linoxide.com/wp-content/uploads/2016/02/2.png)
|
||||
|
||||
Here we can see that the total disk size is still the same that is 10 GB while we have already increased it to 50 GB from the back end.
|
||||
|
||||
### 3. Expanding Space without Rebooting VM ###
|
||||
|
||||
Now run the following commands to expand the disk space in the physical volume of the Operating System without rebooting the virtual machine by Re-scanning the SCSI Bus and then adding SCSI Device.
|
||||
|
||||
# ls /sys/class/scsi_host/
|
||||
# echo "- - -" > /sys/class/scsi_host/host0/scan
|
||||
# echo "- - -" > /sys/class/scsi_host/host1/scan
|
||||
# echo "- - -" > /sys/class/scsi_host/host2/scan
|
||||
|
||||
Check the names of your SCSI devices and then rescan the SCSI buses using below commands.
|
||||
|
||||
# ls /sys/class/scsi_device/
|
||||
# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
|
||||
# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
|
||||
|
||||
That will rescan the current scsi bus and the disk size that we increased from the VM guest settings will be show up as you can see in the below image.
|
||||
|
||||
![Rescan disk device](http://blog.linoxide.com/wp-content/uploads/2016/02/3.png)
|
||||
|
||||
### 4. New Disk Partition: ###
|
||||
|
||||
Once you are able to see the increased disk space inside your system then the run the following command to format your disk for creating a new partition by following the steps to increase your physical disk volume.
|
||||
|
||||
# fdisk /dev/sda
|
||||
Welcome to fdisk (util-linux 2.23.2) press the 'm' key for help
|
||||
Command (m for help): m
|
||||
Command action
|
||||
a toggle a bootable flag
|
||||
b edit bsd disklabel
|
||||
c toggle the dos compatibility flag
|
||||
d delete a partition
|
||||
g create a new empty GPT partition table
|
||||
G create an IRIX (SGI) partition table
|
||||
l list known partition types
|
||||
m print this menu
|
||||
n add a new partition
|
||||
o create a new empty DOS partition table
|
||||
p print the partition table
|
||||
q quit without saving changes
|
||||
s create a new empty Sun disklabel
|
||||
t change a partition's system id
|
||||
u change display/entry units
|
||||
v verify the partition table
|
||||
w write table to disk and exit
|
||||
x extra functionality (experts only)
|
||||
|
||||
Command (m for help):
|
||||
|
||||
Type the 'p' to print the current partition table then create a new primary partition by typing the 'n' key and selecting the available sectors. Change the disk type to 'Linux LVM' by using 't' command and selecting the code to '8e' or leave as it to its default type that is '83'.
|
||||
|
||||
Now write the table to disk and exit by Entring 'w' key as shown.
|
||||
|
||||
Command (m for help): w
|
||||
The partition table has been altered!
|
||||
|
||||
Calling ioctl() to re-read partition table.
|
||||
|
||||
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
|
||||
The kernel still uses the old table. The new table will be used at
|
||||
the next reboot or after you run partprobe(8) or kpartx(8)
|
||||
|
||||
![New disk Volume](http://blog.linoxide.com/wp-content/uploads/2016/02/3A.png)
|
||||
|
||||
### 5. Creating Physical Volume: ###
|
||||
|
||||
As indicated above run the 'partprobe' or kpartx command so that the tables are ready to use and then create the new Physical Volume using the below commands.
|
||||
|
||||
# partprobe
|
||||
# pvresize /dev/sda3
|
||||
|
||||
To check the newly created volume run the following command to see if the new physical volume has been created and visible. After that we will extend the Volume Group 'centos' with the newly create Physical Volume as shown.
|
||||
|
||||
# pvdisplay
|
||||
# vgextend centos /dev/sda3
|
||||
|
||||
![Extend volume Group](http://blog.linoxide.com/wp-content/uploads/2016/02/3B.png)
|
||||
|
||||
### 6. Extending Logical Volume: ###
|
||||
|
||||
Now we will extend the Logical Volume to increase the disk space on it using the the below command.
|
||||
|
||||
# lvextend -L +40G /dev/mapper/centos-root
|
||||
|
||||
Once you get the successfully increased message, run the command as shown below to extend the size of your logical volume .
|
||||
|
||||
# xfs_growfs /dev/mapper/centos-root
|
||||
|
||||
The size of the '/' partition has been increased successfully, you can check the size of your disk drives by using the 'df' command as shown.
|
||||
|
||||
![Increase disk space](http://blog.linoxide.com/wp-content/uploads/2016/02/3C.png)
|
||||
|
||||
### 7. Extending Root Partition by Adding New Disk Without Reboot: ###
|
||||
|
||||
This is the second method with but with quite similar commands to increase the size of the Logical volume in CentOS 7.
|
||||
|
||||
So, the first step is to Open the setting of your VM guest settings and click on the 'Add' new button and proceed to the next option.
|
||||
|
||||
![Add new disk](http://blog.linoxide.com/wp-content/uploads/2016/02/3D.png)
|
||||
|
||||
Choose the required configuration for the new disk by selecting the size of the new disk and its type as shown in the below image.
|
||||
|
||||
![New disk setup](http://blog.linoxide.com/wp-content/uploads/2016/02/3E.png)
|
||||
|
||||
Then come to the server side and repeat the following commands to scan your disk devices to the new disk is visible on the system.
|
||||
|
||||
# echo "- - -" > /sys/class/scsi_host/host0/scan
|
||||
# echo "- - -" > /sys/class/scsi_host/host1/scan
|
||||
# echo "- - -" > /sys/class/scsi_host/host2/scan
|
||||
|
||||
List the names of your SCSi devices
|
||||
|
||||
# ls /sys/class/scsi_device/
|
||||
# echo 1 > /sys/class/scsi_device/1\:0\:0\:0/device/rescan
|
||||
# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
|
||||
# echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
|
||||
# fdisk -l
|
||||
|
||||
![Scanning new disk](http://blog.linoxide.com/wp-content/uploads/2016/02/3F.png)
|
||||
|
||||
Once the new disk is visible run the below commands to create the new physical volume and add it to the volume group as shown.
|
||||
|
||||
# pvcreate /dev/sdb
|
||||
# vgextend centos /dev/sdb
|
||||
# vgdisplay
|
||||
|
||||
![Extending Volume Group](http://blog.linoxide.com/wp-content/uploads/2016/02/3G.png)
|
||||
|
||||
Now extend the Logical Volume by adding the disk space on it and then add it to the root partition.
|
||||
|
||||
# lvextend -L +20G /dev/mapper/centos-root
|
||||
# xfs_growfs /dev/mapper/centos-root
|
||||
# df -h
|
||||
|
||||
![Increase / Partition](http://blog.linoxide.com/wp-content/uploads/2016/02/3H.png)
|
||||
|
||||
### Conclusion: ###
|
||||
|
||||
Managing disk partitions in Linux CentOS 7 is a simple process to increase the disk space of any of your logical volumes by using the steps as described in this article. You don't need to give your production server's reboot for this purpose but simply rescan your SCSi devices and expand your desired LVM. We hope you find this article much helpful. Feel free to leave your valuable comments or suggestions.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-how-to/add-new-disk-centos-7-without-rebooting/
|
||||
|
||||
作者:[Kashif S][a]
|
||||
译者:[runningwater](https://github.com/runningwater
|
||||
)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/kashifs/
|
@ -0,0 +1,173 @@
|
||||
如何在CentOS 7 中添加新磁盘而不用重启系统
|
||||
================================================================================
|
||||
|
||||
对大多数系统管理员来说扩充 Linux 服务器的磁盘空间是日常的工作之一。因此这篇文章会在通过使用 Linux 命令,在 CentOS 7 系统上演示一些简单的操作步骤来扩充您的磁盘空间而不需要重启您的生产服务器。关于扩充和增加新的磁盘到 Linux 系统,我们会提及多种方法和多种可行性,所以可按您所需选择最适用的一种。
|
||||
|
||||
### 1. 为虚拟机客户端扩充磁盘空间: ###
|
||||
|
||||
在为 Linux 系统增加磁盘卷之前,您需要添加一块新的物理磁盘或是从正使用的 VMware vShere、工作站或着其它的基础虚拟环境软件中进行设置,从而扩充一块系统正使用的虚拟磁盘空间。
|
||||
|
||||
![Increase disk](http://blog.linoxide.com/wp-content/uploads/2016/02/1.png)
|
||||
|
||||
### 2. 检查磁盘空间: ###
|
||||
|
||||
运行如下命令来检查当前磁盘空间大小。
|
||||
|
||||
# df -h
|
||||
# fdisk -l
|
||||
|
||||
![Fdisk check](http://blog.linoxide.com/wp-content/uploads/2016/02/2.png)
|
||||
|
||||
可以看到,虽然我们已经在后端给其增加到 50 GB 的空间,但此时的总磁盘大小仍然为 10 GB。
|
||||
|
||||
### 3. 扩展空间而无需重启虚拟机 ###
|
||||
|
||||
现在运行如下命令就可以来扩展操作系统的物理卷磁盘空间,而且不需要重启虚拟机,系统会重新扫描 SCSI (注:Small Computer System Interface 小型计算机系统接口)总线并添加 SCSI 设备。
|
||||
|
||||
# ls /sys/class/scsi_host/
|
||||
# echo "- - -" > /sys/class/scsi_host/host0/scan
|
||||
# echo "- - -" > /sys/class/scsi_host/host1/scan
|
||||
# echo "- - -" > /sys/class/scsi_host/host2/scan
|
||||
|
||||
使用下面的命令来检查 SCSI 设备的名称,然后重新扫描 SCSI 总线。
|
||||
|
||||
# ls /sys/class/scsi_device/
|
||||
# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
|
||||
# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
|
||||
|
||||
如下图所示,会重新扫描 SCSI 总线,随后我们从虚拟机客户端设置的磁盘大小会正常显示。
|
||||
|
||||
![Rescan disk device](http://blog.linoxide.com/wp-content/uploads/2016/02/3.png)
|
||||
|
||||
### 4. 创建新磁盘分区: ###
|
||||
|
||||
一旦在系统中可以看到扩展的磁盘空间,就可以运行如下命令来格式化您的磁盘以创建一个新的分区。请按如下操作步骤来扩充您的物理磁盘卷。
|
||||
|
||||
# fdisk /dev/sda
|
||||
Welcome to fdisk (util-linux 2.23.2) press the 'm' key for help
|
||||
Command (m for help): m
|
||||
Command action
|
||||
a toggle a bootable flag
|
||||
b edit bsd disklabel
|
||||
c toggle the dos compatibility flag
|
||||
d delete a partition
|
||||
g create a new empty GPT partition table
|
||||
G create an IRIX (SGI) partition table
|
||||
l list known partition types
|
||||
m print this menu
|
||||
n add a new partition
|
||||
o create a new empty DOS partition table
|
||||
p print the partition table
|
||||
q quit without saving changes
|
||||
s create a new empty Sun disklabel
|
||||
t change a partition's system id
|
||||
u change display/entry units
|
||||
v verify the partition table
|
||||
w write table to disk and exit
|
||||
x extra functionality (experts only)
|
||||
|
||||
Command (m for help):
|
||||
|
||||
键入 'p' 来查看当前的分区表信息,然后键入 'n' 键来创建一个新的主分区,选择所有可用的扇区。 使用 't' 命令改变磁盘类型为 'Linux LVM',然后选择编码 '8e' 或者默认不选,它默认的类型编码为 '83'。
|
||||
|
||||
现在输入 'w' 来保存分区表信息并且退出命令环境,如下示:
|
||||
|
||||
Command (m for help): w
|
||||
The partition table has been altered!
|
||||
|
||||
Calling ioctl() to re-read partition table.
|
||||
|
||||
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
|
||||
The kernel still uses the old table. The new table will be used at
|
||||
the next reboot or after you run partprobe(8) or kpartx(8)
|
||||
|
||||
![New disk Volume](http://blog.linoxide.com/wp-content/uploads/2016/02/3A.png)
|
||||
|
||||
### 5. 创建物理卷: ###
|
||||
|
||||
根据提示运行 'partprob' 或 'kpartx' 命令以使分区表被真正使用,然后使用如下的命令来创建新的物理卷。
|
||||
|
||||
# partprobe
|
||||
# pvresize /dev/sda3
|
||||
|
||||
要检查新创建的卷,运行如下的命令可以看出新的物理卷是否已经被创建,是否可用。接下来,我们就可以使用这个新的物理卷来扩展 'centos' 卷组了,如下示:
|
||||
|
||||
# pvdisplay
|
||||
# vgextend centos /dev/sda3
|
||||
|
||||
![Extend volume Group](http://blog.linoxide.com/wp-content/uploads/2016/02/3B.png)
|
||||
|
||||
### 6. 扩展逻辑卷: ###
|
||||
|
||||
现在我们使用如下的命令扩展逻辑卷,以增加我们系统正使用的磁盘空间。
|
||||
|
||||
# lvextend -L +40G /dev/mapper/centos-root
|
||||
|
||||
一旦返回增加成功的消息,就可以运行如下命令来扩展您的逻辑卷大小。
|
||||
|
||||
# xfs_growfs /dev/mapper/centos-root
|
||||
|
||||
'/' 分区的大小已经成功的增加了,可以使用 'df' 命令来检查您磁盘驱动的大小。如图示。
|
||||
|
||||
![Increase disk space](http://blog.linoxide.com/wp-content/uploads/2016/02/3C.png)
|
||||
|
||||
### 7. 通过增加新的磁盘来扩充根分区而不用重启系统: ###
|
||||
|
||||
这是第二种方法,它使用的命令非常简单, 用来增加 CentOS 7 系统上逻辑卷空间大小。
|
||||
|
||||
所以第一步是打开您的虚拟机客户端的设置页面,点击 ‘增加’ 按纽,然后继续下一步操作。
|
||||
|
||||
![Add new disk](http://blog.linoxide.com/wp-content/uploads/2016/02/3D.png)
|
||||
|
||||
选择新磁盘所需要的配置信息,如下图所示的,选择新磁盘的大小和它的类型。
|
||||
|
||||
![New disk setup](http://blog.linoxide.com/wp-content/uploads/2016/02/3E.png)
|
||||
|
||||
然后进入服务端重复如下的命令来扫描您的磁盘设备,以使新磁盘在系统中可见。
|
||||
|
||||
# echo "- - -" > /sys/class/scsi_host/host0/scan
|
||||
# echo "- - -" > /sys/class/scsi_host/host1/scan
|
||||
# echo "- - -" > /sys/class/scsi_host/host2/scan
|
||||
|
||||
列出您的 SCSI 设备的名称
|
||||
|
||||
# ls /sys/class/scsi_device/
|
||||
# echo 1 > /sys/class/scsi_device/1\:0\:0\:0/device/rescan
|
||||
# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
|
||||
# echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
|
||||
# fdisk -l
|
||||
|
||||
![Scanning new disk](http://blog.linoxide.com/wp-content/uploads/2016/02/3F.png)
|
||||
|
||||
一旦新增的磁盘可见就可以运行下面的命令来创建新的物理卷,然后增加到卷组,如下示。
|
||||
|
||||
# pvcreate /dev/sdb
|
||||
# vgextend centos /dev/sdb
|
||||
# vgdisplay
|
||||
|
||||
![Extending Volume Group](http://blog.linoxide.com/wp-content/uploads/2016/02/3G.png)
|
||||
|
||||
现在根据此磁盘的空间大小来扩展逻辑卷,然后添加到根分区。
|
||||
|
||||
# lvextend -L +20G /dev/mapper/centos-root
|
||||
# xfs_growfs /dev/mapper/centos-root
|
||||
# df -h
|
||||
|
||||
![Increase / Partition](http://blog.linoxide.com/wp-content/uploads/2016/02/3H.png)
|
||||
|
||||
### 结论: ###
|
||||
|
||||
在 Linux CentOS 7 系统上,使用这篇文章所述的操作步骤来扩充您的任意逻辑卷的磁盘空间,此管理磁盘分区的操作过程是非常简单的。您不需要重启生产线上的服务器,只是简单的重扫描下 SCSI 设备,和扩展您想要的 LVM(逻辑卷管理)。我们希望这文章对您有用。可自由的发表有用的评论和建议。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-how-to/add-new-disk-centos-7-without-rebooting/
|
||||
|
||||
作者:[Kashif S][a]
|
||||
译者:[runningwater](https://github.com/runningwater
|
||||
)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/kashifs/
|
Loading…
Reference in New Issue
Block a user