Skip to content

Instantly share code, notes, and snippets.

@rpunt
Last active December 14, 2015 19:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rpunt/5136965 to your computer and use it in GitHub Desktop.
# This is a preseed partman recipe that will later allow the created on # LVM-on-software-RAID, somethat that wasn't possible directly in the # preseed at the time (~2003)
# This is a preseed partman recipe that will later allow the created on
# LVM-on-software-RAID, somethat that wasn't possible directly in the
# preseed at the time (~2003)
d-i lvmcfg/activevg boolean false
d-i lvmcfg/vgdelete_names select vg00
d-i lvmcfg/vgcreate_name string vg00
d-i lvmcfg/vgdelete_confirm boolean true
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-md/confirm boolean true
d-i partman-auto/disk string /dev/sda
# the entire drive has to be allocated using a preseed partman recipe,
# so create “/tmp/removeme” at the end to leave some free space in the VG
d-i partman-auto/expert_recipe string host3 ::
200 200 200 ext3 \
$primary{ } $bootable{ } \
method{ format } format{ } \
use_filesystem{ } \
filesystem{ ext3 } \
mountpoint{ /boot } . \
512 512 512 \
linux-swap $primary{ } \
method{ swap } \
format{ } . \
100 1000000 1000000000 ext3 \
method{ lvm } \
use_filesystem{ } \
format{ } \
vg_name{ vg00 } . \
5120 5120 5120 ext3 \
$lvmok{ } \
in_vg{ vg00 } \
lv_name{ usr } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ ext3 } \
mountpoint{ /usr } . \
5120 5120 5120 ext3 \
$lvmok{ } \
in_vg{ vg00 } \
lv_name{ slash } \
method{ format } \
use_filesystem{ } \
filesystem{ ext3 } \
mountpoint{ / } . \
5120 5120 5120 ext3 \
$lvmok{ } \
in_vg{ vg00 } \
lv_name{ var } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ ext3 } \
format{ } \
mountpoint{ /var } . \
2048 2048 2048 ext3 \
$lvmok{ } \
in_vg{ vg00 } \
lv_name{ tmp } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ ext3 } \
mountpoint{ /tmp } . \
512 512 512 ext3 \
$lvmok{ } \
in_vg{ vg00 } \
lv_name{ home } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ ext3 } \
mountpoint{ /home } . \
512 61440 1000000000 ext3 \
$lvmok{ } \
in_vg{ vg00 } \
lv_name{ removeme } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ ext3 } \
mountpoint{ /tmp/removeme } . \
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm boolean true
#!/bin/bash
# Once the base OS is installed, the machine reboots; the admin then logs in as root using
# a known password defined in the preseed, changes the password, and then runs partman.sh
# to start the final configuration process.
#
# If there were such a thing as the Hack of the Year award, this config script would have
# been a contender. Since drive SDA is in use, we can’t effectively release it for
# partitioning until we reboot using the other drive. We’ve already created our LVM setup
# using the preseed; this script:
#
# 1. creates broken software RAID mirrors using only the partitions in SDB (creating md0
# and md1 as RAID devices),
# 2. migrates the data in /boot from sda1 to md0,
# 3. initializes md1 as a physical volume for LVM,
# 4. migrates the physical extents from PV sda2 to PV md1,
# 5. removes PV sda2 from the volume group,
# 6. removes references to sda in fstab,
# 7. runs the bootloader to rebuild the initrd with the software RAID module, and
# 8. reboots to fully release sda.
#
# Remember, this was all to get around the fact that you can’t create LVM-on-software-RAID
# using a preseed.
#
# Also, at the time this was written, booting LVM from GRUB was as bad idea, if it was
# even possible.
#
# enable the boot log
sed -i -e "s/BOOTLOGD_ENABLE=No/BOOTLOGD_ENABLE=Yes/" /etc/default/bootlogd
# deactive all swap partitions so we're not holding any open, then delete
# the swap line on sda to free the disk for repartitioning later
swapoff -a
sed -i -e "/swap/d" /etc/fstab
# remove the dummy LV to speed the PV migration
umount /tmp/removeme
rm -rf /tmp/removeme
sed -i -e "/removeme/d" /etc/fstab
lvchange -a n /dev/vg00/removeme
lvremove /dev/vg00/removeme
# partition SDB
sfdisk /dev/sdb << EOF
,24,fd,*
,62,82
,,fd
EOF
# SDB needs swap, and RAID partitions
# create md1 first to ensure it's ready when we provision it as a PV mkswap /dev/sdb2
echo "/dev/sdb2 none swap sw 0 0" >>/etc/fstab
mdadm -C /dev/md1 --run -n 2 -l 1 /dev/sdb3 missing
mdadm -C /dev/md0 --run -n 2 -l 1 /dev/sdb1 missing
# sleep for a bit to ensure arrays created
sleep 10
# migrate the LVs from SDA to SDB
pvcreate /dev/md1
vgextend vg00 /dev/md1
pvmove /dev/sda5
vgreduce vg00 /dev/sda5
pvremove /dev/sda5
# resize /home
lvextend -L 60g /dev/vg00/home
resize2fs /dev/vg00/home
# copy /boot to SDB
mke2fs -j /dev/md0
mount /dev/md0 /mnt/
cp -ax /boot/* /mnt/
umount /boot
umount /mnt
mount /dev/md0 /boot
sed -i -e 's/sda1/md0/' /etc/fstab
# wipe SDA's partition table
dd if=/dev/zero of=/dev/sda count=1 bs=512
# setup mdadm.conf
echo "DEVICE partitions" >/etc/mdadm/mdadm.conf
echo "CREATE owner=root group=disk mode=0660 auto=yes" >>/etc/mdadm/mdadm.conf
echo "HOMEHOST <system>" >>/etc/mdadm/mdadm.conf
echo "MAILADDR user1@domain.com,user2@domain.com" >>/etc/mdadm/mdadm.conf
mdadm --detail --scan >>/etc/mdadm/mdadm.conf
# fix a known bug in mdadm - "--detail --scan" outputs metadata version 00.90, should be 0.90
sed -i -e "s/metadata=00.90/metadata=0.90/" /etc/mdadm/mdadm.conf
# rebuild the ramdisk to include the MDADM module update-initramfs -uk all
lilo -H
# reboot
shutdown -r now
#!/bin/bash
# This script duplicates the partition table from sdb to sda, then adds the RAID
# components from SDA to the mirror set. LVM metadata is stored on the RAID set, so we
# don’t need to worry about losing any configs in that regard.
#
# This is can be run manually after a reboot, but automated in some other way
# add SDA to the RAID mirrors
sfdisk -d /dev/sdb | sfdisk /dev/sda
echo "/dev/sda2 none swap sw 0 0" >>/etc/fstab
mdadm -a /dev/md0 /dev/sda1
mdadm -a /dev/md1 /dev/sda3
sleep 10
lilo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment