Linux dd命令在扩增SWAP分区时的应用(2)


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.


[root@linuxidc ~]# partprobe /dev/sdb //让内核重读分区表
[root@linuxidc ~]# cat /proc/partitions //确保内核重读分区表完成
major minor  #blocks  name


  8    0  20971520 sda
  8    1    305203 sda1
  8    2  19615365 sda2
  8    3    1044225 sda3
  8    16  20971520 sdb
  8    17    2939863 sdb1
[root@linuxidc ~]#mkswap /dev/sdb1 //格式化
Setting up swapspace version 1, size = 3010412 kB
[root@linuxidc ~]# swapon /dev/sdb1 //启用该swap分区
[root@linuxidc ~]# free -m
            total      used      free    shared    buffers    cached
Mem:          502        394        107          0        30        273
-/+ buffers/cache:        90        412
Swap:        3890          0      3890


[root@linuxidc ~]# swapoff /dev/sdb1 //关闭该swap分区
[root@linuxidc ~]# free -m
            total      used      free    shared    buffers    cached
Mem:          502        393        108          0        30        273
-/+ buffers/cache:        89        413
Swap:        1019          0      1019

2.当硬盘没有剩余的存储可创建新分区时,可以利用dd命令在已存的分区中创建一个文件,充当swap分区。
    具体步骤:(现已脚本的形式呈现)
[root@linuxidc ~]# vi createswap.sh
#!/bin/bash
echo -n "Please input your number:  "
read number
echo -n "Please input your swapfile name and the whole path:  "
read path
dd if=/dev/zero of=$path bs=1M count=$number
mkswap $path
swapon $path
free -m
echo "The swap created"

结束语:到此教程完毕。

Linux dd命令制作U盘系统启动盘 

Linux/UNIX: 使用 dd 命令创建 1GB 大小的二进制 

如何在Ubuntu 14.04中创建SWAP交换分区文件 

如何扩展/删除SWAP分区

在OpenStack虚拟机实例中创建SWAP分区的一种方法

Linux 中交换空间 (SWAP)应该分多大才好?

Linux SWAP 分区建立及释放内存

Linux SWAP 交换分区配置说明

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/16701.html