I have created a bootable CD from a USB stick (built from Ubuntu core 12.04 according to this example) by
- copying the files of the USB stick's boot partition (containing vmlinuz and initrd.img) into a folder
CD_root/
, - adding isolinux to that folder (according to these instructions)
- copying an image
rootfs.part
of the root partition of the USB stick into the folder and - using mkisofs.
How can I boot from DVD into the image of the root partition?
Some more details and a somewhat more precise version of the question:
I can start booting into the init script (using virtualbox on a Ubuntu 12.04 host): With kernel parameter break=mountroot
I can drop to a shell right before the image rootfs.part
should be mounted and insert:
mkdir /run/cdrom
mount -t iso9660 /dev/sr0 /run/cdrom
losetup /dev/loop0 /run/cdrom/rootfs.part
mount -o ro /dev/loop0 /root
How could I achieve this part (or its gist of mounting /root) automatically? Do I have to patch initrd.img
(how) or are there other options such as maybe kernel parameters?
At this point, the files inside rootfs.part
are visible at root/
. (They include /root/sbin/init
, /root/sbin/modprobe
, root/lib/modules/*
, …) I tried to continue and simulate the normal proceeding of the init script (certainly somewhat out of context):
udevadm control --timeout=121 --exit
mount -n -o move /dev /root/dev
mount -n -o move /run/ /root/run
mount -n -o move /sys /root/sys
mount -n -o move /proc /root/proc
exec run-init /root /sbin/init </dev/console >/dev/console 2>&1
Unfortunately, this doesn't lead very far. Lots of error messages about missing modprobe
and devices such as /dev/loop0
not existing appear and repeat infinitely. (Maybe the DVD should be mounted differently?)
Best Answer
Abstract
Meanwhile, I managed to solve the problem. My key mistake was to mount the image of the root partition without write permission (as it is stored on DVD). Currently, the usual workaround for this appears to be using
overlayfs
andtmpfs
. Additionally, it appears to be common practice to use squashfs for providing the image of the root partition.Alternative solution
With Remastersys, there exists a package that can backup a running Debian system to a Live-DVD. While I managed to get it to build a booting DVD, I found the result not satisfying for my purposes. (Some issues: The existing system has to be modified. There was too much emphasis on reinstalling the Live-DVD and additional packages. There were too many features to be configured. On each boot of the DVD, there were two minutes of waiting for some network configuration.) Additionally, I find it hard to understand what is really going on. So I chose another way.
My solution
In the following, I give the details of what I did as
root
on a Ubuntu 12.04. I've stripped away any application specific elements trying to provide a concise and general example for creating a bootable DVD from a USB stick booting a Linux based on Ubuntu Core 12.04. (Because of the stripping, the code shown below is not tested. So please tell me if you find a mistake and I will fix it.)Configuring isolinux
First the DVD filesystem structure is created within a directory
CD_root
(cf. Isolinux)I assume that the boot partition of the bootable stick is mounted under
stick_boot/
and that the kernel booted is stored there and namedvmlinuz
.The content of
isolinux.cfg
is as follows:VMLINUZ
), even if it is copied to the CD filesystem in lowercase letters.INITRD.IMG
.rootfs.squash
must be specified without such changes./dev/sda1
) is enough to have it mounted usingsquashfs
.Building the initrd
The
initrd.img
used on the bootable stick must be patched. The rootfs of the bootable stick can be used to build the patched initrd. It can be protected from permanent changes by usingoverlayfs
andtmpfs
(in the same way as these will be used to provide a writable version of the squashed root filesystem stored on the DVD). I assume that the root filesystem of the bootable stick (that is to be protected from change) is mounted understick_rootfs
:patch_root/
.Two modules must be added to the initrd:
During the boot, the DVD must be mounted under
/cdrom
so that the squashed image of the root filesystem/cdrom/rootfs.squash
is accessible. This is achieved with the following local-premount script:Its content is:
This script must be executable:
The writeable view of the root filesystem is provided by a well documented script
root-ro
which I took with little changes from this german / english source.The essential changes concern the modifications applied to the fstab at the bottom of the script. I only use a single entry for the
proc
filesystem (I remove any entries for root/
or/boot
):The patched initrd can now be built within a
chroot
environment on the protected root filesystem of the stick:uname -r
on the booted system on the USB stick).Now the patched initrd can be copied to the isolinux folder:
The changes to
stick_rootfs
can now be undone / forgotten:Building the root filesystem
The squashed image of the root filesystem of the bootable stick must also be patched. Again the image of the stick is protected using
overlayfs
andtmpfs
(reusing the directories already created):Old cache files should be removed to avoid hanging / failing network configuration, when booting from DVD:
Optionally, the eject script from casper (as used e.g. in the DVDs produced by
remastersys
) could be used to eject the DVD at shutdown:The patched image can now be squashed:
The changes to
stick_rootfs
can now again be undone / forgotten:Creating the DVD image
Finally the iso image
dvd.iso
can be created:That's all. The iso image is ready to be burned to a CD / DVD.
Some Warnings
I got to this solution mostly by trial and error. Thus, I'm not so confident, that a stable system emerges. (Still, up to now, after some tests on virtualbox and a few iMacs, this appears to be the case.)
The way to provide access to the content of the booting CD / DVD (cf. init script
/etc/initramfs-tools/scripts/local-premount/cdmount
) could certainly be improved: In the presence of multiple optical drives, probably all of them should be checked (sr?, hd?, ...). I don't know how to directly determine the device from which the CD / DVD is being booted. I feel this should be possible (maybe evaluating/sys
or/proc
?). Maybe, it was not even necessary to explicitly mount the booting device (another time?)? After all, its content is already being accessed when executing the init scripts.The file
/etc/fstab
in the squashed image of the root partition could probably use an entry for the (properly mounted) CD / DVD.Maybe the
/boot
directory on the iso image should contain the usual files and be properly mounted into the life system. This might provide more flexibility when working with the life system (such as: temporarily installing software modifying the initrd during a life session, providing better output when debugging in a life session, ...)?