From 3e3d78aacf7bfd252c57ace95c0615d38313032a Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Fri, 13 Aug 2021 15:07:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2=D0=BE=D1=87=D0=BD=D1=8B=D1=85=20=D0=B0?= =?UTF-8?q?=D1=80=D1=85=D0=B8=D0=B2=D0=BE=D0=B2=20=D0=B8=20=D1=81=D0=BA?= =?UTF-8?q?=D1=80=D0=B8=D0=BF=D1=82=20=D0=B8=D1=85=20=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acos-installer.sh | 93 +++++++++++++++++++++++++++++++++++++ mk_installation_archives.sh | 87 ++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100755 acos-installer.sh create mode 100755 mk_installation_archives.sh diff --git a/acos-installer.sh b/acos-installer.sh new file mode 100755 index 0000000..965c93d --- /dev/null +++ b/acos-installer.sh @@ -0,0 +1,93 @@ +#!/bin/sh +set -e + +if [ -z "$2" ] +then + echo "Справка: $0 <устройство для установки> <конфигурационный файл ignition>" + echo "Пример: $0 /dev/sda config.ign" + exit 1 +fi + +DEVICE=$1 +IGNITION_CONFIG=$2 +BRANCH=alt/x86_64/containeros/stable +OS_NAME=alt-containeros +MOUNT_DIR=/tmp/acos +REPO_LOCAL=$MOUNT_DIR/ostree/repo + +if [ ! -b $DEVICE ] +then + echo "Первый параметр должен быть именем блочного устройства" + exit 1 +fi + +if [ ! -f $IGNITION_CONFIG ] +then + echo "Второй параметр должен быть именем существующего файла" + exit 1 +fi + +if [ `id -u` -ne 0 ] +then + echo "Запуск скрипта $0 возможет только от пользователя root (uid=0)" + exit 1 +fi + +set +e +mount|grep ^$DEVICE +if [ "$?" -eq 0 ] +then + echo "Диск, на который выполняется установка, должен быть непримонтированным" + exit 1 +fi +set -e + +parted $DEVICE print +if [ "$?" -ne 0 ] +then + exit 1 +fi + +read -p "Вы уверены, что хотите установить ACOS на данный диск (y/n)? " -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + exit 1 +fi + +#На диске, на который выполняется установка создать файловую систему. Метка boot нужна для поиска раздела в ignition. +dd if=/dev/zero of=$DEVICE bs=1M count=3 +parted $DEVICE mktable msdos 2>&1 | grep -v /etc/fstab +parted -a optimal $DEVICE mkpart primary ext4 2MIB 100% 2>&1 | grep -v /etc/fstab +parted $DEVICE set 1 boot on 2>&1 | grep -v /etc/fstab +mkfs.ext4 -L boot "$DEVICE"1 +mkdir $MOUNT_DIR +mount "$DEVICE"1 $MOUNT_DIR + +tar xf acos_root.tar.xz -C $MOUNT_DIR + +grub-install --root-directory=$MOUNT_DIR $DEVICE +ln -s ../loader/grub.cfg $MOUNT_DIR/boot/grub/grub.cfg + +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` + +rm -rf $MOUNT_DIR/ostree/deploy/$OS_NAME/var +tar xf var.tar.xz -C $MOUNT_DIR/ostree/deploy/$OS_NAME/ +touch $MOUNT_DIR/ostree/deploy/$OS_NAME/var/.ostree-selabeled + +#Создать конфигурационные файлы ignition +mkdir $MOUNT_DIR/ignition +cp $IGNITION_CONFIG $MOUNT_DIR/ignition/ +touch $MOUNT_DIR/boot/ignition.firstboot + +#Установить пароль рута в новой системе +echo +echo +echo +chroot $MOUNT_DIR/ostree/boot.1/$OS_NAME/*/0/ passwd diff --git a/mk_installation_archives.sh b/mk_installation_archives.sh new file mode 100755 index 0000000..f4884d0 --- /dev/null +++ b/mk_installation_archives.sh @@ -0,0 +1,87 @@ +#!/bin/sh +set -e + +if [ `id -u` -ne 0 ] +then + echo "Запуск скрипта $0 возможет только от пользователя root (uid=0)" + exit 1 +fi + +MAIN_ROOT=root +MAIN_REPO=repo +BRANCH=alt/x86_64/containeros/stable +ACOS_ROOT=acos_root + +mkdir $MAIN_ROOT +tar xf out/acos-latest-x86_64.tar -C $MAIN_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 $MAIN_ROOT/etc/net/ +rm -f $MAIN_ROOT/etc/resolv.conf +ln -sf /run/systemd/resolve/resolv.conf $MAIN_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 $MAIN_ROOT systemctl enable ignition-firstboot-complete.service ostree-remount.service sshd docker +sed -i 's/^LABEL=ROOT\t/LABEL=boot\t/g' $MAIN_ROOT/etc/fstab +sed -i 's/^AcceptEnv /#AcceptEnv /g' $MAIN_ROOT/etc/openssh/sshd_config +sed -i 's/^# WHEEL_USERS ALL=(ALL) ALL$/WHEEL_USERS ALL=(ALL) ALL/g' $MAIN_ROOT/etc/sudoers +sed -i 's|^HOME=/home$|HOME=/var/home|g' $MAIN_ROOT/etc/default/useradd +echo "blacklist floppy" > $MAIN_ROOT/etc/modprobe.d/blacklist-floppy.conf +mkdir $MAIN_ROOT/sysroot +ln -s sysroot/ostree $MAIN_ROOT/ostree + +mv -f $MAIN_ROOT/home $MAIN_ROOT/opt $MAIN_ROOT/srv $MAIN_ROOT/mnt $MAIN_ROOT/var/ +mv -f $MAIN_ROOT/root $MAIN_ROOT/var/roothome +mv -f $MAIN_ROOT/usr/local $MAIN_ROOT/var/usrlocal +ln -sf var/home $MAIN_ROOT/home +ln -sf var/opt $MAIN_ROOT/opt +ln -sf var/srv $MAIN_ROOT/srv +ln -sf var/roothome $MAIN_ROOT/root +ln -sf ../var/usrlocal $MAIN_ROOT/usr/local +ln -sf var/mnt $MAIN_ROOT/mnt + +chroot $MAIN_ROOT chgrp wheel /usr/bin/sudo /bin/su +chroot $MAIN_ROOT chmod 710 /usr/bin/sudo /bin/su +chroot $MAIN_ROOT chmod ug+s /usr/bin/sudo /bin/su + +KERNEL=`find $MAIN_ROOT/boot/ -type f -name "vmlinuz-*"` +SHA=`sha256sum "$KERNEL" | awk '{print $1;}'` +mv "$KERNEL" "$KERNEL-$SHA" +rm -f $MAIN_ROOT/boot/vmlinuz +rm -f $MAIN_ROOT/boot/initrd* + +cat < $MAIN_ROOT/ostree.conf +d /run/ostree 0755 root root - +f /run/ostree/initramfs-mount-var 0755 root root - +EOF +chroot $MAIN_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 $MAIN_ROOT/lib/modules` +rm -f $MAIN_ROOT/ostree.conf +rm -rf $MAIN_ROOT/usr/etc +mv $MAIN_ROOT/etc $MAIN_ROOT/usr/etc + +tar -cJf var.tar.xz -C $MAIN_ROOT var +rm -rf $MAIN_ROOT/var/* + +#Создание главного ostree-репозитория и коммита в нем +ostree init --repo=$MAIN_REPO --mode=archive +ostree commit --repo=$MAIN_REPO --tree=dir=$MAIN_ROOT -b $BRANCH \ + --no-xattrs --no-bindings --parent=none --mode-ro-executables \ + --add-metadata-string=version=sisyphus.`date +%Y%m%d`.0.0 + +mkdir $ACOS_ROOT +ostree admin init-fs --modern $ACOS_ROOT +ostree pull-local --repo $ACOS_ROOT/ostree/repo $MAIN_REPO $BRANCH +tar -cJf acos_root.tar.xz -C $ACOS_ROOT `ls $ACOS_ROOT` + + +#rm -rf root repo var.tar.xz acos_root acos_root.tar.xz