问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

(急)linux怎样更改交换空间的大小

发布网友 发布时间:2022-04-24 17:09

我来回答

4个回答

热心网友 时间:2022-04-12 11:26

从你的截图上看,你的问题应该是如何缩小LVM分区,而不是更改交换分区,请明确一下。

这篇文章,你参考一下。
How to shrink a default install LVM PV to create another partition

A default installation of Fedora will use all available free space to create two new partitions: a small /boot, and all the remaining space for a single LVM physical volume (PV). This sometimes poses problems for those who later wish to make room for more regular partitions, to install Another Operating System into, for example. The short solution: reinstall Fedora with custom sizes to leave free space; the long solution: this howto.
Applicable to Fedora Versions

* All

Requirements

1. A default installation of Fedora using LVM (without LUKS encryption)
2. A desire to do things the hard way.

Doing the Work

Summary of steps below: Boot rescue and skip mounting, activate lvm (vgchange -ay), fsck root filesystem, shrink root filesystem (resize2fs), shrink root logical volume (lvresize), lvremove LogVol01 swap LV and add it back to allow pvresize to succeed, shrink PV (pvresize), shrink partition (parted), and finally create new partitions in the free space, now or later.

For the example below, assume we installed Fedora onto all of an 80GB drive, and now we want to squish Fedora down to 50GB to make room for a new 30GB partition <i>after it</i>.

1. Boot into rescue mode and on the last step make sure to SKIP mounting your filesystems under /mnt/sysimage
2. Activate LVM

lvm vgchange -a y

3. fsck your single, large root filesystem on LogVol00

fsck -fC /dev/VolGroup00/LogVol00

4. Shrink your (ext3) filesystem inside the LogVol00 container BEFORE shrinking its container

resize2fs -p /dev/VolGroup00/LogVol00 50G

5. Shrink the LogVol container to match

lvm lvresize /dev/VolGroup/LogVol00 --size 50G

6.

There is now enough free physical space available (lvm pvs) to shrink the physical volume by that much in order to make room for a new partition of that size or smaller. Unfortunately, the current implementation of "pvresize" is lacking - from the manpage: "pvresize will refuse to shrink PhysicalVolume if it has allocated extents after where its new end would be. In the future, it should relocate these elsewhere in the volume group if there is sufficient free space, like pvmove does."

Because of this limitation, it is necessary to temporarily remove your LogVol01 swap LV, which is still physically allocated at the very end of your PV, then add it back such that it's newly located immediately after the smaller LogVol00 nearer to the start of the PV (and partition).

You first must determine how large your current LogVol01 swap is so you can recreate it with the same size. Take note of the "LSize" column for LogVol01 from the output of:

lvm lvs

Assuming your swap was "2.00G", for example, do:

lvm lvremove /dev/VolGroup00/LogVol01
lvm lvcreate --size 2G --name LogVol01 VolGroup00
mkswap /dev/VolGroup00/LogVol01

7. Shrink the Physical Volume

First, determine how much you can shrink it, by running:

sh-3.2# lvm pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 80.00G 71.00G

Take note of the PV to be resized, and of PSize and PFree. You can now resize your /dev/sda2 PV down to a final size of anything between 9G and 80G. We want to shrink down to 50G in this example, leaving 30G free for later.
And now for the pvresize:

lvm pvresize /dev/sda2 --setphysicalvolumesize 50G

If this step fails, it's probably because you're trying to shrink too small, and/or there are still allocated extents -- other than swap, which you moved in the step above -- after where the new tail end would be. A future version of pvresize will automatically move those to earlier free space as needed. (As an alternative, if you have lots of free space on another drive, you could pvcreate there, then pvmove temporarily, then pvresize, and pvmove back.)
8. FINALLY - Shrink the PARTITION containing the shrunk PV to match its new size. WARNING: This is the trickiest bit to get right e to unit conversion and conventions (GB vs GiB, rounding error, etc), so we'll be using the SECTOR unit (512bytes) as well as giving ourselves a margin of error. It also involves a tiny bit of critical advanced addition arithmetic.

Display the PV sizes in SECTORS and take note of the smaller PSize:

lvm pvs --units s

Display the partition Size in SECTORS using parted and take note of the Start sector and partition Number of the partition with "lvm" in the Flags column:

parted /dev/sda unit s print

POINT OF NO RETURN - HAVE BACKUPS

So now we need to nuke the old, large partition from the partition table, and immediately recreate it with the exact same Start sector, but with a newer, shorter End sector. To calculate the new End sector, ADD the partition Start sector to the PV PSize, and then add a safety margin of around 131072 sectors (64MB) to that.

