vaido-world / download-ubuntu

0 stars 0 forks source link

Add option to Modify Booting for Smoother persistent USB #18

Open BoQsc opened 4 years ago

BoQsc commented 4 years ago

For Non UEFI systems

Rufus use \isolinux
\stdmenu.cfg - TAB request or else boots to Ubiquity

Boot to: "try Ubuntu" for persistent USB instead of Ubiquity

For UEFI systems

E:\boot\grub\grub.cfg

Disable Disk Files Check

Tutor and explanation.
Google Query I searched with

image

Set timeout to 0

image

BoQsc commented 4 years ago

Research Grub "try ubuntu" menu item in grub.cfg and isolinux and make sure to replace Ubiquity with "try ubuntu" persistent.

BoQsc commented 4 years ago

Boot straight to the Try Ubuntu instead of Ubiquity choose menu

Copy isolinux boot line to grub

E:\isolinux\txt.cfg

file=/cdrom/preseed/ubuntu.seed initrd=/casper/initrd quiet splash

E:\boot\grub\grub.cfg Paste like this: image

BoQsc commented 4 years ago

Remember to add fsck.mode=skip to stop the need of fsck every boot time

image

BoQsc commented 4 years ago

Sometimes when the Linux USB is shutdown by simply clicking shutdown button.
The Linux operating system does not shutdown and become stuck with this error:

[sdb] tag#0 access beyond end of device

IMG_20200511_180423

Note

[sdb] tag#0 access beyond end of device`

Probably happens when reached the memory last bit of the device's storage memory, or the device is empty and inaccesible.

BoQsc commented 4 years ago

One more modification required, if possible stop the "remove installation media and press enter":

IMG_20200511_190236

BoQsc commented 4 years ago

Make LiveCD run completely from RAM

https://askubuntu.com/questions/829917/can-i-boot-a-live-usb-fully-to-ram-allowing-me-to-remove-the-disk

BoQsc commented 4 years ago

Please remove the installation medium, then press ENTER:

https://unix.stackexchange.com/questions/528577/how-to-skip-please-remove-the-installation-medium-then-press-enter

http://manpages.ubuntu.com/manpages/bionic/man7/casper.7.html#:~:text=noprompt

Screenshot (160)

BoQsc commented 4 years ago

https://forums.linuxmint.com/viewtopic.php?t=282437

Adding to the script before shutdown might help decrease shutdown time for Ubuntu live.

BoQsc commented 4 years ago

Editing Iso files on Windows (untested, still probably with complete .iso extraction)

https://superuser.com/questions/1121465/how-do-i-edit-a-linux-iso-on-windows-using-command-line

Download: http://fy.chalmers.se/~appro/linux/DVD+RW/tools/win32/

https://mailing.comp.cdwrite.narkive.com/vJYHiiAs/growisofs-m-option-do-not-remove-old-files

https://superuser.com/questions/1121465/how-do-i-edit-a-linux-iso-on-windows-using-command-line#comment2027187_1122355

BoQsc commented 4 years ago

Finding and replacing Grub boot items/switches after Rufus jobs completion

https://stackoverflow.com/questions/23075953/batch-script-to-find-and-replace-a-string-in-text-file-without-creating-an-extra/23076141

BoQsc commented 4 years ago

Detecting connected USB devices

https://stackoverflow.com/questions/10868613/detect-usb-and-copy-to-usb-drive-using-batch-script

BoQsc commented 4 years ago

Additional: List detailed information about USB device

fsutil fsinfo volumeInfo E:

List free disk size

fsutil volume diskfree E:

Remount USB flash drive

fsutil volume dismount E:

Query for USB flash Drive Label

fsutil volume queryLabel E:

Set Label for the USB flash Drive

fsutil volume setLabel E: test
Note: setting inside autorun.inf of USB flash drive will override setLabel

;label = Ubuntu 20.04 LTS amd64
BoQsc commented 4 years ago

Accessing information about unknown unmounted USB devices using uuid

fsutil volume list
fsutil volume diskfree \?\Volume{97bd7694-b600-487f-a866-7694c80b6ead}\

BoQsc commented 4 years ago

Accessing unmounted USB devices requires Administrator Privilegies

fsutil fsinfo volumeInfo \?\Volume{97bd7694-b600-487f-a866-7694c80b6ead}\

BoQsc commented 4 years ago

tweak-for-persistent-usb.cmd

@ECHO OFF
SETLOCAL EnableDelayedExpansion

