linux 分区与挂载

1.磁盘分区

传统的MBR分区方式,一块硬盘可以分四个主分区,分配完四个主分区后即使硬盘还有剩余空间也无法再继续分区。如果需要更多地分区那么就需要在扩展分区中创建逻辑分区来实现。

      fdisk

[root@localhost ~]# fdisk -l                  #查看磁盘分区表

磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009248a

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM


[root@localhost ~]# fdisk /dev/sda2
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x7823acaf 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag                          #切换分区启动标记
   b   edit bsd disklabel
   c   toggle the dos compatibility flag               #编辑bsd磁盘标签
   d   delete a partition                              #删除分区
   g   create a new empty GPT partition table          #创建一个空的GPT分区表
   G   create an IRIX (SGI) partition table            
   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                #创建sun磁盘标签
   t   change a partition's system id                  #修改磁盘ID      
   u   change display/entry units                      #修改容量单位
   v   verify the partition table                      #检验分区表
   w   write table to disk and exit                    #保存并退出
   x   extra functionality (experts only)              #扩展功能

命令(输入 m 获取帮助):n                                 #创建新分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)         #主分区 
   e   extended                                        #扩展分区
Select (default p): p
分区号 (1-4,默认 1):1        
起始 扇区 (2048-40916991,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-40916991,默认为 40916991):+2G
分区 1 已设置为 Linux 类型,大小设为 2 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sda2:20.9 GB, 20949499904 字节,40916992 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x7823acaf

     设备 Boot      Start         End      Blocks   Id  System
/dev/sda2p1            2048     4196351     2097152   83  Linux

命令(输入 m 获取帮助):n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
分区号 (2-4,默认 2):2
起始 扇区 (4196352-40916991,默认为 4196352):
将使用默认值 4196352
Last 扇区, +扇区 or +size{K,M,G} (4196352-40916991,默认为 40916991):
将使用默认值 40916991
分区 2 已设置为 Extended 类型,大小设为 17.5 GiB

命令(输入 m 获取帮助):n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
添加逻辑分区 5
起始 扇区 (4198400-40916991,默认为 4198400):
将使用默认值 4198400
Last 扇区, +扇区 or +size{K,M,G} (4198400-40916991,默认为 40916991):+2G
分区 5 已设置为 Linux 类型,大小设为 2 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sda2:20.9 GB, 20949499904 字节,40916992 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x7823acaf

     设备 Boot      Start         End      Blocks   Id  System
/dev/sda2p1            2048     4196351     2097152   83  Linux
/dev/sda2p2         4196352    40916991    18360320    5  Extended
/dev/sda2p5         4198400     8392703     2097152   83  Linux

命令(输入 m 获取帮助):d
分区号 (1,2,5,默认 5):5
分区 5 已删除

命令(输入 m 获取帮助):p

磁盘 /dev/sda2:20.9 GB, 20949499904 字节,40916992 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x7823acaf

     设备 Boot      Start         End      Blocks   Id  System
/dev/sda2p1            2048     4196351     2097152   83  Linux
/dev/sda2p2         4196352    40916991    18360320    5  Extended

命令(输入 m 获取帮助):w
The partition table has been altered!




[root@localhost ~]# partprobe  /dev/sda           #使用partprobe重新读取分区表

 

猜你喜欢

转载自blog.csdn.net/weixin_38280090/article/details/81697452
今日推荐