Last active
October 2, 2024 04:07
-
-
Save MakiseKurisu/3a44918bccf3383c0b5ccf362f429c8b to your computer and use it in GitHub Desktop.
Migrate Proxmox VE to a custom partition layout feat. Btrfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following script was tested for fresh install only, without any VM | |
# Assuming Proxmox is installed in /dev/sda with LVM-ext4 partition and UEFI boot, and the target disk is /dev/sdb | |
# Prepare | |
sed -i "s/deb/#deb/" /etc/apt/sources.list.d/pve-enterprise.list | |
apt update | |
apt full-upgrade -y | |
# WARNING! Check your target disk device name! | |
lsblk | |
# Set up partition table | |
# Sample layout: 512M ESP partition (same size as Proxmox) + rest as a single Btrfs partition. No swap partition. | |
(echo g; echo n; echo ''; echo ''; echo '+512M'; echo t; echo 1; echo n; echo ''; echo ''; echo ''; echo w) | fdisk /dev/sdb | |
# Create boot partition | |
dd if=/dev/zero of=/dev/sdb1 bs=1M | |
mkfs.fat -F32 /dev/sdb1 | |
# Create root partition | |
mkfs.btrfs -f /dev/sdb2 | |
mkdir /mnt/btrfs | |
mount /dev/sdb2 /mnt/btrfs | |
rsync -aAXx --numeric-ids --info=progress2 --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /mnt/btrfs | |
# Fix boot | |
# Below is the minimal mounting set for grub-install to work in chroot | |
for i in /dev /proc /sys; do mount -B $i /mnt/btrfs$i; done | |
mount /dev/sdb1 /mnt/btrfs/boot/efi | |
chroot /mnt/btrfs | |
sed -i 's/GRUB_DISTRIBUTOR="Proxmox Virtual Environment"/GRUB_DISTRIBUTOR="Proxmox Virtual Environment for Btrfs"/g' /etc/default/grub | |
grub-install /dev/sdb | |
mkdir /boot/efi/EFI/BOOT | |
cp /boot/efi/EFI/proxmox/grubx64.efi /boot/efi/EFI/BOOT/BOOTX64.EFI | |
update-grub | |
# Fix /etc/fstab | |
echo "# <file system> <mount point> <type> <options> <dump> <pass>" > /etc/fstab | |
# Disable fsck for Btrfs. See fsck.btrfs(8). | |
echo "UUID=`blkid -s UUID -o value /dev/sdb2` / btrfs defaults 0 0" >> root/etc/fstab | |
echo "UUID=`blkid -s UUID -o value /dev/sdb1` /boot/efi vfat defaults 0 1" >> root/etc/fstab | |
echo "proc /proc proc defaults 0 0" >> /etc/fstab | |
# Finish | |
exit | |
reboot | |
# If you need to set up RAID-1 for rootfs, please check | |
# https://gist.github.com/MakiseKurisu/1b46df3374c1dcbab1048b23312a4e0e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment