Git

Basic Git Operations

git submodule update --init --recursive

Send Patch to the mailing list

# Add the files you want to commit
git add .

# -s for adding the signed-off-by
# To adding correct name and emails in the singed-off-by,
# we have to set them by:
# git config --global user.name "name"
# git config --global user.email "email"
# They are stored in the ~/.gitconfig file.

# Note: commit patch and selftest in two seperate commits
git commit -s -m "Message"

# format-patch generates an patch named "XXX.patch" for sending
git format-patch -1

# Modify the patch file accordingly,
# for example, add the description of this patch or bug between
# "Subject" and "Signed-off-by"
# Adding fix tag, like: Fixes: da70d184a8c3(12characters) ("xxx")

# Write the cover letter
git branch --edit-description

# Generate patches
# git format-patch -2 --cover-letter --output-directory patches/

# Fill the title in the cover letter

# Run scripts/checkpatch.pl on each patch file to ensure their style is correct

# Configure the ~/.gitconfig file for sending this patch like below:
# [sendemail]
#    smtpencryption = tls
#    smtpserver = 
#    smtpuser = 
#    smtpserverport = 587
#    tocmd = "`pwd`/scripts/get_maintainer.pl --nogit --norolestats --nol"
#    cccmd = "`pwd`/scripts/get_maintainer.pl --nogit --norolestats --nom"
#
# tocmd and cccmd will automatically decide the mail receivers.
# You can also comment out these two lines
# and specify the receivers manually, like "--cc XXX --to XX".
git send-email --to XXX --cc XXX XXX.patch
# You need to enter your mailbox password in this step.

Reply to the Mailing Lists

    git send-email \
    --in-reply-to=20231121173206.3594040-1-tao.lyu@epfl.ch \
    --to=XXX \
    --cc=XXX \
    /path/to/YOUR_REPLY

Duplicate a Repo with Full History

git clone A-url
cd A
git remote add B B-url
git push B --set-upstream HEAD:master

References

  1. How to generate and submit patch to Linux kernel
  2. How to config your sendemail info
  3. How to apply patches from the Linux Kernel Mailing List
  4. Reply instruction

How to resize a qcow2 image?

Qcow2 image resize includes extention and shrink.

Extention

To extend a qcow2 image, you need to shutdown your virtual machine and resize the qcow2 image first. After that, the size of storage devices inside the virtual machine increase. However, the size of formatted file system on these devices still unchanged. You have to use resize2fs to tell the file system adjust its size.

qemu-img resize image.qcow2 +10G
resize2fs /dev/sda

Shrink

To shrink a qcow2 image, you need to boot your virtual machine and resize the file system on the devices, followed by the qcow2 image shrink after the VM shutdown.

However, if you are going to shrink from the root partition, which is an EXT file system , on the qcow2 image, it becomes problematic, as EXT4 doesn’t support online resize. You have to unmount the EXT4 file system and then you can resize it.

To that end, there are two sulutions, temporally creating an in-memory root file system and pivot root to it, or operating on the file system using Network Block Device (NBD) supported by qemu-nbd on the host.

Pivot_root

qemu-nbd

# Enable NBD on the Host
modprobe nbd max_part=8

# Connect the QCOW2 as network block device
qemu-nbd --connect=/dev/nbd0 /var/lib/vz/images/100/vm-100-disk-1.qcow2

# Find The Virtual Machine Partitions
fdisk /dev/nbd0 -l

# Mount the partition from the VM
mount /dev/nbd0 /mnt/somepoint/

# After you done, unmount and disconnect
umount /mnt/somepoint/

# Resize the file system
e2fsck -f /dev/nbd0
resize2fs /dev/nbd0 9G

# gparted
gparted /dev/nbd0

qemu-nbd --disconnect /dev/nbd0

# qcow2 resize
qemu-img resize disk.qcow2 --shrink 9G

# You have to use convert to get rid of the shrinked empty parts
qemu-img convert -p -f qcow2 focal.qcow2 -O qcow2 new-focal.qcow2

rmmod nbd