SOLVED - Unmount persistence image from Buster live USB

If none of the more specific forums is the right place to ask
Post Reply
Message
Author
kkman007
Posts: 20
Joined: 2020-08-09 19:53
Location: London

SOLVED - Unmount persistence image from Buster live USB

#1 Post by kkman007 »

Hi

I am using a persistence image file to store and save system settings such as WIFI for my Debian Buster Live image run from a USB stick. As I want to run the live image in RAM so I could remove the USB once the system boots up, I wanted to write a script to allow the persistence image to be unmounted after the saved settings are loaded.

However there are a number of mounts and I was hoping for some advise as what is the best way to unmount the persistence image after the system has booted up.

Below are the mounts which I think I need to remove, but is there a better way?

/dev/sda3 on /run/live/persistence/sda3 type ext2 (rw,noatime)

/dev/loop1 on /run/live/persistence/loop1 type ext3 (rw,noatime)

/dev/sda3 on /lib/live/mount/persistence/sda3 type ext2 (rw,noatime)

/dev/loop1 on /lib/live/mount/persistence/loop1 type ext3 (rw,noatime)

overlay on /etc/NetworkManager/system-connections type overlay (rw,noatime,lowerdir=/run/live/rootfs/filesystem.squashfs//etc/NetworkManager/system-connections,upperdir=/run/live/persistence/loop1/etc/NetworkManager/system-connections/rw,workdir=/run/live/persistence/loop1/etc/NetworkManager/system-connections/work)

Can I add a suplimentry question. Having unmounted the persistence image, can I remount it later within the running system, without needing a reboot and have it persist changes. Hope that makes sense.

Any advise would be helpful.
Thanks


***************** SOLVED *****************

OK I have looked at how to get a persistent storage detached from a live USB booted into RAM.

I use LXDE Desktop and so pcmanfm is the default destop manager. So to unmount the persistence file I need to disable pcmanfm first.

The solution is to look at /proc/cmdline to see if persistence is used. Take the persistence file name and find its mount point.
Then read the persistence.conf file. For each file either create a direct mount or a union mount depending if the line includes the word union.

Below is the code to unmount the persistence image to safly remove the USB stick

fsType=`findmnt -T /run/live/persistence/$device --output FSTYPE --noheading`
if [ "$fsType" = "fuseblk" ]; then
fsType="ntfs"
fi
sudo mkdir /tmp/hold
pcmanfm --desktop-off --profile LXDE
// For unions we need to copy the contents before we unmount to keep the information
sudo cp /etc/NetworkManager/system-connections/* /tmp/hold/
sudo umount /lib/live/mount/persistence/$loopD
sudo umount /run/live/persistence/$loopD
sudo losetup -d /dev/$loopD
sudo umount /lib/live/mount/persistence/$device
sudo umount /etc/NetworkManager/system-connections
// For normal entries just unmount
sudo umount /home/splashos/Desktop # add here
sudo umount /run/live/persistence/$device # add here
sudo rm /etc/NetworkManager/system-connections/*
sudo cp /tmp/hold/* /etc/NetworkManager/system-connections/
sudo rm -rf /tmp/hold
#sleep 1
setsid pcmanfm --desktop --profile LXDE &
#sleep 1
disown

If we want to reconnect the persistence back
sudo mount -t ext2 -o noatime /dev/sda3 /run/live/persistence/sda3
sudo losetup -fP /run/live/persistence/sda3/area2/usbPersistence
sudo mount -o loop /dev/loop1 /run/live/persistence/loop1
sudo mount -t overlay overlay -o noatime,lowerdir=/run/live/rootfs/filesystem.squashfs/etc/NetworkManager/system-connections,upperdir=/run/live/persistence/loop1/etc/NetworkManager/system-connections/rw,workdir=/run/live/persistence/loop1/etc/NetworkManager/system-connections/work /etc/NetworkManager/system-connections
sudo mount --bind /run/live/persistence/loop1/home/splashos/Desktop/ /home/splashos/Desktop/
sudo mount --bind /run/live/persistence/sda3 /lib/live/mount/persistence/sda3
sudo mount --bind /run/live/persistence/loop1 /lib/live/mount/persistence/loop1
echo
echo Remounted Persistence, press any key to continue
pcmanfm --desktop-off --profile LXDE
sleep 1
setsid pcmanfm --desktop --profile LXDE &

Post Reply