User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Vdesktop: Ever wanted to run an img file before flashing it to an SD card?

Sun Sep 15, 2019 1:02 pm

TL;DR I have made a script to run Raspbian, within Raspbian.

This script is excellent in these situations:
  • Migrating to a clean install of Raspbian and want to compare the appearance of both OS'es at once.
  • Running two versions of software at the same time, one in the host, other in the guest.
  • Running something you might want to undo (such as compiling) and don't want your main OS modified.
  • "Switch" OSes without ever shutting down or swapping SD cards.
  • Run Raspbian Stretch on a Pi 4.
Here's a screenshot of Vdesktop running Stretch inside Buster!
Image

To download:

Code: Select all

git clone https://github.com/Botspot/vdesktop
chmod +x /home/pi/vdesktop/rc.local /home/pi/vdesktop/vdesktop
On the first run Vdesktop will prompt you to install Xephyr and Systemd-nspawn.

To download and run a fresh Stretch image:

Code: Select all

cd
git clone https://github.com/Botspot/vdesktop
chmod +x /home/pi/vdesktop/rc.local /home/pi/vdesktop/vdesktop
wget http://downloads.raspberrypi.org/raspbian_full/images/raspbian_full-2019-04-09/2019-04-08-raspbian-stretch-full.zip
unzip /home/pi/2019-04-08-raspbian-stretch-full.zip
sudo /home/pi/vdesktop/vdesktop /home/pi/2019-04-08-raspbian-stretch-full.img
Command usage:
Boot from an image file:

Code: Select all

sudo /home/pi/vdesktop/vdesktop /home/pi/2019-04-08-raspbian-stretch-full.img
Or a block device:

Code: Select all

sudo /home/pi/vdesktop/vdesktop /dev/sda
Or the root directory of the guest:

Code: Select all

sudo /home/pi/vdesktop/vdesktop /home/pi/raspbian-stretch/
Once the guest has booted, you have to log in with the guest's credentials.
Default username is pi
Default password is raspberry
Then the guest's GUI will appear in a Xephyr window.

To do:
  • Write up a more comprehensive set of instructions, and add come CLI flags.
  • autologin to the guest, so the user doesn't have to do it manually.
  • auto-detect default desktop session profile to correctly boot pi-top OS and Raspbian that doesn't have raspberrypi-ui-mods installed.
  • Sync sound between host and guest, preferably avoiding pulseaudio.
  • display text at guest's default size instead of autoscaling to Xephyr's aspect ratio.
  • display guest's default mouse pointer instead of the fall-back Adwaita.
Last edited by Botspot on Mon Jan 13, 2020 3:40 pm, edited 10 times in total.
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP

hippy
Posts: 6770
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Powerful Tool to run a Stretch Container in Buster. Testers wanted, comments wanted.

Sun Sep 15, 2019 3:10 pm

Excelent stuff. On my 3B (non-plus) I managed to get Buster running under Buster okay -

Code: Select all

