Hai*_*ood 27 partitioning lvm gparted 12.10
我已经安装了 Ubuntu 12.10 作为我系统上唯一的操作系统。
我告诉 Ubuntu 覆盖所有内容,因为我很着急,因此我只有 Ubuntu 创建的两个分区,一个几百 MB 的引导分区,然后是其他所有分区。
主分区大约600GB,
我希望将其调整为 450GB,以便我可以将 Windows 8 安装为双启动。
问题是我无法弄清楚如何缩小分区,通常从 Gparted (gparted-live-0.14.1-6-i486.iso) live iso 可以正常工作,只需调整大小即可。
但是这次Ubuntu已经安装了LVM。
因此,Ubuntu 分区旁边有一个锁定图标。这会阻止我做任何事情,我可以选择分区,并且有一个“停用”选项,如果我是对的,我认为是停用交换?如果我这样做,我可以操纵分区。
我在这里问在我破坏我的系统之前这是否是正确的做法。
我的想法正确吗?
所以,经过一些长时间的聊天后,我归结为这个命令
sudo lvresize --verbose --resizefs -L -150G /dev/ubuntu/root
Run Code Online (Sandbox Code Playgroud)
这成功地缩小了逻辑分区。

但现在我有困难的部分。
现在我需要缩小物理分区,以便我可以创建一个具有安装 Windows 8 空间的新物理分区。
所以我想我可以跑
pvresize --setphysicalvolumesize {any size here} /dev/sda5
Run Code Online (Sandbox Code Playgroud)
但我回来了:
/dev/sda5: 不能调整到 xxxxx 范围,因为稍后分配。
我认为这是由于此图像导致的交换:
,那么我的下一步是什么?
$: lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu/root
LV Name root
VG Name ubuntu
LV UUID G7Z3dA-xska-8QpO-Y5oD-aIVO-D8l1-22s6dO
LV Write Access read/write
LV Creation host, time ubuntu, 2013-01-29 22:06:02 +1300
LV Status available
# open 1
LV Size 540.42 GiB
Current LE 138348
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Path /dev/ubuntu/swap_1
LV Name swap_1
VG Name ubuntu
LV UUID 14qpRy-H5jl-dTAq-CVle-k7Bz-95Rm-Y46zOs
LV Write Access read/write
LV Creation host, time ubuntu, 2013-01-29 22:06:04 +1300
LV Status available
# open 2
LV Size 7.97 GiB
Current LE 2041
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
Run Code Online (Sandbox Code Playgroud)

