第一步 查看当前系统磁盘挂载
查看系统硬盘挂载情况: lsblk -f
sda
├─sda1 ext4 / 7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot
├─sda2 ext4 fe1d0eea-50ea-4d44-853b-1c39e5129021 /
├─sda3 ext4 df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1
├─sda4
├─sda5 ext4 ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2
└─sda6 swap f306ece0-a790-41d7-b685-63585b8534e4 [SWAP]
sad :表示当前系统有一个物理硬盘 sda
sda1:第一个物理硬盘的第一个分区
ext4:这个分区的格式(linux 常用的格式)
7cc94e03-8b1a-4845-97fb-49a2c39afd8c:表示这个分区的唯一标识(唯一ID)
/boot:标识这个分区挂载的目录
*[SWAP]*交换分区
交换分区:当又大量数据需要写入内存,但内存不足时,剩余的数据将写入减缓分区
交换分区的说明:在大数据集群中安装集群之前将减缓分区关闭掉
fdisk -l:查看磁盘挂载信息
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x00040944
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 2637 20971520 83 Linux
/dev/sda3 2637 3681 8386560 83 Linux
/dev/sda4 3681 5222 12379136 5 Extended
/dev/sda5 3681 4700 8183808 83 Linux
/dev/sda6 4700 5222 4193280 82 Linux swap / Solaris
第二步:为虚拟机添加新的硬盘
在 vm 虚拟机,右键-》设置 -》 硬盘-》添加 -》下一步。。。。
重启linux 系统
重新查看磁盘挂载情况
fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x00040944
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 2637 20971520 83 Linux
/dev/sda3 2637 3681 8386560 83 Linux
/dev/sda4 3681 5222 12379136 5 Extended
/dev/sda5 3681 4700 8183808 83 Linux
/dev/sda6 4700 5222 4193280 82 Linux swap / Solaris
/dev/sdb:表示全新的硬件
第三步: 对磁盘进行分区并格式化
查看新添加的分区
[root@node01 ~]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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
对新磁盘进行分区
fdisk /dev/sdb
[root@node01 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7a1242ed.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).
Command (m for help): m(帮助)(n : 添加一个分区,d : 删除分区 w: 保存写入)
Command (m for help): n(添加分区)
Command action
e extended
p primary partition (1-4)
p(设置分区的类型)
Partition number (1-4): 1(第一个分区)
First cylinder (1-1305, default 1): 1(第一个分区的起始位置)
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): 650(第一个分区的结束位置)
Command (m for help): n(添加分区)
Command action
e extended
p primary partition (1-4)
p(设置分区的类型)
Partition number (1-4): 2(第二个分区)
First cylinder (651-1305, default 651): (第二个分区的起始位置)
Using default value 651
Last cylinder, +cylinders or +size{K,M,G} (651-1305, default 1305): (第二个分区的结束位置)
Using default value 1305
Command (m for help): w(保存)
The partition table has been altered!
对新分区进行格式化
mkfs -t ext4 /dev/sdb1
[root@node01 ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
326400 inodes, 1305273 blocks
65263 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1337982976
40 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 38 mounts or
格式完毕后,磁盘自动分配UUID,我只分了两个分区所以有两个UUID
[root@node01 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sdb
├─sdb1 ext4 cbfa9e9c-ba46-42e3-8587-14cd46f91fe2
└─sdb2 ext4 b236fa69-60ab-4e68-aac7-ec25354ef36c
sda
记住sdb中的UUID方便后面使用
忘记也可以现查
第四步:硬盘的挂载
前提:挂载的目录必须已经存在
mkdir /mnt/disk3
mkdir /mnt/disk4
挂载磁盘方法1
mount /dev/sdb1 /mnt/disk3
mount /dev/sdb2 /mnt/disk4
取消挂载:umount /mnt/disk4
[root@node01 mnt]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sdb
├─sdb1 ext4 10023089-17e3-4dbf-af6a-447b7e2011d2 /mnt/disk3
└─sdb2 ext4 21d817f4-a13d-42dd-992b-591bc8ea1994 /mnt/disk4
sda
├─sda1 ext4 7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot
├─sda2 ext4 fe1d0eea-50ea-4d44-853b-1c39e5129021 /
├─sda3 ext4 df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1
├─sda4
├─sda5 ext4 ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2
└─sda6 swap f306ece0-a790-41d7-b685-63585b8534e4 [SWAP]
或者
[root@node01 mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 2.1G 17G 12% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sda3 7.8G 18M 7.4G 1% /mnt/disk1
/dev/sda5 7.6G 18M 7.2G 1% /mnt/disk2
/dev/sdb1 4.8G 10M 4.6G 1% /mnt/disk3
/dev/sdb2 4.9G 11M 4.6G 1% /mnt/disk4
挂载磁盘方法2
开机自动挂载
修改/etc/fstab 文件,在文件中添加自动挂载配置
权限不够cat /etc/fstab
UUID=fe1d0eea-50ea-4d44-853b-1c39e5129021 / ext4 defaults 1 1
UUID=7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot ext4 defaults 1 2
UUID=df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1 ext4 defaults 1 2
UUID=ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2 ext4 defaults 1 2
UUID=10023089-17e3-4dbf-af6a-447b7e2011d2 /mnt/disk3 ext4 defaults 1 2
UUID=21d817f4-a13d-42dd-992b-591bc8ea1994 /mnt/disk4 ext4 defaults 1 2
UUID=f306ece0-a790-41d7-b685-63585b8534e4 swap swap defaults 0 0
把之前保存的UUID填入 后面跟创建好的挂载目录
保存退出
重新挂载系统内所有的硬盘
mount -a
[root@node01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 2.1G 17G 12% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sda3 7.8G 18M 7.4G 1% /mnt/disk1
/dev/sda5 7.6G 18M 7.2G 1% /mnt/disk2
/dev/sdb1 4.8G 10M 4.6G 1% /mnt/disk3
/dev/sdb2 4.9G 11M 4.6G 1% /mnt/disk4
完成
总结:方法一 为临时挂载重启消失
方法二 为开机自动挂载