pi@Pi3B:~ $ sudo /home/pi/vdesktop/vdesktop /home/pi/2019-06-20-raspbian-buster.img 
OK, looks like you specified an .img file.
e2fsck 1.44.5 (15-Dec-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
... etc ...
But had problems trying to run other images which I have run before on a 3B ...

Code: Select all

pi@Pi3B:~ $ sudo /home/pi/vdesktop/vdesktop /home/pi/lineage-14.1-20180615-UNOFFICIAL-KonstaKANG-rpi3.img 
OK, looks like you specified an .img file.
/home/pi/vdesktop/vdesktop: line 134: 264192
2361344 * 512: syntax error in expression (error token is "2361344 * 512")
Unable to create loop device

Code: Select all

pi@Pi3B:~ $ sudo /home/pi/vdesktop/vdesktop /home/pi/chromiumos_image_r70.img 
OK, looks like you specified an .img file.
/home/pi/vdesktop/vdesktop: line 134: * 512: syntax error: operand expected (error token is "* 512")
Unable to create loop device
That may be as expected, not being Raspbian images and all, but it does seem to point to a "syntax error" in vdesktop.

User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Re: Powerful Tool to run a Stretch Container in Buster. Testers wanted, comments wanted.

Sun Sep 15, 2019 7:30 pm

hippy wrote:
Sun Sep 15, 2019 3:10 pm

Code: Select all

pi@Pi3B:~ $ sudo /home/pi/vdesktop/vdesktop /home/pi/chromiumos_image_r70.img 
OK, looks like you specified an .img file.
/home/pi/vdesktop/vdesktop: line 134: * 512: syntax error: operand expected (error token is "* 512")
Unable to create loop device
That may be as expected, not being Raspbian images and all, but it does seem to point to a "syntax error" in vdesktop.
Yes, vdesktop is only designed to boot Raspbian images at this time; the main reason for that being that the container is actually running the host's kernel. So images such as Chromium OS are not supported. Second reason is that the image mounting utility my script is using is only intended for Raspbian img files. So it has no clue what to do when faced with Chromium OS'es 15 partitions. Edit: So that's where the syntax error is coming from.
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP

User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Wed Sep 25, 2019 3:23 pm

Good morning, everyone.

Well my Pi 4 finally arrived, and after some extensive testing in several configurations, I am relieved to announce that using vdesktop, Raspbian Stretch runs at 100% native speed on a Pi 4.

The vdesktop script has been updated a bit and a couple bugs worked out (see the github page for more details), so if anyone out there has suggestion or bug report, please let me know!

Also, I am working on a bootable image with vdesktop installed and a Raspbian Stretch demo image downloaded. So if anyone has any experience on the proper way to create a clean bootable image, please let me know!
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12597
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Thu Sep 26, 2019 8:13 pm

Thread moved to general discussion, as requested by OP.

sunilvb
Posts: 5
Joined: Sun Feb 02, 2014 2:54 am

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Fri Sep 27, 2019 11:00 pm

Was able to install and run Stretch on RPi 4!!

Observations :
[FAILED] Failed to start Remout Root and Kernel File System
[FAILED] Failed to start rng-tools.service
[FAILED] Failed to start Avahi mDNS/DNS-SD stack
[FAILED] FAiled to start LSB: Resize the root filesystem to fill partition

In spite of the FAILED msg, I was able to login and start the guest os (Stretch on Buster). Although, the task bar icons are invisible.
The browser does not connect to internet.
Questions:
How do I ssh into the guest from host or external computer on the network?
What options are available to communicate from host to guest?
How do I copy file from host to guest and vice versa?

User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Sat Sep 28, 2019 11:00 pm

sunilvb wrote:
Fri Sep 27, 2019 11:00 pm
[FAILED] Failed to start Remout Root and Kernel File System
[FAILED] Failed to start rng-tools.service
[FAILED] Failed to start Avahi mDNS/DNS-SD stack
[FAILED] FAiled to start LSB: Resize the root filesystem to fill partition
That is completely normal, and in fact part of the beauty of systemd-nspawn:
systemd-nspawn limits access to various kernel interfaces in the container to read-only, such as /sys, /proc/sys or /sys/fs/selinux. The host's network interfaces and the system clock may not be changed from within the container. Device nodes may not be created. The host system cannot be rebooted and kernel modules may not be loaded from within the container.
sunilvb wrote:
Fri Sep 27, 2019 11:00 pm
Although, the task bar icons are invisible.
Strange. It works for me every time. Well I lengthened the "grace period", it should work now.
sunilvb wrote:
Fri Sep 27, 2019 11:00 pm
The browser does not connect to internet.
I noticed that too. Only seems to be a problem on the Pi 4, not earlier models. I'll have to research it.
sunilvb wrote:
Fri Sep 27, 2019 11:00 pm
How do I ssh into the guest from host or external computer on the network?
Well from the host, that's easy. Just type commands into the same terminal you entered the guest's username and password.
From another computer on the local network, I have never tried this. But I think the guest would need internet connection, so once I get that working again it should work like it would on a normal Pi.
sunilvb wrote:
Fri Sep 27, 2019 11:00 pm
What options are available to communicate from host to guest?
Currently the Xephyr window only "listens" to the keyboard and mouse. So far I have had no luck getting the guest to be able to communicate with a usb device connected to the host machine.
sunilvb wrote:
Fri Sep 27, 2019 11:00 pm
How do I copy file from host to guest and vice versa?
Very easy. I forgot to mention this. Vdesktop mounts all img files to /mnt/virtualdesktop by default. So just go in there and you can access everything.
Edit: Vdesktop now mounts img files and block devices to /media/pi/vdesktop. That way, the desktop will show them as a mounted disk.
Last edited by Botspot on Mon Jan 13, 2020 3:44 pm, edited 1 time in total.
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP

User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Mon Sep 30, 2019 1:59 am

Update: bootable image released. Download it here, and see the first post for details.
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP

WoodyC
Posts: 4
Joined: Sun Jan 12, 2020 8:03 am

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Sun Jan 12, 2020 8:10 am

Excellent works, thank you!

Now I can run Raspbian Stretch inside Raspbian Buster. But there is a little problem, the script did not work with image with 3 partitions. Partition details as below:

Code: Select all

Disk /dev/loop7: 29.9 GiB, 32111591424 bytes, 62717952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Device       Boot    Start      End  Sectors  Size Id Type
/dev/loop7p1          8192   532480   524289  256M  c W95 FAT32 (LBA)
/dev/loop7p2        540672 45139967 44599296 21.3G 83 Linux
/dev/loop7p3      45139968 62717951 17577984  8.4G 83 Linux
* p1 is boot, p2 is / and p3 is a data partition.

Error output as below.

Code: Select all

OK, looks like you specified an .img file.
./vdesktop: line 181: 540672
45139968 * 512: syntax error in expression (error token is "45139968 * 512")
Unable to create loop device
umount: /mnt/virtualdesktop/etc/rc.local: no mount point specified.
umount: /mnt/virtualdesktop/etc/profile: no mount point specified.
umount: /mnt/virtualdesktop: not mounted.
losetup: option requires an argument -- 'd'
Try 'losetup --help' for more information.

If I delete the last partition in the image, it run well.

User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Sun Jan 12, 2020 10:32 pm

I took the freedom to condense the quote below.
WoodyC wrote:
Sun Jan 12, 2020 8:10 am
the script did not work with image with 3 partitions.
If I delete the last partition in the image, it run well.
Good suggestion. It's fixed. Just re-run your script and it should auto-update with the new version.

What happened was I just borrowed most of RonR's image-mount bash script to mount image files. It works, but it's cumbersome:

Code: Select all

PART="Linux"
  MNT="$mntpnt"
  IMG="$1"
  if [ "${PART}" = "" ]; then
    PART="type=83"
  else
    PART="$(tr [A-Z] [a-z] <<< "${PART}")"
    if [ "${PART}" = "w95" ];then
      PART="type=c"
    elif [ "${PART}" = "linux" ];then
      PART="type=83"
    else
      usage
    fi
  fi
  
  INFO="$(sfdisk -d "${IMG}")"
  START=$(grep "${PART}" <<< "${INFO}" | sed -n 's|^.*start=\s\+\([0-9]\+\).*$|\1|p')
  SIZE=$(grep "${PART}" <<< "${INFO}" | sed -n 's|^.*size=\s\+\([0-9]\+\).*$|\1|p')
  LOOP="$(losetup -f --show -o $((${START} * 512)) --sizelimit $((${SIZE} * 512)) "${IMG}")"
  if [ $? -ne 0 ]; then
    echo "Unable to create loop device"
    exit 1
  fi
  if [ "${PART}" = "type=c" ]; then
    dosfsck "${LOOP}"
  else
    FS_TYPE=$(blkid "${LOOP}" | sed -n 's|^.*TYPE="\(\S\+\)".*|\1|p')
    if [ "${FS_TYPE}" = "f2fs" ]; then
      fsck.f2fs "${LOOP}"
    else
      fsck.ext4 -f "${LOOP}"
    fi
  fi
  if [ $? -ne 0 ]; then
    losetup -d "${LOOP}"
    echo "Filesystem appears corrupted"
    exit 1
  fi
  mount "${LOOP}" ${MNT}
  echo ""
  echo "${IMG} mounted on ${MNT}"
Yes, a lot longer than necessary. And only works if the img has 2 partitions.
So I re-wrote it:

Code: Select all

LOOP="$(losetup -fP --show $1)"
  echo "$LOOP"
  mount -o rw "${LOOP}p2" "$mntpnt"
  mount -o rw "${LOOP}p1" "${mntpnt}/boot"
A lot shorter, it works considerably faster, mounts boot properly, and won't freak out if there's a third partition. 8-)
Your problem should be solved.

