ostree_on_alt/mk_acos.sh

118 lines
4.8 KiB
Bash
Raw Permalink Normal View History

2021-08-24 10:30:51 +03:00
#!/bin/sh
if [ `id -u` -ne 0 ]
then
echo "Запуск скрипта $0 возможет только от пользователя root (uid=0)"
exit 1
fi
ROOT=root
REPO_MAIN=repo
BRANCH=alt/x86_64/coreos/stable
DEVICE=/dev/sdb
OS_NAME=alt-coreos
MOUNT_DIR=/tmp/acos
REPO_LOCAL=$MOUNT_DIR/ostree/repo
mkdir $ROOT
tar xf out/acos-latest-x86_64.tar -C $ROOT --exclude=./dev/tty --exclude=./dev/tty0 --exclude=./dev/console --exclude=./dev/urandom --exclude=./dev/random --exclude=./dev/full --exclude=./dev/zero --exclude=/dev/null --exclude=./dev/pts/ptmx --exclude=./dev/null
#####################
apt-get remove -y -o "RPM::RootDir=$PWD/root" NetworkManager-daemon openresolv etcnet
rm -rf $ROOT/etc/net/
rm -f $ROOT/etc/resolv.conf
ln -sf /run/systemd/resolve/resolv.conf $ROOT/etc/resolv.conf
apt-get install -o "RPM::RootDir=$PWD/root" dracut-network-055-alt2.noarch.rpm
apt-get install -o "RPM::RootDir=$PWD/root" ignition
#####################
#Вынести в m-i-p
chroot $ROOT systemctl enable ignition-firstboot-complete.service ostree-remount.service sshd docker
sed -i 's/^LABEL=ROOT\t/LABEL=boot\t/g' $ROOT/etc/fstab
sed -i 's/^AcceptEnv /#AcceptEnv /g' $ROOT/etc/openssh/sshd_config
sed -i 's/^# WHEEL_USERS ALL=(ALL) ALL$/WHEEL_USERS ALL=(ALL) ALL/g' $ROOT/etc/sudoers
sed -i 's|^HOME=/home$|HOME=/var/home|g' $ROOT/etc/default/useradd
echo "blacklist floppy" > $ROOT/etc/modprobe.d/blacklist-floppy.conf
mkdir $ROOT/sysroot
ln -s sysroot/ostree $ROOT/ostree
mv -f $ROOT/home $ROOT/opt $ROOT/srv $ROOT/mnt $ROOT/var/
mv -f $ROOT/root $ROOT/var/roothome
mv -f $ROOT/usr/local $ROOT/var/usrlocal
ln -sf var/home $ROOT/home
ln -sf var/opt $ROOT/opt
ln -sf var/srv $ROOT/srv
ln -sf var/roothome $ROOT/root
ln -sf ../var/usrlocal $ROOT/usr/local
ln -sf var/mnt $ROOT/mnt
chroot $ROOT chgrp wheel /usr/bin/sudo /bin/su
chroot $ROOT chmod 710 /usr/bin/sudo /bin/su
chroot $ROOT chmod ug+s /usr/bin/sudo /bin/su
KERNEL=`find $ROOT/boot/ -type f -name "vmlinuz-*"`
SHA=`sha256sum "$KERNEL" | awk '{print $1;}'`
mv "$KERNEL" "$KERNEL-$SHA"
rm -f $ROOT/boot/vmlinuz
rm -f $ROOT/boot/initrd*
cat <<EOF > $ROOT/ostree.conf
d /run/ostree 0755 root root -
f /run/ostree/initramfs-mount-var 0755 root root -
EOF
chroot $ROOT dracut --reproducible --gzip -v --no-hostonly \
-f /boot/initramfs-$SHA \
--add ignition --add ostree \
--include /ostree.conf /etc/tmpfiles.d/ostree.conf \
--include /etc/systemd/network/eth0.network /etc/systemd/network/eth0.network \
--omit-drivers=floppy --omit=nfs --omit=lvm --omit=iscsi \
--kver `ls $ROOT/lib/modules`
rm -f $ROOT/ostree.conf
rm -rf $ROOT/usr/etc
mv $ROOT/etc $ROOT/usr/etc
mv $ROOT/var ./var
mkdir $ROOT/var
#Создание главного ostree-репозитория и коммита в нем
ostree init --repo=$REPO_MAIN --mode=archive
ostree commit --repo=$REPO_MAIN --tree=dir=$ROOT -b $BRANCH --no-xattrs --no-bindings --parent=none --mode-ro-executables --add-metadata-string=version=sisyphus.`date +%Y%m%d`.0.0
exit 0;
#На диске, на который выполняется установка создать файловую систему и минимальный набор каталогов для ostree. Метка boot нужна для поиска раздела в ignition.
parted $DEVICE mktable msdos
parted -a optimal $DEVICE mkpart primary ext4 2MIB 100%
parted $DEVICE set 1 boot on
mkfs.ext4 -L boot "$DEVICE"1
mkdir $MOUNT_DIR
mount "$DEVICE"1 $MOUNT_DIR
ostree admin init-fs --modern $MOUNT_DIR
#Установить GRUB
grub-install --root-directory=$MOUNT_DIR $DEVICE
ln -s ../loader/grub.cfg $MOUNT_DIR/boot/grub/grub.cfg
#Выполнить развертывание операционной системы из репозитория ostree.
ostree pull-local --repo $REPO_LOCAL $REPO_MAIN $BRANCH
ostree config --repo $REPO_LOCAL set sysroot.bootloader grub2
ostree refs --repo $REPO_LOCAL --create alt:$BRANCH $BRANCH
ostree admin os-init $OS_NAME --sysroot $MOUNT_DIR
OSTREE_BOOT_PARTITION="/boot" ostree admin deploy alt:$BRANCH --sysroot $MOUNT_DIR --os $OS_NAME \
--karg-append=ignition.platform.id=metal --karg-append=\$ignition_firstboot \
--karg-append=net.ifnames=0 --karg-append=biosdevname=0 \
--karg-append=quiet --karg-append=root=UUID=`blkid --match-tag UUID -o value "$DEVICE"1`
# --karg-append=ignition.platform.id=metal --karg-append=ignition.config.url=http://31.184.254.102/tmp/example2.ign \
rm -r $MOUNT_DIR/ostree/deploy/$OS_NAME/var
mv var $MOUNT_DIR/ostree/deploy/$OS_NAME/var
touch $MOUNT_DIR/ostree/deploy/$OS_NAME/var/.ostree-selabeled
#Создать конфигурационные файлы ignition
mkdir $MOUNT_DIR/ignition
cp config.ign $MOUNT_DIR/ignition/
touch $MOUNT_DIR/boot/ignition.firstboot
#Установить пароль рута в новой системе
chroot $MOUNT_DIR/ostree/boot.1/$OS_NAME/*/0/ passwd