磁盘管理+fdisk+gdisk+mkfs.xfs+mkswap+blkid

对sdb这块盘划分一个100M的分区出来,并格式化为xfs的文件系统

[root@break ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x401b175c 创建新的 DOS 磁盘标签。

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

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

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@break ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@break ~]# mkdir /sdb1
[root@break ~]# mount /dev/sdb1 /sdb1
[root@break ~]# df -h 
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   10G  4.7G  5.4G   47% /
devtmpfs                 975M     0  975M    0% /dev
tmpfs                    992M     0  992M    0% /dev/shm
tmpfs                    992M   11M  982M    2% /run
tmpfs                    992M     0  992M    0% /sys/fs/cgroup
/dev/sr0                 4.2G  4.2G     0  100% /mnt
/dev/sda1                197M  135M   62M   69% /boot
tmpfs                    199M  8.0K  199M    1% /run/user/42
tmpfs                    199M     0  199M    0% /run/user/0
/dev/sdb1                 97M  5.2M   92M    6% /sdb1

解决分区无法卸载的问题

[root@break ~]# cd /sdb1
[root@break sdb1]# umount /sdb1
umount: /sdb1:目标忙。
        (有些情况下通过 lsof(8) 或 fuser(1) 可以
         找到有关使用该设备的进程的有用信息)
方法一:cd出去,然后在执行卸载命令。

方法二:一个终端上执行lsof查看进程,另一个终端上杀死这个bash,然后卸载。
在这里插入图片描述
在这里插入图片描述

开机自动挂载的2种方式

**方式一:**写入配置文件,让它开机自动挂载。vim /etc/fstab
在这里插入图片描述
在这里插入图片描述
**方式二:**使用UUID来进行开机自动挂载.

blkid查看UUID情况,然后使用以下命令重定向到文件中。

在这里插入图片描述

/etc/fstab写入内容的说明

在这里插入图片描述
在这里插入图片描述

MBR与GPT+gdisk与fdisk类似

gdisk主要是用来划分容量大于2T的硬盘,大于2T fdisk搞不定

GPT分区:GPT,全局唯一标识分区表(GUID Partition Table),
它使用128位GUID来唯一标识每个磁盘和分区,与MBR存在单一故障点不同,GPT提供分区表信息的冗余
一个在磁盘头部一个在磁盘尾部;它通过CRC校验和来检测GPT头和分区表中的错误与损坏;
默认一个硬盘支持128个分区。它没有限制主分区个数。

MBR概述:全称为Master Boot Record,即硬盘的主引导记录。
硬盘的0柱面、0磁头、1扇区称为主引导扇区(也叫主引导记录MBR)。
它由三个部分组成,主引导程序、硬盘分区表DPT(Disk Partition table)和分区有效标志(55AA)。
在总共512字节的主引导扇区里主引导程序(boot loader)占446个字节,
第二部分是Partition table区(分区表),即DPT,占64个字节,硬盘中分区有多少以及每一分区的大小都记在其中。第三部分是magic number,占2个字节,固定为55AA。
分区编号:主分区1-4 ,逻辑分区5……
LINUX规定:逻辑分区必须建立在扩展分区之上,而不是建立在主分区上
分区作用:
主分区:主要是用来启动操作系统的,它主要放的是操作系统的启动或引导程序,/boot分区最好放在主分区上
扩展分区不能使用的,它只是做为逻辑分区的容器存在的;我们真正存放数据的是主分区和逻辑分区,大量数据都放在逻辑分区中

对sdb做gpt分区,创建一个sdb1。

[root@break ~]# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format.
THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************


Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-41943006, default = 206848) or {+-}size{KMGTP}: 
Last sector (206848-41943006, default = 41943006) or {+-}size{KMGTP}: +1G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

扩展swap分区

Swap分区在系统的物理内存不够用的时候,把硬盘空间中的一部分空间释放出来,以供当前运行的程序使用。
mkswap /devices (格式化成swap格式)
swapon /swap (激活/swap,加入到swap分区中)
vim /etc/fstab (开机自启动新添加的swap分区)  ,在最后追加:
/devices swap swap defaults 0 0
如果不想使用需要删除,只需要执行#swapoff /swap

使用新的分区进行扩展swap

#使用gdisk进行分区
[root@break ~]# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): E443781A-4F76-4AC9-B286-AA0429923793
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 39845821 sectors (19.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[root@break ~]# reboot
#分区格式化+开启分区+关闭
[root@break ~]# mkswap /dev/sdb1
mkswap: /dev/sdb1: warning: wiping old xfs signature.
正在设置交换空间版本 1,大小 = 1048572 KiB
无标签,UUID=15b3b984-f3ea-4032-83b2-1b0af7a13565
[root@break ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1982         410        1187          10         384        1362
Swap:          2047           0        2047
[root@break ~]# swapon /dev/sdb1
[root@break ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1982         410        1187          10         384        1362
Swap:          3071           0        3071
[root@break ~]# swapoff /dev/sdb1
[root@break ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1982         416        1181          10         384        1356
Swap:          2047           0        2047

使用新的文件进行swap扩展

dd if=/dev/zero of=swap_file bs=1M count=500
mkswap /root/swap_file
mkswap -f /root/swap_file
swapon /root/swap_file           激活
free -m 
swapoff /root/swap_file           关闭
swapon -s                              查看
dd if=/dev/zero of=swap_file bs=1M count=500
记录了500+0 的读入
记录了500+0 的写出
524288000字节(524 MB)已复制,2.4751 秒,212 MB/秒
[root@break ~]# ll /root/swap_file 
-rw-------. 1 root root 524288000 3月  28 23:01 /root/swap_file
[root@break ~]# mkswap /root/swap_file 
mkswap: /root/swap_file: warning: wiping old swap signature.
正在设置交换空间版本 1,大小 = 511996 KiB
无标签,UUID=bfe10c31-8721-45a4-9a32-6ea37d184325
[root@break ~]# swapon /root/swap_file
[root@break ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1982         423        1177          10         381        1349
Swap:          2547           0        2547
[root@break ~]# swapoff /root/swap_file
[root@break ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1982         423        1177          10         381        1349
Swap:          2047           0        2047
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值