From: Raphaƫl Gertz Date: Fri, 24 Mar 2017 23:58:24 +0000 (+0100) Subject: Switch to single btrfs data device X-Git-Tag: 0.1~8 X-Git-Url: https://git.rapsys.eu/distgen/commitdiff_plain/eb11babe9f1cd3766c1d7a5f67a06d0f88d55d04 Switch to single btrfs data device Switch to grub2 --- diff --git a/config/mdnames.conf b/config/mdnames.conf index d22a708..6e746ee 100644 --- a/config/mdnames.conf +++ b/config/mdnames.conf @@ -1,6 +1,4 @@ # boot md names MDBOOT='mdboot' -# slash md names -MDSLASH='mdslash' # data md names MDDATA='mddata' diff --git a/config/mountpoint.conf b/config/mountpoint.conf index d0def73..d66a42f 100644 --- a/config/mountpoint.conf +++ b/config/mountpoint.conf @@ -1,2 +1,2 @@ # mount point -MOUNTPOINT='/media/slash' +MOUNTPOINT='/media/data' diff --git a/genimg b/genimg index 9091ac2..6da825d 100755 --- a/genimg +++ b/genimg @@ -28,7 +28,6 @@ fi if [ `losetup ${LOOPA} >/dev/null 2>&1; echo $?` -ne 1 -o `losetup ${LOOPB} >/dev/null 2>&1; echo $?` -ne 1 ]; then echo "Loopa or loopb already exists, try to run:" echo "mdadm -S /dev/md/$MDBOOT" - echo "mdadm -S /dev/md/$MDSLASH" echo "mdadm -S /dev/md/$MDDATA" echo "losetup -d ${LOOPA}" echo "losetup -d ${LOOPB}" diff --git a/lib/boot.sh b/lib/boot.sh index 021a384..0e4186f 100644 --- a/lib/boot.sh +++ b/lib/boot.sh @@ -3,6 +3,12 @@ # Bind mount /dev mount --bind /dev ${MOUNTPOINT}/dev +# Bind mount /proc +mount --bind /proc ${MOUNTPOINT}/proc + +# Bind mount /sys +mount --bind /sys ${MOUNTPOINT}/sys + # Backup old mtab mv ${MOUNTPOINT}/etc/mtab ${MOUNTPOINT}/etc/mtab.orig @@ -10,38 +16,21 @@ mv ${MOUNTPOINT}/etc/mtab ${MOUNTPOINT}/etc/mtab.orig #cat /proc/self/mounts | grep -E '^(/dev/m|devtmpfs)' | perl -pne 's%/media(/?)%$1%' | sort | uniq > /media/etc/mtab perl -pne "/^(devtmpfs \\/dev|\\/dev\\/(md|dm|mapper))/ || undef \$_; s%${MOUNTPOINT}/?%/%" /proc/self/mounts > ${MOUNTPOINT}/etc/mtab -# Backup old device.map -mv ${MOUNTPOINT}/boot/grub/device.map ${MOUNTPOINT}/boot/grub/device.map.orig - -# Install grub -for i in $LOOPB $LOOPA; do - # Create new device map - echo "(hd0) $i" > ${MOUNTPOINT}/boot/grub/device.map - - # Fix grub - #XXX: e2fs_stage1_5 is 20 sectors embedded, but it fail with gpt - #XXX: we use install command directly instead of setup (hd0) because it fail with loop - cat << EOF | chroot ${MOUNTPOINT} grub --device-map=/boot/grub/device.map -root (hd0,0) -install --stage2=/boot/grub/stage2 /grub/stage1 (hd0) /grub/stage2 p /grub/menu.lst -EOF -done - -# Restore old device.map -mv -f ${MOUNTPOINT}/boot/grub/device.map.orig ${MOUNTPOINT}/boot/grub/device.map - -# Bind mount /proc -mount --bind /proc ${MOUNTPOINT}/proc - -# Bind mount /sys -mount --bind /sys ${MOUNTPOINT}/sys - # Extract last kernel version KVER=`chroot ${MOUNTPOINT} rpm -qa | perl -pne '/kernel-server-latest/||undef $_;s%^kernel-(server)-latest-([^-]+)-(.+)$%\2-\1-\3%'` + # Regenerate initrd #XXX: force non hostonly else it don't store commandline : rd.luks.uuid rd.md.uuid ip=dhcp rd.neednet=1 DRACUT_SKIP_FORCED_NON_HOSTONLY=1 chroot ${MOUNTPOINT} mkinitrd -f /boot/initrd-${KVER}.img ${KVER} +# Generate grub config +chroot ${MOUNTPOINT} grub2-mkconfig -o /boot/grub2/grub.cfg + +# Install grub +for i in $LOOPB $LOOPA; do + chroot ${MOUNTPOINT} grub2-install $i +done + # Umount dev umount ${MOUNTPOINT}/sys @@ -54,5 +43,8 @@ umount ${MOUNTPOINT}/dev # Reset mtab mv -f ${MOUNTPOINT}/etc/mtab.orig ${MOUNTPOINT}/etc/mtab +# Umount home +umount ${MOUNTPOINT}/home + # Umount boot umount ${MOUNTPOINT}/boot diff --git a/lib/device.sh b/lib/device.sh index 1957287..a4d4f51 100644 --- a/lib/device.sh +++ b/lib/device.sh @@ -5,101 +5,46 @@ for i in ${SDA} ${SDB}; do # Create empty file of 8GB dd if=/dev/zero of=${i} bs=$((8192*1024)) count=1024 # Create partition table - #XXX: we generate gpt table then fake mbr compat one - cat << EOF | fdisk ${i} -g + #XXX: we generate gpt table + cat << EOF | gdisk ${i} +o +Y n 1 2048 -+256M -t -29 ++2M +ef02 n 2 -526336 -+4G -t -2 -29 -n -3 -8914944 -+2G -t -3 -19 -n -4 -13109248 -16777182 -t -4 -29 -x -A -1 -M -r -d -n -p -1 -2048 + +256M -t -fd +fd00 n -p -2 -526336 -+4G -t -2 -fd -n -p 3 -8914944 + +2G -t -3 -82 +8200 n -p -13109248 -16777182 -t 4 -fd -a -1 -p -x -M -r -p + + +fd00 w +Y EOF # Add it with partition scan losetup -f -P ${i} done # Create raids -mdadm --create /dev/md/${MDBOOT} --level=1 --metadata=0.90 --homehost=${NETHOSTNAME} --name=${MDBOOT} --assume-clean --raid-devices=2 ${LOOPA}p1 ${LOOPB}p1 -mdadm --create /dev/md/${MDSLASH} --level=1 --metadata=default --homehost=${NETHOSTNAME} --name=${MDSLASH} --assume-clean --raid-devices=2 ${LOOPA}p2 ${LOOPB}p2 +#XXX: grub2 support standard linux raid1 device +#mdadm --create /dev/md/${MDBOOT} --level=1 --metadata=0.90 --homehost=${NETHOSTNAME} --name=${MDBOOT} --assume-clean --raid-devices=2 ${LOOPA}p2 ${LOOPB}p2 +mdadm --create /dev/md/${MDBOOT} --level=1 --metadata=default --homehost=${NETHOSTNAME} --name=${MDBOOT} --assume-clean --raid-devices=2 ${LOOPA}p2 ${LOOPB}p2 mdadm --create /dev/md/${MDDATA} --level=1 --metadata=default --homehost=${NETHOSTNAME} --name=${MDDATA} --assume-clean --raid-devices=2 ${LOOPA}p4 ${LOOPB}p4 # Create slash luks partition #XXX: low iter time, should need around 100000 minimum -echo -n $LUKSPASSWORD | cryptsetup -c aes-xts-plain64 -h sha512 -s 512 --iter-time 2000 --use-urandom --uuid ${LUKSSLASHUUID} -d - --batch-mode luksFormat /dev/md/${MDSLASH} - -# Open luks partition -echo -n $LUKSPASSWORD | cryptsetup -d - --batch-mode luksOpen /dev/md/${MDSLASH} ${SLASHNAME} - -# Create data luks partition -#XXX: low iter time, should need around 100000 minimum -echo -n $LUKSPASSWORD | cryptsetup -c aes-xts-plain64 -h sha512 -s 512 --iter-time 2000 --use-urandom --uuid ${LUKSDATAUUID} -d - --batch-mode luksFormat /dev/md/${MDDATA} +echo -n $LUKSPASSWORD | cryptsetup -c aes-xts-plain64 -h sha512 -s 512 --iter-time 2000 --use-urandom --uuid ${LUKSDATAUUID} -d - --batch-mode luksFormat /dev/md/${MDDATA} # Open luks partition echo -n $LUKSPASSWORD | cryptsetup -d - --batch-mode luksOpen /dev/md/${MDDATA} ${DATANAME} - diff --git a/lib/free.sh b/lib/free.sh index a01b368..69fbfb9 100644 --- a/lib/free.sh +++ b/lib/free.sh @@ -4,12 +4,10 @@ umount ${MOUNTPOINT} # Close slash luks partition -cryptsetup close ${SLASHNAME} cryptsetup close ${DATANAME} # Stop raids mdadm --manage /dev/md/${MDBOOT} -S -mdadm --manage /dev/md/${MDSLASH} -S mdadm --manage /dev/md/${MDDATA} -S # Detach loops diff --git a/lib/mkfs.sh b/lib/mkfs.sh index 1ccc671..34bfe2e 100644 --- a/lib/mkfs.sh +++ b/lib/mkfs.sh @@ -5,11 +5,26 @@ mkfs.ext3 -L 'boot' -U ${BOOTUUID} /dev/md/${MDBOOT} # Create swap on it -mkswap -U ${SWAPAUUID} ${LOOPA}p3 -mkswap -U ${SWAPBUUID} ${LOOPB}p3 - -# Create filesystem -mkfs.btrfs -L 'slash' -U ${SLASHUUID} /dev/mapper/${SLASHNAME} +mkswap -L 'swapa' -U ${SWAPAUUID} ${LOOPA}p3 +mkswap -L 'swapb' -U ${SWAPBUUID} ${LOOPB}p3 # Create filesystem mkfs.btrfs -L 'data' -U ${DATAUUID} /dev/mapper/${DATANAME} + +# Make mount point +mkdir -p ${MOUNTPOINT} + +# Mount base filesystem +mount /dev/mapper/${DATANAME} ${MOUNTPOINT} + +# Create slash subvolume +btrfs subvolume create ${MOUNTPOINT}/slash + +# Create home subvolume +btrfs subvolume create ${MOUNTPOINT}/home + +# Set slash as default +btrfs subvolume set-default $(btrfs subvolume list ${MOUNTPOINT} | grep slash | perl -pne 's/^ID\s([0-9]+)\s.*$/\1/') ${MOUNTPOINT} + +# Unmount slash filesystem +umount ${MOUNTPOINT} diff --git a/lib/root.sh b/lib/root.sh index 6f6af1e..8efdc47 100644 --- a/lib/root.sh +++ b/lib/root.sh @@ -4,7 +4,7 @@ mkdir -p ${MOUNTPOINT} # Mount slash filesystem -mount /dev/mapper/${SLASHNAME} ${MOUNTPOINT} +mount /dev/mapper/${DATANAME} ${MOUNTPOINT} # Make boot in mount point mkdir -p ${MOUNTPOINT}/boot @@ -12,3 +12,8 @@ mkdir -p ${MOUNTPOINT}/boot # Mount boot filesystem mount /dev/md/${MDBOOT} ${MOUNTPOINT}/boot +# Make home in mount point +mkdir -p ${MOUNTPOINT}/home + +# Mount home filesystem +mount -o subvol=/home /dev/mapper/${DATANAME} ${MOUNTPOINT}/home