Make your own RescueCD based on Funtoo Linux

Gif cd.png

This tutorial explains howto build your own RescueCD, no need for a Linux installed on disk for that. After configuring the new system, just burn the new ISO file, using the official Area31 Hackerspace tool.

Note

A virtual machine is strongly recommended for this procedure, including for security reasons

Warning

you need to boot with a 32bits kernel:

Edit.png

Construction of the environment Funtoo

Get the RescueCD from Area31

https://www.area31.net.br/wiki/RescueCD_oficial
After boot using RescueCD from Area31, create and format all partitionsː

# mkswap /dev/sda2
# mkfs.ext4 /dev/sda1

Activate swap and mount /mnt/custom directoryː

# swapon /dev/sda2
# mkdir -p /mnt/custom ; mount /dev/sda1 /mnt/custom

Get and extract stage3 (32bits) from http://www.funtoo.org/I686 ː

# wget http://ftp.osuosl.org/pub/funtoo/funtoo-current/x86-32bit/i686/stage3-latest.tar.xz -P /mnt/custom
# mkdir -p /mnt/custom/customcd/files ; tar xpf /mnt/custom/stage3-latest.tar.xz -C /mnt/custom/customcd/files

CHROOT

Configure network and use the chroot

# cp /etc/resolv.conf /mnt/custom/customcd/files/etc/
# mkdir -p /mnt/custom/customcd/files/var/cache/portage /mnt/custom/portage-chroot
# mount -o bind /mnt/custom/portage-chroot /mnt/custom/customcd/files/var/cache/portage
# mkdir -p /mnt/custom/meta-repo /mnt/custom/customcd/files/var/git
# mount -o bind /mnt/custom/meta-repo/ /mnt/custom/customcd/files/var/git
# cd /mnt/custom/customcd/files/ ; mount -o bind /proc/ proc ; mount -o bind /sys sys ; mount -o rbind /dev dev
# chroot /mnt/custom/customcd/files/ /bin/bash

RescueCD Configuration into CHROOT

# . /etc/profile ; cd ; export PS1="(chroot) $PS1"

Update portage tree

#  ego sync

Get Area31 overlay

# mkdir -p /etc/portage/localpatches /mnt/funtoo /var/overlay
# cd /var/overlay ; git clone https://github.com/area31/area31-ebuilds.git

configure make.conf

###########################################################################
## ATTENTION: THIS IS THE MAKE.CONF ON THE LIVECD                        ##
## PLEASE EDIT /mnt/custom/customcd/files/etc/portage/make.conf INSTEAD  ##
###########################################################################

CFLAGS="-O2 -march=i686 -mtune=generic -pipe"
CHOST="i686-pc-linux-gnu"
CXXFLAGS="-O2 -march=i686 -mtune=generic -pipe"

#MAKEOPTS="-j5"
#PORTAGE_NICENESS="19"

ACCEPT_LICENSE="*"
FEATURES="-collision-detect -protect-owned assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync multilib-strict news parallel-fetch preserve-libs sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"

DISTDIR="/var/cache/portage/distfiles"
PKGDIR="/var/cache/portage/packages"

#PYTHON_TARGETS="python2_7 python3_4"
#PYTHON_SINGLE_TARGET="python3_4"

#RUBY_TARGETS="ruby22 ruby24"

VIDEO_CARDS="i915 i965 vmware intel nouveau radeon vesa vmware apm ast cirrus dummy glint i128 i740 mach64 nv r128 rendition s3 savage siliconmotion sisusb tdfx trident via"
INPUT_DEVICES="evdev keyboard mouse synaptics vmmouse"

foobashrc_modules = "localpatch"
LOCALPATCH_OVERLAY="/etc/portage/localpatches"
#PORTDIR_OVERLAY="/var/overlay/area31-ebuilds/local"

PAX_MARKINGS="none"

L10N="en"

Install app-portage/eix

# emerge app-portage/eix
# eix-update

Remove debian-sources and update world

# emerge -C sys-kernel/debian-sources
# emerge -auDN @world

Install Area31 ebuild and dependencies to LiveCD

# emerge sys-apps/sysresccd-area31 app-misc/livecd-tools sys-kernel/linux-firmware
# rc-update add sysresccd default

Configure livecd profile

Remove systemd and include others mix-ins:

# epro mix-ins +no-systemd +lxqt +X +audio

