Thomas’ Lab Notes

Stuff worth not forgetting

Setting Up GRUB/GPT/LVM

Notes on setting up a machine to use GPT partitioning, LVM for all filesystems (including root), and GRUB2 to boot.

Starting with a vanilla Debian 7.8 setup. Here we assume that /dev/sdb is the disk that will ultimately contain the system.

GPT setup

(parted) mklabel gpt
(parted) mkpart primary 2048s 4095s                                       
(parted) set 1 bios_grub on                                               
(parted) name 1 "BIOS Boot Partition"                                     
(parted) mkpart primary 4096s 100%                                        
(parted) set 2 lvm on                                                     
(parted) name 2 "LVM"

Do we want a swap partition there??? If we don’t provision one now, we’ll have to swap to an LVM LV.

LVM setup

pvcreate /dev/sdb1
# Format given disk for LVM

vgcreate tank /dev/sdb2
# Create a volume group with that disk as the underlying storage

lvcreate -n rootfs -L 10G tank
lvcreate -n home -l 100%FREE tank

Filesystem

mkfs.ext4 /dev/mapper/tank-rootfs
mkfs.ext4 /dev/mapper/tank-home
mount -t ext4 /dev/mapper/tank-rootfs /mnt

Set up root filesystem (including /boot subdirectory) in /mnt.

Make sure that /etc/fstab on tank-rootfs points to the proper root fs.

GRUB2

for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt$i; done
chroot /mnt
rm -f /boot/grub/device.map
grub-mkconfig -o /boot/grub/grub.cfg
grub-install /dev/sdb