This document describes the installation of Debian Jessie via debootstrap on a Logical Volume which in turn is installed on a Software Raid managed by mdadm. The partition table will be gpt with grub2
Please note that this doc is primarily for my personal use but I want so share it with the community. If you have any amendments please just leave me a note or send me a pull-request.
Motivation
When operating large virtual machines, there is a need a making backups with minimum downtime. My strategie here is to shutdown the vm (like a Windows Server on KVM) to have them in a consistent state. Then I create a LVM snapshot and start the machine again.
This gives me the time to write the image to some other location.
In my older installations I had the /boot partition on a dedicated RAID1 drive. However this lead to a fragmentation of my disks and when I use a RAID5 or RAID10 this is just a waste of diskspace and rather unflexible.
Partitioning
I asume you have system with empty disks that you have started with some debian based live system like grml.
I my case I'm currently working on a system with two disk. But my approach will be also applicable for systems with many disks and differen raid levels. The only thing you need to keep in mind is that, depending on the configured raid level, the drives should have the same size and speed in order to make a decent raid array.
So let've a look my first disk:
parted /dev/sda print
It gives me something like:
Error: /dev/sda: unrecognised disk label
Model: ATA TOSHIBA DT01ACA3 (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: unknown
Disk Flags:
Which is what I expected from a blank disk. If you have something else here, make sure to clean the disk completely.
First I create a gpt:
parted /dev/sda mklabel gpt
And have a look at it again:
parted /dev/sda mklabel gpt
Which shows me now:
Model: ATA TOSHIBA DT01ACA3 (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
Now I have a blank partition table but no partitions yet. I change this by creating a 4MB BIOS boot partition:
parted /dev/sda mkpart primary 1s 4MB
I'm answering the parted questions as follows:
Warning: You requested a partition from 512B to 4000kB (sectors 1..7812).
The closest location we can manage is 17.4kB to 4000kB (sectors 34..7812).
Is this still acceptable to you?
Yes/No? y
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
The resulting partition table looks like this:
parted /dev/sda print
Model: ATA TOSHIBA DT01ACA3 (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 4000kB 3983kB primary
We mark this partition as bios_grub:
parted /dev/sda set 1 bios_grub on
The result should look like this:
Model: ATA TOSHIBA DT01ACA3 (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 4000kB 3983kB primary bios_grub
Furthermore we need a raid partition:
parted /dev/sda mkpart primary 4000kB 100%free
Afterwards the disk should look like this:
parted /dev/sda print
Model: ATA TOSHIBA DT01ACA3 (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 4000kB 3983kB primary bios_grub
2 4000kB 3001GB 3001GB primary
We mark the new partition as raid:
parted /dev/sda set 2 raid on
Which gives us:
parted /dev/sda print
Model: ATA TOSHIBA DT01ACA3 (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 4000kB 3983kB primary bios_grub
2 4000kB 3001GB 3001GB primary raid
Since we need the same layout on the other disk we repeat these steps on the second disk.
Afterwards it is good time to make a reboot into the live system to ensure the kernel loads the new partition tables.
The next step is the creation of the raid array. In our approach it doesn't really matter if we create a RAID1/5/10. So in this case we go for the raid1 since we have only two disks.
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda2 /dev/sdb2
We can have a look at the generated array and it's state:
cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb2[1] sda2[0]
2930131392 blocks super 1.2 [2/2] [UU]
[=>...................] resync = 7.7% (226749568/2930131392) finish=261.9min speed=171988K/sec
unused devices: <none>
We create a pysical volume for the lvm:
pvcreate /dev/md0
pvdisplay
"/dev/md0" is a new physical volume of "2.73 TiB"
--- NEW Physical volume ---
PV Name /dev/md0
VG Name
PV Size 2.73 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID liP0K6-ZwPJ-lZ2f-iG60-fbbR-BIbI-KHgYmL
We can now create the volume group:
vgcreate vg0 /dev/md0
... and the actual logical volume for the root partition:
lvcreate -n root_vol -L 20G vg0
lvdisplay
--- Logical volume ---
LV Path /dev/vg0/root_vol
LV Name root_vol
VG Name vg0
LV UUID rWdEuJ-Ji4M-d14D-b1FE-UQJx-xH1c-w2rM6x
LV Write Access read/write
LV Creation host, time rescue, 2016-01-15 10:32:00 +0100
LV Status available
# open 0
LV Size 20.00 GiB
Current LE 5120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
Creation of the swap partion
lvcreate -n swap_vol -L 8G vg0
mkswap /dev/vg0/swap_vol
Creation of the filesystem:
mkfs.ext4 /dev/vg0/root_vol
mounting the filesystem
mount -t auto /dev/vg0/root_vol /mnt/
Installing the base system
debootstrap --arch amd64 jessie /mnt http://ftp.de.debian.org/debian
In preparation for the chroot we bind mount dev and sys:
mount --bind /dev /mnt/dev
mount -t sysfs /sys /mnt/sys
and chroot:
chroot /mnt /bin/bash
... some other bind mounts:
mount -tproc none /proc
mount -t devpts devpts -o noexec,nosuid,gid=5,mode=620 /dev/pts
Add some repositorys and update:
echo 'deb http://httpredir.debian.org/debian jessie main contrib non-free' > /etc/apt/sources.list
echo 'deb-src http://httpredir.debian.org/debian jessie main contrib non-free' >> /etc/apt/sources.list
echo 'deb http://httpredir.debian.org/debian jessie-updates main contrib non-free' >> /etc/apt/sources.list
echo 'deb-src http://httpredir.debian.org/debian jessie-updates main contrib non-free' >> /etc/apt/sources.list
echo 'deb http://security.debian.org/ jessie/updates main contrib non-free' >> /etc/apt/sources.list
echo 'deb-src http://security.debian.org/ jessie/updates main contrib non-free' >> /etc/apt/sources.list
echo 'deb http://httpredir.debian.org/debian jessie-backports main contrib non-free' >> /etc/apt/sources.list
apt-get update
To avoid some issues with iucode:
apt-get install -t jessie-backports iucode-tool -y
Install some packages:
apt-get install locales grub2 mdadm udev ssh host isc-dhcp-client pciutils vim molly-guard locate systemd dbus keyboard-configuration linux-image-amd64 firmware-linux firmware-linux-nonfree memtest86 lvm2 -y
Prepare the fstab. Replace the UUIDs withe your respective UUID's:
echo 'proc /proc proc defaults 0 0' > /mnt/etc/fstab
echo 'UUID="09a33a6d-40de-42c9-a805-9f0ec863564a" none swap sw 0 0' >> /mnt/etc/fstab
echo 'UUID="ffa8e791-a025-43bc-8e66-bcaf5cddb0e1" / ext4 defaults,errors=remount-ro 0 1' >> /mnt/etc/fstab
You'll be asked by grub where to install the the bootloader. Make sure it will be installed on the disks that hold the bios_grub partition. In this case it is /dev/sda and /dev/sdb.
Make sure the network interface will be eth0 on the next reboot:
rm /etc/udev/rules.d/70-persistent-net.rules
export INTERFACE=eth0
export MATCHADDR=`ip addr show $INTERFACE | grep ether | awk '{print $2}'`
/lib/udev/write_net_rules
Check:
cat /etc/udev/rules.d/70-persistent-net.rules
Create NIC configuration:
echo "auto lo" > /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
echo "auto eth0" >> /etc/network/interfaces
echo "iface eth0 inet dhcp" >> /etc/network/interfaces
Open /etc/default/grub and add:
GRUB_PRELOAD_MODULES="lvm"
To avoid race conditions with the lvm during boot time add rootdelay=5
to GRUB_CMDLINE_LINUX_DEFAULT
Now save and run:
grub-mkconfig && update-grub
Now either set a password via passwd
or place you public key in /root/.ssh/authorized_keys
to be able to log-into your new system.
Now keep your fingers crossed an reboot!