Install dependencies

Configure useflags:

# vi /etc/portage/package.use

sys-fs/lvm2 lvm1 readline static thin udev
net-misc/networkmanager dhclient modemmanager ncurses nss ppp resolvconf wext wifi
net-misc/tigervnc drm nls pam server xorgmodule -dri3 -gnutls -java opengl -xinerama
x11-base/xorg-server glamor ipv6 suid udev xorg xvfb
media-libs/mesa classic dri3 egl gallium gbm llvm nptl video_cards_i915 video_cards_i965 video_cards_intel video_cards_nouveau video_cards_radeon video_cards_vmware xa
media-libs/libepoxy X
dev-libs/glib dbus mime xattr
sys-kernel/aufs-sources symlink
xfce-base/xfce4-meta mixer ristretto svg terminal thunar thunar-volman tumbler xfburn
media-sound/pulseaudio X alsa alsa-plugin asyncns bluetooth caps dbus equalizer gdbm glib gnome ipv6 orc qt4 ssl tcpd udev webrtc-aec -doc -gtk -jack -libressl -libsamplerate -lirc -native-headset -neon -ofono-headset -oss -realtime -selinux -sox -system-wide -systemd -test -zeroconf
x11-libs/gtk+ X abi_x86_32 -cups -abi_mips_n32 -abi_mips_n64 -abi_mips_o32 -abi_ppc_32 -abi_ppc_64 -abi_s390_32 -abi_s390_64 -abi_x86_64 -abi_x86_x32 -aqua -broadway -cloudprint -colord -examples -introspection -test -vim-syntax -wayland -xinerama
x11-libs/cairo X glib svg xcb
dev-cpp/cairomm X
x11-libs/gdk-pixbuf X
x11-libs/libxkbcommon X
kde-frameworks/kwindowsystem X
x11-libs/pango X
sys-block/gparted btrfs dmraid f2fs fat hfs jfs mdadm ntfs policykit reiser4 reiserfs xfs udf cryptsetup
sys-block/parted debug nls readline device-mapper
dev-cpp/gtkmm X
sys-boot/grub binfont device-mapper fonts grub_platforms_efi-32 grub_platforms_pc mount multislot nls themes -grub_platforms_efi-64
lxqt-base/lxqt-meta about filemanager icons oxygen policykit admin -lightdm lximage -minimal powermanagement -sddm -ssh-askpass -sudo
>=dev-qt/qtgui-5.9.4-r3 egl
# echo ">=net-misc/tigervnc-1.9.0" >> /etc/portage/package.mask
# emerge sys-apps/rescan-scsi-bus net-misc/dhcpcd media-sound/alsa-utils net-misc/dhcp sys-fs/mdadm sys-fs/lvm2 app-editors/vim sys-fs/cryptsetup sys-libs/gpm net-misc/networkmanager-vpnc net-misc/networkmanager-openvpn net-misc/networkmanager net-misc/networkmanager-pptp app-portage/genlop app-portage/foobashrc app-portage/cpuid2cpuflags sys-process/htop sys-process/acct sys-process/atop sys-process/audit sys-process/cronbase sys-process/glances sys-process/iotop sys-process/lsof sys-process/nmon sys-process/vixie-cron mail-mta/postfix net-misc/tigervnc sys-auth/consolekit sys-fs/ntfs3g www-client/elinks app-editors/hexcurse app-editors/hexedit app-editors/joe sys-fs/fuse www-client/links app-editors/zile sys-block/gparted lxde-base/lxterminal sys-boot/grub:0 sys-boot/grub:2 net-misc/telnet-bsd net-analyzer/nmap net-misc/iputils lxqt-base/lxqt-meta app-admin/syslog-ng x11-base/xorg-x11 sys-apps/lshw app-arch/lz4 app-arch/unrar app-arch/p7zip app-arch/sharutils app-arch/snappy app-arch/dpkg x11-terms/xterm sys-apps/ipmitool sys-apps/ipmiutil www-plugins/adobe-flash app-misc/screen sys-power/acpi sys-boot/lilo sys-boot/gnu-efi sys-block/thin-provisioning-tools sys-block/parted sys-block/open-isns sys-block/nbd sys-block/mbuffer net-wireless/bluez net-wireless/crackle net-wireless/iw net-wireless/spectools net-wireless/wpa_supplicant app-shells/zsh x11-misc/xvkbd net-print/boomaga app-text/wgetpaste app-text/pastebinit net-ftp/filezilla app-text/evince app-text/tree

# rc-update add lvm boot
# rc-update add device-mapper boot
# rc-update add dmcrypt boot
# rc-update add mdraid boot
# rc-update add gpm sysinit
# rc-update add NetworkManager default
# rc-update add autoconfig default
# rc-update add autorun default
# rc-update add dbus default
# rc-update add dostartx default
# rc-update add load-fonts-keymaps default
# rc-update add netconfig2 default
# rc-update add tigervnc default
# rc-update add consolekit default
# rc-update add syslog-ng default
# rc-update del keymap default
# mv /usr/bin/vi /usr/bin/vim-legacy ; ln -s /usr/bin/vim /usr/bin/vi
# ln -s /etc/portage/foobashrc.bashrc /etc/portage/bashrc

Compile AUFS kernel

Configure ebuild

# echo "sys-kernel/aufs-sources symlink" >> /etc/portage/package.use
# emerge sys-kernel/aufs-sources

Configure AUFS kernel

# cd /usr/src/linux ; wget https://area31.net.br/downloads/isoroot-rescuecd-area31/kernel-aufs-4.14.15 -O .config

Compile and install AUFS kernel and modules

# make oldconfig ; make ; make install ; make modules_install

ZFS support (OPTIONAL)

Unmask ZFS ebuilds

Configure useflags:

# echo "sys-fs/zfs -rootfs" >> /etc/portage/package.use
Configure keywords:

# vi /etc/portage/package.keywords

=sys-kernel/spl-0.7.9 **
=sys-fs/zfs-0.7.9 **
=sys-fs/zfs-kmod-0.7.9 **

Compile ZFS ebuilds

# emerge sys-kernel/spl sys-fs/zfs-kmod sys-fs/zfs

# rc-update add zfs-import boot
# rc-update add zfs-mount boot
# rc-update add zfs-share default
# rc-update add zfs-zed default

Install optional ebuilds

# emerge sys-apps/iucode_tool sys-firmware/intel-microcode

Configure fstab

Clean fstab:

# > /etc/fstab

Configure automatic login [RECOMMENDED]

Make script bashlogin

# touch /bin/bashlogin ; chmod +x /bin/bashlogin ; vi /bin/bashlogin
With the following content:

#!/bin/sh
# ============ ENV VARS ================================
cd /root
export LANG=en_US.UTF-8
export HOME=/root
export SHELL=/bin/bash
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export MAIL=/var/mail/root
export USER=root

source /etc/profile

# ============ PRINT MESSAGE ===========================
lc1='\e[01;31m' # light red
dc1='\e[00;31m' # dark red
lc2='\e[01;37m' # white
dc2='\e[00;37m' # gray

# fix broken console with utf8 in the alternative-kernels
echo -n -e '\033%G'
kbd_mode -u

LINES=$(stty size|cut -d" " -f1)
fbecho() 
{
  [ $LINES -ge 28 ] && echo
}

# ============ SHELL PROMPT ============================
exec $SHELL --login

Configure inittab

# vi /etc/inittab
Change the lines below the comment '# TERMINALS' 'to the following pattern:

# TERMINALS
c1:12345:respawn:/sbin/agetty -nl /bin/bashlogin 38400 tty1 linux
c2:12345:respawn:/sbin/agetty -nl /bin/bashlogin 38400 tty2 linux
c3:12345:respawn:/sbin/agetty -nl /bin/bashlogin 38400 tty3 linux
c4:12345:respawn:/sbin/agetty --noclear 38400 tty4 linux
c5:2345:respawn:/sbin/agetty 38400 tty5 linux
c6:2345:respawn:/sbin/agetty 38400 tty6 linux

That way we will automatically log in to TTY's from 1 to 3.

Configure Time Zone

/etc/localtime is used to specify the timezone that your machine is in, and defaults to UTC. If you would like your Funtoo Linux system to use local time, you should replace /etc/localtime with a symbolic link to the timezone that you wish to use.

# ln -sf /usr/share/zoneinfo/MST7MDT /etc/localtime
or configure other Time Zone using cpː

# cp /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime
Check using date commandː

# date -R
Wed, 14 Feb 2018 13:52:20 -0200

