需求:
新建一个新的磁盘空间,并且将其挂载为新的分区,用来存储数据
1、为虚拟机新添加一块磁盘,这里不多做描述
。。
2、添加磁盘完成后,查看新增的磁盘
[root@zabbix ~]# fdisk -l
此时看不到新增的磁盘
3、我们需要在不关机的前提下,重新扫描SCSI总线来添加设备
3.1 确定主机总线号
[root@zabbix ~]# ls /sys/class/scsi_host/
host0 host1 host2
3.2 重新扫描SCSI总线来添加设备
echo "- - -">/sys/class/scsi_host/host0/scan
echo "- - -">/sys/class/scsi_host/host1/scan
echo "- - -">/sys/class/scsi_host/host2/scan
3.2 再次查看,可以看到磁盘已经新增上来了,盘符为/dev/sdb
[root@zabbix ~]# fdisk -l
Disk /dev/sdc: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
可以看到我新增的磁盘为 Disk /dev/sdc: 17.2 GB
也可以使用lsblk -l 查看磁盘
[root@zabbix ~]# lsblk -l
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 300G 0 disk
sda1 8:1 0 200M 0 part /boot
sda2 8:2 0 80G 0 part /opt
sda3 8:3 0 8G 0 part [SWAP]
sda4 8:4 0 1K 0 part
sda5 8:5 0 80G 0 part /
sda6 8:6 0 131.8G 0 part /data
sdb 8:16 0 300G 0 disk
sdb1 8:17 0 300G 0 part /data/ve_data
sdc 8:32 0 16G 0 disk
4、磁盘分区
[root@zabbix ~]# fdisk /dev/sdc
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
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2088, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088):
Using default value 2088
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
5、查看分区好的磁盘,/dev/sdb
[root@zabbix ~]# fdisk -l
Disk /dev/sdc: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9beab82b
Device Boot Start End Blocks Id System
/dev/sdc1 1 2088 16771828+ 83 Linux
或
[root@zabbix ~]# lsblk -l
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 300G 0 disk
sda1 8:1 0 200M 0 part /boot
sda2 8:2 0 80G 0 part /opt
sda3 8:3 0 8G 0 part [SWAP]
sda4 8:4 0 1K 0 part
sda5 8:5 0 80G 0 part /
sda6 8:6 0 131.8G 0 part /data
sdb 8:16 0 300G 0 disk
sdb1 8:17 0 300G 0 part /data/ve_data
sdc 8:32 0 16G 0 disk
sdc1 8:33 0 16G 0 part
6、查看文件系统格式
方法一:df -T
这个是最简单的命令,文件系统类型在Type列输出。只可以查看已经挂载的分区和文件系统类型。如下所示:
[root@zabbix ~]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda5 ext4 82438832 9835304 68409224 13% /
tmpfs tmpfs 1962232 68 1962164 1% /dev/shm
/dev/sda1 ext4 194241 75446 108555 42% /boot
/dev/sda6 ext4 135903408 121157096 7836104 94% /data
/dev/sda2 ext4 82438832 5965332 72279196 8% /opt
/dev/sdb1 ext4 309501980 64328 293709216 1% /data/ve_data
方法二:parted -l
parted -l 命令会输出文件系统类型(File system), 其中参数l表示列出所有设备的分区信息。如下所示:
[root@zabbix ~]# parted -l
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 1049kB 211MB 210MB primary ext4 启动
2 211MB 86.1GB 85.9GB primary ext4
3 86.1GB 94.7GB 8590MB primary linux-swap(v1)
4 94.7GB 322GB 227GB extended
5 94.7GB 181GB 85.9GB logical ext4
6 181GB 322GB 142GB logical ext4
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 32.3kB 322GB 322GB primary ext4
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 17.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 32.3kB 17.2GB 17.2GB primary
方法三:blkid
查看已格式化分区的UUID和文件系统。使用blkid可以输出分区或分区的文件系统类型,查看TYPE字段输出。如下所示:
[root@zabbix ~]# blkid
/dev/sda5: UUID="6b9fa85f-b1cc-4ad8-90bd-b29b41247491" TYPE="ext4"
/dev/sda1: UUID="71f6b4fa-a219-4194-a157-8fc49695b6fd" TYPE="ext4"
/dev/sdb1: UUID="b2b426b9-2211-409d-99c2-87a7b26e29e9" TYPE="ext4"
/dev/sda2: UUID="2b351da8-3394-4e58-9661-ee5845d2d585" TYPE="ext4"
/dev/sda3: UUID="96b414f8-0d84-49ad-8446-42c509b5c1f3" TYPE="swap"
/dev/sda6: UUID="a63519e0-189d-48c1-9095-349535966ab9" TYPE="ext4"
方法四:lsblk -f
有些系统可能没有这个命令,需要安装。注意:lsblk -f也可以查看未挂载的文件系统类型。如下所示:
[root@zabbix ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sr0
sda
├─sda1 ext4 71f6b4fa-a219-4194-a157-8fc49695b6fd /boot
├─sda2 ext4 2b351da8-3394-4e58-9661-ee5845d2d585 /opt
├─sda3 swap 96b414f8-0d84-49ad-8446-42c509b5c1f3 [SWAP]
├─sda4
├─sda5 ext4 6b9fa85f-b1cc-4ad8-90bd-b29b41247491 /
└─sda6 ext4 a63519e0-189d-48c1-9095-349535966ab9 /data
sdb
└─sdb1 ext4 b2b426b9-2211-409d-99c2-87a7b26e29e9 /data/ve_data
sdc
└─sdc1
7、新建分区指定相应文件系统
[root@zabbix ~]# mkfs.ext4 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1048576 inodes, 4192957 blocks
209647 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
128 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
查看新增分区磁盘的文件系统格式,可以看到sdc1格式为ext4
[root@zabbix ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sr0
sda
├─sda1 ext4 71f6b4fa-a219-4194-a157-8fc49695b6fd /boot
├─sda2 ext4 2b351da8-3394-4e58-9661-ee5845d2d585 /opt
├─sda3 swap 96b414f8-0d84-49ad-8446-42c509b5c1f3 [SWAP]
├─sda4
├─sda5 ext4 6b9fa85f-b1cc-4ad8-90bd-b29b41247491 /
└─sda6 ext4 a63519e0-189d-48c1-9095-349535966ab9 /data
sdb
└─sdb1 ext4 b2b426b9-2211-409d-99c2-87a7b26e29e9 /data/ve_data
sdc
└─sdc1 ext4 bb1e3d2b-504b-4ce1-9428-1ff6bfad0423
8、至此新增磁盘已经分区完毕,需要把它挂载到某个目录下才能使用
我在/data 目录下创建test_data目录
[root@zabbix data]# mkdir test_data
9、将/dev/sdc1挂载到/data/test_data
[root@zabbix data]# mount /dev/sdc1 test_data/
10、查看磁盘分配情况,可以看到磁盘已经分配好挂载好
[root@zabbix data]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 79G 9.4G 66G 13% /
tmpfs 1.9G 68K 1.9G 1% /dev/shm
/dev/sda1 190M 74M 107M 42% /boot
/dev/sda6 130G 116G 7.5G 94% /data
/dev/sda2 79G 5.7G 69G 8% /opt
/dev/sdb1 296G 63M 281G 1% /data/ve_data
/dev/sdc1 16G 44M 15G 1% /data/test_data
11、设置开机自动挂载该磁盘
查看/dev/sdc1的UUID
[root@zabbix data]# blkid /dev/sdc1
/dev/sdc1: UUID="bb1e3d2b-504b-4ce1-9428-1ff6bfad0423" TYPE="ext4"
编辑/etc/fstab文件把sdc1按照上一行的文件格式写入
[root@zabbix data]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 16 11:22:16 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=6b9fa85f-b1cc-4ad8-90bd-b29b41247491 / ext4 defaults 1 1
UUID=71f6b4fa-a219-4194-a157-8fc49695b6fd /boot ext4 defaults 1 2
UUID=a63519e0-189d-48c1-9095-349535966ab9 /data ext4 defaults 1 2
UUID=2b351da8-3394-4e58-9661-ee5845d2d585 /opt ext4 defaults 1 2
UUID=96b414f8-0d84-49ad-8446-42c509b5c1f3 swap swap defaults 0 0
UUID=b2b426b9-2211-409d-99c2-87a7b26e29e9 /data/ve_data ext4 defaults 1 2
UUID=bb1e3d2b-504b-4ce1-9428-1ff6bfad0423 /data/test_data ext4 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0