Difference between revisions of "Creating a Live CD"

From LFScript
 
Line 80: Line 80:
  
 
<pre>./lfscript -Bux fsos -i install_root -I install_overhead</pre>
 
<pre>./lfscript -Bux fsos -i install_root -I install_overhead</pre>
 +
 +
== Security ==
 +
It is a bad idea to keep SSH keys on your Live CD, so remove them:
 +
<pre>rm -rvf install_root/etc/ssh/ssh_host_*_key</pre>
 +
 +
If you have installed OpenSSH (and the OpenSSH bootscript), these keys need to be regenerated using a custom boot script. If you are not installing <code>fsos</code>, take a look at the page '[[FsOS_without_X11]]' for an example of the boot script.
  
 
== Unmount the system image ==
 
== Unmount the system image ==

Latest revision as of 21:22, 15 April 2017

This page guides you through the steps required to create a Live CD of your system. The ability to create a Live CD is one of the core features of LFScript.

All commands presented here should be executed from the LFScript directory

Compile your system

Although it is not required, it is highly recommended that you compile your system into packages beforehand. For example:

./lfscript -Bux fsos

This command builds all packages (except those that are only for the 32-bit version) of fsOS.

Create a system image

dd if=/dev/zero of=sources/rootfs-$(uname -m).img bs=1G seek=10 count=0

This command should instantly create a 10GB sparse file. The file will not actually take up 10GB of your precious free disk space. It's actual size will initially be zero. Once it has a file system, has been mounted and starts to contain actual files it will automatically grow and use real disk space as needed (up to 10GB). This means that the actual size of the file will never be greater than the minimum size needed to contain your system.

Some filesystems do not support sparse files. On those systems, the above command will create a true 10GB file. For example, if you are using Ubuntu and you have your home folder encrypted (ecryptfs), you can not have sparse files anywhere in your home tree.

The file will be created in the sources directory, because the buildiso script will need to be able to find the image.

The $(uname -m) part will automatically resolve to your host system CPU architecture (i686, x86_64, or something else), giving the image a name like rootfs-i686.img. Using $(uname -m) in these commands makes them suitable for copy-pasting on any machine.

Create a file system on the image

This command should work on any machine with a recent kernel:

mkfs.ext4 -F sources/rootfs-$(uname -m).img

However, if you want to optimize for size at this stage (this does NOT affect the size of the final ISO image) and have btrfs available you could issue this one in stead:

mkfs.btrfs sources/rootfs-$(uname -m).img

A compressed btrfs system image will take up about 500MB of space if you just install a basic LFS system on it, compared to 1.3GB for an uncompressed ext4 image.

Any file system for Linux should work just fine, and it does not even matter if the OS you will install in it has support for the file system you have selected. Later on, the image will be converted to SquashFS anyway.

Create temporary installation directories

mkdir -v install_root

And if you would like to keep the overhead of sources and tools directories out of the image (only affects the system image size, not the ISO size):

mkdir -v install_overhead

Mount the system image

If you installed an ext4 fle system on the system image:

mount -o loop sources/rootfs-$(uname -m).img install_root

Or if you used btrfs:

mount -o loop,compress sources/rootfs-$(uname -m).img install_root

Install your system to the image

This installation command takes the form of ./lfscript [your_system_options] -i install_root -I install_overhead. If you did not create the overhead directory, leave out -I install_overhead.

For example:

./lfscript -Bux fsos -i install_root -I install_overhead

Security

It is a bad idea to keep SSH keys on your Live CD, so remove them:

rm -rvf install_root/etc/ssh/ssh_host_*_key

If you have installed OpenSSH (and the OpenSSH bootscript), these keys need to be regenerated using a custom boot script. If you are not installing fsos, take a look at the page 'FsOS_without_X11' for an example of the boot script.

Unmount the system image

umount install_root

Build the ISO image

./lfscript -Bux buildiso

The script that builds the ISO image could just as well be designed for use outside of LFScript (and in fact, with LFScript 3 it was). However, by executing BuildISO through LFScript the ISO is created by your own system, which removes the need to have the utilities required to run BuildISO (like SquashFS and cdrtools for example) installed on your host system. This reduces the risk of build failures considerably.

Once completed, your Live CD ISO image will be saved to your packages directory.

Cleanup

This command removes both the temporary installation directories, and the original system image which you probably don't need anymore:

rm -rvf install_root install_overhead sources/rootfs-$(uname -m).img