这是我的磁盘架构,来自lsblk
和lvs
。我想要做的是将sda5
其类型调整Extended
为块设备的大小/dev/sda
(100GB)
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
|-sda1 8:1 0 243M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 49.8G 0 part
|-osiris-root 254:0 0 45.8G 0 lvm /
`-osiris-swap_1 254:1 0 4G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root osiris-wi-ao---- 45.76g
swap_1 osiris-wi-ao---- 4.00g
有没有办法使用 或任何其他工具来做到这parted
一点fdisk
?提前致谢。
fdisk -l /dev/sda*
输出
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x00082e2b
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 104855551 104353794 49.8G 5 Extended
/dev/sda5 501760 104855551 104353792 49.8G 8e Linux LVM
Disk /dev/sda1: 243 MiB, 254803968 bytes, 497664 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 /dev/sda2: 1 KiB, 1024 bytes, 2 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
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sda2p1 2 104353793 104353792 49.8G 8e Linux LVM
Disk /dev/sda5: 49.8 GiB, 53429141504 bytes, 104353792 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
答案1
要扩展您的sda5
,您也需要扩展它的容器sda2
。使用命令行工具,最简单的方法是使用sfdisk
:
sfdisk /dev/sda
这将打印当前的分区表,它应该与您在中看到的内容匹配fdisk
:
Disk image: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0xe59ec859
Old situation:
Device Boot Start End Sectors Size Id Type
image1 * 2048 499711 497664 243M 83 Linux
image2 501758 104855551 104353794 49.8G 5 Extended
image5 501760 104855551 104353792 49.8G 83 Linux
Type 'help' to get more information.
在>>>
提示符下,开始重新定义所有分区:
2048,497664,83,*
(这是第一个分区:起始扇区、扇区长度、类型和*
使其可引导的 a)。sfdisk
将回应
Created a new DOS disklabel with disk identifier 0x03408377.
Created a new partition 1 of type 'Linux' and of size 243 MiB.
image1 : 2048 499711 (243M) Linux
并提示image2
( sda2
)。进入
501758,,5
它指示sfdisk
从扇区 501758 开始创建一个扩展分区,并占据此后的所有可用空间;sfdisk
将输出
Created a new partition 2 of type 'Extended' and of size 99.8 GiB.
image2 : 501758 209715199 (99.8G) Extended
对于image3
,只需输入
501760
sfdisk
然后会输出
Created a new partition 5 of type 'Linux' and of size 99.8 GiB.
image5 : 501760 209715199 (99.8G) Linux
并提示image6
,我们不需要,所以输入
quit
这将导致sfdisk
打印新的分区表并询问您是否要将其写入磁盘:
New situation:
Device Boot Start End Sectors Size Id Type
image1 * 2048 499711 497664 243M 83 Linux
image2 501758 209715199 209213442 99.8G 5 Extended
image5 501760 209715199 209213440 99.8G 83 Linux
Do you want to write this to disk? [Y]es/[N]o:
如果您确信起始扇区全部匹配并且sda1
仍然正常,请按Y写入分区表并返回 shell。
完成后,运行
pvresize /dev/sda5
调整 LVM PV 的大小;然后,您应该能够使用新分配的磁盘空间(在新 LV 中,或扩展现有 LV)。