:loop
CALL :spinner
SET /A "count=0"
FOR /F "tokens=1*" %%A in ('fsutil fsinfo drives') DO (
    FOR %%C IN (%%B) DO (
        IF EXIST %%C\boot\grub (
            for /F delims^=^"^ tokens^=4 %%D in ('fsutil volume queryLabel %%C') do (
                SET /A "count=!count!+1"
                SET "selection[!count!]=%%C"
                ECHO ▒▒[!count!.]▒▒▒[ %%C ]▒▒[ %%D  ]
            )
        )
    )
)
            ECHO ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
CHOICE /C 1234567890 /N /T 1 /D 0 /M "Pasirinkite laikmena:"
echo !selection[%ERRORLEVEL%]!  sdf

GOTO :loop

:spinner
chcp 65001 >NUL
set mSpinner=%mSpinner%.
if %mSpinner%'==....' (set mSpinner=.)
cls

echo █▀                                  ▀█
echo        Aptinkamos USB laikmenos%mSpinner%
echo █▄                                  ▄█
goto :EOF

:spinners
set mSpinner=%mSpinner%.
if %mSpinner%'==....' (set mSpinner=.)
cls
ECHO Aptiktos USB laikmenos
echo Installation in progress%mSpinner%
ping 127.0.0.1 -n 2 >nul
goto :EOF

pause
BoQsc commented 4 years ago

Bypassing Tab Requirement while booting syslinux

.\syslinux.cfg points to .\isolinux\isolinux.cfg

# D-I config version 2.0
# search path for the c32 support libraries (libcom32, libutil etc.)
path 
include menu.cfg
default vesamenu.c32
#prompt 0
#timeout 50
#ui gfxboot bootlogo

Commenting out in .\isolinux\isolinux.cfg

image

BoQsc commented 4 years ago

https://unix.stackexchange.com/questions/32243/how-do-i-configure-syslinux-to-boot-immediately

BoQsc commented 4 years ago

.\isolinux\txt.cfg

default live
label live
  menu label ^Try Ubuntu without installing
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/ubuntu.seed initrd=/casper/initrd quiet splash ---
label live-nomodeset
  menu label ^Try Ubuntu without installing (safe graphics)
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/ubuntu.seed initrd=/casper/initrd quiet splash nomodeset ---
label live-install
  menu label ^Install Ubuntu
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/ubuntu.seed only-ubiquity initrd=/casper/initrd quiet splash ---
label live-install-nomodeset
  menu label ^Install Ubuntu (safe graphics)
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/ubuntu.seed only-ubiquity initrd=/casper/initrd quiet splash nomodeset ---
label memtest
  menu label Test ^memory
  kernel /install/mt86plus
label hd
  menu label ^Boot from first hard disk
  localboot 0x80
BoQsc commented 4 years ago

isolinux.cfg

# D-I config version 2.0
# search path for the c32 support libraries (libcom32, libutil etc.)
path 
include menu.cfg
default live
#default vesamenu.c32
#prompt 0
#timeout 50
#ui gfxboot bootlogo
BoQsc commented 4 years ago

Patching isolinux

@ECHO OFF
@setlocal enableextensions enabledelayedexpansion

SET "RANDOM_FILENAME=%RANDOM%_find_replace.txt"
FOR /F "delims=*" %%A IN (E:\isolinux\isolinux.cfg) DO (
    SET "line=%%A"

        ECHO.!line! | FINDSTR /C:"default vesamenu.c32" 1>NUL
        IF ERRORLEVEL 1 (
            ECHO !line! >> "%TEMP%\%RANDOM_FILENAME%"

        ) ELSE (
            IF "!line:~0,1!" == "#" (
                ECHO was commented
                ECHO !line:~1! >> "%TEMP%\%RANDOM_FILENAME%"
                CALL :restore

            ) Else (
                ECHO default live >> "%TEMP%\%RANDOM_FILENAME%"
                ECHO !line! >> "%TEMP%\%RANDOM_FILENAME%"

            )

        )

    )

PAUSE

:restore

FOR /F "delims=*" %%A IN (%TEMP%\%RANDOM_FILENAME%) DO (
    SET "line=%%A"

        ECHO.!line! | FINDSTR /C:"default live" 1>NUL
        IF ERRORLEVEL 1 (
            ECHO !line! >> "%TEMP%\edited-%RANDOM_FILENAME%"

        ) ELSE (
            IF "!line:~0,1!" == "#" (
                ECHO !line! >> "%TEMP%\edited-%RANDOM_FILENAME%"
            )
        ) 

)

