- 准备工作,在virtualbox中新建一台虚拟机(centos7)
-
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
,设置onboot=yes
之后service network restart
查看是否能上网 -
创建新的磁盘
-
- 磁盘信息
# 查看磁盘使用情况
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 8.0G 981M 7.1G 12% /
devtmpfs 485M 0 485M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 6.7M 490M 2% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/sda1 1014M 129M 886M 13% /boot
tmpfs 100M 0 100M 0% /run/user/0
# 列出指定的外围设备的[分区表]状况
[root@localhost ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0002f85d
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 8585 MB, 8585740288 bytes, 16769024 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-swap: 1073 MB, 1073741824 bytes, 2097152 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@localhost ~]# lsblk
#sda1-->意思是第一个硬盘(a)的第一个分区(1)
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 10G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 9G 0 part
├─centos-root 253:0 0 8G 0 lvm /
└─centos-swap 253:1 0 1G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
sr0 11:0 1 1024M 0 rom
#列出所有设备的[分区]信息
[root@localhost ~]# parted -l
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 10.7GB 9663MB primary lvm
# 说明这块磁盘上没有分区表
Error: /dev/sdb: unrecognised disk label
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 1074MB 1074MB linux-swap(v1)
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 8586MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 8586MB 8586MB xfs
- 挂载磁盘
- 由
fdisk -l
命令可知,新加的磁盘名称为/dev/sdb
- 在这里不进行分区,直接将整块磁盘格式化,挂载点为/data
- 格式化为xfs文件系统
[root@localhost ~]# mkfs.xfs -f /dev/sdb
- 挂载磁盘
# 注意一定要有/data目录,没有就用mkdir创建一个,但是如果原来就有 # /data目录下的数据一定要备份,要不然会丢失 [root@localhost ~]# mount /dev/sda /data
- 检查是否已经挂载上了
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 8.0G 982M 7.1G 12% / devtmpfs 485M 0 485M 0% /dev tmpfs 496M 0 496M 0% /dev/shm tmpfs 496M 6.8M 490M 2% /run tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 1014M 129M 886M 13% /boot tmpfs 100M 0 100M 0% /run/user/0 /dev/sdb 10G 33M 10G 1% /data
- 可以看到/data挂载点已经是10G了
- 由
- 使挂载永久生效
[root@localhost ~]# vi /etc/fstab
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=179fcfbf-cd9a-4659-8f9c-573abba4971f /boot xfs defaults 0 0
UUID=39BB-EB15 /boot/efi vfat umask=0077,shortname=winnt 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
#添加下面这一行
/dev/sdb /data xfs defaults 0 0
- 重启机器发现磁盘已经挂载到/data了
- 未分配的磁盘空间如何查看
- lsblk命令
[root@localhost ~]# lsblk #sda1-->意思是第一个硬盘(a)的第一个分区(1) #如果你的sda磁盘下有未分配空间,那么该磁盘下的所有分区的总大小是小于sda节点的size的 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 10G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 9G 0 part ├─centos-root 253:0 0 8G 0 lvm / └─centos-swap 253:1 0 1G 0 lvm [SWAP] sdb 8:16 0 10G 0 disk sr0 11:0 1 1024M 0 rom
- 使用系统图像界面的图形化磁盘管理工具
- 其他