请注意,以上截图来自 Ubuntu 存储库中的 Gparted 版本,而不是最新版本
matthew@play:~$ sudo fdisk -l
Disk /dev/sda: 750.2 GB, 750156374016 bytes
255 heads, 63 sectors/track, 91201 cylinders, total 1465149168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c5bec
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 1465147391 732322817 5 Extended
/dev/sda5 501760 1465147391 732322816 8e Linux LVM
Disk /dev/mapper/ubuntu-root: 741.3 GB, 741334843392 bytes
255 heads, 63 sectors/track, 90128 cylinders, total 1447919616 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/ubuntu-root doesn't contain a valid partition table
Disk /dev/mapper/ubuntu-swap_1: 8560 MB, 8560574464 bytes
255 heads, 63 sectors/track, 1040 cylinders, total 16719872 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/ubuntu-swap_1 doesn't contain a valid partition table
Run Code Online (Sandbox Code Playgroud)
matthew@play:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
root ubuntu -wi-ao-- 690.42g
swap_1 ubuntu -wi-ao-- 7.97g
Run Code Online (Sandbox Code Playgroud)
matthew@play:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu 1 2 0 wz--n- 698.39g 0
Run Code Online (Sandbox Code Playgroud)
matthew@play:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 ubuntu lvm2 a-- 698.39g 0
Run Code Online (Sandbox Code Playgroud)
小智 19
这些是调整 LVM 或 LVM2 分区大小所需的所有步骤 -
sudo lvresize --verbose --resizefs -L -150G /dev/ubuntu/root
sudo pvresize --setphysicalvolumesize {any size here} /dev/sda5
/dev/sda5: cannot resize to xxxxx extents as later ones are allocated.
Run Code Online (Sandbox Code Playgroud)
您必须重新排列 LVM 末尾的未分配空间。这意味着在 root 和 swap_1 分区之后。因此,您需要使用以下命令移动该可用空间
pvs -v --segments /dev/sda5
This will show the output like below
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-xxx
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx nnn 0 free
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyy zzz swap 0 linear /dev/sda5:yyy-zzz
Run Code Online (Sandbox Code Playgroud)
现在使用下面的命令删除外部碎片 -
sudo pvmove --alloc anywhere /dev/sda5:yyy-zzz
Run Code Online (Sandbox Code Playgroud)
现在让我们看看它是怎么回事——
pvs -v --segments /dev/sda5
This will show the output like below
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-xxx
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx nnn swap 0 linear /dev/sda5:xxx-yyy(-1)
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyy zzz 0 free
Run Code Online (Sandbox Code Playgroud)
之后使用 gparted 并将 LVM 调整为最大已用区域,其余部分将位于未分配的空间中。享受...
我会,现在你已经有了更小的根 LV,lvremove交换 LV 并重新创建它。这应该迫使它直接附加到根 LV 的位置。完成后,您应该能够访问pvresize物理卷。然后是编辑分区表 ( fdisk) 以将分区缩小到 PV 的新大小的可怕部分,从而释放空间供 Windows 安装程序使用。
对于缩小分区的大小,我建议比 PV 报告的大小略大几 MB,并增大 PV 和根 LV 以填充可用范围。这样你就可以确定你 A) 使用 LVM 的所有分区大小,并且不会因为无法访问而丢失空间,并且 B) 不会通过将二进制 KiB/MiB/GiB 误解为十进制 KB 来切断 PV 中的重要数据在 fdisk 操作期间 /MB/GB 或反之亦然。
新的交换,如果你创建一个新的交换以确保它像我上面建议的那样附加到根 LV,将会有一个不同的 UUID,因此你的 /etc/fstab 将不匹配。调整大小完成后,您将需要mount /dev/ubuntu/root /mnt编辑 /mnt**/etc/fstab**。
在 fstab 文件中,您需要找到与下面类似的交换条目,并使用 报告的值更新 UUID= 之后的十六进制blkid。
blkid在我的系统上的步骤如下:
跑
blkid /dev/ubuntu/swap_1
Run Code Online (Sandbox Code Playgroud)
哪个输出
/dev/ubuntu/swap_1: UUID="9e99b37a-38af-4987-85eb-92048abd9825" TYPE="swap"
Run Code Online (Sandbox Code Playgroud)9e99b37a-38af-4987-85eb-92048abd9825
从根 LV 编辑 /etc/fstab 并插入 UUID 值代替旧的 UUID。
找
UUID=**old-uuid** none swap sw 0 0
Run Code Online (Sandbox Code Playgroud)
替换新的 UUID 代替旧的 uuid
UUID=9e99b37a-38af-4987-85eb-92048abd9825 none swap sw 0 0
Run Code Online (Sandbox Code Playgroud)
或者,您可以替换 UUID 机制并使用/dev/ubuntu/swap_1,例如
/dev/ubuntu/swap_1 none swap sw 0 0
Run Code Online (Sandbox Code Playgroud)使用软件中心的 KVPM。我使用整个磁盘和一个巨大的 LVM 安装了 Ubuntu 14.10 LTS(我知道一个巨大的 LVM 有什么意义),但想为另一个操作系统和一个数据驱动器添加另外两个 LVM。我使用了 KVPM,它在描述中说 KDE 分区管理器,但它在 14.04 上运行良好。以下是步骤。
从您选择的终端运行 KVPM,
sudo kvpm- 如果你只是运行kvpm,live CD 会给你一个错误并挂起。
一旦 kvpm 打开了 GUI,转到标记为 some_drive-vg 的选项卡
写这个比执行整个过程花了我更长的时间。
顺便说一句,在所有更改后,我调整大小的 /root 分区功能完美。只需在您选择的操作系统中重新启动到您的硬盘,即可享受新发现的卷。