GOTO :EOF
BoQsc commented 4 years ago
BoQsc commented 4 years ago

"Just boot to Linux"

BoQsc commented 4 years ago
@ECHO OFF
@setlocal enableextensions enabledelayedexpansion

SET "RANDOM_FILENAME=%RANDOM%_find_replace.txt"
FOR /F "delims=*" %%A IN (E:\isolinux\isolinux.cfg) DO (
    SET "line=%%A"

        ECHO.!line! | FINDSTR /C:"default vesamenu.c32" 1>NUL
        IF ERRORLEVEL 1 (
            ECHO !line! >> "%TEMP%\!RANDOM_FILENAME!"
            ECHO writing 
        ) ELSE (
            IF "!line:~0,1!" == "#" (
                ECHO was commented
                ECHO !line:~1! >> "%TEMP%\!RANDOM_FILENAME!"
                CALL :restore
                ECHO started

            ) Else (
                ECHO default live >> "%TEMP%\!RANDOM_FILENAME!"
                ECHO !line! >> "%TEMP%\!RANDOM_FILENAME!"

            )

        )

    )
ECHO end

PAUSE

:restore

FOR /F "delims=*" %%B IN (%TEMP%\%RANDOM_FILENAME%) DO (
    SET "line=%%B"

        ECHO.!line! | FINDSTR /C:"default live" 1>NUL
        IF ERRORLEVEL 1 (
            ECHO !line! >> "%TEMP%\edited-%RANDOM_FILENAME%"

        ) ELSE (
            IF "!line:~0,1!" == "#" (
                ECHO !line! >> "%TEMP%\edited-%RANDOM_FILENAME%"
            )
        ) 

)
SET "RANDOM_FILENAME=edited-%RANDOM_FILENAME%"
echo %RANDOM_FILENAME%

GOTO :EOF
BoQsc commented 4 years ago

"File in progress"

BoQsc commented 4 years ago

Search and replace

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%A in (E:\isolinux\txt.cfg) do (
    SET "line=%%A"
    SET ""
    SET s=!s:quiet=quiet haha!
    echo !s!
)

pause

https://stackoverflow.com/questions/10742686/search-and-replace-in-a-file-using-windows-batch-programming/10744709#10744709

BoQsc commented 4 years ago

New lines in Batch

https://stackoverflow.com/questions/24877969/replace-string-with-a-new-line-in-batch/24885713#24885713\

BoQsc commented 4 years ago

Substitution with variables

https://stackoverflow.com/questions/2772456/string-replacement-in-batch-file/2773504#2773504

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

SET "substitue=quiet"
SET "word=quiethaha"
for /f "delims=" %%a in (E:\isolinux\txt.cfg) do (
    SET "line=%%a"

    CALL SET "line=%%line:%substitue%=%word%%%"
    echo !line!
)

pause
BoQsc commented 4 years ago

ECHO new line in Batch

https://techsupportwhale.com/echo-new-line-in-batch-file/

BoQsc commented 4 years ago

https://www.dostips.com/forum/viewtopic.php?f=3&t=9603&p=61950#p61950

BoQsc commented 4 years ago

WMIC USB model name

wmic diskdrive where "MediaType='Removable Media'" get index,model
BoQsc commented 4 years ago
@setlocal enableextensions enabledelayedexpansion
@ECHO OFF
CALL :Find_and_comment "default vesamenu.c32" in_file "E:\isolinux\isolinux.cfg"
ECHO -------
CALL :Insert_line "default live" in_file "E:\isolinux\isolinux.cfg" at_position 3
ECHO -------
CALL :Find_and_remove "default live" in_file "E:\isolinux\isolinux.cfg" 
ECHO -------
CALL :Find_and_uncomment "default vesamenu.c32" in_file "E:\isolinux\isolinux.cfg"

pause
EXIT
:Find_and_comment

SET "FIND_STRING=%1"
SET "SOURCE_FILE=%3"
SET "RANDOM_FILE_NAME=%RANDOM%_find_replace.txt"
SET "line="
FOR /F "USEBACKQ delims=*" %%A IN (%SOURCE_FILE%) DO (
    SET "line=%%A"

    ECHO !line! | FINDSTR /C:!FIND_STRING! 1>NUL
    IF ERRORLEVEL 1 (
        ECHO !line!
    ) ELSE (

        IF NOT "!line:~0,1!" == "#" (
            ECHO #!line!
        ) ELSE (
            ECHO !line!
        )
    )

)
GOTO :EOF