Nuke it

parted /dev/sda rm 2

Recreate it smaller + safety margin. NOTE: remeber to append the letter "s" to your values to qualify them as sectors. (e.g. "123s")

parted /dev/sda mkpart primary 401625s 105390297s
parted /dev/sda set 2 lvm on
parted /dev/sda print
fdisk -l /dev/sda

9. Almost done. OPTIONAL STEP: pvresize, lvresize, and resize2fs once more, in that order, but without an explicit size given, such that you can safely grow it back up into the small safety margin you used above. Skip it.
10. Verify you didn't make a major oops truncating something by running fsck again:

fsck -fC /dev/VolGroup00/LogVol00

11. All done. You now have some free unpartitioned space outside of LVM to play with.

热心网友 时间:2022-04-12 12:44

0,用这个命令fdisk新建一个分区,分区类型是swap
1,用这个命令mkswap来创建一个交换空间,具体信息可查看手册
2,用这个命令swapon来挂载交换空间
4,用这个命令swapoff来缷载交换空间

按这个流程来做,就可以了。有命令不会用的,查man手册

热心网友 时间:2022-04-12 14:19

可以使用windows xp启动光盘的PQ-Magic来重新分区。

热心网友 时间:2022-04-12 16:10

你好,我不是很理解你的提问,也说说见解吧,呵呵。

为什么要更改交换空间的大小呢?

你是在虚拟机里玩的!如果当时给的硬盘小了点,导致现在的空间不足!你完全可以再添加一块新硬盘的!

我通常在虚拟机里添加多块硬盘的!没什么问题的。
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
膀胱癌医生要为什么要检查上尿路? 游览器书签怎样添加到手机桌面 玫瑰花是早上开还是晚上开 玫瑰是晚上开花吗 左拾遗是什么官左拾遗的解释 怎样炖羊肉好吃又烂 怎样炖羊肉软烂无膻味好吃 ...之心度君子之腹的意思以小人之心度君子之腹的解释以小人之心度君子... 以小人之心度君子之腹什么意思以小人之心度君子之腹出处介绍 苹果macbook pro开机音乐是什么 苹果台式电脑声音苹果电脑开机声音怎么设置 如何减小现有的linux swap分区~ linux下16GB内存如何设置交换分区大小 电脑填表怎样曾行? 在东莞跑外卖哪个地点合适单价高? 哪一种外卖员赚钱我准备想做? 如何在安装Linux之后自己修改Swap分区大小 请问送外卖什么城市好?一天能赚多少钱? 天津现在外卖生意怎么样?一天可以跑多少单?一单可以赚多少钱? 有没有做送外卖工作的朋友 工资待遇怎么样 在哪个城市单价高? 在哪个城市送外卖工资高? 3线城市的外卖员一个月大概能挣多少钱呢?为什么很多年轻人去送外卖了呢? 想去跑外卖,哪里的单价高一些,本人想洗心革面了 nct考级需要一级一级考吗 2008年12月14日10点14生人,男孩请高人指点如何起名,谢谢! 肖鼠,此命五行木旺缺金;日主天干为水,生于春季;必须有木助,但忌火太多。如何取名? 本命属鼠,男,五行木旺缺金;日主天干为木,生于春季 如何取名? 五行缺金怎么起名 五行缺金 应起什么名字? oppo手机总是自动黑屏 我的oppo屏幕会自己动,这是怎么回事,而且动的厉害 电脑填表的时候出现乱码还点不动怎么办? 交换分区是什么,有什么用,能更改大小吗求大神普及 电脑表格填写下一格上一格的字为什么向右移动? 怎么在已经装好的red hat 9.0 下 更改 交换分区的大小 电脑填表时如何打勾? vm linux设置交换分区 帮忙用电脑填写一份简单的表格(表格已做好,只需上网查阅资料填写) 怎样练内侧胸肌? 内侧胸肌除了飞鸟怎么练?? 怎么练胸肌的内侧? 怎样用哑铃夹胸练内侧胸肌? 胸肌内侧怎么练?就是中缝,要让这条缝看起来深一下 如何练胸肌内侧! 怎么练胸肌内侧? 内胸肌怎么练 怎么锻炼内下侧胸肌? 怎样练胸肌内侧及下侧 达人高手类请进 我女儿姓冉 2010917生的 想要个诗意点的名字 冉姓女孩取名,三个字,第二字要求带“木”的字(五行中的十二画),第三字五行中的带“火”的字十二画。 姓薛起什么名字好听呢