📜 ⬆️ ⬇️

Live debian

Good all the time of day!

Imagine the situation: you have a well-tuned and debugged system running Debian. At some point you want to make this system installed on the HDD start to boot from a USB flash drive or from a CD and work in ReadOnly mode. A typical application of such a solution is various street kiosks or thin clients, the state of which is reset to its original state upon each reboot.

Today I want to talk about how to achieve a similar result, but first a little theory.
As you know, the Linux operating system Debian being installed on the HDD consists of 4 fairly independent components, each of which can be selected or customized to your taste, namely:
')
1. The loader is what runs after the BIOS and loads Debian. The default is “GRUB”, but you can use any other. We will use Syslinux because able to load the OS from a flash drive, CD-ROM and the network.
2. Kernel or “core” is actually the central part of the OS around which everything is spinning. We will use what comes as part of the distribution.
3. initrd is an intermediate file system that helps the kernel find RootFS. Requires a small modification, fortunately not manual.
4. RootFS - root FS. This is what we have to convert so that the OS can boot in RO mode.

We believe that you already have a system with all the programs and packages that interest you. Let us analyze the work of the script that will do everything for us:
#!/bin/bash #      initrd   "/boot",   ,      VMLINUZ="vmlinuz-3.2.0-4-amd64" INITRD="initrd.img-3.2.0-4-amd64" ISO="iso"<source lang="bash"> #   ,      : apt-get install squashfs-tools apt-get install live-boot live-boot-initramfs-tools apt-get install mtools syslinux dosfstools #       [ -d /$ISO ] && rm -rf /$ISO mkdir /$ISO mkdir /$ISO/binary mkdir /$ISO/binary/live mkdir /$ISO/binary/syslinux mkdir /$ISO/fscopy #    RootFS       tar -cpf - --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=boot --exclude=$ISO . | tar xf - -C /$ISO/fscopy/ rm -r /$ISO/fscopy/tmp/* /$ISO/fscopy/var/tmp/* rm /$ISO/fscopy/var/cache/apt/archives/*.deb rm /$ISO/fscopy/etc/udev/rules.d/*-persistent-net.rules rm /$ISO/fscopy/initrd.img /$ISO/fscopy/vmlinuz > /$ISO/fscopy/etc/fstab mkdir /$ISO/fscopy/proc mkdir /$ISO/fscopy/sys mkdir /$ISO/fscopy/dev/pts #   RootFS    squashfs mksquashfs /$ISO/fscopy/* /$ISO/binary/live/filesystem.squashfs #    initrd    cp /boot/$INITRD /$ISO/binary/live/initrd.img cp /boot/$VMLINUZ /$ISO/binary/live/vmlinuz #    "syslinux.cfg"   Syslinux cat > /$ISO/binary/syslinux/syslinux.cfg <<EOF CONSOLE 0 default linux label linux kernel /live/vmlinuz append initrd=/live/initrd.img boot=live quiet splash noconfig ro EOF #  ,     "/iso/binary/"  ,     dd     #  ,        "/iso/binary/" # /iso/binary/live/vmlinuz —  # /iso/binary/live/initrd.img — initrd,        Squashfs # /iso/binary/live/filesystem.squashfs — RootFS    # /iso/binary/syslinux/syslinux.cfg —    dd if=/dev/zero of=/$ISO/Debian_ro.img bs=10M count=35 LOFI=`losetup -f` losetup $LOFI /$ISO/Debian_ro.img mkdosfs -I $LOFI syslinux $LOFI TMP_DIR="/tmp/$$" mkdir $TMP_DIR mount $LOFI $TMP_DIR cp -r /$ISO/binary/* $TMP_DIR umount $TMP_DIR; rm -r $TMP_DIR losetup -d $LOFI #       "Debian_ro.img",       


Some useful links:

A rather detailed description in Russian of the features of the Squashfs file system: ru.wikipedia.org/wiki/Squashfs
Description of all additional parameters that can be passed to the kernel: live.debian.net/manpages/2.x/en/html/live-boot.7.html

PS If there is a sufficiently large number of applicants, then the topic can be continued with the articles “Live CentOS” and “Live Solaris 10”.

Source: https://habr.com/ru/post/226973/


All Articles