如何不用重启在CentOS 7 RHEL 7虚拟机中添加一块新硬盘

如何不用重启在CentOS 7 RHEL 7虚拟机中添加一块新硬盘,第1张

在ESXi或者vCenter中添加一块新的20G硬盘

显示当前磁盘分区

Disk/dev/sda:32.2 GB,32212254720 bytes,62914560 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

Disk label type: dos

Disk identifier:0x0006b96a

DeviceBootStartEndBlocksIdSystem

/dev/sda1 *2048102604751200083Linux

/dev/sda2 102604862914559309442568eLinux LVM

Disk/dev/mapper/centos-swap:2147 MB,2147483648 bytes,4194304 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

Disk/dev/mapper/centos-root:29.5 GB,29536288768 bytes,57688064 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

[root@centos7 ~]# fdisk -l

确定主机总线号

[root@centos7 ~]# ls /sys/class/scsi_host/

host0 host1 host2

重新扫描SCSI总线来添加设备

[root@centos7 ~]# echo "- - -">/sys/class/scsi_host/host0/scan

[root@centos7 ~]# echo "- - -">/sys/class/scsi_host/host1/scan

[root@centos7 ~]# echo "- - -">/sys/class/scsi_host/host2/scan

验证磁盘和分区并确保20GB硬盘已经添加了。在本例中,出现了下面这行 “Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors” 并且可以确认没有重启服务器就添加了新盘:

[root@centos7 ~]# fdisk -l

Disk/dev/sda:32.2 GB,32212254720 bytes,62914560 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

Disk label type: dos

Disk identifier:0x0006b96a

DeviceBootStartEndBlocksIdSystem

/dev/sda1 *2048102604751200083Linux

/dev/sda2 102604862914559309442568eLinux LVM

Disk/dev/mapper/centos-swap:2147 MB,2147483648 bytes,4194304 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

Disk/dev/mapper/centos-root:29.5 GB,29536288768 bytes,57688064 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

Disk/dev/sdb:21.5 GB,21474836480 bytes,41943040 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

你说的是xfs文件系统吧

第一步:添加一块新的硬盘,假设他名字为/dev/sdb

第二步:使用fdisk命令对sdb硬盘进行分区:

[root@linuxprobe ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

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

Building a new DOS disklabel with disk identifier 0x47d24a34.

敲击字符p查看分区表信息(当前为空):

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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

Disk label type: dos

Disk identifier: 0x47d24a34

Device Boot Start End Blocks Id System

敲击字符n创建新的分区信息:

Command (m for help): n

敲击字符p,这个p代表是主分区,e为扩展分区:

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p

敲击数字1代表分区编号为1:

Partition number (1-4, default 1): 1

磁盘的起始扇区,直接回车即可:

First sector (2048-41943039, default 2048):

键入+2G,代表该分区的大小为2G:

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G

Partition 1 of type Linux and of size 2 GiB is set

再看下分区表信息(增加了sdb1分区信息):

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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

Disk label type: dos

Disk identifier: 0x47d24a34

Device Boot Start End Blocks Id System

/dev/sdb1 2048 4196351 2097152 83 Linux

敲击字符w,将上述分区信息保存:

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

让内核同步分区信息(此步骤仅在没有找到分区设备的情况下才需要执行,非必要动作。):

[root@linuxprobe ~]# partprobe

第3步:格式化为xfs文件系统。

在Linux系统中用于格式化的命令是mkfs,它支持的文件类型有:

cramfs,ext2,ext3,ext4,fat,msdos,xfs,btrfs,minix,vfat

使用方法非常的简单:"mkfs.文件类型名称",例如要格式分区为ext4,则命令为"mkfs.ext4 硬盘分区名称"。

使用mkfs.xfs来对/dev/sdb1进行格式化:

[root@linuxprobe ~]# mkfs.xfs /dev/sdb1

meta-data=/dev/sdb1 isize=256 agcount=4, agsize=131072 blks

= sectsz=512 attr=2, projid32bit=1

= crc=0

data = bsize=4096 blocks=524288, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=0

log =internal log bsize=4096 blocks=2560, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

第4步:将硬盘设备挂载到/newFS目录。

[root@linuxprobe ~]# mkdir /newFS

[root@linuxprobe ~]# mount /dev/sdb1 /newFS/

第5步:设置系统启动后自动挂载该硬盘设备。

[root@linuxprobe ~]# vim /etc/fstab

/dev/sdb1 /newFS xfs defaults 0 0

建议你看下http://www.linuxprobe.com/chapter-06.html系统学习


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/bake/11842306.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存