rpm -Uhv http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm yum -y install dropbear
cd /usr/share/dracut/modules.d mkdir 40unlock cd 40unlock
cat > install << 'EOF' #!/bin/bash cat /etc/shadow|grep root > ${moddir}/shadow dracut_install /lib64/libnss_compat.so.2 dracut_install /lib64/libnss_files.so.2 dracut_install /lib64/libnss_dns.so.2 inst_dir "/etc/dropbear" inst "${moddir}/dropbear_rsa_host_key" "/etc/dropbear/dropbear_rsa_host_key" inst_dir "/home" inst_dir "/home/root" inst_dir "/home/root/.ssh" inst "${moddir}/.profile" "/home/root" [ -s "${moddir}/authorized_keys" ] && inst "${moddir}/authorized_keys" "/home/root/.ssh/authorized_keys" inst "/etc/localtime" inst "${moddir}/nsswitch.conf" "/etc/nsswitch.conf" inst "/etc/resolv.conf" inst "/etc/host.conf" inst "/etc/hosts" inst "${moddir}/shadow" "/etc/shadow" inst "${moddir}/passwd" "/etc/passwd" inst "${moddir}/shells" "/etc/shells" inst "${moddir}/unlock" "/bin/unlock" inst_hook pre-trigger 01 "$moddir/remote-ssh.sh" inst_hook pre-pivot 01 "$moddir/clean.sh" dracut_install sed awk dropbear ifconfig route blkid cut killall true mkdir dracut_install -o ps find grep less cat tac head tail false rmdir rm touch vi ping ssh scp lsmod EOF
cat > check << 'EOF' #!/bin/sh exit 0 EOF
cat > installkernel << 'EOF' #!/bin/bash instmods e1000 EOF
lspci -k
command). echo 'root:x:0:0:root:/home/root:/bin/sh' > passwd echo '/bin/sh' > shells echo 'export PATH=/sbin:/usr/sbin:$PATH' >.profile dropbearkey -t rsa -f dropbear_rsa_host_key
cat >nsswitch.conf << 'EOF' passwd: files shadow: files group: files initgroups: files hosts: files dns bootparams: files ethers: files netmasks: files networks: files protocols: files rpc: files services: files automount: files aliases: files EOF
cat >remote-ssh.sh << 'EOF' #!/bin/sh /sbin/modprobe e1000 /sbin/ifconfig lo 127.0.0.1/8 /sbin/ifconfig lo up /sbin/ifconfig eth0 192.168.100.203/24 /sbin/ifconfig eth0 up /sbin/route add default gw 192.168.100.1 /bin/mkdir -p /var/log /usr/sbin/dropbear -E -m -p 2222 -a -K 600 > /var/log/lastlog EOF
cat > clean.sh << 'EOF' #!/bin/sh /usr/bin/killall dropbear EOF
cat > unlock << 'EOF' if [ -f /etc/crypttab ] ; then sed '/^$/d;/^#/d' /etc/crypttab > /tmp/crypttab n=1 line="`sed -n "$n"p /tmp/crypttab`" while [ -n "$line" ]; do name="`echo $line|awk '{ print $1 }'`" dev="`echo $line|awk '{ print $2 }'`" key="`echo $line|awk '{ print $3 }'`" if [ "$key" = "none" ]; then luksname="$name" if [ "${dev%%=*}" = "UUID" ]; then device="`blkid -t $dev|cut -d: -f1`" else device=$dev fi echo "Password [$device ($luksname)]:" while :; do cryptsetup luksOpen $device $luksname && break done fi n=$((n+1)) line="`sed -n "$n"p /tmp/crypttab`" done sed -i /cryptsetup/c\ true /pre-pivot/* [ "$1" = "-noexit" ] && exit 0 killall plymouth killall cryptroot-ask fi exit 0 EOF
-noexit
parameter is -noexit
to the -noexit
, then the processes preventing the loading will not be killed and it will be possible to modify the primary system from initramfs by pre-mounting the necessary partitions. To continue the download, you need to unmount previously manually mounted partitions and execute the command:killall cryptroot-ask
[root@crypt 40unlock]# ls -al 56 drwxr-xr-x. 2 root root 4096 31 17:36 . drwxr-xr-x. 32 root root 4096 31 17:35 .. -rwxr-xr-x. 1 root root 17 31 17:35 check -rwxr-xr-x. 1 root root 36 31 17:36 clean.sh -rw-------. 1 root root 427 31 17:36 dropbear_rsa_host_key -rwxr-xr-x. 1 root root 1066 31 17:35 install -rwxr-xr-x. 1 root root 27 31 17:36 installkernel -rw-r--r--. 1 root root 222 31 17:36 nsswitch.conf -rw-r--r--. 1 root root 35 31 17:36 passwd -rw-r--r--. 1 root root 34 31 17:36 .profile -rwxr-xr-x. 1 root root 270 31 17:36 remote-ssh.sh -rw-r--r--. 1 root root 8 31 17:36 shells -rwxr-xr-x. 1 root root 740 31 17:36 unlock
chmod a+x check clean.sh install installkernel remote-ssh.sh unlock dracut -f
unlock
SUBSYSTEM!="block", GOTO="luks_end" ACTION!="add|change", GOTO="luks_end" ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="/bin/remote-ssh.sh" LABEL="luks_end"
Source: https://habr.com/ru/post/156989/
All Articles