Any more bug reports? Improvements or suggestions?
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP

WoodyC
Posts: 4
Joined: Sun Jan 12, 2020 8:03 am

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Mon Jan 13, 2020 2:26 pm

Thank you for the quick response and solution. It is now working fine with the image having three partitions. The new version also found to have added nice features, showing mounted volume on desktop and keep it mounting on guest close. It’s very convenient.

However, the auto update (at least on the old version) appear to have issue. It detect the new version but couldn't update it successfully. Output show as below.
================================================================
Vdesktop has a new version. Would you like to download it? [Y/n]
y
OK. Downloading Vdesktop.
New version has been downloaded. Vdesktop is exiting.
cp: target '.' is not a directory
================================================================
I've download the new version from GitHub instead.

Thank you!

User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Re: Vdesktop: Ultimate Raspbian Virtual Machine Script. Feedback wanted!!

Mon Jan 13, 2020 3:26 pm

WoodyC wrote:
Mon Jan 13, 2020 2:26 pm
It detect the new version but couldn't update it successfully. Output show as below.

Code: Select all

Vdesktop has a new version. Would you like to download it? [Y/n]
y
OK. Downloading Vdesktop.
New version has been downloaded. Vdesktop is exiting.
cp: target '.' is not a directory
It's always worked fine for me. I improved the update procedure, it should work better now.
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP

