Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Root partition as SquashFS + Aufs2 [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
claudio
Tux's lil' helper
Tux's lil' helper


Joined: 11 Sep 2005
Posts: 84
Location: Bern, Switzerland

PostPosted: Sun Jul 26, 2009 8:40 pm    Post subject: Root partition as SquashFS + Aufs2 [SOLVED] Reply with quote

UPDATE: jump over the next few replies and read hirakendu's contribution and later

Hi all.

Has anyone experience with a squashed root filesystem on Gentoo (OpenRC)? The two important parts SquashFS and Aufs2 are quite easy to install and also to build the squashed root filesystem, but how to get ahead from there is not clear.

There is an old HOWTO http://www.gentoo-wiki.info/HOWTO_Read-only_root_filesystem wich describes a modification of /sbin/rc. Does anybody know what to do on current Gentoo installations and how the kernel in grub.conf should be called?

Thanks in advance...
Claudio


Last edited by claudio on Thu Aug 13, 2009 9:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
nukem996
l33t
l33t


Joined: 13 Nov 2003
Posts: 776

PostPosted: Mon Jul 27, 2009 3:05 am    Post subject: Reply with quote

I actually did this at work for our embedded Linux systems. We're Debain based but you should be able to do the same on Gentoo. What I did was create a script which is run in the initrd. This script is run after the driver has been mounted but before pivoting into the new system.

All the script does it mount everything properly on the location /root which is where Debian pivots into.
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Mon Jul 27, 2009 6:31 am    Post subject: Reply with quote

Hi,

I use genkernel (with a slightly modified linuxrc) to do that with unionfs... I could provide you a diff if you like!
The only thing that i really had to change (besides the kernel and the initramfs) was /etc/init.d/checkroot, where it remounts the root readonly... just remark that line! :wink:

My grub config looks like this (works for usb, cd, localdrive...):
Code:
default 0
timeout 10
#splashimage=(hd0,0)/boot/grub/splash.xpm.gz

title Funtoo Linux...
#root (hd0,0)
kernel /boot/vmlinuz looptype=squashfs init=/linuxrc loop=/2009-netboot.unionfs root=/dev/ram0 udev cdroot
initrd /boot/initrd


Hope that Helps!
Gruess us Luzärn! :P
_________________
Power to the people!
Back to top
View user's profile Send private message
claudio
Tux's lil' helper
Tux's lil' helper


Joined: 11 Sep 2005
Posts: 84
Location: Bern, Switzerland

PostPosted: Mon Jul 27, 2009 8:43 am    Post subject: Reply with quote

I didn't use genkernel yet. Is there an other way to handle this, or shoud I use a genkernel with initramfs?
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Mon Jul 27, 2009 9:09 am    Post subject: Reply with quote

I just use genkernel to produce the initramfs... Apart from that, its quite the same as a manual compilation if you use the --menuconfig option from it...

However, to your question:
The problem is, that you have to mount it the right way, before the init-process triggers all the startup-scripts... So you either need to have an initramfs which does that, or you could do it in /sbin/rc!
I just took the first variant, as it leaves the system itself untouched, and i am able to boot up the normal uncompressed root without changing that much!

I really like the init-scripts in genkernels ramfs... sure, you could write your own! But as i am basically a lazy person and i won't reinvent the wheel...
I use the same init-image for every kind of boot... just the grub-parameters are different (obviously)! :wink:

I would say: go for genkernel!
But at the end of the day, it's up to you, how you do it! :wink:
_________________
Power to the people!
Back to top
View user's profile Send private message
claudio
Tux's lil' helper
Tux's lil' helper


Joined: 11 Sep 2005
Posts: 84
Location: Bern, Switzerland

PostPosted: Mon Jul 27, 2009 1:12 pm    Post subject: Reply with quote

nativemad wrote:
or you could do it in /sbin/rc!

I don't think so! /sbin/rc is binary and not a shell script. Moreover the aufs2 module has to be loaded very soon.

nativemad wrote:
I would say: go for genkernel!

Clearly demonstrated! :o
This thread tends to become longer after my next tries... (da hani e landes-bonus, gäu :wink: )
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Mon Jul 27, 2009 1:49 pm    Post subject: Reply with quote

This is the diff that i use against the current genkernel package...
The Write-loops are located in /root! (one for every top-level dir). You could change that, but i took it to simply use the tmpfs on /root which gets created earlier with the "cdroot" parameter through genkernel... /var/something could also be an option here!

As i haven't had any contact with aufs so far, i can't tell you how the mount-command should look like! Also, at the end of that patch, you can see that i copy some tools to the initramfs via gen_initramfs.sh. You should copy the aufs-tools there! :wink:
Code:
                                     
316,317c316,323                                                                                       
<       good_msg "Making tmpfs for ${NEW_ROOT}"                                                       
<       mount -n -t tmpfs tmpfs "${NEW_ROOT}"                                                         
---                                                                                                   
> # mad hack                                                                                           
>         good_msg "Making super union mount for ${NEW_ROOT}"                                         
>         mount -t tmpfs tmpfs "${NEW_ROOT}"                                                           
>                                                                                                     
> mkdir ${NEW_ROOT}/root                                                                               
>                                                                                                     
> #     good_msg "Making tmpfs for ${NEW_ROOT}"                                                       
> #     mount -n -t tmpfs tmpfs "${NEW_ROOT}"                                                         
527,528c533,548                                                                                       
<                       good_msg 'Mounting squashfs filesystem'                                       
<                       mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
---                                                                                                                   
> #mad                                                                                                                 
>                        good_msg 'Mounting squashfs filesystem and a union over it... mad'                           
> mkdir -p ${NEW_ROOT}/mnt/squash                                                                                     
> mount -t squashfs -o loop,ro ${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP} ${NEW_ROOT}/mnt/squash                         
> #                       mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
> for x in usr lib opt bin sbin ${ROOT_TREES}                                                                           
>         do                                                                                                             
>                 if [ ! -e ${NEW_ROOT}/${x} ] || [ ! -e ${NEW_ROOT}/mnt/squash/${x} ]; then                             
>                         mkdir ${NEW_ROOT}/${x}                                                                         
>                         mkdir ${NEW_ROOT}/root/${x}                                                                   
>                         mount -t unionfs -o rw,dirs=${NEW_ROOT}/root/${x}=rw:${NEW_ROOT}/mnt/squash/${x}=ro writeloop${x} ${NEW_ROOT}/${x}
>                 fi                                                                                                                       
> done                                                                                                                                     
>                                                                                                                                           
>                       #good_msg 'Mounting squashfs filesystem'                                                                           
>                       #mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"                   
596c616,619                                                                                                                                 
<       good_msg "Copying read-write image contents to tmpfs"                                                                               
---                                                                                                                                         
> # mad                                                                                                                                     
> good_msg "Just waisting your time here... ;-)"                                                                                           
>                                                                                                                                           
> #     good_msg "Copying read-write image contents to tmpfs"                                                                               
598c621                                                                                                                                     
<       (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")                                                               
---                                                                                                                                         
> #     (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")                                                               
601,637c624,660                                                                                                                             
<       for x in ${ROOT_LINKS}                                                                                                             
<       do                                                                                                                                 
<               if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]                                                                                 
<               then                                                                                                                       
<                       ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null                                               
<               else                                                                                                                       
<                       # List all subdirectories of x                                                                                     
<                       find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory                                   
<                       do                                                                                                                 
<                               # Strip the prefix of the FS_LOCATION                                                                       
<                               directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"                                                       
<                                                                                                                                           
<                               # Skip this directory if we already linked a parent directory                                               
<                               if [ "${curent_parrent}" != '' ]; then                                                                     
<                                       var=`echo "${directory}" | grep "^${curent_parrent}"`                                               
<                                       if [ "${var}" != '' ]; then                                                                         
<                                               continue                                                                                   
<                                       fi                                                                                                 
<                               fi                                                                                                         
<                               # Test if the directory exists already                                                                     
<                               if [ -e "/${NEW_ROOT}/${directory}" ]                                                                       
<                               then                                                                                                       
<                                       # It does exist, link all the individual files                                                     
<                                       for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`                                           
<                                       do                                                                                                 
<                                       if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then                                                                                                                                 
<                                                       ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null     
<                                               fi                                                                                           
<                                       done                                                                                                 
<                               else                                                                                                         
<                                       # It does not exist, make a link to the livecd                                                       
<                                       ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null                                       
<                                       current_parent="${directory}"                                                                         
<                               fi                                                                                                           
<                       done                                                                                                                 
<               fi                                                                                                                           
<       done                                                                                                                                 
---                                                                                                                                           
> #     for x in ${ROOT_LINKS}                                                                                                               
> #     do                                                                                                                                   
> #             if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]                                                                                   
> #             then                                                                                                                         
> #                     ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null                                                 
> #             else                                                                                                                         
> #                     # List all subdirectories of x                                                                                       
> #                     find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory                                     
> #                     do                                                                                                                   
> #                             # Strip the prefix of the FS_LOCATION                                                                         
> #                             directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"                                                         
> #                                                                                                                                           
> #                             # Skip this directory if we already linked a parent directory                                                 
> #                             if [ "${curent_parrent}" != '' ]; then                                                                       
> #                                     var=`echo "${directory}" | grep "^${curent_parrent}"`                                                 
> #                                     if [ "${var}" != '' ]; then                                                                           
> #                                             continue                                                                                     
> #                                     fi                                                                                                   
> #                             fi
> #                             # Test if the directory exists already
> #                             if [ -e "/${NEW_ROOT}/${directory}" ]
> #                             then
> #                                     # It does exist, link all the individual files
> #                                     for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
> #                                     do
> #                                     if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
> #                                                     ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
> #                                             fi
> #                                     done
> #                             else
> #                                     # It does not exist, make a link to the livecd
> #                                     ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
> #                                     current_parent="${directory}"
> #                             fi
> #                     done
> #             fi
> #     done
641c664
<               sleep 10
---
>               sleep 1
661c684
<               sleep 10
---
>               sleep 1
diff -r genkernel/gen_initramfs.sh mad-genkernel/gen_initramfs.sh
31a32,36
> #mad patch
>         cp -a /usr/local/bin/unionctl ${TEMP}/initramfs-base-temp/sbin/
>         cp -a /usr/local/bin/uniondbg ${TEMP}/initramfs-base-temp/sbin/
>         cp -a /usr/local/bin/unionimap ${TEMP}/initramfs-base-temp/sbin/
> # end mad


...i wörd dem ehner Bärner-Bonus säge... aber mer wänd do jo kei vorurteil pflege! :wink:
_________________
Power to the people!
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Tue Jul 28, 2009 6:57 pm    Post subject: Reply with quote

I had a setup like this a long time ago for running gentoo on my eee laptop. The only things I remember needing were a manual kernel compile (I needed this since I was using squash-lzma), and fstab mounted everything, it didn't need scripts because only /usr/ was inside the squashfs.

(Now I wish I'd kept the USB install scripts I'd made...)
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Wed Jul 29, 2009 5:28 am    Post subject: Reply with quote

It is a bit different, if you want to have the whole root in a readonly squashfs!
Single parts like /usr, /root or even /var to some degrees are really easy to place "somewhere else" and let fstab do... But during bootup with a squash as root, you don't even get to that desired fstab without an initramdrive/linuxrc which mounts that and a Union-fs-solution on top of that!! :P

My goal was just one prepared install (in a chroot), to serve several pxe clients, use it on an USB-stick, DVD or as a simple fallback system for my notebook (even without a seperate partition), where it can happen that my normal gentoo installation won't run anymore for some reasons....(kms, kde4, intel anyone?) :wink:
--Yes, i dualboot gentoo and gentoo! :P

The cool thing about it is that you can do with it whatever you like and just reboot to reset it... like a common livecd, but with the advantage of gentoo in the backgroud!

I hope that sheds some light. :wink:
_________________
Power to the people!
Back to top
View user's profile Send private message
claudio
Tux's lil' helper
Tux's lil' helper


Joined: 11 Sep 2005
Posts: 84
Location: Bern, Switzerland

PostPosted: Wed Jul 29, 2009 8:11 am    Post subject: Reply with quote

Ok, my first genkernel ended in a glorious mess! The nvidia and vmware kernel modules can't be loaded and there are tons of error messages while booting up the system. There's maybe a mess between the "normal" kernel and the genkernel...

But let me ask a few questions:
1) Should I call "genkernel --unionfs all"? Is the unionfs this way fully supported?
2) Do I have to apply your patch for gen_initramfs.sh *before* I call "genkernel"?
3) I don't have any "/proc/config.gz" -> do I need it for genkernel?
4) Do you load any modules in /etc/modules.autoload.d/kernel-2.6 explictly?
5) Isn't the boot speed much slower with genkernel? Or is there an "abbreviation"?

Thanx...
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Wed Jul 29, 2009 10:06 am    Post subject: Reply with quote

nativemad wrote:
It is a bit different, if you want to have the whole root in a readonly squashfs!
Single parts like /usr, /root or even /var to some degrees are really easy to place "somewhere else" and let fstab do... But during bootup with a squash as root, you don't even get to that desired fstab without an initramdrive/linuxrc which mounts that and a Union-fs-solution on top of that!! :P

My goal was just one prepared install (in a chroot), to serve several pxe clients, use it on an USB-stick, DVD or as a simple fallback system for my notebook (even without a seperate partition), where it can happen that my normal gentoo installation won't run anymore for some reasons....(kms, kde4, intel anyone?) :wink:
--Yes, i dualboot gentoo and gentoo! :P

The cool thing about it is that you can do with it whatever you like and just reboot to reset it... like a common livecd, but with the advantage of gentoo in the background!

I hope that sheds some light. :wink:


Ah that makes sense. I did try using squashfs for the root, but since mine was only ever used on a USB drive it wasn't worth the pain of figuring out all the switch_root voodoo.
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Wed Jul 29, 2009 11:43 am    Post subject: Reply with quote

Quote:
1) Should I call "genkernel --unionfs all"? Is the unionfs this way fully supported?

No, it's not supported anymore afaik! My patch just modifies the squash-mount function from genkernel, with the assumption that there is a unionfs!
I always use "genkernel --no-clean --menuconfig all". It generates an initramfs which contains anything... and if its involked with squashfs as looptype, it mounts the union over it and so on... But it can also be used with the normal grub options like its documented in the handbook!
Quote:
2) Do I have to apply your patch for gen_initramfs.sh *before* I call "genkernel"?

Yes! The gen_initramfs-script produces the init-image, with the union-tools and the modified startup-script! If you want to have it all in place, than patch it first! :wink:
Quote:
3) I don't have any "/proc/config.gz" -> do I need it for genkernel

No, you don't need it really... You could just use the .config of your normal kernel and load it through menuconfig (just make sure that you save it as /usr/src/linux/.config, before you leave the menuconfig... Genkernel itself tries to have a kind of standart-config in it, but i don't like it either.. Anyhow, It's up to you how you want to configure your kernel! :P
Quote:
4) Do you load any modules in /etc/modules.autoload.d/kernel-2.6 explictly

No, not at all!
Quote:
5) Isn't the boot speed much slower with genkernel? Or is there an "abbreviation"?

At first, i was a bit disappointed about the bootup... Then i've seen, that the genkernel-squashroot-function copies some dirs over to a ramdrive (/etc as example), before it boots up... But as i create a writeable union over the whole system, i just remarked that part in the script (as can be seen in the patch). And now i must admit, that it actually boots faster over pxe/nfs than with a local installation! Just try to keep the numbers of modules low, and it will not waste time to load them! :wink:

To your mess: Those external modules need a recompile with another kernel... but how do you prepare the image!?! Out of a normal install or do you do it in a chroot?
I would just take the normal .config, load it through genkernel and let it compile... then you can make 2 entries in grub.conf like one with initramfs and one without (both pointing to the same genkernel-kernel-image). That way, you can test the init a bit, before you move on with the squash-image...
_________________
Power to the people!
Back to top
View user's profile Send private message
claudio
Tux's lil' helper
Tux's lil' helper


Joined: 11 Sep 2005
Posts: 84
Location: Bern, Switzerland

PostPosted: Thu Jul 30, 2009 8:06 am    Post subject: Reply with quote

Well, my fresh new genkernel works fine! :D
I went the
Code:
genkernel --no-clean --menuconfig all

way with my previous .config file. And indeed - the difference between the normal kernel and the genkernel is very small.

That was the good message. And the bad follows: I'm fighting with the unionfs and the shell script.

When you look at /usr/share/genkernel/gen_initramfs.sh you see following functions (snipped):
Code:
append_base_layout()
append_busybox()
append_blkid()

append_unionfs_fuse() {
   if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
   then
      rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
   fi
   cd ${TEMP}
   mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
   bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
      gen_die 'Could not extract unionfs-fuse binary cache!'
   chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
   cd "${TEMP}/initramfs-unionfs-fuse-temp/"
   find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
   rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
}

append_multipath()
...dmraid, lvm, evms mdadm, splash, overlay, luks, firmware...
append_modules()
append_auxilary()
append_data()

create_initramfs() {
   print_info 1 "initramfs: >> Initializing..."

   # Create empty cpio
   CPIO="${TMPDIR}/initramfs-${KV}"
   echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
      || gen_die "Could not create empty cpio at ${CPIO}"

   append_data 'base_layout'
   append_data 'auxilary' "${BUSYBOX}"
   append_data 'busybox' "${BUSYBOX}"
   append_data 'lvm' "${LVM}"
   append_data 'dmraid' "${DMRAID}"
   append_data 'evms' "${EVMS}"
   append_data 'mdadm' "${MDADM}"
   append_data 'luks' "${LUKS}"
   append_data 'multipath' "${MULTIPATH}"

   if [ "${NORAMDISKMODULES}" -eq '0' ]
   then
      append_data 'modules'
   else
      print_info 1 "initramfs: Not copying modules..."
   fi

   append_data 'blkid' "${DISKLABEL}"

   append_data 'unionfs_fuse' "${UNIONFS}"

   append_data 'splash' "${SPLASH}"

   if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
   then
      append_data 'firmware'
   fi

   # This should always be appended last
   if [ "${INITRAMFS_OVERLAY}" != '' ]
   then
      append_data 'overlay'
   fi

   gzip -9 "${CPIO}"
   mv -f "${CPIO}.gz" "${CPIO}"

   if isTrue "${INTEGRATED_INITRAMFS}"
   then
#      cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/usr/initramfs_data.cpio.gz
      mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio.gz
#      sed -i "s|^.*CONFIG_INITRAMFS_SOURCE=.*$|CONFIG_INITRAMFS_SOURCE=\"${TMPDIR}/initramfs-${KV}.cpio.gz\"|" ${KERNEL_DIR}/.config
      sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
      echo -e "CONFIG_INITRAMFS_SOURCE=\"${TMPDIR}/initramfs-${KV}.cpio.gz\"\nCONFIG_INITRAMFS_ROOT_UID=0\nCONFIG_INITRAMFS_ROOT_GID=0" >> ${KERNEL_DIR}/.config
   fi

   if ! isTrue "${CMD_NOINSTALL}"
   then
      if ! isTrue "${INTEGRATED_INITRAMFS}"
      then
         copy_image_with_preserve "initramfs" \
            "${TMPDIR}/initramfs-${KV}" \
            "initramfs-${KNAME}-${ARCH}-${KV}"
      fi
   fi
}


If I run genkernel like above, I get following:
Code:
(chroot) mrtux / # genkernel --no-clean --menuconfig all
* Gentoo Linux Genkernel; Version 3.4.10.905
* Running with options: --no-clean --menuconfig all

* Linux Kernel 2.6.29-gentoo-r6 for x86...
*         >> Running oldconfig...
* config: --no-clean is enabled; leaving the .config alone.
* config: >> Invoking menuconfig...


*** End of Linux kernel configuration.
*** Execute 'make' to build the kernel or try 'make help'.

*         >> Compiling 2.6.29-gentoo-r6 bzImage...
*         >> Compiling 2.6.29-gentoo-r6 modules...
* Copying config for successful build to /etc/kernels/kernel-config-x86-2.6.29-gentoo-r6
* busybox: >> Using cache
* initramfs: >> Initializing...
*         >> Appending base_layout cpio data...
*         >> Appending auxilary cpio data...
*         >> Appending busybox cpio data...
*         >> Appending modules cpio data...
*
* Kernel compiled successfully!
*
* Required Kernel Parameters:
*     real_root=/dev/$ROOT
*
*     Where $ROOT is the device node for your root partition as the
*     one specified in /etc/fstab


Now, I'm quite a bit confused, what I should do now. Where do I have to insert the mount commands? It seems that the genkernel scripts changed and I cannot apply your patch.

An other question: how did you emerge uionionfs? Did you apply any patches from somewhere else? BTW aufs2 works out of the box...

Hey nativemad, mersi viu mau! Hättisch es Bier verdient! :lol:
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Thu Jul 30, 2009 9:24 am    Post subject: Reply with quote

Ok, i've seen, that something with my diff-command was obviously wrong.... Here's a better one:
Code:
diff -uNr genkernel/defaults/linuxrc mad-genkernel/defaults/linuxrc
--- genkernel/defaults/linuxrc  2009-07-30 10:59:55.000000000 +0200
+++ mad-genkernel/defaults/linuxrc      2009-06-16 13:27:16.000000000 +0200
@@ -313,8 +313,14 @@                                                       
                                                                           
 if [ "${CDROOT}" = '1' ]                                                 
 then                                                                     
-       good_msg "Making tmpfs for ${NEW_ROOT}"                           
-       mount -n -t tmpfs tmpfs "${NEW_ROOT}"                             
+# mad hack                                                               
+        good_msg "Making super union mount for ${NEW_ROOT}"               
+        mount -t tmpfs tmpfs "${NEW_ROOT}"                               
+                                                                         
+mkdir ${NEW_ROOT}/root                                                   
+                                                                         
+#      good_msg "Making tmpfs for ${NEW_ROOT}"                           
+#      mount -n -t tmpfs tmpfs "${NEW_ROOT}"                             
                                                                           
        for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
        do                                                                         
@@ -524,8 +530,22 @@                                                               
                        FS_LOCATION='mnt/livecd'                                   
                elif [ "${LOOPTYPE}" = 'squashfs' ]                                 
                then                                                               
-                       good_msg 'Mounting squashfs filesystem'                     
-                       mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
+#mad                                                                                                                 
+                       good_msg 'Mounting squashfs filesystem and a union over it... mad'                             
+mkdir -p ${NEW_ROOT}/mnt/squash                                                                                       
+mount -t squashfs -o loop,ro ${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP} ${NEW_ROOT}/mnt/squash                           
+#                       mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
+for x in usr lib opt bin sbin ${ROOT_TREES}                                                                           
+        do                                                                                                             
+                if [ ! -e ${NEW_ROOT}/${x} ] || [ ! -e ${NEW_ROOT}/mnt/squash/${x} ]; then                             
+                        mkdir ${NEW_ROOT}/${x}                                                                         
+                        mkdir ${NEW_ROOT}/root/${x}                                                                   
+                        mount -t unionfs -o rw,dirs=${NEW_ROOT}/root/${x}=rw:${NEW_ROOT}/mnt/squash/${x}=ro writeloop${x} ${NEW_ROOT}/${x}
+                fi                                                                                                                       
+done                                                                                                                                     
+                                                                                                                                         
+                       #good_msg 'Mounting squashfs filesystem'                                                                           
+                       #mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"                   
                        test_success 'Mount filesystem'                                                                                   
                        FS_LOCATION='mnt/livecd'                                                                                           
                elif [ "${LOOPTYPE}" = 'gcloop' ]                                                                                         
@@ -593,52 +613,55 @@                                                                                                                     
                CHROOT=/union                                                                                                             
        else                                                                                                                               
                                                                                                                                           
-       good_msg "Copying read-write image contents to tmpfs"                                                                             
+# mad                                                                                                                                     
+good_msg "Just waisting your time here... ;-)"                                                                                           
+                                                                                                                                         
+#      good_msg "Copying read-write image contents to tmpfs"                                                                             
        # Copy over stuff that should be writable                                                                                         
-       (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")                                                               
+#      (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")                                                               
                                                                                                                                           
        # Now we do the links.                                                                                                             
-       for x in ${ROOT_LINKS}                                                                                                             
-       do                                                                                                                                 
-               if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]                                                                               
-               then                                                                                                                       
-                       ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null                                             
-               else                                                                                                                       
-                       # List all subdirectories of x                                                                                     
-                       find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory                                 
-                       do                                                                                                                 
-                               # Strip the prefix of the FS_LOCATION                                                                     
-                               directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"                                                       
-                                                                                                                                         
-                               # Skip this directory if we already linked a parent directory                                             
-                               if [ "${curent_parrent}" != '' ]; then                                                                     
-                                       var=`echo "${directory}" | grep "^${curent_parrent}"`                                             
-                                       if [ "${var}" != '' ]; then                                                                       
-                                               continue                                                                                   
-                                       fi                                                                                                 
-                               fi                                                                                                         
-                               # Test if the directory exists already                                                                     
-                               if [ -e "/${NEW_ROOT}/${directory}" ]                                                                     
-                               then                                                                                                       
-                                       # It does exist, link all the individual files                                                     
-                                       for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`                                         
-                                       do                                                                                                 
-                                       if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then                                                                                                                                 
-                                                       ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null     
-                                               fi                                                                                           
-                                       done                                                                                                 
-                               else                                                                                                         
-                                       # It does not exist, make a link to the livecd                                                       
-                                       ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null                                       
-                                       current_parent="${directory}"                                                                         
-                               fi                                                                                                           
-                       done                                                                                                                 
-               fi                                                                                                                           
-       done                                                                                                                                 
+#      for x in ${ROOT_LINKS}                                                                                                               
+#      do                                                                                                                                   
+#              if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]                                                                                   
+#              then                                                                                                                         
+#                      ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null                                                 
+#              else                                                                                                                         
+#                      # List all subdirectories of x                                                                                       
+#                      find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory                                     
+#                      do                                                                                                                   
+#                              # Strip the prefix of the FS_LOCATION                                                                         
+#                              directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"                                                         
+#                                                                                                                                           
+#                              # Skip this directory if we already linked a parent directory                                                 
+#                              if [ "${curent_parrent}" != '' ]; then                                                                       
+#                                      var=`echo "${directory}" | grep "^${curent_parrent}"`                                                 
+#                                      if [ "${var}" != '' ]; then                                                                           
+#                                              continue                                                                                     
+#                                      fi                                                                                                   
+#                              fi                                                                                                           
+#                              # Test if the directory exists already                                                                       
+#                              if [ -e "/${NEW_ROOT}/${directory}" ]                                                                         
+#                              then                                                                                                         
+#                                      # It does exist, link all the individual files                                                       
+#                                      for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`                                             
+#                                      do                                                                                                   
+#                                      if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then                                                                                                                                 
+#                                                      ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null     
+#                                              fi                                                                                           
+#                                      done                                                                                                 
+#                              else                                                                                                         
+#                                      # It does not exist, make a link to the livecd                                                       
+#                                      ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null                                       
+#                                      current_parent="${directory}"                                                                         
+#                              fi                                                                                                           
+#                      done                                                                                                                 
+#              fi                                                                                                                           
+#      done                                                                                                                                 

        if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
        then
-               sleep 10
+               sleep 1
        fi
        mkdir initramfs proc tmp sys 2>/dev/null
        chmod 1777 tmp
@@ -658,7 +681,7 @@
        check_slowusb
        if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
        then
-               sleep 10
+               sleep 1
        fi
 else
        if [ "${USE_UNIONFS_NORMAL}" = '1' ]
diff -uNr genkernel/gen_initramfs.sh mad-genkernel/gen_initramfs.sh
--- genkernel/gen_initramfs.sh  2009-07-30 10:59:55.000000000 +0200
+++ mad-genkernel/gen_initramfs.sh      2009-06-16 13:28:04.000000000 +0200
@@ -29,6 +29,11 @@
        mknod -m 660 console c 5 1
        mknod -m 660 null c 1 3
        mknod -m 600 tty1 c 4 1
+#mad patch
+        cp -a /usr/local/bin/unionctl ${TEMP}/initramfs-base-temp/sbin/
+        cp -a /usr/local/bin/uniondbg ${TEMP}/initramfs-base-temp/sbin/
+        cp -a /usr/local/bin/unionimap ${TEMP}/initramfs-base-temp/sbin/
+# end mad

        date '+%Y%m%d' > ${TEMP}/initramfs-base-temp/etc/build_date

Just save it into a file (be aware, that it sometimes adds whitespaces at the front of each line [at least when i copy stuff from the forums].. delete them!) and then:
Code:

cd /usr/share
patch -p0 </path/to/my/diff


But before you do that: modify it to your needs!!! Here are the important things where you need to make adjustments for aufs:
The mount command (all in one line):
Code:
  mount -t unionfs -o rw,dirs=${NEW_ROOT}/root/${x}=rw:${NEW_ROOT}/mnt/squash/${x}=ro writeloop${x} ${NEW_ROOT}/${x}

And the copy-part:
Code:

cp -a /usr/local/bin/unionctl ${TEMP}/initramfs-base-temp/sbin/
cp -a /usr/local/bin/uniondbg ${TEMP}/initramfs-base-temp/sbin/
cp -a /usr/local/bin/unionimap ${TEMP}/initramfs-base-temp/sbin/


Yes, i applied the kernel-patch for unionfs manually, and also compiled the tools by hand! (http://www.filesystems.org/project-unionfs.html)
Does the ebuild for aufs work? Does it contain a kernel-module?? -if so, then i guess you'll also have to copy over the module.ko into the init, and load it via insmod, before your're going to mount!!

---now i wonder if i should just try out aufs2 as well...

...hmm ha ghört "d'gorte-bier" seige ned schlächt... :P
_________________
Power to the people!
Back to top
View user's profile Send private message
claudio
Tux's lil' helper
Tux's lil' helper


Joined: 11 Sep 2005
Posts: 84
Location: Bern, Switzerland

PostPosted: Fri Jul 31, 2009 11:20 am    Post subject: Reply with quote

Ok, guys... I think it's a bit too much for me now to build this squash/aufs thing with genkernel! Once, there was a request to include aufs into genkernel in 2007: https://bugs.gentoo.org/201038. For me, it's too complicated to reintegrate this into genkernel...

I'm thinking about to give unionfs a try or to build myself a small initramfs like http://en.gentoo-wiki.com/wiki/Initramfs or http://www.mail-archive.com/aufs-users@lists.sourceforge.net/msg00687.html or http://twoday.tuwien.ac.at/luki/stories/323030/comment.

The advange of an own small initramfs is that I know what I'm doing unlike the huge genkernel thing. If I've found out something, I'll post...
Thanks for all the help I've recieved...
Claudio
Back to top
View user's profile Send private message
hirakendu
Guru
Guru


Joined: 24 Jan 2007
Posts: 386
Location: san diego

PostPosted: Sun Aug 02, 2009 5:47 pm    Post subject: Reply with quote

I don't have the time to go through all the posts in this thread, but since I use aufs2+squashfs for my livedisk, here is my way :). I use a small custom initrd or initramfs. I prefer the initramfs way instead of initrd. You may have a look at my initramfs related stuff, self-explanatory initrd/initramfs generating script and most importantly, the linuxrc/init scripts.

In short, you need a kernel with support for initramfs/initrd, aufs2 and squashfs (and possibly all basic filesystems and sata/pata drivers) built-in (not modular). (<ad>You may have a look at my helium-sources kernel patchset or zen-sources or hitchhiker sources.</ad>) This initramfs/init assumes that the squashfs image of the system is livedisk.sfs and mounts the necessary stuff and starts the actual init. Sample GRUB entries:
Code:
#initramfs-based
title Gentoo-1
kernel /vmlinuz
# optional: vga=791 splash=silent,theme:natural_gentoo CONSOLE=/dev/tty1 nopat
initrd /initramfs.igz

#initrd-based
title Gentoo-2
kernel /vmlinuz root=/dev/ram0 init=/linuxrc
# optional: vga=791 splash=verbose rootdelay=0 nopat
initrd /initrd

. (Hope I haven't forgotten something in an attempt to make things simple :D.)
_________________
Helium Sources || Gentoo Minimal Livecd
Back to top
View user's profile Send private message
claudio
Tux's lil' helper
Tux's lil' helper


Joined: 11 Sep 2005
Posts: 84
Location: Bern, Switzerland

PostPosted: Thu Aug 13, 2009 9:34 pm    Post subject: Reply with quote

[SOLVED]
Here's my way to boot from a squashed root filesystem wich is readonly. The squashed image is in this example located on a harddisk partition and not on a cdrom drive. With the help of this forum and http://en.gentoo-wiki.com/wiki/Initramfs I managed it to work (copy-paste...).

My partitions in the following example:
/dev/sda1 /boot
/dev/sda2 / (this is the root wich will be squashed; later unused)
/dev/sda3 /mnt/imgpart (this is the partition where the squash image resides)


0. Forget genkernel -> it's too complicated


1a. You have a running Gentoo system
1b. You need a compiled kernel in /usr/linux


my current conditions:
* Found kernel source directory:
* /usr/src/linux
* Found kernel object directory:
* /lib/modules/2.6.29-gentoo-r6/build
* Found sources for kernel version:
* 2.6.29-gentoo-r6


2. Emerge some stuff
Code:
emerge -pv git aufs2 busybox

[ebuild   R   ] sys-apps/busybox-1.14.2  USE="pam static -debug -make-symlinks -savedconfig (-selinux)" 0 kB
[ebuild     U ] dev-util/git-1.6.4 [1.6.3.3] USE="bash-completion curl -gtk iconv perl xinetd -cgi -cvs -doc -emacs -mozsha1 (-ppcsha1) -subversion -threads -tk -webdav" 2,357 kB
[ebuild     U ] sys-fs/aufs2-0_p20090727 [0_p20090601-r1] USE="kernel-patch -debug -inotify -ramfs" 0 kB

note: aufs2-0_p20090727 doesn't work with gentoo-sources-2.6.29, but aufs2-0_p20090601-r1 works out of the box


3. Create the initramfs directory
Do the steps according to http://en.gentoo-wiki.com/wiki/Initramfs and hirakendu examples

Code:
mount /boot
mkdir /usr/src/initramfs
cd /usr/src/initramfs
mkdir -p bin lib dev etc proc sbin sys mnt/union mnt/static mnt/dynamic mnt/imgpart
mkdir -p lib/modules/2.6.29-gentoo-r6/misc # used for "aufs" kernel module
cp -a /lib/modules/2.6.29-gentoo-r6/misc/aufs.ko lib/modules/2.6.29-gentoo-r6/misc/
cp -a /bin/busybox bin/
ln -s busybox bin/sh
touch etc/mdev.conf
cp -a /lib/{ld-*,libc-*,libc.so*,libdl*} lib/
cp -a /lib/{libm-*,libm.so*,libpam.so*,libpam_misc*} lib/


4. Create a new init shell script
This one is a bit raw, but you can use it as a good starting point.

nano -w init

Code:
#!/bin/busybox sh

# Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys

busybox --install -s

mknod /dev/null c 1 3
mknod /dev/tty c 5 0

# Do your stuff here.
echo "This script mounts rootfs RO with an aufs RW layer."
modprobe aufs

sleep 7
mdev -s

# Parse the kernel command line from grub

CMDLINE="$(cat /proc/cmdline)"

parse_disk() {
  if [ "$(echo $1|cut -c -5)" = "UUID=" ]; then
    # $1 is a UUID
    echo $(findfs $1)
  elif [ "$(echo $1|cut -c -6)" = "LABEL=" ]; then
    # $1 is a LABEL
    echo $(findfs $1)
  elif [ "$(echo $1|cut -c -5)" = "/dev/" ]; then
    # $1 is a device name
    echo $1
  else
    # $1 is unrecognized.
    echo "unknow-disk"
  fi
}


for p in ${CMDLINE};
do
  key=${p%%=*}
  value=${p#*=}

  case $key in
  imgpart)
    IMGPART=`parse_disk $value`
    ;;
  imgfile)
    IMGFILE=$value
    ;;
  esac
done

if [ -z "${IMGPART}" ]; then
  echo "Specify the squash image partition after the kernel command ${CMDLINE}"
  echo "example: kenrel... imgpart=/dev/sda2 imgfile=/gentoo.sqs"
  exec /bin/sh
  exit 0
fi

if [ -z "${IMGFILE}" ]; then
  echo "Specify the squash image file after the kernel command ${CMDLINE}"
  echo "example: kenrel... imgpart=/dev/sda2 imgfile=/gentoo.sqs"
  exec /bin/sh
  exit 0
fi

echo IMGPART=${IMGPART}
echo IMGFILE=${IMGFILE}

if [ ! -b "${IMGPART}" ]; then
  echo No partition with ${IMGPART} has been found
  exec /bin/sh
  exit 0
fi

# ok, parsing done

# Mount the partitions
# 1) mount the partition where the squash image resides
mount -o ro ${IMGPART} /mnt/imgpart

# 2) init a loop pointing to the image file
loop_free=$(losetup -f | sed s#p/#p#)
losetup $loop_free /mnt/imgpart/${IMGFILE}

# 3) mount the squashfs to /mnt/static
mount -t squashfs $loop_free /mnt/static

# Note: if you don't want to use a squashed image, you just
#       can mount your read only root to /mnt/static
#       example: mount -o ro /dev/sda2 /mnt/static

# 4) mount a memory filesystem for the write access to the static image
# unclear: memory size? -o size=1024M
mount -t tmpfs tmpfs /mnt/dynamic

# 5) mount the writable overlay to the static image
mount -t aufs -o br=/mnt/dynamic:/mnt/static=ro none /mnt/union

# Clean up.
mount --move /mnt/dynamic /mnt/union/mnt/dynamic
mount --move /mnt/static /mnt/union/mnt/static
mount --move /mnt/imgpart /mnt/union/mnt/imgpart
umount /proc
umount /sys

# Boot the real thing.
exec switch_root /mnt/union /sbin/init

echo "Failed to switch_root, dropping to a shell"
exec /bin/sh


5. Create your own initramfs
Attention: it's created in /boot!
Code:
mount /boot
chmod a+x /usr/src/initramfs/init
find . -print0 | cpio -ov -0 --format=newc | gzip -9 > /boot/my-initramfs.cpio.gz


6. Edit your grub.conf
nano -w /boot/grub/grub.conf

Code:
title=My initramfs with 2.6.29
root (hd0,0)
kernel /kernel-2.6.29-generic-a imgpart=/dev/sda3 imgfile=/gentoo-lxde.squash
initrd /my-initramfs.cpio.gz


7. Create the squash image of the root
(Note: remove the root / entry from /etc/fstab)
Do this NOT from a running system but take a Live Distro and mount the root device:

Code:
mount /dev/sda2 /mnt/gentoo
mount /dev/sda3 /mnt/imgpart
cd /mnt/gentoo
mksquashfs . /mnt/imgpart/gentoo-lxde.squash


Note
There is a problem on unmounting the disks on system halt:
- Unmounting loopback devices failed: in use but fuser finds nothing
- the same for /mnt/dynamic /mnt/static /mnt/imgpart
-> maybe somebody has a solution for this...


Good luck!
claudio
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Thu Aug 20, 2009 3:02 pm    Post subject: Reply with quote

Hi Claudio,

nice that you've got it to work! :P
But i find your linuxrc a bit raw... (pxe for example would not work... and that my main usage)
I've got it working with genkernel and aufs2 now! <-If anybody is interested in it, just let me know! :P

For your shutdown problem... just add your mountpoints to /etc/init.d/halt.sh in the list of RC_NO_UMOUNTS....

Cheers!
_________________
Power to the people!
Back to top
View user's profile Send private message
skunk
l33t
l33t


Joined: 28 May 2003
Posts: 646
Location: granada, spain

PostPosted: Thu Aug 20, 2009 3:10 pm    Post subject: Reply with quote

nativemad wrote:
If anybody is interested in it, just let me know! :P

i'm, thank you! :)
it would be nice to have a small howto on this argument...
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Thu Aug 20, 2009 4:01 pm    Post subject: oy Reply with quote

okok, here we go....

1. get the basic stuff...
Code:

echo dev-util/git curl >>/etc/portage/package.use
echo sys-fs/aufs2 -kernel-patch >>/etc/portage/package.use #<-I don't know if that USE is broken?!?! it hasn't patched anything and didn't worked for me
echo sys-fs/aufs2 >>/etc/portage/package.unmask
echo sys-fs/aufs2 >>/etc/portage/package.keywords

emerge -av aufs2 genkernel


2. patch the source!
Code:
diff -uNr genkernel/defaults/linuxrc mad-genkernel/defaults/linuxrc                                             
--- genkernel/defaults/linuxrc  2009-08-20 16:38:28.000000000 +0200                                             
+++ mad-genkernel/defaults/linuxrc      2009-08-20 15:17:52.000000000 +0200                                     
@@ -313,8 +313,9 @@                                                                                             
                                                                                                               
 if [ "${CDROOT}" = '1' ]                                                                                       
 then                                                                                                           
-       good_msg "Making tmpfs for ${NEW_ROOT}"                                                                 
+       good_msg "Making aufs2 for ${NEW_ROOT}"                                                                 
        mount -n -t tmpfs tmpfs "${NEW_ROOT}"                                                                   
+       mkdir ${NEW_ROOT}/root                                                                                 
                                                                                                               
        for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys                           
        do                                                                                                     
@@ -524,8 +525,17 @@                                                                                           
                        FS_LOCATION='mnt/livecd'                                                               
                elif [ "${LOOPTYPE}" = 'squashfs' ]                                                             
                then                                                                                           
-                       good_msg 'Mounting squashfs filesystem'                                                 
-                       mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
+                       good_msg 'Mounting squashfs filesystem and the aufs2 over it'                                 
+                       mkdir -p ${NEW_ROOT}/mnt/squash                                                               
+                       mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/squash"
+                       modprobe aufs                                                                                 
+                       for AUFSLOOP in bin usr lib opt sbin ${ROOT_TREES}; do                                         
+                           if [ ! -e ${NEW_ROOT}/${AUFSLOOP} ] || [ ! -e ${NEW_ROOT}/root/${AUFSLOOP} ] && [ ! ${AUFSLOOP} = "root" ]; then
+                               mkdir -p ${NEW_ROOT}/${AUFSLOOP}                                                                           
+                               mkdir -p ${NEW_ROOT}/root/${AUFSLOOP}                                                                       
+                               mount -t aufs -o br=/${NEW_ROOT}/root/${AUFSLOOP}:${NEW_ROOT}/mnt/squash/${AUFSLOOP}=ro none ${NEW_ROOT}/${AUFSLOOP}
+                           fi                                                                                                                     
+                       done                                                                                                                       
                        test_success 'Mount filesystem'                                                                                             
                        FS_LOCATION='mnt/livecd'                                                                                                   
                elif [ "${LOOPTYPE}" = 'gcloop' ]                                                                                                   
@@ -593,52 +603,52 @@                                                                                                                               
                CHROOT=/union                                                                                                                       
        else                                                                                                                                       
                                                                                                                                                   
-       good_msg "Copying read-write image contents to tmpfs"                                                                                       
+       good_msg "Prepare to get started..."                                                                                                       
        # Copy over stuff that should be writable                                                                                                   
-       (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")                                                                       
+       #(cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")                                                                       
                                                                                                                                                   
        # Now we do the links.                                                                                                                     
-       for x in ${ROOT_LINKS}                                                                                                                     
-       do                                                                                                                                         
-               if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]                                                                                         
-               then                                                                                                                               
-                       ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null                                                       
-               else                                                                                                                               
+       #for x in ${ROOT_LINKS}                                                                                                                     
+       #do                                                                                                                                         
+       #       if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]                                                                                         
+       #       then                                                                                                                               
+       #               ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null                                                       
+       #       else                                                                                                                               
                        # List all subdirectories of x                                                                                             
-                       find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory                                           
-                       do                                                                                                                         
+       #               find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory                                           
+       #               do                                                                                                                         
                                # Strip the prefix of the FS_LOCATION                                                                               
-                               directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"                                                               
+       #                       directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"                                                               
                                                                                                                                                   
                                # Skip this directory if we already linked a parent directory                                                       
-                               if [ "${curent_parrent}" != '' ]; then                                                                             
-                                       var=`echo "${directory}" | grep "^${curent_parrent}"`                                                       
-                                       if [ "${var}" != '' ]; then                                                                                 
-                                               continue                                                                                           
-                                       fi                                                                                                         
-                               fi                                                                                                                 
+       #                       if [ "${curent_parrent}" != '' ]; then                                                                             
+       #                               var=`echo "${directory}" | grep "^${curent_parrent}"`                                                       
+       #                               if [ "${var}" != '' ]; then                                                                                 
+        #                                      continue                                                                                           
+       #                               fi                                                                                                         
+       #                       fi                                                                                                                 
                                # Test if the directory exists already                                                                             
-                               if [ -e "/${NEW_ROOT}/${directory}" ]                                                                               
-                               then                                                                                                               
+       #                       if [ -e "/${NEW_ROOT}/${directory}" ]                                                                               
+       #                       then                                                                                                               
                                        # It does exist, link all the individual files                                                             
-                                       for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`                                                   
-                                       do                                                                                                         
-                                       if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
-                                                       ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null                   
-                                               fi                                                                                                         
-                                       done                                                                                                               
-                               else                                                                                                                       
+       #                               for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`                                                         
+       #                               do                                                                                                                 
+       #                               if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
+       #                                               ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null                   
+       #                                       fi                                                                                                         
+       #                               done                                                                                                               
+       #                       else                                                                                                                       
                                        # It does not exist, make a link to the livecd                                                                     
-                                       ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null                                                   
-                                       current_parent="${directory}"                                                                                     
-                               fi                                                                                                                         
-                       done                                                                                                                               
-               fi                                                                                                                                         
-       done                                                                                                                                               
+       #                               ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null                                                   
+       #                               current_parent="${directory}"                                                                                     
+       #                       fi                                                                                                                         
+       #               done                                                                                                                               
+       #       fi                                                                                                                                         
+       #done                                                                                                                                             

        if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
        then
-               sleep 10
+               sleep 1
        fi
        mkdir initramfs proc tmp sys 2>/dev/null
        chmod 1777 tmp
@@ -658,7 +668,7 @@
        check_slowusb
        if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
        then
-               sleep 10
+               sleep 1
        fi
 else
        if [ "${USE_UNIONFS_NORMAL}" = '1' ]
diff -uNr genkernel/gen_initramfs.sh mad-genkernel/gen_initramfs.sh
--- genkernel/gen_initramfs.sh  2009-08-20 16:38:28.000000000 +0200
+++ mad-genkernel/gen_initramfs.sh      2009-08-20 14:30:41.000000000 +0200
@@ -436,7 +436,8 @@
        done

        cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
-
+       mkdir -p ${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}/misc
+       cp -v /lib/modules/${KV}/misc/aufs.* ${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}/misc
        mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
        for group_modules in ${!MODULES_*}; do
                group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"


Just save that in a file (whatch out for whitespaces at the beginning of each line!!!) and then
Code:

cd /usr/share
patch -p0 </path/to/the/diff-file/above


3. configure & compile the kernel
Code:

genkernel --menuconfig --no-clean all


4. Use and enjoy
The kernel-boot-parameters should then be like
Code:
looptype=squashfs init=/linuxrc loop=/2009-netboot.unionfs root=/dev/ram0 udev cdroot

Or however your squashfs is named..... :-)

Hope that helps... feel free to ask further, if i missed something! :wink:
_________________
Power to the people!
Back to top
View user's profile Send private message
madMAx43v3r
n00b
n00b


Joined: 03 Nov 2006
Posts: 13

PostPosted: Wed Feb 10, 2010 1:33 am    Post subject: Reply with quote

got this working with the squash file being loaded into tmpfs at bootup.
its definitely faster than a WD raptor rootfs, but not as fast as i had it once with /usr being in uncompressed tmpfs.

the decompressing is just too slow, my 3Ghz Core2 needs 3min to decompress a 1.5G squashfs (using only one core).

as i have 8gigs of ram i gonna try to put only the important stuff in ram and the squashfs on hdd. then i would use an extra tmps to write the changes to, so i can save them easily to hdd at say every 15min (this is because i learned the hard way :)

also tried that readahead-list stuff, but once you moved some data around you end up having a dvd rip loaded into ram instead of the files on the list xD

btw there where some stupid problems that cost me hours to figure out:
1) lzma squashfs (aka squashfs-devel) is broken (at least for me, even when using gzip: dmesg spammed with "unable to read inode" etc.)
2) i needed to "ln -s /proc/mounts /etc/mtab" in order to get udev working after a switch_root
3) paludis fails to reinstall packages because of rename(2) returning "Invalid cross-device link" (but portage works)
workaround: uninstall and install (so far)
Back to top
View user's profile Send private message
devsk
Advocate
Advocate


Joined: 24 Oct 2003
Posts: 2995
Location: Bay Area, CA

PostPosted: Fri Feb 12, 2010 6:03 am    Post subject: Reply with quote

what's the lure of squashfs+aufs2 for root filesystem? Does it boot faster? Do programs load faster? What's the gain? And how much?
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Fri Feb 12, 2010 9:29 am    Post subject: Reply with quote

Quote:
what's the lure of squashfs+aufs2 for root filesystem? Does it boot faster? Do programs load faster? What's the gain? And how much?

I use it, as i have several diskless PC's that boot via pxe... The real advantage is that i just need one netboot-image for everything. Changes to it are just locally in ram (expect for /home which is a normal nfs-share).
The normal gentoo-livecd behavior is that a ramdrive is created and the changeable things like /root /var and so on are copied over during boot (you can see that on the minimal-cd...). With Aufs2/unionfs, i just created a ramdrive over everything (also /usr, which isn't writeable in the common scenario) and only write things to it, if it really changes. The step to copy stuff over isn't necessary with it and therefore it boots faster from the squash (How much faster depends on the media itself... for example a pxe-boot over WAN/VPN is extremly faster, while there's not much difference, if the squash is on the local drive or something.)
Programs do not benefit directly... prelinking has a much greater effect!
But the data is only read from squash as they are needed, and not copied over in every case... :wink:
This is also great, if you have a very large /var and not so much Ram for example! :wink:
_________________
Power to the people!
Back to top
View user's profile Send private message
madMAx43v3r
n00b
n00b


Joined: 03 Nov 2006
Posts: 13

PostPosted: Fri Feb 12, 2010 3:40 pm    Post subject: Reply with quote

devsk wrote:
what's the lure of squashfs+aufs2 for root filesystem? Does it boot faster? Do programs load faster? What's the gain? And how much?


having root as squash image loaded into ram is faster, almost as fast as a second program start, than normal HDD access. of course the bootup time doesnt change much as you need to read the image from disk, so there are only a few seconds saved if you make sure it doesnt get fragmented on disc too much (make an extra partition).

having the image on HDD doesnt give you much benefit, only in special cases like /usr/portage and such...
Back to top
View user's profile Send private message
lonewolfnight
n00b
n00b


Joined: 16 Feb 2004
Posts: 14
Location: St. Paul MN

PostPosted: Tue Apr 06, 2010 9:57 pm    Post subject: Reply with quote

What are you doing for the checkroot files and fstab?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum