Debian live

From campisano.org
Jump to navigation Jump to search

Debian live on USB pen-drive using Grub 2

Intro

This tutorial will show how to prepare a USB pen-drive with a bootable Debian GNU/Linux LIVE system.


Usually, LIVE system are read-only. This means that the user lost any changes at reboot. To avoid that, this pen-drive will have have a separate partition to store the user modified data. Moreover, Windows systems will not like this such of pen-drive with filesystem different than his FAT filesystem. To avoid problems with Windows, this pen-drive will have an additional separate partition to work both with Windows (MacOS etc.) and Linux systems.


At the end of the follow tutorial, we will have a pen-drive formatted with the follows partitions:

  • a Windows compatible FAT32 partition (of any size)
  • a bootable Linux EXT2 partition with Grub bootloader and Debian Live ISO image (currently need to be >= 2.5GB)
  • a Linux EXT4 partition used for Persistence, i.e. to save your data (better if >= 2GB).


Note: this tutorial use an ISO image named 'unofficial', but not worry: this image comes from the debian.org site, it is tagged as unofficial only because it contains non-free firmware usually useful to have something like wireless drivers working without have to do more work.

Take a look at the following sample links to choose your iso image:

In this example, we will use the archive stable image with firmware (unofficial) and XFCE from the follow link:

USB pen-drive partition

  • partition the pen-drive (in this example is a 16GB pen-drive, the device name on your computer will be different, in this example we will use /dev/sdX)


NOTE, your ISO image file cannot be stored on the Windows or Persistence partitions, or they will be mounted only 'read-only' inside the Debian LIVE system.


We will made 3 partitions:

  • 1) /dev/sdX1 partition with a Windows compatible FAT32 filesystem of 6GB, to share data between different O.S.;
  • 2) /dev/sdX2 partition with a bootable Linux EXT2 filesystem of 3GB containing the Grub bootloader and the Debian LIVE ISO image (it MUST be greater than your ISO image);
  • 3) /dev/sdX3 partition with a Linux EXT4 filesystem with the remaining space, used for Persistence, to keep your user data and to install custom programs.
root@host:~# fdisk -c=nondos -u=sectors /dev/sdX
o       ## empty all
n       ## new
p       # primary
[enter] # default, partition 1
[enter] # default, start at initial disk
+6G     # 6GB of size
t       # type of the unique existen partition
c       # W95 FAT32 (LBA) partition up to 2Tb size
n       ## new
p       # primary
[enter] # default, partition 2
[enter] # default start at the end of previous partition
+3G     # 3GB size
t       # type of the only partition
2       # select partition 2
17      # Hidden HPFS/NTFS
a       # enable boot
2       # select partition 2
n       ## new
p       # primary
[enter] # default, partition 3
[enter] # default start at the end of previous partition
[enter] # all remaining space
t       # type of the only partition
3       # select partition 3
17      # Hidden HPFS/NTFS
p       ## print new future partition, check if is equal to below description
w       ## WRITE CHANGES AND EXIT!!!
root@host:~# 


  • If all is ok, your configuration is something like:
root@host:~# fdisk -c=nondos -u=sectors -l /dev/sdX

Disk /dev/sdX: 14.6 GiB, 15614803968 bytes, 30497664 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb4b3e678

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sdX1           2048 12584959 12582912    6G  c W95 FAT32 (LBA)
/dev/sdX2  *    12584960 18876415  6291456    3G 17 Hidden HPFS/NTFS
/dev/sdX3       18876416 30497663 11621248  5.6G 17 Hidden HPFS/NTFS

Prepare the first partition for Windows use

root@host:~# mkfs.vfat -v -n win_usb -F 32 /dev/sdX1

Prepare the second partition for Debian Live Image

root@host:~# mkfs.ext2 -v -L debian_live /dev/sdX2
root@host:~# mkdir /tmp/sdX2
root@host:~# mount -t ext2 /dev/sdX2 /tmp/sdX2
root@host:~# mkdir -p /tmp/sdX2/boot/debian
root@host:~# wget -c -P /tmp/sdX2/boot/debian http://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/archive/9.5.0-live+nonfree/i386/iso-hybrid/debian-live-9.5.0-i386-xfce+nonfree.iso
root@host:~# umount /tmp/sdX2
root@host:~# rmdir /tmp/sdX2

Prepare the second partition to be bootable with Grub bootloader

root@host:~# mkdir /tmp/sdX2
root@host:~# mount -t ext2 /dev/sdX2 /tmp/sdX2
root@host:~# mkdir -p /tmp/sdX2/boot/
root@host:~# apt-get install grub-pc-bin
root@host:~# grub-install --no-floppy --recheck --target=i386-pc --boot-directory=/tmp/sdX2/boot /dev/sdX
root@host:~# nano /tmp/sdX2/boot/grub/grub.cfg
  • Edit the content of /tmp/sdX2/boot/grub/grub.cfg :
search --no-floppy --set=root --label debian_live

set debian_iso_path=/boot/debian/debian-live-9.5.0-i386-xfce+nonfree.iso
set debian_vmlinuz=(loop)/live/vmlinuz-4.9.0-7-686
set debian_initrd=(loop)/live/initrd.img-4.9.0-7-686

menuentry "Debian GNU/Linux Live" {
    echo ${root}
    echo ${debian_iso_path}
    echo ${debian_vmlinuz}
    echo ${debian_initrd}
    loopback loop ${debian_iso_path}
    linux ${debian_vmlinuz} boot=live findiso=${debian_iso_path} persistence persistence-media=removable-usb persistence-storage=filesystem components
    initrd ${debian_initrd}
}
  • cleanup
root@host:~# umount /tmp/sdX2
root@host:~# rmdir /tmp/sdX2

Prepare the third partition for Debian Live persistence

root@host:~# mkfs.ext4 -v -L persistence /dev/sdX3
root@host:~# mkdir /tmp/sdX3
root@host:~# mount -t ext4 /dev/sdX3 /tmp/sdX3
root@host:~# nano /tmp/sdX3/persistence.conf
  • Edit the content of /tmp/sdX3/persistence.conf :
/home
/root
/etc
/bin union
/sbin union
/srv union
/usr union
/var union
  • Cleanup
root@host:~# umount /tmp/sdX3
root@host:~# rmdir /tmp/sdX3

Additional Packages

After the Debian LIVE boot, you can install additional packages, for instance:

sudo apt-get update
sudo apt-get install gcc g++ make autoconf automake cmake git git-gui gitk geany diffuse kdiff3-qt

References

See also

  • Knoppix with persistence: [1]