You are not logged in.

#1 2018-11-22 09:47:18

Markus.N2
Member
From: Germany
Registered: 2013-08-22
Posts: 99

[SOLVED] arch-chroot: is there a way to have / in /etc/mtab ?

Hi,

I'm currently playing around with chroot environments for educational purposes. One of my chroot's should contain a minimal, but fully functional Arch system, including pacman. So I've installed the base system into a VM and rsync'ed the guest's filesystem into an empty direcotry on the host.

Unfortunately, pacman does not work "inside" this chroot environment (yes, I've used arch-chroot isntead of chroot). It complans it's unable to determine the mount point and free space of /. I think I've found the cause: /etc/mtab does not contain a / entry, as it does "outside".
"Inside", the file looks like this (please look especially at the last line):

proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
sys /sys sysfs ro,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,nosuid,relatime,size=16380888k,nr_inodes=4095222,mode=755 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
shm /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0
tmp /tmp tmpfs rw,nosuid,nodev 0 0
/dev/mapper/root /etc/resolv.conf ext4 rw,noatime 0 0

and I'm missing a line like this:

/dev/mapper/data / ext4 rw,noatime 0 0

because the chroot environment is located on /data.

Looking at the arch-chroot script, I've found the function

chroot_add_resolv_conf() {
  # lots of lines deleted for brevity
  # ...
  chroot_add_mount /etc/resolv.conf "$resolv_conf" --bind
}

and it looks like the last line creates the mtab entry that ... well ... appears not only useless but even wrong to me. Wrong, because it references the outside's / instead of /data where the files really are.

Playing around a bit with bind mounts, I still could not achieve to have the desired /etc/mtab line "inside". Is it even possible ?

Thanks and Regards,
Markus

Last edited by Markus.N2 (2018-11-22 11:07:20)

Offline

#2 2018-11-22 10:00:43

sincomil
Member
Registered: 2018-02-13
Posts: 106

Re: [SOLVED] arch-chroot: is there a way to have / in /etc/mtab ?

Use pacstrap to create fully functionial Arch system inside specific directory, then arch-chroot to that firectory and you will get what you want, thx.
Edit: pacstrap is part of extra/arch-install-scripts package

Last edited by sincomil (2018-11-22 10:04:46)

Offline

#3 2018-11-22 10:31:08

laurent85
Member
Registered: 2018-01-28
Posts: 9

Re: [SOLVED] arch-chroot: is there a way to have / in /etc/mtab ?

Bind mounting the new root onto itself before chrooting would achieve what you need, /etc/mtab in new root will contain a tmpfs type entry for /:

sudo mount -o bind /path/to/new/root /path/to/new/root
sudo arch-chroot /path/to/new/root

Offline

#4 2018-11-22 11:07:00

Markus.N2
Member
From: Germany
Registered: 2013-08-22
Posts: 99

Re: [SOLVED] arch-chroot: is there a way to have / in /etc/mtab ?

Oh whow, that was quick !

Well ... bind-mounting to itself was one thing I haven't tried so far. I even think I would never have had this idea without this forum.

Thanks a lot.

Offline

#5 2018-11-22 12:46:47

regid
Member
Registered: 2016-06-06
Posts: 201

Re: [SOLVED] arch-chroot: is there a way to have / in /etc/mtab ?

laurent85 wrote:

Bind mounting the new root onto itself before chrooting would achieve what you need, /etc/mtab in new root will contain a tmpfs type entry for /:

sudo mount -o bind /path/to/new/root /path/to/new/root
sudo arch-chroot /path/to/new/root

Are there other side effects for bind mounting a directory onto itself, not necessarily related to installation?
Qouting my ouestion from yesterday, that was redirected to this thread:

mount --bind /tmp/root.x86_64 /tmp/root.x86_64

is copied from Install_from_existing_Linux#Method_A:_Using_the_bootstrap_image_(recommended).
Why would one want to bind mount a directory over itself?
I suspect the benefits are the side effects, perhaps somethings to do with namespaces. In any case, can you elaborate?


powerofforreboot.efi (AUR): Utilities to be used from within a UEFI boot manager or shell.

Offline

#6 2018-11-22 13:32:52

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,783
Website

Re: [SOLVED] arch-chroot: is there a way to have / in /etc/mtab ?

That wasn't an invitation to hijack this thread. You wanted to know what is accomplished by that step, and now you know. If you want to discuss your concerns then please continue to use your own thread.

https://wiki.archlinux.org/index.php/Co … _hijacking

Closing.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB