Difference between revisions of "Grub"

From Briki
Jump to: navigation, search
(Moving root partition to a new disk)
 
Line 47: Line 47:
 
== Moving root partition to a new disk ==
 
== Moving root partition to a new disk ==
 
https://superuser.com/questions/615956/how-can-i-specify-a-different-disk-to-be-root-in-grub-cfg-when-running-grub-mkco
 
https://superuser.com/questions/615956/how-can-i-specify-a-different-disk-to-be-root-in-grub-cfg-when-running-grub-mkco
 +
 +
Ensure you also change the boot order in your motherboard BIOS if you've installed the boot sector to a new drive.

Latest revision as of 20:19, 4 February 2021

Moving boot record and /boot to a new disk

  • Setup new disk with GPT partition table
  • For BIOS (not EFI) booting, create a ~2MB partition at the start of the disk, with the bios_grub flag
 sudo parted -a optimal -s /dev/sdX -- mklabel gpt mkpart bios 0% 2MB set 1 bios_grub on
  • Create a boot partition (but don't set the boot flag)
 sudo parted -a optimal -s /dev/sdX -- mkpart boot 2MB 5GB
 sudo mkfs.ext4 /dev/sdX2
  • Use the remainder of the space as desired
  • Example "parted /dev/sdX -- print free" for a bootable drive:
Model: ATA ST3320620A (scsi)
Disk /dev/sde: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  1049kB  1031kB               bios  bios_grub
 2      1049kB  2000MB  1999MB  ext4         boot
 3      2000MB  320GB   318GB   ext4         tmp
        320GB   320GB   335kB   Free Space
  • Mount new boot partition at /mnt, and copy boot partition onto it:
mount /dev/sdXY /mnt
cp -a /boot/* /mnt
  • Edit /etc/fstab and change /boot partition mount to UUID for new partition (use /dev/disk/by-uuid to determine partition uuid)
  • Unmount existing /boot, and mount new /boot
umount /boot
mount /boot
  • Install grub boot loader into the bios partition, using the /boot partition for OS loading. Note that the disk is specified, rather than a partition:
grub-install /dev/sdX
  • Update grub to match the new partition layout:
update-grub
  • Restart (or halt and disconnect old drive), and cross your fingers!

Updating /boot/grub/device.map

This file is no longer generated (or kept up to date) by default in recent grub versions, since it's largely unused. To update it manually:

 sudo grub-mkdevicemap

Moving root partition to a new disk

https://superuser.com/questions/615956/how-can-i-specify-a-different-disk-to-be-root-in-grub-cfg-when-running-grub-mkco

Ensure you also change the boot order in your motherboard BIOS if you've installed the boot sector to a new drive.