Last active
January 24, 2017 11:49
-
-
Save bebehei/f81cb310eb71113e01f231604f7afe9a to your computer and use it in GitHub Desktop.
LVM/LUKS partition creation
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
#!/bin/bash | |
# stop on first error | |
set -e | |
DEVICE=/dev/sdb | |
LUKS_DEVNAME=CRYPTsys-$(hostname) | |
VGROUP=VGsys-$(hostname) | |
LV_VOLUME_PREFIX=LV-$(hostname)- | |
PART_PREFIX=$(hostname)- | |
MPT=/mnt/new | |
# Use the physical blocksize of your system | |
BLOCKSIZE=$(cat /sys/block/$(basename $DEVICE)/queue/physical_block_size) | |
# You may want to additionally randomize any bit on your drive | |
#dd if=/dev/urandom of=$DEVICe bs=10M | |
parted ${DEVICE} mktable gpt | |
parted ${DEVICE} mkpart fat32 0.5GB 1GB | |
parted ${DEVICE} mkpart ext2 1GB 100% | |
parted ${DEVICE} set 1 boot on | |
parted ${DEVICE} set 2 lvm on | |
parted ${DEVICE} print | |
for i in 1 2; do | |
parted ${DEVICE} align-check opt ${i} | |
done | |
# Plain, non-encrypted boot-partition | |
mkfs.fat -n boot -F32 ${DEVICE}1 | |
# Encrypt the whole partition | |
cryptsetup -y luksFormat ${DEVICE}2 | |
cryptsetup luksOpen ${DEVICE}2 ${LUKS_DEVNAME} | |
pvcreate /dev/mapper/${LUKS_DEVNAME} | |
vgcreate ${VGROUP} /dev/mapper/${LUKS_DEVNAME} | |
lvcreate -n ${LV_VOLUME_PREFIX}root -L 50G /dev/${VGROUP} | |
lvcreate -n ${LV_VOLUME_PREFIX}home -L 200G /dev/${VGROUP} | |
lvcreate -n ${LV_VOLUME_PREFIX}swap -L 8G /dev/${VGROUP} | |
# Format every partition | |
mkfs.ext4 -b ${BLOCKSIZE} -L ${PART_PREFIX}root /dev/${VGROUP}/${LV_VOLUME_PREFIX}root | |
mkfs.ext4 -b ${BLOCKSIZE} -L ${PART_PREFIX}home /dev/${VGROUP}/${LV_VOLUME_PREFIX}home | |
mkswap -p ${BLOCKSIZE} -L ${PART_PREFIX}swap /dev/${VGROUP}/${LV_VOLUME_PREFIX}swap | |
mkdir -p $MPT | |
mount /dev/${VGROUP}/${LV_VOLUME_PREFIX}root $MPT | |
mkdir -p $MPT/home $MPT/boot | |
mount /dev/${VGROUP}/${LV_VOLUME_PREFIX}home $MPT/home | |
mount ${DEVICE}1 $MPT/boot | |
# Install your system now to $MPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment