When upgrading Ubuntu 14.04 on EC2 instances, you might encounter GRUB reinstallation prompts due to:
1. Disk UUID changes after EBS volume detachment/reattachment
2. EC2 instance type changes affecting storage controllers
3. Manual modifications to /boot/grub/menu.lst
To determine the appropriate boot device:
lsblk -o NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID
df /boot
sudo fdisk -l
For AWS EC2, typically select /dev/xvda
(or /dev/nvme0n1
for newer instances). Additional EBS volumes should not be selected unless they're part of a RAID boot configuration.
To bypass interactive prompts during upgrades:
sudo DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" upgrade -y
For explicit GRUB reinstallation:
sudo grub-install /dev/xvda
sudo update-grub
When prompted about /boot/grub/menu.lst
modifications:
- Choose option 2 (keep local version) if you've made custom boot parameters
- Select option 1 (package maintainer's version) for standard configurations
To preview changes before deciding:
sudo apt-get -d install grub-pc
sudo dpkg --configure -a
Add these configurations to /etc/default/grub
:
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=lsb_release -i -s 2> /dev/null || echo Debian
GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0"
GRUB_CMDLINE_LINUX=""
For persistent settings across reboots:
sudo grub-mkconfig -o /boot/grub/grub.cfg
sudo update-initramfs -u
If you encounter boot issues:
# From recovery mode or live CD:
sudo mount /dev/xvda1 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
grub-install /dev/xvda
update-grub
exit
sudo umount /mnt/dev /mnt/proc /mnt/sys
sudo umount /mnt
When you see this message during an apt-get upgrade
, it typically means:
1. Your EC2 instance's storage configuration changed (common with EBS volume modifications) 2. The system detects a mismatch between GRUB's configuration and actual disk identifiers 3. A kernel update triggered GRUB reconfiguration
For EC2 instances, you should always select the root device where Ubuntu is installed. Here's how to verify:
# List block devices and their mount points lsblk -o NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT # Check current GRUB installation sudo fdisk -l | grep "Disk /dev"
Example output for a typical EC2 instance:
NAME MAJ:MIN RM SIZE RO FSTYPE MOUNTPOINT xvda 202:0 0 8G 0 └─xvda1 202:1 0 8G 0 ext4 / xvdf 202:80 0 50G 0 ext4 /mnt/data
In this case, you should select /dev/xvda
(the root device) during GRUB installation.
Important rules for EBS volumes:
- Never install GRUB to additional EBS volumes (like /dev/xvdf in the example)
- Only install to the root device where /boot is located
- Additional volumes should never be selected in the GRUB installation prompt
To prevent interactive prompts during upgrades, use these commands:
# Preseed debconf answers for GRUB sudo debconf-set-selections <<'EOF' grub-pc grub-pc/install_devices multiselect /dev/xvda grub-pc grub-pc/install_devices_empty boolean true EOF # Non-interactive upgrade with DEBIAN_FRONTEND sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
For the menu.lst
prompt, here's the safest approach:
# First, back up your current configuration sudo cp /boot/grub/menu.lst /boot/grub/menu.lst.bak # To accept maintainer's version (recommended for most cases): echo "grub grub/update_grub_changeprompt_threeway boolean false" | sudo debconf-set-selections echo "grub-pc grub2/linux_cmdline string" | sudo debconf-set-selections echo "grub-pc grub2/device_map_regenerated note" | sudo debconf-set-selections
After the upgrade, verify GRUB is correctly installed:
# Check GRUB installation sudo grub-install --recheck /dev/xvda sudo update-grub # Verify boot files ls -la /boot/grub/
If you accidentally select wrong options, use this recovery:
# From a live CD or recovery mode: sudo mount /dev/xvda1 /mnt sudo mount --bind /dev /mnt/dev sudo mount --bind /proc /mnt/proc sudo mount --bind /sys /mnt/sys sudo chroot /mnt grub-install /dev/xvda update-grub exit sudo umount /mnt/dev /mnt/proc /mnt/sys sudo umount /mnt