Creating Debian Jessie live media using netinstaller iso

Why using netinstall iso?
Well... nothing really special behind my choice of source installation medium, but i already download the net install iso and i really don't want to re-download the base system for my debian jessie system.

What's the requirement for making this minimal live system installation?
a working debian system, in my case a debian lenny system
an internet connection

Now, here's the step to create debian jessie live media:

1. Mount netinstall iso
    root@lennycom:/# mount -o loop <YOUR-ISO-LOCATION> <YOUR-MOUNT-LOCATION>    

   in my case, my iso is at /media/Data1/debian-8.4.0-amd64-netinst.iso  and my mount location is at /media/unt, so the command is:
    root@lennycom:/# mount -o loop /media/Data1/debian-8.4.0-amd64-netinst.iso /media/unt

2. Create new folder and rename it to livemedia-try1. go to the livemedia-try1 folder and create new folder, then rename it to liveimage.

    root@lennycom:/# mkdir /media/Data2/livemedia-try1
    root@lennycom:/# cd /media/Data2/livemedia-try1
    root@lennycom:/media/Data2/livemedia-try1# mkdir liveImage
    root@lennycom:/media/Data2/livemedia-try1# mkdir liveImage/live

3. Use debootstrap command to create a temporary debian system.

     root@lennycom:/media/Data2/livemedia-try1# debootstrap --arch=amd64 --variant=minbase --no-check-gpg jessie tmpRoot file:///media/unt/

   This step will create a new folder named tmpRoot, which is our temporary debian system. At this point, we have two sub-folder under livemedia-try1 folder. The first one is liveImage folder which contain live sub-folder, the other one is tmpRoot, which contain our temporary debian jessie system. Now we'll make several adjustment to the tmpRoot folder so that our system can boot properly.

4. Next step is to execute chroot command to temporaily set our root environment to tmpRoot folder, but before we do that, we'll setup several adjustment so our temporary root can function properly.

4.1 We need to set up the dns server so our temporary system can properly connect to internet and find debian repository. To do that, we copy resolv.conf from our current system to the tmpRoot system.

    root@lennycom:/media/Data2/livemedia-try1# cp /etc/resolv.conf ./tmpRoot/etc/resolv.conf
4.2 Next, we need to bind our /dev folder to our tmpRoot/dev folder. To do that, run mount command with bind option:
    root@lennycom:/media/Data2/livemedia-try1# mount -o bind /dev tmpRoot/dev/
4.3 Now we can temporarily change our root folder to tmpRoot by doing chroot command:
    root@lennycom:/media/Data2/livemedia-try1# chroot tmpRoot


5. Mount proc,sys and devpts:

    root@lennycom:/# mount -t proc none proc
    root@lennycom:/# mount -t sysfs none sys
    root@lennycom:/# mount -t devpts none /dev/pts

6. Set LC_ALL and HOME environment variable:
    root@lennycom:/# export LC_ALL=C
    root@lennycom:/# export HOME=/root

7. Update apt-get database:
    root@lennycom:/# apt-get update
8. Install necessary packages. For minimal installation we will install dbus, uuidgen, linux-image-amd64 and live-boot, but feel free to add more package if you want to..
    root@lennycom:/# apt-get install dialog dbus linux-image-amd64 live-boot

8.1 Answer Yes to continue installation

9. Set root password so we can logged into the newly installed system later
    root@lennycom:/# passwd root
10. The temporary system is ready for booting, now we unmount proc, sysfs and devpts before exiting the temporary root
    root@lennycom:/# umount -lf proc
    root@lennycom:/# umount -lf sys
    root@lennycom:/# umount -lf dev/pts

11. Exit the temporary root
    root@lennycom:/# exit

12. Unbind the dev folder in tmpRoot
    root@lennycom:/media/Data2/livemedia-try1# umount -lf tmpRoot/dev
13. Create squashfs for the system
    root@lennycom:/media/Data2/livemedia-try1# mksquashfs tmpRoot liveImage/live/system.squashfs
14. Copy vmlinuz and initrd from boot folder inside tmpRoot to liveImage/live folder
    root@lennycom:/media/Data2/livemedia-try1# cp tmpRoot/boot/vmlinuz<PRESS-TAB-BUTTON-TO-COMPLETE-THE-FILENAME> liveImage/live/

    root@lennycom:/media/Data2/livemedia-try1# cp tmpRoot/boot/initrd<PRESS-TAB-BUTTON-TO-COMPLETE-THE-FILENAME> liveImage/live/

15. Copy bootloader to make the media bootable. Since we will build a live iso cd, then our bootloader will be isolinux. An alternative option if we want to make a live usb drive is to use syslinux, which basically is the same thing only a little different in the details.

15a. Making a bootable iso cd
    - Copy all necesary files to isolinux folder
        root@lennycom:/media/Data2/livemedia-try1#cd liveImage

        root@lennycom:/media/Data2/livemedia-try1/liveImage# cp /usr/share/misc/pci.ids ./isolinux/ 

        root@lennycom:/media/Data2/livemedia-try1/liveImage# cp /usr/lib/syslinux/isolinux.bin ./isolinux/

        root@lennycom:/media/Data2/livemedia-try1/liveImage# cp /usr/lib/syslinux/menu.c32 ./isolinux/ 

        root@lennycom:/media/Data2/livemedia-try1/liveImage# touch ./isolinux/isolinux.cfg

    - Open isolinux.cfg with text editor and put these lines:

        UI menu.c32

        prompt 0

        menu title Jessie Live

        timeout 50
        label Debian Jessie
        menu label ^Debian Jessie
        menu default
        kernel /live/vmlinuz
        append initrd=/live/initrd.img boot=live       
    - create live iso cd using genisoimage

        root@lennycom:/media/Data2/livemedia-try1/liveImage# genisoimage -rational-rock -volid "Debian Live" -cache-inodes -joliet -full-iso9660-filenames -b isolinux/isolinux.bin -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -output ../debian-live.iso ./

15b. An altenative bootable usb drive
    - Make sure usb drive is bootable by set the boot flag on.
   - Mount usb drive and copy all necessary files to root folder of the usb drive

        mount /dev/<YOUR-USB-DEVICE-PARTITION> /media/usbdrive

        cd /media/usbdrive
        root@lennycom:/media/usbdrive# cp /usr/share/misc/pci.ids ./
        root@lennycom:/media/usbdrive# cp /usr/lib/syslinux/menu.c32 ./
        root@lennycom:/media/usbdrive# touch ./syslinux.cfg

    - Open syslinux.cfg with text editor and put the same lines as the isolinux.cfg above.
    - transfer syslinux by executing this command:

       syslinux -i /dev/<YOUR-USB-DEVICE-PARTITION>
      in my case, the usb device partition is on /dev/sdc1 so the command is:
        root@lennycom:/media/usbdrive# syslinux -i /dev/sdc1 
    - Copy the mbr binary to the usb device mbr by executing this command:
        root@lennycom:/media/usbdrive# dd if=/usr/lib/syslinux/mbr.bin of=/dev/sdc bs=440 count=1 conv=notrunc

16. Done. Now it's time to test the iso linux.

0 Responses to "Creating Debian Jessie live media using netinstaller iso"