# boot md names
MDBOOT='mdboot'
-# slash md names
-MDSLASH='mdslash'
# data md names
MDDATA='mddata'
# mount point
-MOUNTPOINT='/media/slash'
+MOUNTPOINT='/media/data'
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}"
# 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
#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
# Reset mtab
mv -f ${MOUNTPOINT}/etc/mtab.orig ${MOUNTPOINT}/etc/mtab
+# Umount home
+umount ${MOUNTPOINT}/home
+
# Umount boot
umount ${MOUNTPOINT}/boot
# 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}
-
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
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}
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
# 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