Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    squashfs system multiboot from sd/usb


    For a past few days I'm struggling to create sd card with few root filestystems to choose from on boot. The idea is to convert running system to squashfs file and put it on sd card. Systems should be readonly and any additional files added later should be kept on rw partition mounted on start. Any other files should be kept in RAM and lost after reboot. So partitions should be like this:

    1st - vmlinuz, kernel, grub files, os1.squash, os2.squash and so on
    2nd - mounted to, for instance to /mnt/ after boot with extra files available across systems (after succeeding booting OS at all )

    For testing purposes I'm using vmware, with one HDD with centos 6.5 installed and run from it, and second HDD simulating SD card which is plugged to base OS, then unplugged and run by its own on another virtual machine.

    So what I do is:

    Rsync running system to /root/sqfs/
    sudo rsync -av --one-file-system --exclude=/proc/* --exclude=/dev/* --exclude=/sys/* --exclude=/tmp/* --exclude=/home/* --exclude=/lost+found --exclude=/var/tmp/* --exclude=/boot/grub/* --exclude=/root/* --exclude=/var/mail/* --exclude=/var/spool/* --exclude=/media/* --exclude=/etc/fstab --exclude=/etc/mtab --exclude=/etc/hosts --exclude=/etc/shadow* --exclude=/etc/gshadow* --exclude=/root/sqfs/ --exclude=/etc/resolv.conf --exclude=/etc/hostname / sqfs/
    creating squashfs file from it
    sudo mksquashfs /root/sqfs/ /root/os1.squash -noappend
    using fdisk on second HDD to create two primary partitions and make 1st bootable

    creating filesystems on them
    mkfs.ext2 /dev/sdb1
    mkfs.ext3 /dev/sdb2
    mounting partitions and moving squash fs there
    mkdir /mnt/sq1
    mkdir /mnt/sq2
    mount /dev/sdb1 /mnt/sq1
    mount /dev/sdb2 /mnt/sq2
    cp /root/os1.squash /mnt/sq1/
    copy kernel
    cp /boot/vmlinuz-2.6.32-431.el6.x86_64 /mnt/sq1/vmlinuz
    cp /boot/initramfs-2.6.32-431.el6.x86_64.img /mnt/sq1/initrd.img
    instaling grub
    grub-install --no-floppy --root-directory=/mnt/sq1/ /dev/sdb1
    and editing grub in /mnt/sq1/boot/grub/grub.cfg
    title os1
            kernel /vmlinuz root=live:LABEL=os1.squash rootfstype=auto live_dir=/ ro liveimg nodiskmount nolvmmount rd.luks=0 rd.lvm=0
            initrd /initrd.img
    So I end up with structure like this:
    ├── boot
    │** └── grub
    │**     ├──
    │**     ├── e2fs_stage1_5
    │**     ├── fat_stage1_5
    │**     ├── ffs_stage1_5
    │**     ├── grub.conf
    │**     ├── iso9660_stage1_5
    │**     ├── jfs_stage1_5
    │**     ├── minix_stage1_5
    │**     ├── reiserfs_stage1_5
    │**     ├── stage1
    │**     ├── stage2
    │**     ├── ufs2_stage1_5
    │**     ├── vstafs_stage1_5
    │**     └── xfs_stage1_5
    ├── initrd.img
    ├── os1.squash
    └── vmlinuz
    Then after boot an choosing os1 dracut throws warning
    dracut Warning: No root device "block:/dev/mapper/live-rw" found
    Most probably I don't use kernel parameters right, can u please give me hint how it supposed be done?

  2. #2
    OK. Got it!

    The main problem was wrong structure in squashfs file. File system need to be in file formatted as ext3 then in folder THEN squashed. This link was a big help: ttps://


    	dd if=/dev/zero of=/home/images/ext3fs.img bs=1MB count=4096
    	mkfs.ext3 /home/images/ext3fs.img
    	mount -o loop /home/images/ext3fs.img /mnt/next3fs
    	cp -dpR ${dir_w_filesys}/* /mnt/next3fs/
    Also when formatting first partition I use label
    	mkfs.ext3 -L part1 /dev/sdb1
    And then in grub you can use:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts