User:Jlo/Replacing Debian Jessie with Alpine remotely
< User:Jlo
Stage 1
something is wrong about init at reboot time :(
#!/bin/sh export DEBIAN_FRONTEND=noninteractive apt-get -y install rsync extlinux rm -fr /boot/boot ln -sf . /boot/boot rsync -avzur my.server.home:debian/boot/* /boot/ rsync -avzur my.server.home:debian/apks /boot/ rsync -avzu my.server.home:debian/debian.apkovl.tar.gz /boot/ rsync -auv my.server.home:debian/.alpine-release /boot/ rm -fr /tmp/apkovl mkdir /tmp/apkovl tar xzf /boot/debian.apkovl.tar.gz -C /tmp/apkovl cp /etc/network/interfaces /tmp/apkovl/etc/network/ cp -r /etc/openvpn /tmp/apkovl/etc/ cp -r /etc/ssh /tmp/apkovl/etc/ cd /tmp/apkovl unlink etc/runlevels/default/local mkdir -p /tmp/apkovl/etc/init.d for v in /tmp/apkovl/etc/openvpn/*.conf ; do vn=$(basename $v|cut -d. -f1) ln -fs openvpn /tmp/apkovl/etc/init.d/openvpn.$vn ln -fs /etc/init.d/openvpn.$vn /tmp/apkovl/etc/runlevels/default/openvpn.$vn done tar czf /boot/debian.apkovl.tar.gz . cat > /boot/extlinux.conf << EOF timeout 20 prompt 1 default hardened label hardened kernel /boot/vmlinuz-hardened initrd /boot/initramfs-hardened append alpine_dev=sda1:ext2 modloop=modloop-hardened modules=loop,cramfs,sd-mod,usb-storage,ext2 quiet EOF dd if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sda extlinux -i /boot sync reboot
Stage 2
not tested yet
#!/bin/sh BEGIN=$(date +%s) name=$1 D=sda echo "Manufacturing box named *${name}*..." rc-service modloop stop umount /media/sda* || (echo "Unable to umount sda. Aborting..." ; exit 1) ### Partition the SSD $D parted -a cylinder -s /dev/${D} -- \ mklabel msdos \ mkpart primary fat32 0% 1% \ mkpart primary ext2 1% 2% \ mkpart primary ext2 2% 7% \ mkpart extended 7% 100% \ mkpart logical ext2 7% 9% \ mkpart logical ext2 9% 15% \ mkpart logical ext2 15% 20% \ mkpart logical ext2 21% 22% \ mkpart logical ext2 22% 23% \ mkpart logical ext2 23% 24% \ mkpart logical ext2 24% 25% \ mkpart logical ext2 25% 26% \ mkpart logical ext2 26% 27% \ mkpart logical ext2 27% 28% \ mkpart logical ext2 28% 29% \ mkpart logical ext2 29% 30% \ set 1 boot on \ || exit 1 ### prepare boot partition mkfs.vfat /dev/${D}1 || exit 1 mkdir -p /media/${D}1 setup-bootable /media/${B} /dev/${D}1 || exit 1 mount -t vfat /dev/${D}1 /media/${D}1 || exit 1 ### format partition to hold apkovl and apk/cache; it must be of ext? type mkfs.ext4 -F -q /dev/${D}2 || exit 1 mkdir -p /media/${D}2 mount -t ext4 /dev/${D}2 /media/${D}2 || exit 1 ### format remaining partitions with f2fs for i in $(seq 3 16);do [ $i -eq 4 ] && continue mkfs.f2fs -q /dev/${D}$i || exit 1 mkdir -p /media/${D}$i mount -t f2fs /dev/${D}$i /media/${D}$i || exit 1 mkdir -p /media/${D}$i/.wd chmod 777 /media/${D}$i/.wd chmod +t /media/${D}$i/.wd done ### copy apkovl and apk/cache and stuff rsync -azur --numeric-ids root@my.server.home:sda* /media/ || exit 1 ### prepare new apkovl rm -fr /tmp/template mkdir -p /tmp/template tar xzf /media/${S}2/$(hostname).apkovl.tar.gz -C /tmp/template || exit 1 rm /media/${D}2/$(hostname).apkovl.tar.gz cd /tmp/template rm -f etc/ssh/ssh_host_* for f in $(grep -r $(hostname) etc 2> /dev/null | cut -d: -f1|sort -u);do sed -i -e s/$(hostname)/${name}/g $f;done for f in $(grep -r ${S} etc 2> /dev/null | cut -d: -f1|sort -u);do sed -i -e s/${S}/${D}/g $f;done echo "/dev/sdb2 /media/sdb2 ext4 ro,relatime,errors=continue,user_xattr,acl 0 2" > etc/fstab echo "/dev/sda3 /media/sda3 f2fs defaults,ro 0 2" >> etc/fstab for i in $(seq 5 16);do echo "/dev/sda$i /media/sda$i f2fs defaults 0 2" >> etc/fstab;done echo "With great power comes great responsibility!" > etc/motd mkdir -p etc/manufacture date +%s > etc/manufacture/manufactured date >> etc/manufacture/manufactured rm etc/apk/cache ln -s /media/${D}2/cache etc/apk/cache ln -s /etc/init.d/local etc/runlevels/default/local tar czf /media/${D}2/${name}.apkovl.tar.gz . || exit 1 ### copy installed system to proxy partition rsync -aur --numeric-ids /media/${D}1 /media/${D}5/ || exit 1 ### done sync umount /media/${D}* END=$(date +%s) DURATION=$(($END-$BEGIN)) echo "Manufacture process took $DURATION seconds to complete." logger "Manufacture process took $DURATION seconds to complete." reboot