Skip to content

Instantly share code, notes, and snippets.

@JorgenEvens
Last active April 1, 2023 09:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JorgenEvens/04cab9e9f6dd2e2e385df9ada90fb552 to your computer and use it in GitHub Desktop.
Save JorgenEvens/04cab9e9f6dd2e2e385df9ada90fb552 to your computer and use it in GitHub Desktop.
Script to convert legacy boot debian to UEFI
#!/bin/bash
set -e
apt update
apt install lvm2 gparted
# Convert MBR to GPT
sgdisk -g /dev/xvda
partprobe
# resize partitions
gparted
cd /tmp
# mount root
mkdir install
mount /dev/*-vg/root install
# mount boot
cd install
mount /dev/xvda1 boot
mkdir -p boot/efi
mount /dev/xvda2 boot/efi
# mount environment
mount --bind /dev dev
mount --bind /sys sys
mount --bind /proc proc
mount --bind /run run
# install grub-efi
chroot . << EOF
apt install -y grub-efi
grub-install /dev/xvda
echo "UUID=$(blkid -o value /dev/xvda2 | head -n1) /boot/efi vfat defaults 0 2" >> /etc/fstab
EOF
@24mu13
Copy link

24mu13 commented Apr 1, 2023

Hi, thank you for the script! I would like to convert my MBR to GPT in Debian 12.
Just a couple of quick questions:

  1. Is this script intended to be run using Live OS on USB ?
  2. gparted / resize partitions is it just a placeholder for resizing manually the partitions right? Even using other apps/methods..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment