Can I make SYSLINUX load a root fs from an image file on an NTFS partition?

2

2

SYSLINUX allows me to boot from a FAT16 USB-stick by loading a kernel image and an initial ram-disk (initrd) image from there.

To get more space and a faster access, I can mount an NTFS partition from a hard disk after bootup, then use the loopback device to mount a file system image from there to replace /home or even chroot into it, but that is way after the bootup process, making system updates impossible.

Is there a way to make SYSLINUX itself mount the fs-image from the NTFS partition as root fs?

Or can I modify the initrd image to mount the new root fs way more early in the bootup process? I know how to mount and alter that image, but Iḿ lost in the scripts therein and don't know when and how they are executed.

Chaos_99

Posted 2013-05-25T08:50:35.927

Reputation: 681

Answers

2

Yes, that's possible. And it even works with built-in functions. Just edit your syslinux.cfg to include the following:

LABEL linux
LINUX /boot/vmlinuz
APPEND root=/dev/disk/by-label/data rootfstype=ntfs loop=images/linux_root.img loopfstype=ext4 rw
INITRD /boot/initrd.img 

Obviously, you have to copy your kernel image (vmlinuz) and your initial RAM-disk image (initrd.img) to the FAT partition you want to boot off with SYSLINUX. (The path is relative to the partitions root.)

The root= parameter specifies the device and partition the root file system image lies on. You can of course also use the /dev/sda1 notation or the /dev/disk/by-UUID/SOMECRYPTYCNUMBER version.

The rootfstype specifies the file system of the partition the file system image lies on. NTFS and FAT are both supported out of the box. For more exotic formats you need to edit the initrd.img to include and load the appropriate kernel modules.

loop= gives the path to the root file system image relative to the base of the partition it lies on. loopfstype= specifies its internal type. It will, obviously, be mounted at / after boot. The partition the image was loaded from will me mounted at /host automatically if this folder exists. (You won't be able to mount it anywhere else if it is NOT mounted there atomatically. But you are able to move it to another mount point with mount -m if it is.)

Don't forget to copy and overwrite the kernel and the initrd.img on the FAT partition every time those get updated by a system update or strange things may happen on boot.

Unfortunately, there is no way of including a swap-partition in the same way. You have either to use a real partition for that or try to find a way to activate one after boot from the running system.

Expect approx. 10% CPU overhead for writing into the loop-device mounted through the NTFS-wrapper.

Chaos_99

Posted 2013-05-25T08:50:35.927

Reputation: 681

Excellent Q&A. Will definitely give it a try. Such image based root file system is still writable correct? – xpt – 2014-09-01T14:38:08.510

Yes, the root file system is writable. Of course only within the bounds of its fixed image size. – Chaos_99 – 2014-09-01T20:23:32.643

it depends on /init script in initrd – eri – 2014-02-24T14:32:24.917

worked with the scripts deliverd with the Mint distro version 14 and 15 – Chaos_99 – 2014-02-25T07:42:15.717

yes, it will work on every Ubuntu based distro. – eri – 2014-02-25T20:00:43.917