Thursday 12 May 2016

Booting Dr.Web LiveDisk ISO with persistence from grub2


A DrWeb_Persistent.imgPTN23 file can be found here. It was made as follows:
1. Make a 800MB FAT32 partition on a USB drive
2. Download and run the DrWeb USB creator utility drweb-livedisk-900-usb.exe
3. Run it to extract the files to the USB drive
4. Boot the USB drive on a real system - this prepares it
5. Refresh the updates - reboot and check updates are persistent
6. Drag-and-drop the USB drive letter onto the MPI_FAT32 Desktop icon to make a .imgPTN23 file (syslinux 603, auto-convert). I modified the \syslinux\txt.cfg and the \boot\grub\grub.cfg files to add nomodeset vga=ask ignore_uuid. 
Note: Updates are not persistent even on their own flash drive!  So it obviously has a bug!

Booting from ISO

The Dr.Web ISO boots fine in MBR mode from E2B and can be booted from the ISO with persistence by adding a .mnu file.

However, during testing of the new GRUB2 menu system for E2B, I tried the Dr.Web LiveDisk ISO (drweb-livedisk-900-cd.iso - free), but it did not boot using the grub2 menu that I 'borrowed' from the 'Multiboot USB Flash drive' project here (I got a 'squashfs not found' type error).

After many attempts to get it booting from an ISO using the cheat code 'iso-scan/filename=', I finally looked at the 'casper' linux shell script file located inside the initrd file in the scripts folder (using 7Zip), and found this code...



parse_cmdline() {
    for x in $(cat /proc/cmdline); do
        case $x in
            showmounts|show-cow)
                export SHOWMOUNTS='Yes' ;;
            persistent)
                export PERSISTENT="Yes" ;;
            nopersistent)
                export PERSISTENT="" ;;
            persistent-path=*)
                export PERSISTENT_PATH="${x#persistent-path=}" ;;
            union=*)
                export UNIONFS="${x#union=}";;
            ip=*)
                STATICIP=${x#ip=}
                if [ "${STATICIP}" = "" ]; then
                    STATICIP="frommedia"
                fi
                export STATICIP ;;
            uuid=*)
                UUID=${x#uuid=} ;;
            ignore_uuid)
                UUID="" ;;
            live-media-path=*)
                LIVE_MEDIA_PATH="${x#live-media-path=}"
                export LIVE_MEDIA_PATH
                echo "export LIVE_MEDIA_PATH=\"$LIVE_MEDIA_PATH\"" >> /etc/casper.conf ;;
            toram)
                export TORAM="Yes" ;;
            todisk=*)
                export TODISK="${x#todisk=}" ;;
        esac
    done
    if [ "${UNIONFS}" = "" ]; then
        export UNIONFS="DEFAULT"
    fi
}


From this I could find no 'fromiso' or 'isoscan/filename' cheat code with which to tell the kernel what ISO file to find the squashfs files in! There was no mention of 'iso-scan' in any other script either! So it looks like booting from an ISO file is not going to be possible using cheat codes.

Next, I tried a 'flat-file' boot by extracting the contents of the ISO file to my USB drive (2nd partition for the grub2 menu ssytem).

After some experimentation, I found that the key to getting it to work was to use the 'ignore_uuid' cheat code. This told the kernel not to try looking for the 'cdrom'.

For the final .grub2 menu file, I ended up with this menu (note that some long lines may wrap over to the next line):

# only tested on FAT32 so far
#drweb-livedisk-900-cd.iso  extract iso to \ISO_Extract\drweb  (probably only casper folder needed)
#EFI64 MBR64 EFI32 MBR32
if [ -e "$root2$isoextpath/drweb/casper/vmlinuz" ]; then
menuentry "DrWeb live CD (extracted)" --unrestricted --class drweb{
set root=$root2
set fldname=drweb
# must use ignore_uuid  !!!
linux  $isoextpath/$fldname/casper/vmlinuz  boot=casper live-media-path=$isoextpath/$fldname/casper ignore_uuid --
initrd $isoextpath/$fldname/casper/initrd.lz
boot
}
fi

Folder structure
===========
\ISO_Extract\drweb\casper-rw
\ISO_Extract\drweb\casper (folder)
\ISO_Extract\drweb\install (folder)

You can have persistence by creating a 200MB ext2 file using RMPrepUSB - Create ext2 file - casper-rw - casper-rw - 200 on a spare USB drive, and then copy the file the \ISO_Extract\drweb folder.

I will provide a ready-made 200MB file in the grub2 download which you can unzip and use.
Dr.Web with persistent desktop and updates.
This works under both MBR and UEFI and on both 32-bit and 64-bit systems even though there are no UEFI boot files in the ISO!

I have not tested NTFS yet, but I see some people have reported that it does not boot on NTFS partitions.

P.S. I just retested this and now it stops and prompts me with:
'Please provide a name for this disk' 
Same disk, same file, same menu!

I don't know what I changed! Usually this message means it is looking for a .disk folder in the root, but even if extract it from the ISO and put it there (and in several other places!), I still get the message and it doesn't boot! grrrrr...
It can be made to continue by typing  ALT+F1 - enter some random text e.g. "xxx" - then press [ENTER] key and it should continue to boot (press ALT+F7 to return to message console if required).

Dr Web 2021_04 ISO

Here is a .grubfm file for the agFM menu system. The USB drive must only contain two partitions.

Persistence seems to work but maybe not for Updates?

# drweb-livedisk-900-cd_2021_04 with persistence file in root or same folder as ISO.

# This grubfm file must be in same folder as the ISO and have the same filename but with a .grubfm extension
# Select the ISO file in the agFM Menu system and then choose the 'User Menu' option to run this file

# PARTITION 3 and PARTITION 4 MUST BE UNUSED

# available variables are:
# grubfm_file     - e.g. (hd1,msdos1)/test/ubuntu.iso
# grubfm_path     - e.g. /test/ubuntu.iso
# grubfm_dir      - e.g. /test/
# grubfm_device   - e.g. hd1,msdos1
# grubfm_disk     - e.g. hd1
# grubfm_name     - e.g. ubuntu.iso
# grubfm_filename - e.g. ubuntu
# grubfm_fileext  - e.g. iso
# grub_platform   - e.g. efi or pc  (UEFI or Legacy BIOS)
# grub_cpu        - e.g. i386 or x86_64 (i386=Legacy mode or 32-bit UEFI, x86_64=UEFI64)
# grub_uefi_version  - e.g. 2.4
# grub_secureboot
# CPU  (=32 or 64)
# --class=   defines the icon displayed next to the menuentry
# NEVER use hd 0 - instead use ${bootdev}

    # find the persistence file on the E2B USB drive (root or same folder as ISO)
set "grubfm_per=(${grubfm_device})/${grubfm_filename}-rw"
if [ ! -e "${grubfm_per}" ] ; then set "grubfm_per=(${grubfm_device})/${grubfm_dir}${grubfm_filename}-rw"; fi
if [ ! -e "${grubfm_per}" ] ; then echo ERROR: Persistence file not found (${grubfm_per}); fi

if [ ! -e "${grubfm_per}" ] ; then 
echo ERROR ${grubfm_per} does not exist on (${grubfm_device}) ; read ; fi
if [ ! -e "${grubfm_file}" ] ; then 
echo ERROR ${grubfm_file} does not exist on (${grubfm_device}) ; read ; fi
if [ ! -e "(${grubfm_device})${grubfm_path}" ] ; then 
echo ERROR (${grubfm_device})${grubfm_path} does not exist on (${grubfm_device}) ; read ; fi

echo Persistence file=${grubfm_per}

# check file is contiguous
set x=0
set NC=0
stat -c -q -s x "${grubfm_file}"
if [ ! "${x}" = "1" ] ; then 
echo ERROR: ${grubfm_file} is not contiguous or does not exist!
sleep 5
set NC=1
fi
set x=0
stat -c -q -s x "${grubfm_per}"
if [ ! "${x}" = "1" ] ; then 
echo ERROR: ${grubfm_per} is not contiguous or does not exist!
sleep 5
set NC=1
fi
unset x


# Only show menu if 64-bit CPU
if [ "$CPU" = "64" ] ; then
menuentry "Dr Web (64-bit) + persistence" --unrestricted --class ubuntu {
#only update partition table if already empty
if ! test -d (${grubfm_disk},4) ; then partnew --type=0x00 --file="${grubfm_file}" (${grubfm_disk}) 4 ; fi
if test -d (${grubfm_disk},3) ; then echo ERROR: Partition 3 is not empty - cannot use as persistence partition! Press ENTER to continue...; read; fi
    if ! test -d (${grubfm_disk},3) ; then partnew --type=0x00 --file="${grubfm_per}" (${grubfm_disk}) 3 ; echo Ptn3=${grubfm_per}; fi
map -n "${grubfm_file}"
map -u
loopback loop "${grubfm_file}"
set root=loop
#change Xquiet to quiet of you don't want boot info displayed
#change splash to Xsplash if you want to see all boot info
echo Booting...
linux  /casper/vmlinuz  boot=casper persistent union=aufs Xquiet splash console=tty1 ---
initrd /casper/initrd.lz
boot
}
menuentry "Dr Web (64-bit SafeMode, No Net) + persistence" --unrestricted --class ubuntu {
#only update partition table if already empty
if ! test -d (${grubfm_disk},4) ; then partnew --type=0x00 --file="${grubfm_file}" (${grubfm_disk}) 4 ; fi
if test -d (${grubfm_disk},3) ; then echo ERROR: Partition 3 is not empty - cannot use as persistence partition! Press ENTER to continue...; read; fi
    if ! test -d (${grubfm_disk},3) ; then partnew --type=0x00 --file="${grubfm_per}" (${grubfm_disk}) 3 ; echo Ptn3=${grubfm_per}; fi
map -n "${grubfm_file}"
map -u
loopback loop "${grubfm_file}"
set root=loop
#change Xquiet to quiet of you don't want boot info displayed
#change splash to Xsplash if you want to see all boot info
echo Booting...
set safe=acpi=off noapic nolapic edd=on nodmraid nomodeset
#add ${safe} before --- if you want safe mode
linux  /casper/vmlinuz  boot=casper persistent union=aufs Xquiet splash console=tty1 ${safe} ---
initrd /casper/initrd.lz
boot
}
else
# return back to 'open' menu
echo ERROR: Not 64-bit CPU; sleep 5
grubfm "${grubfm_current_path}"
fi




No comments:

Post a Comment