![如何减少根分区的LVM?](https://linux22.com/image/89713/%E5%A6%82%E4%BD%95%E5%87%8F%E5%B0%91%E6%A0%B9%E5%88%86%E5%8C%BA%E7%9A%84LVM%EF%BC%9F.png)
我正在尝试减少专用于根 LVM 的空间,因为我并不真正需要它,而且我有一些疑问。以下是 的输出lvdisplay
:
# lvdisplay
--- Logical volume ---
LV Path /dev/pc_rperez_lvm/root
LV Name root
VG Name pc_rperez_lvm
LV UUID m7XejM-82cZ-hODn-nT8H-y2BM-3B4s-lq2xgn
LV Write Access read/write
LV Status available
# open 1
LV Size 72.37 GiB
Current LE 18527
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/pc_rperez_lvm/home
LV Name home
VG Name pc_rperez_lvm
LV UUID Ehl9tF-XV30-uF4Y-T1Bc-WB8r-Pfim-ONQFn3
LV Write Access read/write
LV Status available
# open 1
LV Size 25.00 GiB
Current LE 6400
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/pc_rperez_lvm/swap
LV Name swap
VG Name pc_rperez_lvm
LV UUID pJuBnV-fhD1-NgOe-xMUc-gck8-CfeM-YkQHAX
LV Write Access read/write
LV Status available
# open 2
LV Size 8.00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
我想要实现的是缩小root
到25GB,然后将可用空间添加到home
.我读过很多文章,但没有提到如何在安装了分区的根分区上实现这一点。那么有了这些信息,是否可以减少安装分区的空间?如果是这样怎么办?如果不是你会推荐我什么?我使用的是 Fedora 23
我缺少什么?
编辑:文件系统:
根据要求,这是使用的文件系统:
# cat /etc/fsatb
/dev/mapper/pc_rperez_lvm-root / ext4
/dev/mapper/pc_rperez_lvm-home /home ext4
/dev/mapper/pc_rperez_lvm-swap swap swap
注意:我读过一些用于管理 LVM(如 GParted)分区的 Live CD,但到目前为止我还没有找到任何,如果你知道的话请添加到你的回复中!
编辑:无法增大其他 LVM
我已经运行了收缩命令pc_lvm_root
,一切都很好,如下所示:
$ sudo ssm resize -s 50G /dev/mapper/pc_rperez_lvm-root
fsck from util-linux 2.28
/dev/mapper/pc_rperez_lvm-root: 425214/4743168 files (0.2% non-contiguous), 9042371/18971648 blocks
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/mapper/pc_rperez_lvm-root to 13107200 (4k) blocks.
The filesystem on /dev/mapper/pc_rperez_lvm-root is now 13107200 (4k) blocks long.
Size of logical volume pc_rperez_lvm/root changed from 72.37 GiB (18527 extents) to 50.00 GiB (12800 extents).
Logical volume root successfully resized.
现在我想将这些 50G 添加到pc_rperez_lvm-home
但我不能,请参阅下面的输出:
$ sudo ssm resize -s+50G /dev/mapper/pc_rperez_lvm-home
SSM Error (2005): There is not enough space in the pool 'pc_rperez_lvm' to grow volume '/dev/mapper/pc_rperez_lvm-home' to size 78538342.4 KB!
编辑:仍然无法增大 LVM
遗憾的是,我还无法扩展家庭 LVM,以下是我根据答案中的建议所做的操作:
$ sudo ssm resize /dev/mapper/pc_rperez_lvm-home
e2fsck 1.42.13 (17-May-2015)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/pc_rperez_lvm-home: 34602/1638400 files (3.0% non-contiguous), 2213886/6553600 blocks
resize2fs 1.42.13 (17-May-2015)
Please run 'e2fsck -f /dev/mapper/pc_rperez_lvm-home' first.
SSM Error (2012): ERROR running command: "resize2fs /dev/mapper/pc_rperez_lvm-home"
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 260K 3.9G 1% /dev/shm
tmpfs 3.9G 1.4M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sdb1 15G 1.6G 13G 11% /run/initramfs/live
/dev/mapper/live-rw 6.3G 4.2G 2.2G 66% /
tmpfs 3.9G 20K 3.9G 1% /tmp
vartmp 3.9G 63M 3.9G 2% /var/tmp
tmpfs 798M 24K 798M 1% /run/user/1000
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/pc_rperez_lvm/root
LV Name root
VG Name pc_rperez_lvm
LV UUID m7XejM-82cZ-hODn-nT8H-y2BM-3B4s-lq2xgn
LV Write Access read/write
LV Status available
# open 0
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/pc_rperez_lvm/home
LV Name home
VG Name pc_rperez_lvm
LV UUID Ehl9tF-XV30-uF4Y-T1Bc-WB8r-Pfim-ONQFn3
LV Write Access read/write
LV Status available
# open 0
LV Size 25.00 GiB
Current LE 6400
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/pc_rperez_lvm/swap
LV Name swap
VG Name pc_rperez_lvm
LV UUID pJuBnV-fhD1-NgOe-xMUc-gck8-CfeM-YkQHAX
LV Write Access read/write
LV Status available
# open 2
LV Size 8.00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
$ sudo e2fsck -f /dev/mapper/pc_rperez_lvm-home
e2fsck 1.42.13 (17-May-2015)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/pc_rperez_lvm-home: 34602/1638400 files (3.0% non-contiguous), 2213886/6553600 blocks
此时有想法吗?
编辑:所需信息
$ sudo vgdisplay
--- Volume group ---
VG Name pc_rperez_lvm
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 105.38 GiB
PE Size 4.00 MiB
Total PE 26976
Alloc PE / Size 21248 / 83.00 GiB
Free PE / Size 5728 / 22.38 GiB
VG UUID Gi0r0L-gRJe-Tzwz-QQE0-CLOY-ofb2-Hk5YCe
$ sudo dumpe2fs -h /dev/mapper/pc_rperez_lvm-home
dumpe2fs 1.42.13 (17-May-2015)
Filesystem volume name: <none>
Last mounted on: /home
Filesystem UUID: eb319b45-03f2-49d3-b849-6e1ff4b19046
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 1638400
Block count: 6553600
Reserved block count: 327680
Free blocks: 4358401
Free inodes: 1607559
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 1022
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Fri Mar 18 13:16:13 2016
Last mount time: Thu Jul 7 08:06:05 2016
Last write time: Thu Jul 7 13:21:17 2016
Mount count: 1
Maximum mount count: -1
Last checked: Thu Jul 7 07:56:48 2016
Check interval: 0 (<none>)
Lifetime writes: 714 GB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: a4d5967b-3ad8-4d22-833d-a6126de8ee41
Journal backup: inode blocks
Journal features: journal_incompat_revoke
Journal size: 128M
Journal length: 32768
Journal sequence: 0x002cb467
Journal start: 0
答案1
不resize2fs
支持缩小已安装的文件系统:
描述 resize2fs 程序将调整 ext2、ext3 或 ext4 文件系统的大小。它可用于放大或缩小设备上未安装的文件系统。如果文件系统已安装,则可以使用它来扩展已安装文件系统的大小,假设内核和文件系统支持在线调整大小。
当您使用 Fedora 发行版时,更改文件系统的大小会更容易,System Storage Manager
因为它会一次性处理底层分区/逻辑卷大小的更改。尽管您需要从以下之一启动系统LiveCD 旋转,由 Fedora 社区提供(我推荐 XFCE 或 LXDE 以减少下载大小),因此在终端窗口中只需发出:
sudo ssm resize -s -5G /dev/mapper/pc_rperez_lvm-root
将根文件系统减少 5 GB,或者
sudo ssm resize -s 15G /dev/mapper/pc_rperez_lvm-root
将 fs 大小设置为 15 GB。
如果ssm
您要下载的 Live CD 中没有该文件,请执行以下操作:
sudo yum install system-storage-manager
在重新调整大小之前。
要将卷扩展到最大可用空间,只需省略该-s
选项:
sudo ssm resize /dev/mapper/pc_rperez_lvm-home
答案2
只是为了让您知道,在做任何事情之前,如果可以的话,请进行完整备份,或者至少备份您的根驱动器。搞乱 LVM 是好事,除非出现错误,否则就很难找回东西了。
现在您将需要在 Live CD 上执行此操作,因为需要卸载根分区,然后从实时会话中的终端执行以下操作。
确保根 LVM 已卸载
应该mount
只显示与 Live CD 相关的安装点
# mount
检查根文件系统是否有错误
# e2fsck -f /dev/mapper/pc_rperez_lvm/root
缩小根文件系统
我们总是希望有一点缓冲空间,以便收缩时安全
# resize2fs /dev/mapper/pc_rperez_lvm/root 23500M
缩小根LV
# lvresize -L 24G pc_rperez_lvm/root
检查根LV
您现在应该看到您有“免费 PE”并且您的根文件系统约为 24G
# vgdisplay
# lvdisplay pc_rperez_lvm/root
扩展根文件系统以填充 LV
不想浪费那个空间。
# resize2fs -M /dev/mapper/pc_rperez_lvm/root
将范围分配给主 LV
# lvresize -l +100%FREE /dev/mapper/pc_rperez_lvm/home
扩展主文件系统
# resize2fs -M /dev/mapper/pc_rperez_lvm/home
重启
# reboot