Goal
To build a minimal Debian based Linux system with a fully functional bash shell, TCP/IP networking with DHCP client and apt setup to be able to install any package from the Debian repositories. The resulting system will use about 157 MB disk space and consume less than 10 MB RAM.
This is now implemented in Bachata Linux.
Prerequisites
A Debian based Linux system to work from (e.g. Ubuntu desktop) with the debootstrap and extlinux packages installed. Some virtualization environment is highly recommended for testing, such as KVM/QEMU.
Install system
This will install the system on a disk mounted at mnt. Choose a hostname for the instance to create, substitute it for ${HOSTNAME}. Substitute the URL to your nearest Debian mirror for ${MIRROR}.
sudo debootstrap --variant=minbase --include=localepurge,netbase,ifupdown,net-tools,isc-dhcp-client,linux-base,linux-image-2.6-686,linux-image-2.6.32-5-686 squeeze mnt ${MIRROR}- sudo rm mnt/etc/udev/rules.d/70-persistent-net.rules
- sudo rm mnt/var/cache/apt/archives/*
- sudo rm mnt/var/cache/apt/*.bin
- sudo rm mnt/var/lib/apt/lists/*
- sudo rm mnt/var/log/dpkg.log*
- sudo rm mnt/var/log/apt/*
- sudo mkdir mnt/boot/extlinux
sudo extlinux --install mnt/boot/extlinux- sudoedit mnt/boot/extlinux/syslinux.cfg
default linux label linux kernel /boot/vmlinuz-2.6.32-5-686 append initrd=/boot/initrd.img-2.6.32-5-686 root=UUID=${UUID} ro quietOnly for KVM/QEMU: add
console=ttyS0to the “append” line - sudoedit mnt/etc/inittab
For KVM/QEMU: uncomment getty ttyS0 and comment out getty tty[1-6]
For others: comment out getty tty[2-6] - sudoedit mnt/etc/passwd – blank password for root
- sudoedit mnt/etc/network/interfaces
auto lo iface lo inet loopback allow-hotplug eth0 iface eth0 inet dhcp
- sudoedit mnt/etc/fstab
# /etc/fstab: static file system information. # # Use 'blkid -o value -s UUID' to print the universally unique identifier # for a device; this may be used with UUID= as a more robust way to name # devices that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc nodev,noexec,nosuid 0 0 UUID=${UUID} / ext2 errors=remount-ro 0 1 - sudoedit mnt/etc/hostname
${HOSTNAME} - sudoedit mnt/etc/locale.nopurge
MANDELETE DONTBOTHERNEWLOCALE SHOWFREEDSPACE #QUICKNDIRTYCALC #VERBOSE en
- sudoedit mnt/etc/apt/sources.list
deb ${MIRROR} squeeze main deb-src ${MIRROR} squeeze main deb http://security.debian.org/ squeeze/updates main deb-src http://security.debian.org/ squeeze/updates main # squeeze-updates, previously known as 'volatile' deb ${MIRROR} squeeze-updates main deb-src ${MIRROR} squeeze-updates main - sudoedit mnt/etc/apt/apt.conf.d/02nocache
Dir::Cache { srcpkgcache ""; pkgcache ""; } - sudoedit mnt/etc/apt/apt.conf.d/02compress-indexes
Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";
- sudo chroot mnt localepurge
- sudo chroot mnt apt-get update
- sudo chroot mnt passwd root
Install on a physical disk
- Create a bootable partition of at least 288 MB with system code 83 “Linux” using
fdisk - sudo mke2fs -L ${HOSTNAME} -t ext2 /dev/xxxx
- sudo UUID=`blkid -o value -s UUID /dev/xxxx`
- mkdir mnt
- sudo mount /dev/xxxx mnt
- Install system as above
- sudo umount mnt
Install in KVM/QEMU
- dd if=/dev/zero of=${HOSTNAME}.img bs=1024 count=288K
- mke2fs -L ${HOSTNAME} -t ext2 ${HOSTNAME}.img
- UUID=`blkid -o value -s UUID ${HOSTNAME}.img`
- mkdir mnt
- sudo mount ${HOSTNAME}.img mnt
- Install system as above
- sudo umount mnt
virt-install --connect qemu:///system -n ${HOSTNAME} -r 256 --os-type linux --os-variant debiansqueeze --import --disk path=${HOSTNAME}.img --network=network:default --graphics none --virt-type kvm
Use --virt-type qemu if your CPU doesn’t support virtualization.
Then you can start it with virsh start ${HOSTNAME} and connect to it with virsh console ${HOSTNAME}
For some reason, doing reboot from inside the guest doesn’t seem to work properly. virsh reboot and virsh shutdown doesn’t work either (you might get that to work by installing some ACPI stuff in the guest). Use halt from inside the guest to have a clean shutdown, and then restart it with virsh start.
Install in VirtualBox 4.1
First create a virtual machine in VirtualBox with an empty VDI disk ${VDI_FILE} of least 288 MB.
Install VDI mounting tool according to this description.
- mkdir vdi-mount
- vdfuse-v82a -f ${VDI_FILE} vdi-mount
- mke2fs -L ${HOSTNAME} -t ext2 vdi-mount/EntireDisk
- mkdir mnt
- sudo mount vdi-mount/EntireDisk mnt
- Install system as above
- sudo umount mnt
- fusermount -u vdi-mount
Then start the virtual machine in VirtualBox.
Install in other virtualization environments
Please tell me how!
Updated with disabling apt cache to save some more disk space.
Remove some log files.
Compress apt indexes.
Fix Debian mirror URL.
Added localepurge.
Clarify Debian mirrors.
Updated required size of disk image.
Updated with using chroot.
Updated with using UUID for root device.
Fixed network configuration.
This is now implemented in Bachata Linux.
Pingback: Bachata Linux | Mikael Ståldal’s technical blog
maybe it would be cool to replace the default mirror with http://http.debian.net as this will also benefit each user, that runs the system later on. That way the nearest mirror is determined at runtime.
Thanks for this. With VirtualBox I was getting:
FATAL: No bootable medium was found.
This was because there was no MBR on the virtual disk. This fixed it for me:
mkdir /tmp/mnt; vdfuse -f ${HOSTNAME}.vdi /tmp/mnt
dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr.bin of=/tmp/mnt/EntireDisk
Thank you so much for your blog.
Could you please let me know how to create it as iso file?
Regards
Here I describe how to create it as an ISO file:
http://www.staldal.nu/tech/2012/01/04/how-to-roll-your-own-bootable-linux-cd-rom/