# modprobe nbd max_part=8 # qemu-nbd --connect=/dev/nbd2 disk.qcow2 # lsblk /dev/nbd2 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nbd2 43:32 0 500G 0 disk ├─nbd2p1 43:33 0 1M 0 part ├─nbd2p2 43:34 0 1G 0 part └─nbd2p3 43:35 0 445.6G 0 part └─ubuntu--vg-ubuntu--lv 253:3 0 200G 0 lvm # pvdisplay /dev/nbd2p3 --- Physical volume --- PV Name /dev/nbd2p3 VG Name ubuntu-vg PV Size 445.62 GiB / not usable 0 # lvdisplay ubuntu-vg --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV Size 200.00 GiB # file -L -s /dev/ubuntu-vg/ubuntu-lv /dev/ubuntu-vg/ubuntu-lv: Linux rev 1.0 ext4 filesystem data, ... (needs journal recovery) (extents) (64bit) (large files) (huge files) # mount /dev/ubuntu-vg/ubuntu-lv /mnt # df -h /mnt Filesystem Size Used Avail Use% Mounted on /dev/mapper/ubuntu--vg-ubuntu--lv 196G 26G 161G 14% /mnt # umount /mnt # e2fsck -f /dev/ubuntu-vg/ubuntu-lv e2fsck 1.45.6 (20-Mar-2020) 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/ubuntu-vg/ubuntu-lv: 479453/13107200 files (0.1% non-contiguous), 7712317/52428800 blocks # resize2fs /dev/ubuntu-vg/ubuntu-lv 29G resize2fs 1.45.6 (20-Mar-2020) Resizing the filesystem on /dev/ubuntu-vg/ubuntu-lv to 7602176 (4k) blocks. The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 7602176 (4k) blocks long. # lvreduce -L 29G /dev/ubuntu-vg/ubuntu-lv WARNING: Reducing active logical volume to 29.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce ubuntu-vg/ubuntu-lv? [y/n]: y Size of logical volume ubuntu-vg/ubuntu-lv changed from 200.00 GiB (51200 extents) to 29.00 GiB (7424 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized. # e2fsck -f /dev/ubuntu-vg/ubuntu-lv e2fsck 1.45.6 (20-Mar-2020) 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/ubuntu-vg/ubuntu-lv: 479453/1900544 files (0.3% non-contiguous), 7004914/7602176 blocks # lvchange -an /dev/ubuntu-vg/ubuntu-lv # vgchange -an ubuntu-vg 0 logical volume(s) in volume group "ubuntu-vg" now active # qemu-nbd --disconnect /dev/nbd2 # qemu-img create -f qcow2 new.qcow2 32G Formatting 'new.qcow2', fmt=qcow2 size=34359738368 cluster_size=65536 lazy_refcounts=off refcount_bits=16 # virt-resize --resize-force /dev/sda3=30G disk.qcow2 new.qcow2 [ 0.0] Examining disk.qcow2 ********** Summary of changes: /dev/sda1: This partition will be left alone. /dev/sda2: This partition will be left alone. /dev/sda3: This partition will be resized from 445.6G to 30.0G. The LVM PV on /dev/sda3 will be expanded using the ‘pvresize’ method. There is a surplus of 1020.7M. An extra partition will be created for the surplus. ********** [ 2.1] Setting up initial partition table on new.qcow2 [ 12.8] Copying /dev/sda1 [ 12.9] Copying /dev/sda2 [ 13.8] Copying /dev/sda3 [ 42.8] Expanding /dev/sda3 using the ‘pvresize’ method Resize operation completed with no errors. Before deleting the old disk, carefully check that the resized disk boots and works correctly. # qemu-nbd --connect=/dev/nbd2 new.qcow # lsblk /dev/nbd2 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nbd2 43:32 0 32G 0 disk ├─nbd2p1 43:33 0 1M 0 part ├─nbd2p2 43:34 0 1G 0 part ├─nbd2p3 43:35 0 30G 0 part │ └─ubuntu--vg-ubuntu--lv 253:3 0 29G 0 lvm └─nbd2p4 # fdisk /dev/nbd2 Command (m for help): p Disk /dev/nbd2: 32 GiB, 34359738368 bytes, 67108864 sectors Device Start End Sectors Size Type /dev/nbd2p1 2048 4095 2048 1M BIOS boot /dev/nbd2p2 4096 2101247 2097152 1G Linux filesystem /dev/nbd2p3 2101248 65015807 62914560 30G Linux filesystem /dev/nbd2p4 65015808 67108799 2092992 1022M Linux filesystem Command (m for help): d Partition number (1-4, default 4): 4 Partition 4 has been deleted. Command (m for help): w The partition table has been altered. Syncing disks. # lvchange -an /dev/ubuntu-vg/ubuntu-lv # vgchange -an ubuntu-vg 0 logical volume(s) in volume group "ubuntu-vg" now active # qemu-nbd --disconnect /dev/nbd2 # qemu-img create -f qcow2 new2.qcow2 100G Formatting 'new2.qcow2', fmt=qcow2 size=107374182400 cluster_size=65536 lazy_refcounts=off refcount_bits=16 # virt-resize --expand /dev/sda3 --LV-expand /dev/ubuntu-vg/ubuntu-lv new.qcow2 new2.qcow2 [ 0.0] Examining new.qcow2 ********** Summary of changes: /dev/sda1: This partition will be left alone. /dev/sda2: This partition will be left alone. /dev/sda3: This partition will be resized from 30.0G to 99.0G. The LVM PV on /dev/sda3 will be expanded using the ‘pvresize’ method. /dev/ubuntu-vg/ubuntu-lv: This logical volume will be expanded to maximum size. The filesystem ext4 on /dev/ubuntu-vg/ubuntu-lv will be expanded using the ‘resize2fs’ method. ********** [ 2.2] Setting up initial partition table on new2.qcow2 [ 12.8] Copying /dev/sda1 [ 12.9] Copying /dev/sda2 [ 13.9] Copying /dev/sda3 [ 38.5] Expanding /dev/sda3 using the ‘pvresize’ method [ 38.5] Expanding /dev/ubuntu-vg/ubuntu-lv using the ‘resize2fs’ method Resize operation completed with no errors. Before deleting the old disk, carefully check that the resized disk boots and works correctly. # virt-filesystems -l -h -a new2.qcow2 Name Type VFS Label Size Parent /dev/sda2 filesystem ext4 - 1.0G - /dev/ubuntu-vg/ubuntu-lv filesystem ext4 - 99G - # ls -alh new2.qcow2 -rw-r--r--. 1 qemu qemu 19G 2022-05-11 Wed 18:37:23 new2.qcow2
개요
내용 도구
앱