磁盘管理

1.                   bootloader(512) 启动引导

                      /      |       \

                     /      |        \

                 mbr(446)  mpt(64)  55aa(2)

                 主引导记录   分区表     硬盘标识

硬盘按类别分为主分区、扩展分区(包含逻辑分区)


2.磁盘查看命令

fdisk -l#系统中的所有磁盘设备

运维学习之磁盘的分区划分、管理及应用、swap分区_Linuxdf -Th#系统正在挂载的磁盘设备

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_02blkid#系统可以挂载的磁盘设备id

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_03Command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition#删除分区

   g   create a new empty GPT partition table

   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

   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)


Command (m for help): n#新建分区

Partition type:

   p   primary (0 primary, 0 extended, 4 free)#分区类型为主分区

   e   extended#分区类型为扩展分区

Select (default p): p#默认为主分区

Partition number (1-4, default 1): 1#主分区id

First sector (2048-20971519, default 2048): #此分区起始位置

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G#分区大小

Partition 1 of type Linux and of size 1 GiB is set


Command (m for help): p


Disk /dev/vdb: 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: 0xf15d342f


   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048     2099199     1048576   83  Linux


Command (m for help): wq#保存退出

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_04partprobe#同步分区表

cat /proc/partitions#查看系统识别的分区信息

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_05mkfs.xfs /dev/vdb1#格式化

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_06mount /dev/vdb1 /mnt#挂载

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_07vim /etc/fstab  #永久挂载

devic    mountpoint    ftype    defaults(mountpoint)    0    0

/dev/vdb1    /mnt      xfs       defaults        0    0

mount -a    #使文件中记录的挂载信息生效

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_08

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_09

删除分区

umount /mnt    卸载/mnt挂载点

注意:当挂载点被使用时,无法解除挂载,需要用fuser -kvm结束使用的进程,再进行卸载

GPT分区方式

优点:支持128个分区,不分主分区和逻辑分区,mbr最多四个系统,比mbr安全性高,有备份功能,容量比mbr大,可识别大于2T的硬盘

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_10更改为gpt格式后进行分区操作如下

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_112.swap

  1. fdisk /dev/vdb#分区

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_12

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_13

2.fdisk中修改swap分区标识

gpt14

doc82

3.

mkswap /dev/vdbn    #格式化成swap类型

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_144.swapon -a /dev/vdbn    #加入swap

swap -s        #查看swap分区

mbr格式下swap分区

更改格式为msdos

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_15

创建swap分区(mbr下swap分区的代码为82)

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_16

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_17

5.vim /etc/fstab

/dev/vdbnswapswapdefaults,pri=100

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_18

6.swapoff /dev/vdbn    #关闭swap分区

文件形式添加swap分区

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_19

配置永久挂载swap文件

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_20查看状态

运维学习之磁盘的分区划分、管理及应用、swap分区_Linux_21

按如上步骤删除swap分区,先关闭,再删除!最后查看swap状态即可!