Configure to UTCː

# ln -sf /usr/share/zoneinfo/UTC /etc/localtime

Make automatic post-login banner [OPTIONAL]

Include banner on /etc/bash/bashrc:

# echo '/bin/bashlogin-banner' >> /etc/bash/bashrc
Create the script with the following content:

# touch /bin/bashlogin-banner ; chmod +x /bin/bashlogin-banner ; vi /bin/bashlogin-banner

#!/bin/sh
# ============ ENV VARS ================================
cd /root
export LANG=en_US.UTF-8
export HOME=/root
export SHELL=/bin/bash
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export MAIL=/var/mail/root
export USER=root

source /etc/profile

# ============ PRINT MESSAGE ===========================
lc1='\e[01;31m' # light red
dc1='\e[00;31m' # dark red
lc2='\e[01;37m' # white
dc2='\e[00;37m' # gray

# fix broken console with utf8 in the alternative-kernels
echo -n -e '\033%G'
kbd_mode -u

LINES=$(stty size|cut -d" " -f1)
fbecho() 
{
  [ $LINES -ge 28 ] && echo
}

VERSION="4.0"

fbecho
echo -e "${lc1} =========== ${lc2}RescueCD Area31 Hackerspace${lc1} -----  ver. ${VERSION}  =========== ${lc2}$(basename $(tty))${dc2}/6 ${lc1}=="
echo -e "              ${dc1}https://www.area31.net.br${dc2}"
echo
echo -e "${dc1}*${lc1} Network Manager${dc2}: NetworkManager${dc2}"
echo -e "${dc1}OBS:${dc2} If you want to manually configure the NetworkManager service first, NetworkManager:"
echo -e "   ${dc1}-${dc2} ${lc2}rc-service NetworkManager stop${dc2} (Required to static IP configuration)"
echo -e "   ${dc1}-${dc2} ${lc2}ifconfig eth0 192.168.x.a${dc2} (static IP)"
echo -e "   ${dc1}-${dc2} ${lc2}route add default gw 192.168.x.b${dc2} (Gateway default)"
echo -e "${dc1}Opcional:${dc2} If you prefer, type ${lc2}net-setup eth0${dc2} to configure network."
fbecho
echo -e "${dc1}*${lc1} Available Text Editors${lc2}: vim${dc2}, ${lc2}nano${dc2}, ${lc2}zile${dc2}, ${lc2}joe${dc2}"
echo -e "${dc1}*${lc1} Available HEX Editors: ${lc2}hexcurse${dc2}, ${lc2}hexedit${dc2}\n"
echo -e "${dc1}*${lc1} Web browsers CLI: ${lc2}elinks${dc2}, ${lc2}w3m${dc2}, ${lc2}links${dc2}"
echo -e "   ${dc1}-${dc2} ${lc2}w3m https://www.area31.net.br${dc2}"
fbecho
echo -e "${dc1}*${lc1} Ntfs-3g${dc2}: If you need write on disk using NTFS, try Ntfs-3g."
echo -e "   Mount disk using ntfs-3g: ${lc2}ntfs-3g /dev/sda1 /mnt/windows${dc2}\n"
echo -e "${dc1}*${lc1} Personalize your RescueCD Funtoo${dc2}: "
echo -e "   Type ${lc2}sysresccd-area31${dc2} to start the RescueCD Customization Wizard."
echo -e "${dc1}OBS:${dc2} RescueCD customization is recommended in a virtualized environment."
fbecho
if [ -f /usr/bin/Xorg ]
then
        echo -e "${dc1}*${lc1} Graphic nterface${dc2}: "
        echo -e "   Type ${lc2}startx${dc2} to start graphic interface"
        echo -e "   ${dc1}-${dc2} Partition manager:..${lc2}gparted${dc2}"
        echo -e "   ${dc1}-${dc2} Web browsers:.......${lc2}firefox-bin${dc2}"
        echo -e "   ${dc1}-${dc2} Graphic Text Editor:.......${lc2}gvim${dc2} e ${lc2}geany${dc2}\n"
        echo -e "${dc1}*${lc1} Tools${dc2}: "
        echo -e "   ${dc1}-${dc2} Diagnostic: ${lc2}glances${dc2}, ${lc2}htop${dc2}, ${lc2}whdd${dc2}, ${lc2}hdparm${dc2}, ${lc2}iostat${dc2}, ${lc2}iotop${dc2}, ${lc2}lsof${dc2}"
        echo -e "   ${dc1}-${dc2} Forensic / Recover: ${lc2}photorec${dc2}, ${lc2}foremost${dc2}, ${lc2}dcfldd${dc2}, ${lc2}ddrescue${dc2}, ${lc2}rdd${dc2}"
        echo -e "\n${lc1} ==================================================================================${lc2}"
