将一个新硬盘能够挂载到linux 系统上(开机自动挂载)

第一步:查看当前系统磁盘挂载

​ 查看系统硬盘挂载情况: 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]

sda:表示表示第一个物理硬盘
sda1 表示是第一个分区
ext4 表示一种分区格式
7cc94e03-8b1a-4845-97fb-49a2c39afd8c :唯一ID
/boot:表示这个分区挂在的目录

第二步:为虚拟机添加新的硬盘

​ 在 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:表示全新的硬件(没有sdb1 sdb2,没有分区没有格式化)

**第三步:对磁盘进行分区并格式化

查看新添加的分区**


[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!

查看新分区

[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
Disk identifier: 0x7a1242ed

   Device Boot      Start         End      Blocks   Id  System
**/dev/sdb1**               1         650     5221093+  83  Linux
**/dev/sdb2**             651        1305     5261287+  83  Linux

对新分区进行格式化

​	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

[root@node01 ~]#  **lsblk  -f** 
NAME   FSTYPE  LABEL            UUID                                 MOUNTPOINT
sdb                                                                  
├─sdb1 ext4                     10023089-17e3-4dbf-af6a-447b7e2011d2 
└─sdb2                       

第四步:硬盘的挂载

​ 开机自动挂载
lsblk -f 查看系统硬盘挂载情况

取消挂载:umount /mnt/disk4

                   NAME   FSTYPE  LABEL            UUID                                 MOUNTPOINT
sdb                                                                  
├─sdb1 ext4                     10023089-17e3-4dbf-af6a-447b7e2011d2 
└─sdb2     

​ 修改/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
**UUID=21d817f4-a13d-42dd-992b-591bc8ea1994 /mnt/disk4              ext4    defaults        1 2**
UUID=f306ece0-a790-41d7-b685-63585b8534e4 swap                    swap    defaults        0 0

/mnt/disk1 都是要自己创建的

保存退出 wq

重新挂载系统内所有的硬盘

​	**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**

你可能感兴趣的:(大数据)