How to copy the files of a previous installation of ubuntu (20.04) inside the lxc container

Hello to everyone.

I’m on the jetson nano,where I have installed ubuntu 22.04 and lxc (via snap). At this point,I have installed ubuntu 20.04 as container and I have enabled the network using the following commands :

lxc launch ubuntu:20.04 focal
lxc start focal
lxc exec focal -- dhclient

as you can see it is running correctly :

root@marietto-nano:/home/marietto/Scaricati/Docker/ub20# lxc list

+-------+---------+----------------------+------+-----------+-----------+
| NAME  |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+-------+---------+----------------------+------+-----------+-----------+
| focal | RUNNING | 10.234.85.232 (eth0) |      | CONTAINER | 0         |
+-------+---------+----------------------+------+-----------+-----------+

root@marietto-nano:/home/marietto/Scaricati/Docker/ub20# lxc exec focal -- bash

root@focal:~# cd /etc/apt
root@focal:/etc/apt# ls
apt.conf.d  auth.conf.d  preferences.d  sources.list  sources.list.d  trusted.gpg.d
root@focal:/etc/apt# apt update
Metadata [116 B]
Fetched 21.4 MB in 8s (2743 kB/s)                                                                                                     
Reading package lists... Done
Building dependency tree       
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@focal:/etc/apt# apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  cloud-init libssl1.1 openssl tzdata
4 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
3 standard LTS security updates
Need to get 2595 kB of archives.
After this operation, 209 kB of additional disk space will be used.

Do you want to continue? [Y/n] y

ok. I stopped here the configuration of ubuntu 20.04 within the container,because previously I have already configured the ubuntu 20.04 installation that I want to use within the container. These files are stored inside the directory /20-new. What I want to do is to copy all these files inside the lxc container (called focal) and try to use it. But,unfortunately,I have some troubles. First of all I don’t understand what’s the path that leads me to those files. Maybe I found it,but there I see only broken links which makes me suspect that maybe something is wrong. I have attached all the pics of the broken links that I found on the system :

https://ibb.co/7KQkxZr
https://ibb.co/GJLWjXd
https://ibb.co/0jXQDWP
https://ibb.co/VjCNfG5

PS : in italian language : collegamento interrotto = broken link :stuck_out_tongue:

thanks.

You should never go poke at LXD’s internal storage directly.
Use lxc file if you need to push/pull files in/out of containers.

I have some questions to ask :

  1. the broken links that you see are a sympthom of something that’s broken or they should be really broken ?

  2. what’s the correct command to copy files from outside to inside the container ? lxc file push /etc/hosts focal/etc/hosts or lxc file pull /etc/hosts focal/etc/hosts ? I don’t understand the difference between pull and push.

  3. can I copy a folder inside the container instead of one file at a time ?

  4. thanks.

Yes, you can copy a full directory. See the docs for pulling and pushing files:
https://linuxcontainers.org/lxd/docs/stable-5.0/howto/instances_access_files/#pull-files-from-the-instance-to-the-local-machine