echo -e "   Default password for root is ${lc2}root${dc2}. To change the root password, type: ${lc2}passwd${dc2}"
echo -e "   Default password for VNC is ${lc2}area31${dc2}. To access using VNC please connect to port ${lc2}5901${dc2}"
        echo -e "\n   RescueCD ${lc1}(Funtoo Linux based)${lc2} created by Area31 Hackerspace${dc1}\n                                   https://www.area31.net.br\n\n${dc2}Have a lot of fun..${dc2}"
fbecho
fi
fbecho

Install aditional locales [OPTIONAL]

# echo 'pt_BR.UTF-8 UTF-8' >> /etc/locale.gen
# locale-gen

Remove unnecessary locales [OPTIONAL]

# emerge app-admin/localepurge
Configure /etc/locale.nopurge ː

1- Comment this line to enable localepurgeː

# NEEDSCONFIGFIRST

2- Go to end in config file, and add/remove locales. Exː

# Following locales won't be deleted from this system
# for example:
pt_BR
en

Save config file and run localepurgeː

# localepurge
After run, localepurge will remove unused locales, and will show some statisticsː

 * localepurge: Disk space freed in /usr/share/man: 2400K
 * localepurge: processing man pages in /usr/local/share/man ...
 * Total disk space freed by localepurge: 95968K

Exit from CHROOT

# exit

Prepare the iso environment (Kernel + GRUB)

Download and extract the required files:

# cd /mnt/custom/customcd
# wget https://area31.net.br/downloads/isoroot-rescuecd-area31/isoroot-rescuecd-area31-3.0-part1.tar.bz2
# wget https://area31.net.br/downloads/isoroot-rescuecd-area31/isoroot-rescuecd-area31-3.0-part2.tar.bz2
# tar xjpf isoroot-rescuecd-area31-3.0-part1.tar.bz2 -C /mnt/custom/customcd
# tar xjpf isoroot-rescuecd-area31-3.0-part2.tar.bz2 -C /mnt/custom/customcd

Prepare new initramfs

Extract initramfs from Área31 RescueCD

# mkdir -p /usr/src/initramfs
# cd /usr/src/initramfs

cat /livemnt/boot/isolinux/initram.igz | xz -d | cpio -id

Copy modules from kernel to initramfs

# cp -rp /mnt/custom/customcd/files/lib/modules/* lib/modules

Make new initramfs

# rm -f /usr/src/initram.igz
# cd /usr/src/initramfs

find . | cpio -H newc -o | xz --check=crc32 --x86 --lzma2 > /usr/src/initram.igz

Copy new initramfs and kernel to isoroot dir

# cp /usr/src/initram.igz /mnt/custom/customcd/isoroot/isolinux/initram.igz
# cp /mnt/custom/customcd/files/boot/32bits/vmlinuz-*-aufs /mnt/custom/customcd/isoroot/isolinux/rescue32
# cp /mnt/custom/customcd/files/boot/64bits/vmlinuz-*-aufs64 /mnt/custom/customcd/isoroot/isolinux/rescue64

Remove temporary files and umount /proc, /dev, /sys

# rm -rf /mnt/custom/customcd/files/usr/src/* /mnt/custom/customcd/files/var/tmp/portage
# cd / ; umount /mnt/custom/customcd/files/var/cache/portage /mnt/custom/customcd/files/var/git
# cd /mnt/custom/customcd/files/ ; umount proc sys
# umount -l dev ; cd

Make iso file

# sh /usr/share/sysresccd-area31/sysresccd-area31-targets make-iso

Get new iso funtoo

ISOs are always generated in the same directory:

/mnt/custom/customcd/isofile

Edit-cd.png

How i customize the RescueCD

  • To customize the RescueCD, either to modify the kernel or add/remove software, visit the article:
https://www.area31.net.br/wiki/RescueCD_-_Personalize_o_LiveCD_e_compile_um_novo_kernel