您的位置:首页 > 运维架构 > Linux

Linux新增磁盘

2017-11-19 22:44 316 查看
http://www.linuxidc.com/Linux/2016-04/130467.htm

1.运行如下命令来检查当前磁盘空间大小
#df -h

#fdisk -l



2. 扩展空间而无需重启虚拟机

现在运行如下命令,通过重新扫描 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 总线,随后我们在虚拟机客户端设置的磁盘大小会正常显示


3. 创建新磁盘分区

一旦在系统中可以看到扩展的磁盘空间,就可以运行如下命令来格式化您的磁盘以创建一个新的分区。请按如下操作步骤来扩充您的物理磁盘卷。
#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 newempty GPT partition table

G create an IRIX (SGI) partition table

l list known partition types

m printthis menu

n add a new partition

o create a newempty DOS partition table

p print the partition table

q quit without saving changes

s create a newemptySun 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:Deviceor resource
busy.

The kernel still uses the old table.Thenew table will be used at

the nextrebootor after you run partprobe(8)or kpartx(8)


可以看到刚刚生成的新分区sdb1

4.格式化分区

将新分区格式化为ext3文件系统 

#mkfs -t ext3 /dev/sdb1

最后写入文件系统信息。 

此时就可以用新创建的分区了 
5.挂载硬盘 

1) 创建挂载点 

在根目录下创建storage目录

#mkdir /storage 

2) 将/dev/sdb1挂载到/storage下 

#mount /dev/sdb1 /storage 

6.设置开机启动自动挂载 

新创建的分区不能开机自动挂载,每次重启机器都要手动挂载。 

设置开机自动挂载需要修改/etc/fstab文件 

#vi /etc/fstab

在文件的最后增加一行

/dev/sdb1 /storage ext3 defaults 1 2 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: