- My VM does not have LVM group. great!
lvdisplay. - shutdown virtual machine and run command in host machine to resize virtual disc:
qemu-img resize vmdisk.img +20G .
This is probably only difference for different vitalization platform. Using different ways to resize image size. - boot up virtual machine and run command to check hard disc size.
fdisk -l . - turn off swap:
swapoff -a - we use parted as partition tool. so call command
parted -
check virtual hard drive's partition info as below.
(parted) print free Model: ATA QEMU HARDDISK (scsi) Disk /dev/sda: 42.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 316MB 315MB primary ext4 boot 2 316MB 19.4GB 19.0GB primary ext4 3 19.4GB 21.5GB 2114MB primary linux-swap(v1) 21.5GB 42.9GB 21.5GB Free Space
- remove swap partition.
(parted) rm 3 - set unit to be KB to avoid wasting too much space.
(parted) unit kb - make a primary partition in the unallocated space.
(parted) mkpart primary 19360907kB 38949673kB - Make all rest unallocated space as swap partition.
mkpart primary 38949673kB 42949670kB - reboot virtual machine
- turn off swap
swapoff -a - Format new created partition as ext4
mkfs.ext4 /dev/sda3 - Format swap partition
mkswap /dev/sda4 - I will mount /home direction to new partion (sda3). So, I backup my home directory first and create new /home directory.
mv /home /homebackup
mkdir home - double check partition info again.
cat /proc/partitions - check the auto mount configurion.
cat /etc/fstab - Format swap partition
mkswap /dev/sda4 - find out sda3 UUID
blkid /dev/sda3 - add sda3 into auto mount
vi /etc/fstab
add line: UUID=e4805e9c-869a-48d5-8783-0bfcb5b65a3e /home ext4 defaults 1 3 - reboot
- move old home directory content into new home directory
cp -rf /homebackup/* /home/ - change the ownership of content to different user account. for example,
chown -R yiyujia:yiyujia ./yiyujia/ - check disc usage info,
df
Also, adding a new disck to existing virtual guest could be good option too.
-
cd into folder to find guest's configuration file as xml and backup it.
/etc/libvirt/qemu -
create a new raw disk image.
qemu-img create -f raw newDisk.img 20G -
Attach newly created disk image
#virsh attach-disk - login guest machine and partition new disck.
No comments:
Post a Comment