Tuesday, April 28, 2020

How to have Multiple persistent for Ubuntu

The previous post discuss to have dual boot on Windows 10 and Ubuntu with persistent partition named "casper-rw". This post is about adding one Ubuntu OS and allow multiple persistent Ubuntu.

Method One solution to have multiple persistent for Ubuntu is to use persistent-path in grub menuentry.

There are limitations for persistent-path solution.

1.1) persistent-path should be a folder in FAT32 partition which also resides the ubuntu iso file. The persistent partition "casper-rw" should be ext4 partition.

1.2) There should be file system casper-rw and home-rw and has a size limitation of maximum 4G each. The persistent partition "casper-rw" does not.

1.3) To create these 2 files, first boot up ubuntu in non-persistent live session
shell script    Select all
# assume the Ubuntu iso file is mounted in Ubuntu in /isodevice and is a FAT32 partition sudo mkdir -p /isodevice/persist1/ cd /isodevice/persist1/ # create casper-rw say 1G and format as an ext file system sudo dd if=/dev/zero of=casper-rw bs=1M count=1024 sudo mkfs.ext4 -L casper-rw -F casper-rw # home-rw usually needs a larger size say 2G sudo dd if=/dev/zero of=home-rw bs=1M count=2046 sudo mkfs.ext4 -L home-rw -F home-rw # create another persist folder sudo mkdir -p /isodevice/persist2/ cd /isodevice/persist2/ # create casper-rw say 1G and format as an ext file system sudo dd if=/dev/zero of=casper-rw bs=1M count=1024 sudo mkfs.ext4 -L casper-rw -F casper-rw # home-rw usually needs a larger size say 2G sudo dd if=/dev/zero of=home-rw bs=1M count=2046 sudo mkfs.ext4 -L home-rw -F home-rw


1.4) The menuentry for both persistent-path and persistent partition are shown below

sudo nano /media/ubuntu/0000-????/grub/grub.cfg    Select all
# menuentry for persistent-path persist1 for Ubuntu 18.04 menuentry "Ubuntu 18.04 persistent-path=/persist1" { set isofile="/ubuntu-18.04.4.iso" # In Linux, you can find UUID by using : sudo blkid /dev/sda? set uuid="XXXX-XXXX" search --fs-uuid --no-floppy --set=root $uuid loopback loop (${root})${isofile} linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} persistent persistent-path=/persist1 quiet splash initrd (loop)/casper/initrd } # menuentry for persistent-path persist1 for Ubuntu 16.04 menuentry "Ubuntu 16.04 persistent-path=/persist2" { set isofile="/ubuntu-16.04.6.iso" # In Linux, you can find UUID by using : sudo blkid /dev/sda? set uuid="XXXX-XXXX" search --fs-uuid --no-floppy --set=root $uuid loopback loop (${root})${isofile} linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} persistent persistent-path=/persist2 quiet splash initrd (loop)/casper/initrd } # menuentry for persistent partition menuentry "Ubuntu 18.04 persistent partition" { set isofile="/ubuntu-18.04.4.iso" insmod ntfs # In Linux, you can find UUID by using : sudo blkid /dev/sda? # set uuid="0000-XXXX" # search --fs-uuid --no-floppy --set=root $uuid # loopback loop (${root})${isofile} # (hd0,3) means /dev/sda3 change it to (hd0,2) or (hd0,4) as necessary # This should be the partition of the ubuntu ISO loopback loop (hd0,3)${isofile} linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} persistent quiet splash initrd (loop)/casper/initrd }


1.5) This persistent-path solution currently does not support the new Ubuntu 19.10 and 20.04 desktop images. Maybe it is still a bug to be solved.




Method Two solution is to create two ext4 partitions casper-rw1 and casper-rw2 so that there is no 4G size limit for method one, two menuentry and OSs and by using script file to rename and swap the partition name to casper-rw before working on the required OS. This method two is also suitable for testing the new Ubuntu 20.04 desktop image.

2.1) Assume, the ext4 partitions are formatted in the USB sticks as
/dev/sda5 casper-rw1 partition with size 10G is for Ubuntu 18.04 persistent
/dev/sda6 casper-rw2 partition with size 10G is for Ubuntu 20.04 persistent


2.2) The menuentry section in grub.cfg has labels showing the existing RW1-OK active persistent partition and other entries
grub.cfg    Select all
menuentry "Ubuntu 18.04 persistent partition RW1-OK" { set isofile="/ubuntu-18.04.4.iso" # In Linux, you can find UUID by using : sudo blkid /dev/sda? set uuid="XXXXXXXXXXXXXXXX" search --fs-uuid --no-floppy --set=root $uuid loopback loop (${root})${isofile} linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} file=/cdrom/preseed/ubuntu.seed persistent quiet splash --- initrd (loop)/casper/initrd } menuentry "Ubuntu 20.04 persistent partition RW2-NO" { set isofile="/ubuntu-20.04.iso" set uuid="XXXXXXXXXXXXXXXX" search --fs-uuid --no-floppy --set=root $uuid # In Linux, you can find UUID by using : sudo blkid /dev/sda? loopback loop (${root})${isofile} linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} file=/cdrom/preseed/ubuntu.seed persistent quiet splash --- initrd (loop)/casper/initrd } menuentry "Ubuntu 18.04 non-persistent Live Session" { set isofile="/ubuntu-18.04.4.iso" # In Linux, you can find UUID by using : sudo blkid /dev/sda? set uuid="XXXXXXXXXXXXXXXX" search --fs-uuid --no-floppy --set=root $uuid loopback loop (${root})${isofile} linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} file=/cdrom/preseed/ubuntu.seed quiet splash --- initrd (loop)/casper/initrd }


2.3) Create the following shell scripts in /isodrive/
rw1.sh    Select all
#!/bin/sh # change to ubuntu 18.04 RW1-OK with /dev/sda5 name as "casper-rw" sudo umount /dev/sda6 && sudo e2label /dev/sda6 "casper-rw2" sudo umount /dev/sda5 && sudo e2label /dev/sda5 "casper-rw" sed -i 's/\(\sRW1-NO\)\(.\{3,4\}$\)/ RW1-OK\2/; s/\(\sRW2-OK\)\(.\{3,4\}$\)/ RW2-NO\2/;' /media/ubuntu/0000-????/grub/grub.cfg grep 'RW[12].\{3,3\}" {' /media/ubuntu/0000-????/grub/grub.cfg

rw2.sh    Select all
#!/bin/sh # change to ubuntu 20.04 RW2-OK with /dev/sda6 name as "casper-rw" sudo umount /dev/sda5 && sudo e2label /dev/sda5 "casper-rw1" sudo umount /dev/sda6 && sudo e2label /dev/sda6 "casper-rw" sed -i 's/\(\sRW1-OK\)\(.\{3,4\}$\)/ RW1-NO\2/; s/\(\sRW2-NO\)\(.\{3,4\}$\)/ RW2-OK\2/;' /media/ubuntu/0000-????/grub/grub.cfg grep 'RW[12].\{3,3\}" {' /media/ubuntu/0000-????/grub/grub.cfg



2.4) Boot into non-persistent live session and run the shell script sudo /bin/sh rw1.sh so that it will rename the /dev/sda5 partition to casper-rw and also adjust the grub menu entry name to indicate which partition Ubuntu 18.04 RW1-OK is active.

2.5) Reboot into grub menu and choose the Ubuntu 18.04 OS RW1-OK to run


2.6) Repeat step 2.4 and boot into non-persistent live session and run sudo /bin/sh rw2.sh & step 2.5 to Ubuntu 20.04 RW2-OK if working on another OS is needed.


No comments: