Расковырял установочный диск, посмотрел на пример инициализации файловой системы:
#!/bin/sh -e
# used for initramfs
export PATH
. /lib/debian-installer/init-debug
debugshell "just booted"
mount /run
mkdir -p /run/lock
mount /proc
mount /sys
/lib/debian-installer/start-udev
init='/bin/busybox init'
for i in $(cat /proc/cmdline); do
case $i in
init=/init|init=init)
# Avoid endless loop
: ;;
init=*)
init=${i#init=} ;;
noshell)
sed -i '/^tty[23]/s/^/#/' /etc/inittab ;;
esac
done
debugshell "before init"
exec $init
на конфигурацию загрузчика GRUB
set loopback="findiso=${iso_path}"
export loopback
fi
menuentry "Debian GNU/Linux Live (kernel 5.10.0-20-amd64)" {
linux /live/vmlinuz-5.10.0-20-amd64 boot=live components splash quiet "${loopback}"
initrd /live/initrd.img-5.10.0-20-amd64
}
Пока появилась только одна совершенно бездарная мысль, подсунуть вместо debian-live-11.6.0-amd64-standard/live/filesystem.squashfs свою систему. Но там предыдущая версия ядра (5.10.0-20).
Ваш метод не раз встречал в процессе поиска решения. Если это не слишком долго по времени, не могли бы выложить единой инструкцией применительно к текущему дистрибутиву? Уверен, много людей скажут Вам спасибо. Может отдельной темой на том или ином форуме. Оно того точно стоит.
И еще, мне почему то кажется, что пакет bootcd тоже должен уметь это делать, но либо я не умею читать документацию, либо авторы не озадачивались такими мелочами, считая их интуитивно понятными.
для жесткого диска это работать не будет, что и видно по выхлопу df. Во втором выхлопе видно, что скорее всего работает. Используется overlay, upper смонтирован в tmpfs(ram).
# vim: set filetype=sh :
# file: bootcdwrite.conf
# copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2001-2020)
# license: GNU General Public License, version 3
# description: bootcdwrite.conf - default config for bootcdwrite
#
# SRCDISK
#
# The Variables SRCDISK defines the root of the files
# that will be copied.
#
# For example, to build an image from a remote system,
# export root-directory with nfs,
# mount it locally to </mnt/remote> and add::
#
# SRCDISK=/mnt/remote
#
# It is added as prefix to KERNEL, INITRD, DISABLE_CRON and NOT_TO_CD,
# if this are relativ paths (without starting "/")
#
# Default::
#
# SRCDISK=/
#
SRCDISK="/"
#
# KERNEL
#
# This defines the kernel which is used.
# More kernels can be defined with KERNEL<number>
# The numbers have to start with 1 and can continue with 2, 3, 4 ... ::
#
# KERNEL1=/boot/vmlinuz-2.6.18-3-686-bigmem
# KERNEL2=/boot/vmlinuz-4.19.0-5-amd64
#
# Default::
#
# KERNEL=vmlinuz
#
KERNEL="/vmlinuz"
#
# APPEND
#
# This can be used to define additional options for the kernel
# For more kernels APPEND<number> can be defined::
#
# APPEND1="vga=normal nomodeset"
# APPEND2=""
#
# Default::
#
# APPEND=""
#
APPEND=""
#
# INITRD
#
# This defines the path to initrd.
# For more kernels INITRD<number> can be defined::
#
# INITRD1=/boot/initrd.img-2.6.18-3-686-bigmem
# INITRD2="initrd.img"
#
# Default::
#
# INITRD="initrd.img"
#
INITRD="/initrd.img"
#
# KLABEL
#
# This defines a label for the kernel to be choosen when booting from bootcd.
# Can defines multiple kernels with <KERNEL<number>> and label <KLABEL<number>>::
#
# KLABEL1=686-3
# KERNEL1=/boot/vmlinuz-2.6.18-3-686-bigmem
# INITRD1=/boot/initrd.img-2.6.18-3-686-bigmem
# APPEND1=
#
# Default::
#
# KLABEL=linux
#
KLABEL="linux"
#
# DISPLAY
#
# Text files to display at boottime (see syslinux doku)
# When pressing F1 at boot time the file defined by <DISPLAY> is shown.
# F2 will show the file defined by <DISPLAY2> and F3
# will show the file defined by <DISPLAY3>
# F10 lists all people mentioned in <changelog>.
#
# The text file <kernelinfo> is replaced with a file which includes kernelinfo.
#
# Default::
#
# DISPLAY="/usr/share/bootcd/default.txt"
# DISPLAY2="kernelinfo"
#
DISPLAY="/usr/share/bootcd/default.txt"
#
# TYP
#
# TYP can be defined as CD or DVD to get a warning if the size of
# the image will be larger as the specified medium.
#
# Default::
#
# TYP=DVD
#
TYP="DVD"
#
# CDDEV
#
# Specifies one or more CD devices to boot from. The first one is the default.
# auto tries to find the bootcd on all SCSI and IDE CDROMS
#
# Default::
#
# CDDEV="auto /dev/hda /dev/hdb /dev/hdc /dev/hdd /dev/sr0 /dev/sr1"
#
CDDEV="auto /dev/hda /dev/hdb /dev/hdc /dev/hdd /dev/sr0 /dev/sr1"
#
# DO_CHECK
#
# Enables some checks or not.
# To check for possible problems can take a long time, but it is recommended to do the checks.
#
# Default::
#
# DO_CHECK=yes
#
DO_CHECK="yes"
#
# NOT_TO_CD
#
# Add directories which should be excluded from bootcd.
# Directories are separated by spaces.
# SRCDISK will be automatically added to each path that does not start with "/".
#
# Default::
#
# NOT_TO_CD=""
#
NOT_TO_CD=""
#
# SSHHOSTKEY
#
# If using ssh it is helpful to have a unique ssh hostkey for each CD.
# To be generated at burntime::
# Default::
#
# SSHHOSTKEY=yes
#
SSHHOSTKEY="yes"
#
# UDEV_FIXNET
#
# If the network interfaces are hardwired in
# /etc/udev/rules.d/xx_persistent-net.rules
# they can removed on bootcd, with:
# Default::
#
# UDEV_FIXNET="yes"
#
UDEV_FIXNET="yes"
#
# VAR
#
# This defines the directoy where the image resists after build.
# Default::
#
# VAR=/var/spool/bootcd
#
VAR="/var/spool/bootcd"
#
# FLOPPY_RUNTIME_DEV
#
# When you booting from cd changes will be read from this device.
# Without a floppy::
#
# FLOPPY_RUNTIME_DEV=""
#
# Default::
#
# FLOPPY_RUNTIME_DEV=/dev/fd0
#
FLOPPY_RUNTIME_DEV="/dev/fd0"
#
# BOOTCDFLOPPY
#
# If the system should boot the kernel from floppy.
# This reduces space on floppy used by bootcdflopcp.
# For this to work FLOPPY_CREATE_DEV has to be specified::
#
# BOOTFLOPPY=yes|no
#
# Default::
#
# BOOTFLOPPY=no
#
BOOTCDFLOPPY=""
#
#
# BOOT_ONLY_WITH_FLOPPY
#
# If you several machines will be booted from the same bootcd, you must have
# each one can hav separat configuraiton (exp: /etc/network/interfaces) on floppy.
# If the floppy can not be mounted, it may be a good idea to stop booting with::
#
# BOOT_ONLY_WITH_FLOPPY=yes
#
# Default::
#
# BOOT_ONLY_WITH_FLOPPY=no
#
BOOT_ONLY_WITH_FLOPPY="no"
#
# CLEAN_VAR
#
# delete some chached files in /var with:
# Default::
#
# CLEAN_VAR=yes
#
CLEAN_VAR="yes"
#
# TO_FSTAB
#
# To add addiditionel entries to fstab. Use for example::
#
# TO_FSTAB="/dev/hdc1 /home ext3 defaults 1 1
#
# Default::
#
# TO_FSTAB=""
#
TO_FSTAB=""
#
# NOTCOMPRESSED
#
# Files or Directory-Trees that should never be compressed on CD can be listed here.
# This can be used for documentation which should be visible without installing the bootcd.
# Default::
#
# NOTCOMPRESSED=""
#
NOTCOMPRESSED="/home"
#
# DISABLE_CRON
#
# Files listed will be on the cdrom with a .no_run_on_bootcd suffix so run-parts won't execute them.
# The original file will be a link to /bin/true.
# This is meant for cron maintenance scripts which are useless on a static cdrom.
# The default is to disable the daily find, standard and security scripts.
# With bootcd2disk this files will be reactivated again.
#
# Default::
#
# DISABLE_CRON="etc/cron.daily/find etc/cron.daily/standard etc/cron.daily/security"
#
DISABLE_CRON="/etc/cron.daily/find /etc/cron.daily/standard /etc/cron.daily/security"
#
# MKISOFS_CHNG
#
# With this variable some options given to mkisofs by bootcdwrite can be changed.
#
# Example: To use <-opt1> and <-opt2 <value>> and
# to not use any previous <-opt1 [<value>...]>, <-opt2 [<value...>]> and
# <-opt3 [<value>...]> and to leave any other options as defined::
#
# MKISOFS_CHNG="-opt1 -opt2 <value> !-opt3"
#
# Default::
#
# MKISOFS_CHNG=""
#
MKISOFS_CHNG=""
#
# extra_changes()
#
# It is possible to define a function called extra_changes to have some
# files modified on the ISO image. Here is an example::
#
# extra_changes() {
# bootcd_global VAR
#
# echo "noname" >$VAR/changes/etc/hostname
#
# mkdir -p $VAR/changes/etc/network
# ( echo "auto lo"
# echo "iface lo inet loopback"
# echo "" echo "auto eth0"
# echo "iface eth0 inet static"
# echo " address 0.0.0.0"
# echo " netmask 255.255.255.0"
# ) >$VAR/changes/etc/network/interfaces
#
# echo "127.0.0.1 localhost noname" >$VAR/changes/etc/hosts
#
# cat $SRCDISK/etc/passwd |
# grep -v -e "^bs:" -e "^bianca:" -e "^tim:" >$VAR/changes/etc/passwd
#
# cat $SRCDISK/etc/shadow |
# grep -v -e "^bs:" -e "^bianca:" -e "^tim:" >$VAR/changes/etc/shadow
#
# cat $SRCDISK/etc/group |
# grep -v -e "^bs:" -e "^bianca:" -e "^tim:" >$VAR/changes/etc/group
# }
#
# Default::
#
# # make sure the function is not defined
# unset -f extra_changes
#
extra_changes() { :; }
#
# BOOTCDMODPROBE
#
# If booted from initrd bootcd has to load the necessary modules.
# If only modules provided by initramfs-tools are needed you can
# specify "standard" here::
#
# BOOTCDMODPROBE=standard
#
# If bootcd should try extra hard to load
# neccessary modules you can specify "bootcd" here.
# Bootcd will use discover for this purpose. So discover has to be installed::
#
# BOOTCDMODPROBE=bootcd
#
# If you specify auto, bootcd will check if discover is installed.
# If it is installed BOOTCDMODPROBE=bootcd will be set, if not
# BOOTCDMODPROBE=standard will be set.
# Be aware that people have reported, that sometimes BOOTCDMODPROBE=bootcd
# may not work but sometimes it is needed.
# Default::
#
# BOOTCDMODPROBE=auto
#
BOOTCDMODPROBE="auto"
#
#!/bin/sh
# Part of raspi-config https://github.com/RPi-Distro/raspi-config
#
# See LICENSE file for copyright and license details
INTERACTIVE=True
ASK_TO_REBOOT=0
get_overlay_now() {
grep -q "boot=overlay" /proc/cmdline
}
get_overlay_conf() {
grep -q "boot=overlay" /boot/grub/grub.cfg
}
get_bootro_now() {
findmnt /boot | grep -q " ro,"
}
get_bootro_conf() {
grep /boot /etc/fstab | grep -q "defaults.*,ro"
}
enable_overlayfs() {
KERN=$(uname -r)
INITRD=initrd.img-"$KERN"-overlay
# mount the boot partition as writable if it isn't already
if get_bootro_now ; then
if ! mount -o remount,rw /boot 2>/dev/null ; then
echo "Unable to mount boot partition as writable - cannot enable"
return 1
fi
BOOTRO=yes
else
BOOTRO=no
fi
cat > /etc/initramfs-tools/scripts/overlay << 'EOF'
# Local filesystem mounting -*- shell-script -*-
#
# This script overrides local_mount_root() in /scripts/local
# and mounts root as a read-only filesystem with a temporary (rw)
# overlay filesystem.
#
. /scripts/local
local_mount_root()
{
local_top
local_device_setup "${ROOT}" "root file system"
ROOT="${DEV}"
# Get the root filesystem type if not set
if [ -z "${ROOTFSTYPE}" ]; then
FSTYPE=$(get_fstype "${ROOT}")
else
FSTYPE=${ROOTFSTYPE}
fi
local_premount
# CHANGES TO THE ORIGINAL FUNCTION BEGIN HERE
# N.B. this code still lacks error checking
modprobe ${FSTYPE}
checkfs ${ROOT} root "${FSTYPE}"
# Create directories for root and the overlay
mkdir /lower /upper
# Mount read-only root to /lower
if [ "${FSTYPE}" != "unknown" ]; then
mount -r -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /lower
else
mount -r ${ROOTFLAGS} ${ROOT} /lower
fi
modprobe overlay || insmod "/lower/lib/modules/$(uname -r)/kernel/fs/overlayfs/overlay.ko"
# Mount a tmpfs for the overlay in /upper
mount -t tmpfs tmpfs /upper
mkdir /upper/data /upper/work
# Mount the final overlay-root in $rootmnt
mount -t overlay \
-olowerdir=/lower,upperdir=/upper/data,workdir=/upper/work \
overlay ${rootmnt}
}
EOF
# add the overlay to the list of modules
if ! grep overlay /etc/initramfs-tools/modules > /dev/null; then
echo overlay >> /etc/initramfs-tools/modules
fi
# build the new initramfs
update-initramfs -c -k "$KERN"
# rename it so we know it has overlay added
mv /boot/initrd.img-"$KERN" /boot/"$INITRD"
# there is now a modified initramfs ready for use...
# modify initrd in /boot/grub/grub.conf
sed -i /boot/grub/grub.cfg -e 's/initrd\.img-'"$KERN"'/'"$INITRD"'/'
# modify command line
if ! grep -q "boot=overlay" /boot/grub/grub.cfg ; then
sed -i '/vmlinuz-'"$KERN"'/ s/$/ boot=overlay/' /boot/grub/grub.cfg
fi
if [ "$BOOTRO" = "yes" ] ; then
if ! mount -o remount,ro /boot 2>/dev/null ; then
echo "Unable to remount boot partition as read-only"
fi
fi
}
is_uname_current() {
test -d "/lib/modules/$(uname -r)"
return $?
}
disable_overlayfs() {
KERN=$(uname -r)
INITRD=initrd.img-"$KERN"-overlay
# mount the boot partition as writable if it isn't already
if get_bootro_now ; then
if ! mount -o remount,rw /boot 2>/dev/null ; then
echo "Unable to mount boot partition as writable - cannot disable"
return 1
fi
BOOTRO=yes
else
BOOTRO=no
fi
# remove the overlay to the list of modules
if grep -q "overlay" /etc/initramfs-tools/modules ; then
sed -i /etc/initramfs-tools/modules -e '/overlay/d'
fi
if update-initramfs -c -k "${KERN}" ; then
update-initramfs -d -k "${KERN}-overlay"
fi
# modify the initrd in /boot/grub/grub.cfg
sed -i /boot/grub/grub.cfg -e 's/'"$INITRD"'/initrd\.img-'"$KERN"'/'
# modify command line
sed -i '/vmlinuz-'"$KERN"'/ s/ boot=overlay//' /boot/grub/grub.cfg
if [ "$BOOTRO" = "yes" ] ; then
if ! mount -o remount,ro /boot 2>/dev/null ; then
echo "Unable to remount boot partition as read-only"
fi
fi
}
enable_bootro() {
if get_overlay_now ; then
echo "Overlay in use; cannot update fstab"
return 1
fi
sed -i /etc/fstab -e "s/\(.*\/boot.*\)defaults\(.*\)/\1defaults,ro\2/"
}
disable_bootro() {
if get_overlay_now ; then
echo "Overlay in use; cannot update fstab"
return 1
fi
sed -i /etc/fstab -e "s/\(.*\/boot.*\)defaults,ro\(.*\)/\1defaults\2/"
}
do_finish() {
if [ $ASK_TO_REBOOT -eq 1 ]; then
whiptail --yesno "Would you like to reboot now?" 20 60 2
if [ $? -eq 0 ]; then # yes
sync
reboot
fi
fi
exit 0
}
do_overlayfs() {
DEFAULT=--defaultno
CURRENT=0
STATUS="disabled"
if [ "$INTERACTIVE" = True ] && ! is_uname_current; then
whiptail --msgbox "Could not find modules for the running kernel ($(uname -r))." 20 60 1
return 1
fi
if get_overlay_conf; then
DEFAULT=
CURRENT=1
STATUS="enabled"
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the overlay file system to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
if [ $RET -eq 0 ]; then
if enable_overlayfs; then
STATUS="enabled"
ASK_TO_REBOOT=1
else
STATUS="unchanged"
fi
elif [ $RET -eq 1 ]; then
if disable_overlayfs; then
STATUS="disabled"
ASK_TO_REBOOT=1
else
STATUS="unchanged"
fi
else
return $RET
fi
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The overlay file system is $STATUS." 20 60 1
fi
if get_overlay_now ; then
if get_bootro_conf; then
BPRO="read-only"
else
BPRO="writable"
fi
whiptail --msgbox "The boot partition is currently $BPRO. This cannot be changed while an overlay file system is enabled." 20 60 1
else
DEFAULT=--defaultno
CURRENT=0
STATUS="writable"
if get_bootro_conf; then
DEFAULT=
CURRENT=1
STATUS="read-only"
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the boot partition to be write-protected?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
if [ $RET -eq 0 ]; then
if enable_bootro; then
STATUS="read-only"
ASK_TO_REBOOT=1
else
STATUS="unchanged"
fi
elif [ $RET -eq 1 ]; then
if disable_bootro; then
STATUS="writable"
ASK_TO_REBOOT=1
else
STATUS="unchanged"
fi
else
return $RET
fi
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The boot partition is $STATUS." 20 60 1
fi
fi
do_finish
}
do_overlayfs
# Booting Debian from a RAM disk #
This guide is adapted from http://reboot.pro/topic/14547-linux-load-your-root-partition-to-ram-and-boot-it/
What you need:
* lots of RAM
* Debian based distribution or any that supports booting from initramfs
* mkinitramfs or a tool to build a new initramfs
* some linux knowledge
* no need to create an image
* no need for Grub4Dos
* no need for a "special driver"
Step 1:
Choose a distribution thats supports booting from initramfs. (like ubuntu)
Step 2:
Install to harddisk. Make sure you split it into multiple partitions (/, /boot, /home, swap, ...).
Step 3:
Boot your new system, install updates, drivers if neccessary (this will improve performance), strip it down to the minimum. Every file will be loaded to RAM ! A fresh install uses about 2 GB auf harddisk-space.
Step 4:
modify `/etc/fstab` :
`cp /etc/fstab /etc/fstab.bak` find the line specifing the root partition and change it in:
none / tmpfs defaults 0 0* save
Step 5:
edit the local script in your initramfs:
cd /usr/share/initramfs-tools/scripts/* make a backup of /usr/share/initramfs-tools/scripts/local
cp local local.bak* modify local, find this line:
```
# FIXME This has no error checking
# Mount root
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}
```
change it to:
```
# FIXME This has no error checking
# Mount root
#mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}
mkdir /ramboottmp
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /ramboottmp
mount -t tmpfs -o size=100% none ${rootmnt}
cd ${rootmnt}
cp -rfa /ramboottmp/* ${rootmnt}
umount /ramboottmp
```
* save
* execute, or rebuild initramfs
mkinitramfs -o /boot/initrd.img-ramboot* replace modified local with original file
cp -f local.bak localStep 6:
* modify this file (needs a better solution)
/boot/grub/grub.cfg* copy the first boot entry and replace the /initrd line with this:
/initrd /boot/initrd.img-ramboot* label the new entry as RAMBOOT
This will boot our generated initramfs instead the original one.
Step 7:
* reboot
* choose standart boot (no ramdisk)
* choose RAMBOOT and all your files on the root partition will be loaded to a tmpfs
For me—running Debian 11 (bullseye)—this line:
/initrd /initrd.img-ramboot
should be:
/initrd /boot/initrd.img-ramboot
Otherwise, it works perfectly on my machine.