recipe of a linux live cd (archived)

15
Recipe of a Linux LiveCD By Buddhika Siddhisena

Upload: bud-siddhisena

Post on 16-Jul-2015

37 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Recipe of a linux Live CD (archived)

Recipe of a Linux LiveCD

ByBuddhika Siddhisena

Page 2: Recipe of a linux Live CD (archived)

2

Agenda

What is a LiveCD

Why run a LiveCD

Understanding the Linux Boot process

Understanding the Linux LiveCD Boot process

How hardware detection could work

Achieving Data Persistence on LiveCD

Short survey of popular LiveCDs

Page 3: Recipe of a linux Live CD (archived)

3

What is a LiveCD

Is a CD that contains an Operating System (OS), capable of booting offdirectly, without first having to be installed.

Will generally have automatic hardware detection, as the OS boots.

May contain more data than the physical size of a CDROM (~700MB) byusing on-the-fly decompression of the file system.

Generally slower to boot when compared to HDD, mainly due to sloweraccess times of CDROM drives.

May offer the ability to remember configuration settings by saving themon to a drive (USB, floppy or HDD).

May offer it to be installed to the hard disk permanently

Page 4: Recipe of a linux Live CD (archived)

4

Why run a LiveCD

Provides an alternative way to try out a new OS/distribution.

Can be used to instantly convert any desktop to your desktop! And youcan't get blamed for doing so.

Can be a valuable resource for recovering data, resetting passwords etc.

Can be used to distribute a demo versions of software thats guaranteed towork with minimum hassle.

And endless other possibilities....

Page 5: Recipe of a linux Live CD (archived)

5

Understanding the Linux Boot process

As the machine boots the BIOS looks for a bootable media depending onthe boot sequence.

BIOS loads the bootloader from a special area in the disk called theMaster Boot Record (MBR). On linux it is usually either LILO or GRUB.

LILO (or GRUB) will attempt to load the kernel and optionally an initialRAM disk (initrd), if specified.

Control is passed to the kernel as it decompresses the initrd and mounts itas the root device.

Page 6: Recipe of a linux Live CD (archived)

6

Understanding the Linux Boot process

The kernel executes /linuxrc from the root device. It will perform variouspre-boot tasks such as loading of additional drivers.

Once linuxrc exits control is passed back to the kernel which will thenmount the real root device as the root file system.

/sbin/init from the real root system is executed which uses /etc/inittabconfiguration to boot rest of the system.

/etc/inittab defines the default runlevel (usually 3 or 5) and as part ofthe boot process all scripts in /etc/rcX.d/ are executed.

Page 7: Recipe of a linux Live CD (archived)

7

Linux boot process in a nutshell

Power supply ON

PC BIOS starts

BIOS looks for a bootable mediaaccording to the setting andloads a program(=LILO) writtenon MBR of a hard drive, and thenLILO gains control.

LILO loads akerne(vmlinuz)andan initial RAMdisk(initrd)Kernel gains control

Kernel expandsinitrd andmounts it as atemporary rootfile system

If an executable /linuxrc existsin the initrd, the kernelexecutes it.

After the /linuxrc isfinished, the kernelmounts a real rootfile system which maybe /dev/hda1

/sbin/init executes/etc/rc.d/rc.sysinitaccording to adescription of/etc/inittab.

Next, init executes/etc/rc.d/rc with a default run level asan argument

For example, in run level 3, /etc/rc.d/rcexecutes shell scripts likeSnnXXXX(nn=number) under /etc/rc.d/rc3.ddirectory in order of S00XXXX to S99XXXXwith a start argument

Page 8: Recipe of a linux Live CD (archived)

8

Understanding the Linux LiveCD Boot process

BIOS finds a bootable CDROM and loads the bootloader (usuallyISOLINUX which is based on the Syslinux bootloader)

ISOLINUX will load the initrd and the kernel image and transfer controlto the kernel.

The kernel decompresses initrd and mounts it as root and executes the/linuxrc script from the LiveCD.

Page 9: Recipe of a linux Live CD (archived)

9

Understanding the Linux LiveCD Boot process

It will load kernel modules required, attempt to guess the CDROM device andmount it. Finally linuxrc will change the real root device of the kernel to thatof initrd, or LiveCD and exit.

