linux添加交换空间

前端之家收集整理的这篇文章主要介绍了linux添加交换空间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我执行了以下程序,以便为交换添加400米,

我从sdb磁盘中取出400米以进行交换增加

一切都很好,但在最后一个命令之前,我表演了

mkswap /dev/rootvg/swap

我从mkswap收到以下警告消息

mkswap: /dev/rootvg/swap: warning: don't erase bootbits sectors
    on whole disk. Use -f to force.
Setting up swapspace version 1,size = 2490364 KiB
no label,UUID=2f42fa37-987d-40a5-8cf6-5707e1d8f077

最后交换按预期扩展到2.4G

但是我很担心来自mkswap命令的警告消息

请告知警告的含义:

mkswap: /dev/rootvg/swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.

如果这样可以吗?

我在linux redhat机器上的程序 – 版本6

# swapon -s
Filename                                Type            Size    Used      Priority
/dev/dm-1                               partition       2064380 0       -1

# free
        total       used       free     shared    buffers     cached
Mem:       5991892     539036    5452856        212      70444     270664
-/+ buffers/cache:     197928    5793964
 Swap:      2064380          0    2064380


# pvs
PV         VG      Fmt  Attr PSize  PFree
 /dev/sdb   rootvg  lvm2 a--u  7.97g 416.00m
 /dev/sdc   orahome lvm2 a--u 30.00g  15.00g

# lsblk /dev/sdb
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb                     8:16   0    8G  0 disk
|-rootvg-swap (dm-1)  253:1    0    2G  0 lvm  [SWAP]
|-rootvg-slash (dm-2) 253:2    0  576M  0 lvm  /
|-rootvg-usr (dm-3)   253:3    0  1.4G  0 lvm  /usr
|-rootvg-home (dm-4)  253:4    0  256M  0 lvm  /home
|-rootvg-opt (dm-5)   253:5    0  416M  0 lvm  /opt
`-rootvg-var (dm-6)   253:6    0    3G  0 lvm  /var

# swapon -s
Filename                                Type            Size    Used     Priority
/dev/dm-1                               partition       2064380 0       -1

# swapoff /dev/rootvg/swap

# lvresize /dev/rootvg/swap -L +400m
 Rounding size to boundary between physical extents: 416.00 MiB.
 Size of logical volume rootvg/swap changed from 1.97 GiB (63 extents) to  2.38 GiB (76 extents).
 Logical volume swap successfully resized.

# mkswap /dev/rootvg/swap
mkswap: /dev/rootvg/swap: warning: don't erase bootbits sectors
    on whole disk. Use -f to force.
Setting up swapspace version 1,UUID=2f42fa37-987d-40a5-8cf6-5707e1d8f077

# swapon /dev/rootvg/swap

# free
         total       used       free     shared    buffers     cached
 Mem:       5991892     539680    5452212        212      70536     270892
 -/+ buffers/cache:     198252    5793640
 Swap:      2490364          0    2490364

解决方法

看起来像一个安全预防措施,以防止您破坏引导扇区等…当您可能打算使用分区时使用整个磁盘.

此警告消息不再出现在CentOS 6.5和Ubuntu 16.04中.

这个较旧的(2006)mkswap.c模糊地定义了bootbits:http://code.metager.de/source/xref/busybox/util-linux/mkswap.c

/*  char     bootbits[1024];    Space for disklabel etc. */

从CentOS 6.5 mkswap.c:

if (is_whole_disk_fd(fd,devname)) {
                /* don't zap bootbits on whole disk -- we know nothing
                 * about bootloaders on the device */
                whole = 1;
                zap = 0;

我对C并不陌生,但新代码看起来更智能,可能保留了引导数据.我不是那么深思.

猜你在找的Linux相关文章