# vgchange -an
# mdmad --stop /dev/mdXFirst written 2014-09-04; Last updated 2019-12-11
The data is encrypted and the system can be booted from remote by using the
serial console to enter the LUKS passphrase. Alternatively dropbear
(small SSH server) could be used to decrypt the disk through SSH if no serial
console is available.
Of course as a possible attacker has control over the hardware and the boot manager and initrd are not encrypted, these methods can be circumvented.
The instructions can be easily adapted for different RAID/LVM setups.
Start rescue system with the required tools:
cryptsetup
mdadm
LVM (pvcreate, vgcreate, lvcreate, etc.)
debootstrap
If the RAID or LVM is active (e.g. automatically assembled by the rescue system), disable them:
# vgchange -an
# mdmad --stop /dev/mdXUse dd if=/dev/urandom of=/dev/.. if you want to wipe the existing data on
the disks.
Add a single partition as “Linux raid autodetect” (fd) on both disks (the
actual partition type does not matter but it can help when looking at the raw
partition in the future).
# fdisk /dev/sda
[...]
# fdisk /dev/sdb
[...]To get the size of the disks, run the command with a very large size, the error message tells it ;-)
# mdadm --create /dev/md/0 --level 1 --raid-devices=2 --size=<size> /dev/sda1 /dev/sdb1Metadata 1.2 is fine, GRUB 2 can boot from it.
# fdisk /dev/md/0In the following example I’ll use two partitions, feel free to adapt to your needs.
Boot partition with at least 200M
LUKS partition for the rest, type “Non-FS data” (da)
Use AES-XTS to prevent a possible CBC malleability attack and a longer iteration time to make brute force attacks more difficult. AES-XTS is default since Jessie.
# cryptsetup luksFormat --iter-time 2000 --cipher aes-xts-plain64 --key-size 512 --hash sha512 /dev/md/0p2
# cryptsetup luksOpen /dev/md/0p2 md0p2_example# pvcreate /dev/mapper/md0p2_example
# vgcreate example /dev/mapper/md0p2_exampleCreate volumes, adapt to your needs.
# lvcreate --size 10G --name root example
# lvcreate --size 4G  --name swap example
# lvcreate --size 4G  --name var  exampleLets keep the rest unused for now. Ext4 can always be resized online later if necessary:
# lvresize -L 10G /dev/example/root
# resize2fs /dev/example/rootBoot partition:
# mkfs.ext4 /dev/md/0p1The other file systems:
# mkfs.ext4 /dev/example/root
# mkfs.ext4 /dev/example/varAnd swap:
# mkswap -f /dev/example/swapMount all file systems.
# mount /dev/example/root /mnt
# cd /mnt
# mkdir boot var
# mount /dev/md/0p1 /mnt/boot
# mount /dev/example/var /mnt/varInstall the base system with debootstrap.
# debootstrap wheezy /mnt http://ftp.de.debian.org/debianMount the necessary virtual file systems.
# mount --bind /dev /mnt/dev
# mount -t devpts devpts /mnt/dev/pts
# mount -t proc proc /mnt/proc
# mount -t sysfs sysfs /mnt/sysCopy mtab and adapt it for the chroot, important for mount and df inside
the chroot which are used by many installers.
# cp /etc/mtab /mnt/etc
# $EDITOR /mnt/etc/mtab# chroot /mnt /bin/bashCreate fstab:
# cat >/etc/ftab
proc                      /proc   proc    defaults,hidepid=2  0 0/dev/md0p1                /boot   ext4    defaults            0 2
/dev/example/root         /       ext4    errors=remount-ro   0 1
/dev/example/var          /var    ext4    defaults            0 2
/dev/example/swap         none    swap    sw                  0 0Create crypttab:
# blkid /dev/md/0p2
[...]
# cat >/etc/crypttab
md0p2_example UUID=[...] none luksSet root password:
# passwdUpdate hostname:
# $EDITOR /etc/hostnameConfigure the network:
# $EDITOR /etc/hosts
# $EDITOR /etc/network/interfaces
# $EDITOR /etc/resolv.confEnable login from serial console. Add the following line to /etc/inittab:
T0:23:respawn:/sbin/getty -L ttyS0 57600 vt100Install a kernel:
# apt-get --no-install-recommends install linux-image-amd64Install important packages:
# apt-get --no-install-recommends install mdadm lvm2 cryptsetup kdbInstall GRUB 2:
# apt-get --no-install-recommends install grub-pcInstall GRUB on /dev/sda and /dev/sdb so the system can boot from either
in case a disk fails:
# grub-install /dev/sda
# grub-install /dev/sdbConfigure GRUB in /etc/default/grub to allow booting over the serial
console:
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=57600"Also enable it for the kernel (important):
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,57600"Don’t forget to run update-grub.
Check if the RAID sync is complete:
# cat /proc/mdstatDone, let’s hope it boots.
# rebootDetect LVM groups in resuce system (if they aren’t detected automatically):
# vgscan
# lvscan
# vgchange -ayLast updated 2019-12-11