#!/bin/shecho Mounting /proc filesystemmount -t proc /proc /procecho Attempting to Mount CD-ROM(mount -t iso9660 /dev/hdb /mnt/cdrom && ln -s /dev/hdb /dev/cdrom) ||(mount -t iso9660 /dev/hdc /mnt/cdrom && ln -s /dev/hdc /dev/cdrom) ||(mount -t iso9660 /dev/hdd /mnt/cdrom && ln -s /dev/hdd /dev/cdrom) ||(mount -t iso9660 /dev/hda /mnt/cdrom && ln -s /dev/hda /dev/cdrom) ||(echo 'cannot mount CD-ROM, dropping you to a shell';sh)echo 0x0100 > /proc/sys/kernel/real-root-dev

umount /proc

Hardware detection scripts will take over as a runlevel service toconfigure the rest of the system.

Page 10: Recipe of a linux Live CD (archived)

10

Hardware detection process

Scripts can use tools such as lspci, /proc/bus/pci/devices, /proc/bus/usb/devicesetc. to determine the system hardware.

bud@babytux bud $ /sbin/lspci0000:00:01.0 PCI bridge: ATI Technologies Inc: Unknown device 70100000:00:02.0 USB Controller: ALi Corporation USB 1.1 Controller (rev03)0000:00:06.0 Multimedia audio controller: ALi Corporation M5451 PCI AC-Link Controller Audio Device (rev 02)0000:00:09.0 Network controller: Harris Semiconductor Prism 2.5 Wavelanchipset(rev 01)0000:00:10.0 IDE interface: ALi Corporation M5229 IDE (rev c4)0000:00:12.0 Ethernet controller: National Semiconductor CorporationDP83815 (MacPhyter) Ethernet Controller0000:01:05.0 VGA compatible controller: ATI Technologies Inc: Unknowndevice 4337

Then by using a database or some sort of pattern matching we can loadthe correct kernel modules to drive those devices.

Check out the Linux PCID Repository at http://pciids.sourceforge.net/ or thefile /usr/share/misc/pci.ids

Page 11: Recipe of a linux Live CD (archived)

11

Hardware detection process

Other tools such as kudzu(http://rhlinux.redhat.com/kudzu/) that comeswith Redhat or discover(http://hackers.progeny.com/discover/) canalso be used

Configuring X windows can be done using tools such using XFree86 andtools such as ddcprobe or read-edid to detect monitor refresh rates.

# XFree86 -configure# get-edid | parse-edid

Usually the /etc, /home and /tmp directories will reside on an ramdiskand will be symlinked from the LiveCD to be able to save settings

Certain files in the /dev directory should also reside on a ram disk.(e.g. /dev/tty*, /dev/pts/* etc.)

Page 12: Recipe of a linux Live CD (archived)

12

Achieving Data Persistence on LiveCD

Data persistence can be achieved by running a shell script to store thecontent of /home or /etc on a USB flash or HDD.

#!/bin/shmount /dev/sda1 /mnt/usbtar -zcvf /mnt/usb/home.tar.gz /hometar -zcvf /mnt/usb/etc.tar.gz /etc

When booting the live CD using ISOLinux, it is possible to passparameters to the kernel, even once that the kernel doesn't understand

boot: linux26 vga=791 home=/mnt/sda etc=/mnt/sda

A bootup script could read this value by examining /proc/cmdline

# cat /proc/cmdline

Page 13: Recipe of a linux Live CD (archived)

13

Short survey of popular LiveCDs

Knoppix - Knoppix is a Live Linux CD based on Debian GNU/LinuxExcellent hardware detectionUses on the fly transparent decompression to store 2.5GB or dataEasy to remaster and make your own LiveCD (e.g. Gnoppix, Damn Small

Linux(DSO), Sinhala Knoppix)http://www.knoppix.net

Mepis – Based on Debian GNU/LinuxVery Good harware detection.Uses on the fly decompression to store about 1.1GB or dataContains some non-free software such as Flash, Java, RealPlayer etc.Easy to install to the HDDhttp://www.mepis.org/

SLAX – Slackware based LiveCD

Fast, works well on slightly older hardwareFits on to a mini CD since the image is only 185MBhttp://slax.linux-live.org/

Page 14: Recipe of a linux Live CD (archived)

14

Short survey of popular LiveCDs

LNX/BBC – Portable card-sized distribution Design to fit to a credit card size CDhttp://www.lnx-bbc.org

Mandrake Move – A live CD based on Mandrake LinuxCommercial and free edition available.http://www.mandrakesoft.com/products/mandrakemove

FreeBSD LiveCD – A LiveCD based FreeBSD OS

http://livecd.sourceforge.net/

Page 15: Recipe of a linux Live CD (archived)

15

Thank You!