磁盘管理

来源:互联网 发布:datamap 软件 编辑:程序博客网 时间:2024/05/23 01:25
######磁盘管理##########
1.名词解释
  mbr:传统分区方案
  mpt:主分区表
  硬盘有效性标示:显示一些硬件的信息
  主分区
  扩展分区:一种容器
  逻辑分区:在扩展分区中的分区


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


3.分区划分
fidsk /dev/vdb




[root@localhost ~]# fdisk /dev/vdb
Welcome to fdisk (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): p
Partition number (2-4, default 2): 2 ##主分区id
First sector (206848-20971519, default 206848): ##此分区的起始位置
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +200M ##分区大小
Partition 2 of type Linux and of size 200 MiB is set


Command (m for help): wq   ##保存并退出,只输入q则表示放弃更改退出
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# 


partprobe ##同步分区表
mkfs.xfs /dev/vdb1 ##格式化
mount /dev/vdb1  /mnt ##临时挂载


vim /etc/fstab ##永久挂载
编写格式:
device    mountpoint    ftype   defaults(mountpoint)   0   0
/dev/vdb1    /mnt        xfs    defaults       0     0
mount -a ##使/etc/fastab中记录的挂载生效


4.删除分区
先使用umount命令解除挂载
  注:当挂载点被使用时,无法解除挂载,需要用fuser -kvm结束使用的进程,然后进行解除挂载
解除挂载之后,使用fdisk /dev/vdb命令 删除分区




5.设定分区方式,将mkdocs 改为 gpt
更改之前需要把正在使用的分区关闭,才可以进行更改
partoff /dev/vdb2
parted /dev/vdb


6.添加swap分区

fdisk  /dev/vdb ##添加一个分区






[root@localhost ~]# partprobe ##同步分区表
[root@localhost ~]# mkswap /dev/vdb2 ##格式化成swap类型
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=b933737a-1409-48b5-8f92-d663d388134b
[root@localhost ~]# swapon -a /dev/vdb2 ##加入swap
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb2                               partition41943000-1
[root@localhost ~]# 


7.用文件来添加swap


dd if=/dev/zero of=/swapfile bs=1M count=1000 ##创建一个1G大小的文件
mkswap /swapfile ##格式化为swap类型
swapon -a /swapfile ##临时添加到swap里
-p + 数字 ##更改优先级 
vim /etc/fstab ##永久添加swap分区
类型:
/swapfile    swap  swap  defaults,pri=1  0 0 #pri优先级


8.删除swap
vim /etc/fstab  ##删除此文件中添加的swap行
swapoff /swapfile ##断开swap文件链接
swapoff /dev/vdb1 ##断开swap磁盘链接
rm -rf /swapfile  ##删除文件
fdisk /dev/vdb  ##删除磁盘分区
partprobe  ##同步分区表
原创粉丝点击