EXIT
:Insert_line 

SET "STRING_TO_INSERT=%1"
Set STRING_TO_INSERT=%STRING_TO_INSERT:"=%

SET "SOURCE_FILE=%3"
SET "INSERT_AT_POSITION=%5"
SET "RANDOM_FILE_NAME=%RANDOM%_find_replace.txt"
SET /A "count=0"
SET "line="
FOR /F "USEBACKQ delims=*" %%C IN (%SOURCE_FILE%) DO (
    SET "line=%%C"
    SET /A "count=!count! +1"
    IF !count! EQU %INSERT_AT_POSITION% (
        ECHO !count! %STRING_TO_INSERT%
        )
        ECHO !count! !line! 

)
GOTO :EOF

EXIT
:Find_and_remove

SET "LINE_TO_REMOVE=%1"
SET LINE_TO_REMOVE=%LINE_TO_REMOVE:"=%

SET "SOURCE_FILE=%3"
SET "RANDOM_FILE_NAME=%RANDOM%_find_replace.txt"
SET /A "count=0"
SET "line="
FOR /F "USEBACKQ delims=*" %%D IN (%SOURCE_FILE%) DO (
    SET "line=%%D"

    ECHO !line! | FINDSTR /B /C:"!LINE_TO_REMOVE!" 1>NUL
    IF ERRORLEVEL 1 (
        ECHO !line!
    ) ELSE (

        IF NOT "!line:~0,1!" == "#" (
            REM Do nothing
        )
    )

)

GOTO :EOF

EXIT
:Find_and_uncomment

SET "FIND_STRING=%1"
SET "SOURCE_FILE=%3"
SET "RANDOM_FILE_NAME=%RANDOM%_find_replace.txt"
SET "line="
FOR /F "USEBACKQ delims=*" %%A IN (%SOURCE_FILE%) DO (
    SET "line=%%A"

    ECHO !line! | FINDSTR /C:!FIND_STRING! 1>NUL
    IF ERRORLEVEL 1 (
        ECHO !line!
    ) ELSE (

        IF "!line:~0,1!" == "#" (
            ECHO !line:~1!
        )
    )

)
GOTO :EOF
BoQsc commented 4 years ago

Using FIND - Searches for words and always ignores spaces

@ECHO OFF
DEL line.txt
FOR /F "delims=*" %%A IN (I:\isolinux\txt.cfg) DO (

    echo %%A >> "line.txt" 
    FIND "label live       " "line.txt" > nul
    IF ERRORLEVEL 1 (
        echo no 
        echo %%A

    ) ELSE (
        echo yes 
        echo %%A

            FIND "append" "line.txt" > nul
            IF ERRORLEVEL 1 (
                REM 

            ) ELSE (
                            echo found 
            )

    )

)
pause
BoQsc commented 4 years ago
@setlocal enableextensions enabledelayedexpansion
@ECHO OFF

CALL :Find_and_comment "label live" in_file "I:\isolinux\txt.cfg"
pause

:Find_and_comment

SET "FIND_STRING=%1"
SET "SOURCE_FILE=%3"
SET "RANDOM_FILE_NAME=%RANDOM%_find_replace.txt"
SET "line="
FOR /F "USEBACKQ delims=*" %%A IN (%SOURCE_FILE%) DO (
    SET "line=%%A"

    IF NOT "!found!" == "true" (

        ECHO !line! | FINDSTR /C:!FIND_STRING! 1>NUL
        IF ERRORLEVEL 1 (
            ECHO !line!

        ) ELSE (
            SET "found=true"
            IF NOT "!line:~0,1!" == "#" (
                ECHO #!line!
            ) ELSE (
                ECHO !line!
            )
        )
    ) ELSE (

        ECHO !line! | FINDSTR /C:append 1>NUL
        IF ERRORLEVEL 1 (
            ECHO !line!

        ) ELSE (
            IF NOT "!line:~0,1!" == "#" (
                ECHO #!line!
            ) ELSE (
                ECHO !line!
            )
        )

    )
)

GOTO :EOF
BoQsc commented 4 years ago

Instructions before Casper boot

https://bugs.launchpad.net/ubuntu/+source/casper/+bug/158976