1. 虚拟机可以添加sisc硬盘,添加了要重启虚拟机才能生效

重启后用fdisk -l可以查看到新添的盘,/dev/sdb是新加的第二块硬盘

[root@web01 ~]# fdisk -l
Disk /dev/sdb: 1073 MB, 1073741824 bytes 
255 heads, 63 sectors/track, 130 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 /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x00096eec
   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          91      524288   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3              91        1045     7658496   83  Linux

2. 磁盘分区

命令fdisk /dev/sdb

[root@yunweivm~]# fdisk /dev/sdb

Device containsneither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a newDOS disklabel with disk identifier 0x29a761e1.

Changes willremain in memory only, until you decide to write them.

After that, ofcourse, the previous content won't be recoverable.

 

Warning: invalidflag 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') andchange display units to

         sectors (command 'u').

 

Command (m forhelp):

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 forhelp): p

 

Disk /dev/sdb:106 MB, 106954752 bytes

64 heads, 32sectors/track, 102 cylinders

Units = cylindersof 2048 * 512 = 1048576 bytes

Sector size(logical/physical): 512 bytes / 512 bytes

I/O size(minimum/optimal): 512 bytes / 512 bytes

Disk identifier:0x29a761e1

 

   Device Boot      Start         End      Blocks  Id  System

 

Command (m forhelp): n

Command action

   e  extended

   p  primary partition (1-4)

p

Partition number(1-4): 1

First cylinder(1-102, default 1):

Using defaultvalue 1

Last cylinder,+cylinders or +size{K,M,G} (1-102, default 102): +10m

Unsupportedsuffix: 'm'.

Supported: 10^N:KB (KiloByte), MB (MegaByte), GB (GigaByte)

            2^N: K  (KibiByte), M (MebiByte), G  (GibiByte)

Last cylinder,+cylinders or +size{K,M,G} (1-102, default 102): +10M

 

Command (m forhelp): p

 

Disk /dev/sdb:106 MB, 106954752 bytes

64 heads, 32sectors/track, 102 cylinders

Units =cylinders of 2048 * 512 = 1048576 bytes

Sector size(logical/physical): 512 bytes / 512 bytes

I/O size(minimum/optimal): 512 bytes / 512 bytes

Disk identifier:0x29a761e1

 

   Device Boot      Start         End     Blocks   Id System

/dev/sdb1               1          11       11248  83  Linux

l查看分区类型

Command (m forhelp): l

 

 0 Empty           24  NEC DOS         81 Minix / old Lin bf  Solaris       

 1 FAT12           39  Plan 9          82  Linux swap /So c1  DRDOS/sec (FAT-

 2  XENIXroot      3c  PartitionMagic  83  Linux           c4 DRDOS/sec (FAT-

 3  XENIXusr       40  Venix 80286     84 OS/2 hidden C:  c6  DRDOS/sec (FAT-

 4  FAT16<32M      41  PPC PReP Boot   85 Linux extended  c7  Syrinx        

 5 Extended        42  SFS             86 NTFS volume set da  Non-FSdata   

 6 FAT16           4d  QNX4.x          87 NTFS volume set db  CP/M / CTOS /.

 7 HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility  

 8 AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df BootIt        

 9  AIXbootable    50  OnTrack DM      93 Amoeba          e1  DOS access   

#如果要修改分区类型,用t

Command (m forhelp): t

Partition number(1-8): 8

Hex code (type Lto list codes): 8e

Changed systemtype of partition 8 to 8e (Linux LVM)

#然后就可以看到Id变成了8e,即现在是lVM类型的分区了

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         130     1044193+  8e  Linux LVM

3. 格式化分区

[root@yunweivm~]# mkfs.ext4 -b 4096 -i 1024 /dev/sdb1 
#格式化指定文件系统,inode和block,实际是默认的,不用指定
[root@yunweivm~]#mkfs.ext4 -T largerfile /dev/sdb1

-t: 文件系统

-T 快速格式化

4. 挂载

[root@yunweivm~]# mount /dev/sdb1 /mnt   

问题排错:如果出现如下错误:
[root@yunweivm~]# mount /dev/sdb1 /mnt  #未格式化,无法挂载
mount: you mustspecify the filesystem type

5. 查看挂载结果

df -hT


6. 修改文件系统方法
先找到/dev/sda5分区对应的UUID

root@vm-ubuntu16:/# blkid /dev/sdb1

/dev/sdb1: UUID="431d40de-2a4a-4867-b9ed-65d7713fc8fa" TYPE="xfs" PARTUUID="1df123cc-01"
然后,我们按照/etc/fstab文件中的格式添加一行如下内容: 
UUID=0001D3CE0001E53B   /home/ubuntu/NewDisk  ntfs  defaults        0       2 
其中第一列为UUID, 第二列为挂载目录(该目录必须为空目录),第三列为文件系统类型,第四列为参数,第五列0表示不备份,最后一列必须为2或0(除非引导分区为1)

  /dev/sdb1 /home xfs defaults 0 0


431d40de-2a4a-4867-b9ed-65d7713fc8fa /home xfs defaults 0 0