WoodyC
Posts: 4
Joined: Sun Jan 12, 2020 8:03 am

Re: Vdesktop: Ever wanted to run an img file before flashing it to an SD card?

Tue Jan 14, 2020 1:34 pm

Good news is version 5 update code is working fine. But, I didn't realize it will erase everything in the ~/vdesktop folder in which I used to store image startup script. May be some warning message before the update is good.

User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Re: Vdesktop: Ever wanted to run an img file before flashing it to an SD card?

Tue Jan 14, 2020 3:00 pm

WoodyC wrote:
Tue Jan 14, 2020 1:34 pm
Good news is version 5 update code is working fine. But, I didn't realize it will erase everything in the ~/vdesktop folder in which I used to store image startup script. May be some warning message before the update is good.
Yes, Vdesktop now clears its folder before putting the new version in. This ensures that all the vdesktop users will have matching folders to prevent problems. Sorry it cleared your script. :oops:
Version 6 vdesktop moves the old version to ~/vdesktop.old instead of deleting it.
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP


User avatar
Botspot
Posts: 490
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas

Re: Vdesktop: Ever wanted to run an img file before flashing it to an SD card?

Tue Feb 04, 2020 9:48 pm

I've been looking for a way to do this for several months: bypass the guest login or at least accommodate for guests whose password is not raspberry. This is the only issue preventing a fully automated GUI tool from being released. Well I finally had a breakthrough solution: override the guest's password file. Vdesktop now mounts its own over top the guest's one temporarily.
Tl;DR In the past, you had to know the guest's password to login. Now, vdesktop ensures the password is always raspberry. When you reach the login screen, no matter what the guest's password actually is, type "raspberry" in the password box.
Ever wanted to run an .img file before flashing it to an SD card?
Or wished you could run Stretch on a Pi 4?
Or wanted to run two versions of Raspbian on a single Pi simultaneously?
You can do all of that, and more, with my Vdesktop script - http://bit.ly/VDESKTOP

Return to “General discussion”