backing up and restoring the eMMC - google-coral

What would be the procedure to backup the onboard eMMC from the SD card image of the google coral dev board?
Similarly, what procedure should we follow to restore the image to the emmc drive onboard?

backup the onboard eMMC from the SD card image
The Mendel OS image isn't installed on the sdcard so do you mean just backing up the emmc so that you can put it on another board? If so, here is the proceedure:
In order to backup emmc, you'll first need to mount your dev board as a USB device on your linux host machine. You do this, by connecting to your board via serial console and put it in u-boot mode (just boot the board up and press any keys within the first 3 seconds), make sure the USB-C cable is also connected. In u-boot prompt, enters:
U-Boot# ums 0 mmc 0
This will mount the dev board on your host machine as a USB device. Locate that device using the "fdisk -l" command. Then you can dd the bytes from that disk into an img file:
$ sudo dd if=/dev/path-to-dev-board of=./backup.img bs=4M status=progress
Be very careful that you are copying from the correct path, or else you'll copy from the wrong device. Next you can dd this backup image to any other board by first mounting a new board on your host machine and then locate the board with fdisk (same steps as above). Then you can dd the backup image to your board by reversing the dd command:
$ sudo dd if=./backup.img of=/dev/path-to-dev-board bs=4M status=progress
Be very careful with the out file path this time, because you can replace the wrong drive with the bytes from backup.img (that would be irreversible).

Related

BeagleBone black USB_mass_storage connect to Windows not working

I have an annoying issue regarding getting USB_mass_storage on BBB to work when connected to Windows
I have created an image :
dd bs=1M if=/dev/zero of=/usb.bin count=64
Formatted it:
mkdosfs /usb.bin -F 32 -I
I have mounted it, copied files to and from it, no problem.
Then I created a USB mass storage :
modprobe g_mass_storage file=./usb.bin stall=0 ro=0
Connected it to a USB port on my Linux, nor problem, I can see and manipulate files
On Windows I can see the drive, the size is correct, but filesystem is not recognized.
With ro=0 I am able to create a partition from within Windows and format it. I can copy files to and from it but when I mount it on BBB I can not see the files copied using Windows. I can still though see the files I copied to the mountpoint on BBB.
Can someone tell me what I am doing wrong ?
I disabled everything regarding g_multi, including RNDIS, Serial, CDC.
And it works perfectly under Linux.
You have created a raw disk image without a partition table on the Linux side. Linux doesn't care if it's a file, if it has a partition table, etc.
Windows however gets confused by the lack of partition table. As you noticed.
Having a partition table is preferable. What you can do on the Linux side of things:
losetup --partscan - Have the file get processed as a disk with partition table and get devices for each partition
Mount the partition directly using an offset
In this particular case the latter is probably the quickest. There is only one partition and the offset is known.
fdisk -l ./usb.bin
Multiply the Start value by the Units size. Use it as the offset below:
mount -o loop,offset=12345 ./usb.bin /mnt
Make sure to never access from both sides at the same time as this will lead to filsystem damage and data loss.
See also e.g. https://askubuntu.com/a/69447

How to mount an FTDI USB device to a docker container?

I would like to be able to access an FTDI serial-to-usb bridge device plugged into a host computer from within a Docker container. From there, I am using a Python script with the pyusb and libusb libraries to process the USB output. That way, I can plug the FTDI board with its attached devices into some computer, run the docker container, and process the data. The container is built using docker-compose.
How we got here
As an earlier test on my host computer, I wrote the following Python script which will run at the start of my design:
import usb.core
import usb.util
# Find the USB device
device = usb.core.find(idVendor = 0x0403, idProduct = 0x601c)
# Check if the device was found. If not, raise an error. If the device was found, print out its info.
if (device == None):
raise ValueError('Device not found')
else:
print(device)
This printed out all the information on the board as expected - manufacturer, interfaces, endpoints, ect. (I was able to find the vendor and product IDs using lsusb -D /dev/bus/usb/003/007, where the numbers were the bus and device numbers given by lsusb).
I then went into my docker container in vscode, installed the two libraries, and ran the same script. This time, I got an error:
usb.core.NoBackendError: No backend available
I went to the pyusb FAQ at https://github.com/pyusb/pyusb/blob/master/docs/faq.rst
and made sure that I didn't have one of the common causes of the error. The error persisted even after I used usb.backend.libusb1.get_backend(...) to specify the backend library by hand.
I came to the realization that a root cause of the problem was that the docker container had no way to access the FTDI USB device in the first place. With a week's worth of experience in Docker, I think that I need to mount the USB device on my host computer to the container using
What has been tried
In my service in the docker-compose file, I've tried to specify the mounting location of the device using the following:
devices:
- "/dev/serial/by-id/<link>:/dev/ttyUSB0"
privileged: true
To find , I went into the /dev/serial/by-id/ directory and used dmesg | grep tty. It displayed a new entry whenever I plugged in a different USB device (Arduino), but did not have any new entries when I plugged in the FTDI board. Because of this, I doubt that my FTDI board is a TTY device, which most of the existing threads seem to focus around. I am not sure how else to give docker-compose what it needs to mount the device.
Because the pyusb library will find my device if it's given several USB devices, simply mounting all of the host USB ports should also solve my problem. I searched around this set of keywords as well, but didn't find much useful information.
TL:DR
How can I mount either an individual FTDI Serial-to-USB bridge device or all of the USB devices on my host computer to a docker container? I'd like to avoid using privileged if possible. I've been working with Ubuntu, Docker, and Python for about a week so I may need it spelled out. Let me know if any more information is needed.
Thanks!

Disk storage files in wsl2. Where does free space disappear?

Earlier I used with hyper-v and docker.
Recently I've installed wsl2 for docker usage.
After wsl2 installation I dowloaded and installed ubuntu 20 and set it in docker desktop settings.
So command wsl --list returns
-* Ubuntu-20.04 Running 2
- docker-desktop Running 2
- docker-desktop-data Running 2
I see in daily work that free space disappears on disk C.
I found few files with huge size and i'd like to know what it is? And if I could delete them or cut?
Here are the files:
c:\Users\***\AppData\Local\Docker\wsl\data\ext4.vhdx-----------55 gb
c:\ProgramData\DockerDesktop\vm-data\DockerDesktop.vhdx--------45 gb
c:\Users\All Users\DockerDesktop\vm-data\DockerDesktop.vhdx----the same as prev. What is it??
General question - how reduce disk usage? And what are that files?
This can be resolved by compacting the vhdx file through diskpart
Below file eats up a lot of diskspace.
C:\Users\xxx\AppData\Local\Docker\wsl\data\ext4.vhdx
Here are the commands to resolve and reclaim your diskspace
Ensure that your docker data is cleaned up
docker system prune -all
Warning: Deletes all your images, container, volumes and all data that's created by docker
Terminate the wsl dist that's unused.
Run the command wsl -l -v and terminate all other entries except the below
Entry with * represents your current dist
docker-desktop
docker-desktop-data
Take the backup of you current dist wsl --export <dist> <path>
diskpart
Opens up a new prompt DISKPART>. Issue the command select vdisk file="your-docker-data-file"
Example: select vdisk file="C:\Users\xxx\AppData\Local\Docker\wsl\data"
Finally, do compact vdisk
I observed the same issue: wsl2 got bigger and bigger and even when I deleted files inside of wsl2, I couldn't see the free space reflected on my host machine.
After some research I found a nice step-by-step instruction by Stephen Rees-Carter how to shrink the used space by wsl2: How to Shrink a WSL2 Virtual Disk
A rough explanation:
wsl2 is compressed in one single image on your host machine called ext4.vhdx (located somewhere C:\Users\<Username>\AppData\Local\Packages\<Distro>\LocalState)
to shrink that file and return unused space diskpart can be used:
select vdisk file="pathTo_ext4.vhdx"
compact vdisk
In my case the wsl2 image size was reduced by ~30%.

How can I save a docker image without having enough storage on my main drive?

My problem:
I'm trying to save a Jetson TX2 docker image that's about 8GB. The OS and other files+OS are taking up around 21GB meaning I only have about 3GB of storage on the machine. I have already pruned old images and containers, and cannot delete or free up any more space. Because of this I've tried saving the docker image to an USB stick.
However, when I try to build the docker file I get the error:
*Error response from daemon: write /var/lib/docker/tmp/docker-export-50xxxxx/layer.tar: no space left on device*
Even though I am trying to save the docker image to an USB with enough space, Docker seems to build the whole file first using the /var/lib/docker/tmp/ folder and then wants to move it to the USB. However there simply isn't enough space on the device. Because of this I keep getting the error listed above.
My question:
Is there any way to save a docker image without using my main drive as intermediary storage? I can ssh into the Jetson and have an USB/SD card with sufficient capacity. If there is another solution that would solve my problem that would be great to hear too.
Mount the USB drive on the system and then use the -o flag of docker export to export the image.
So with an example USB drive mounted on /mnt/usb, use ....
docker export -o /mnt/usb <CONTAINER ID>

In KVM how to clone a VM to a VM with different disk space

Using Centos 6.7 as hot for KVM virtualization, I have created a VM with a virtual disk of size 30GB. I want to clone this VM to a new VM with a different disk size.
The new VM should have a disk space of 60GB.
Is this possible at all? if yes how can I do it?
why you want clone vm to deferent space ?
1 - if you want clone vm for extend hdd of vm
kvm use lvm for each vm so you can extend lvm for increase hdd of vm
lvextend -l +(size of extend in byte or use G for gigabyte) /dev/vgname/lvmNameOfVm
resize2fs /dev/vgname/lvmNameOfVm
you can find lvm and vg name with lvdisplay and vgs
2 - if you need clone for change location of vm to other server
i suggested you first resize your vm and then clone to new vm
note : if you want do this for first time first create a vm for test and do it after test it and work for you use for main vm
you have not controlpanel like solusvm ? if you have your panel can clone vm withouth need do anything on the ssh
I managed to clone a VM and then increase its disk size and because I decided to bring steps I took here because I couldn't find all these steps in one place.
after cloning, to extend the disk size, create a disk with bigger size:
virsh vol-create-as default newdisk 60G
and copy the old disk to the new disk and expand one of the guest's partition:
virt-resize --expand /dev/sda2 olddisk newdisk
change the vm's configuration to use the new disk.
issue this command to edit the configuration file:
#virsh edit <VM_name>
find and replace the old disk name with the new disk name.
more detail about these steps can be found here: http://libguestfs.org/virt-resize.1.html
now start the new vm, log in to it and resize the vm's lvm partion.
lvextend -l +<free_blocks_count> /dev/vg_<VM_name>/lv_root
resize2fs /dev/vg_<VM_NAME>/lv_root
to find number of free blocks issue the following command:
vgdisplay
a great tutorial about these steps can be found here: http://www.tecmint.com/extend-and-reduce-lvms-in-linux/

Resources