You are not logged in.

#1 2017-11-20 14:49:50

probackup-nl
Member
From: Delft
Registered: 2017-11-15
Posts: 83
Website

[solved] How to handcraft initramfs for disaster recovery plan rescue

I would like the custom initramfs it to boot a rescue disk (by label -> udev is needed) and immediately launch the restore procedure. (I know that hand crafting an initramfs might possible be weeks of work.)

I have seen some other minimal initramfs jobs done "by hand craft", like "Linux From Scratch" <http://www.linuxfromscratch.org/blfs/vi … ramfs.html>.

What are the specifics for handcrafting (write your own script to create) initramfs for Arch Linux?

Or should I better study mkinitcpio source?

Last edited by probackup-nl (2017-12-24 09:50:09)

Offline

#2 2017-11-20 15:02:06

frostschutz
Member
Registered: 2013-11-15
Posts: 1,417

Re: [solved] How to handcraft initramfs for disaster recovery plan rescue

There's also this guide https://wiki.gentoo.org/wiki/Custom_Initramfs that should give you an idea about how Initramfs ticks in general - just ignore the Gentoo specific bits.

Not sure exactly what you mean by "restore procedure". If it's something that runs fully automated, that's something you can do with mkinitcpio hooks as well.

Last edited by frostschutz (2017-11-20 15:02:28)

Offline

#3 2017-11-22 20:33:25

probackup-nl
Member
From: Delft
Registered: 2017-11-15
Posts: 83
Website

Re: [solved] How to handcraft initramfs for disaster recovery plan rescue

Thanks

With the help of the Gentoo link and mkinitcpio source code, I was able to build a minimal busybox only initramfs. Without any modules (yet) the .img measures about 1.55Mib in size, after lz -l compression. According to lsinitcpio -a the initramfs image will decompress in about 10 milliseconds on the fanless E3815 CPU @ 1.46GHz.

$ lsinitcpio linux-rescue.img
init
lib64
sbin
bin
lib
usr
usr/lib64
usr/sbin
usr/bin
usr/bin/yes
usr/bin/xxd
usr/bin/wget
usr/bin/wc
usr/bin/vi
usr/bin/uptime
usr/bin/unshare
usr/bin/unlink
usr/bin/uniq
usr/bin/uname
usr/bin/umount
usr/bin/truncate
usr/bin/true
usr/bin/touch
usr/bin/tftp
usr/bin/test
usr/bin/telnet
usr/bin/tail
usr/bin/tac
usr/bin/sync
usr/bin/strings
usr/bin/stat
usr/bin/sort
usr/bin/sleep
usr/bin/shuf
usr/bin/sha512sum
usr/bin/sha256sum
usr/bin/sha1sum
usr/bin/sh
usr/bin/setfont
usr/bin/seq
usr/bin/sed
usr/bin/route
usr/bin/rmdir
usr/bin/rm
usr/bin/reboot
usr/bin/readlink
usr/bin/pwd
usr/bin/ps
usr/bin/printf
usr/bin/poweroff
usr/bin/ping6
usr/bin/ping
usr/bin/pidof
usr/bin/pgrep
usr/bin/paste
usr/bin/partprobe
usr/bin/openvt
usr/bin/nslookup
usr/bin/nsenter
usr/bin/nproc
usr/bin/netstat
usr/bin/nc
usr/bin/mv
usr/bin/mountpoint
usr/bin/mktemp
usr/bin/mkpasswd
usr/bin/mknod
usr/bin/mkfifo
usr/bin/mkdir
usr/bin/md5sum
usr/bin/lsscsi
usr/bin/ls
usr/bin/losetup
usr/bin/loadkmap
usr/bin/loadfont
usr/bin/ln
usr/bin/link
usr/bin/less
usr/bin/killall
usr/bin/kill
usr/bin/kbd_mode
usr/bin/iptunnel
usr/bin/iprule
usr/bin/iproute
usr/bin/ipneigh
usr/bin/iplink
usr/bin/ipaddr
usr/bin/ip
usr/bin/install
usr/bin/init
usr/bin/ifconfig
usr/bin/hexdump
usr/bin/head
usr/bin/halt
usr/bin/grep
usr/bin/getopt
usr/bin/fstrim
usr/bin/fsfreeze
usr/bin/free
usr/bin/fatattr
usr/bin/false
usr/bin/fallocate
usr/bin/expr
usr/bin/env
usr/bin/echo
usr/bin/du
usr/bin/dmesg
usr/bin/dirname
usr/bin/df
usr/bin/dd
usr/bin/cut
usr/bin/cttyhack
usr/bin/cp
usr/bin/clear
usr/bin/chroot
usr/bin/chown
usr/bin/chmod
usr/bin/chgrp
usr/bin/cat
usr/bin/blkdiscard
usr/bin/basename
usr/bin/awk
usr/bin/ash
usr/bin/[
usr/bin/busybox
usr/lib
usr/lib/ld-linux-x86-64.so.2
usr/lib/libc.so.6
usr/lib/libcrypt.so.1
usr/local
usr/local/sbin
usr/local/bin
usr/local/lib
etc
etc/ld.so.cache
etc/ld.so.conf
etc/initrd-release
etc/fstab
etc/mtab
tmp
run
dev
sys
proc

Module autodetection and loading is now finished, as well as networking and ipv4 ip assignment via DHCP. Dropbear SSH server is running. Even nano and flashbench utils are included at an initramfs size of 4.7M (after lz4 -l compression).

Last edited by probackup-nl (2017-11-27 21:29:59)

Offline

#4 2017-11-27 21:30:36

probackup-nl
Member
From: Delft
Registered: 2017-11-15
Posts: 83
Website

Re: [solved] How to handcraft initramfs for disaster recovery plan rescue

I do need to copy users, and wish to resolve message:

sh: can't access tty: job control turned off

https://superuser.com/questions/410472/ … -shellcode might do the trick although there is no /etc/inittab here.

That job control turned off needs further research at https://www.busybox.net/FAQ.html#job_control

exec setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'

makes the sh: can't access tty: job control turned off message go away.

Now at 3.8M initramfs. Block and filesystems to go.

Last edited by probackup-nl (2017-11-28 08:38:50)

Offline

Board footer

Powered by FluxBB