linux-磁盘的管理与swap分区

来源:互联网 发布:淘宝掌柜直播 编辑:程序博客网 时间:2024/05/21 10:01
****************磁盘管理***********


1.  mbr                     主引导记录广义的概念是mbr包含了引导程序,分区表,分隔标示
    mpt                         
    硬盘有效性标示
    主分区
    扩展分区
    逻辑分区


2.磁盘查看命令
   fdisk -l                           ***系统中所有的磁盘设备
   df -Th                             ***系统中正在挂载的磁盘设备
   blkid                              ***系统中可以挂载的设备

3.磁盘分区
  fdisk /dev/vdb
*********************************************************************************
  sk(util-linux 2.23.2).

  Changes will remain in memory only, until you decide to write them.
  Be careful before using the write command.


Command (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 (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (411648-20971519, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +200M
Partition 2 of type Linux and of size 200 MiB 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: 0x5d3b1825

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   83  Linux
/dev/vdb2          411648      821247      204800   83  Linux

Command (m for help): wq

##############################################################################


partprobe                  ##同步分区表

mkfs.xfs /dev/vdb1         ##格式化
mount /dev/vdb1 /mnt       ##挂载
#注意:上述挂载为临时挂载,如果需要永久挂载,需要编辑文件"/etc/fstab"
/dev/vdb1    /mnt    xfs   defaults    0   0

###4、切换分区模式###
##系统默认为dos分区记录方式,此方式最多只有4个分区,且最多可以划分2T空间,在企业使用中不够,所以需要换分区记录方式。
#############################################################################
parted /dev/vdb

GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of command:.
(parted) mk                                                               
mklabel  mkpart   mktable  
(parted) ##mklabel##
New disk label type? ##gpt##                                                  
Warning: The existing disk label on /dev/vdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? ##yes##                                                               
(parted) ##quit##  

############################################################################
##通过上述步骤将dos的分区模式改为gpt的分区模式,gpt的分区方式可以划分128个分区,最多可以划分18eb的空间。如果需要改会以前分区,需要将上图中的gpt改为msdos即可。


4.swap
直接分区

fdisk /dev/vdb                     ##分区

fdisk分区中在wq前输入t,然后输入l查找swap分区标识,输入分区标识,输入wq保存退出
dos的swap分区标识编号为82,gpt为14。

mkswap /dev/vdbn

swapon -a /dev/vdn

swapon -s

以上设置只能临时生效,如果需要永久生效,需要编辑"/etc/fstab"
/dev/vdbn   swap   swap    defaults   0   0

截取文件

1.dd if=/dev/zero of=/swapfile bs=1M count=1000     ##截取一个1G的文件

2.mkswap /swapfile                                  ##将此文件格式化为swap格式

3.swapon -a /swapfile                               ##添加格式化过的/swapfile

 swapon -a /swapfile -p num         ##可以在添加swap时设置优先级

 vim /etc/fstab          ##如果需要开机自动挂载,则配置此文件

 /swapfile swap swap defaults,pri=1  0  0        ##pri=1为设置优先级为1,也可不写