Gentoo Archives: gentoo-user

From: "Canek Peláez Valdés" <caneko@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] What to put in chroot mtab
Date: Fri, 01 Aug 2014 21:44:39
Message-Id: CADPrc803EeGo4S=dhQNfefdCwLWUM-PRuE9SW63YDY2M3YAa-Q@mail.gmail.com
In Reply to: Re: [gentoo-user] What to put in chroot mtab by "J. Roeleveld"
1 On Fri, Aug 1, 2014 at 4:39 PM, J. Roeleveld <joost@××××××××.org> wrote:
2 > On 1 August 2014 23:33:05 CEST, "Canek Peláez Valdés" <caneko@×××××.com> wrote:
3 >>On Fri, Aug 1, 2014 at 4:31 PM, Canek Peláez Valdés <caneko@×××××.com>
4 >>wrote:
5 >>> On Aug 1, 2014 3:46 PM, "J. Roeleveld" <joost@××××××××.org> wrote:
6 >>>>
7 >>>> On 1 August 2014 15:28:01 CEST, Dale <rdalek1967@×××××.com> wrote:
8 >>>> >Peter Humphrey wrote:
9 >>>> >> On Friday 01 August 2014 14:07:08 I wrote:
10 >>>> >>
11 >>>> >>> I run a couple of chroots on this box to build packages for
12 >>other
13 >>>> >boxes on
14 >>>> >>> the LAN. So far, I haven't worked out what I should populate
15 >>>> >/etc/mtab with
16 >>>> >>> in each chroot. Is it enough to "grep ext4 /etc/mtab >
17 >>>> >>> /mnt/chroot/etc/mtab"? That catches all the physical partitions,
18 >>but
19 >>>> >I
20 >>>> >>> imagine I need to add some /proc, /sys and /dev entries as well,
21 >>but
22 >>>> >is
23 >>>> >>> there a simple formula for doing this?
24 >>>> >> I meant to add that one chroot is 32-bit and the other is 64. The
25 >>>> >host is an
26 >>>> >> i5 running openrc.
27 >>>> >>
28 >>>> >
29 >>>> >It has been a good while since I used this. So, make sure it makes
30 >>>> >sense to you before trying this. This may not work if something
31 >>has
32 >>>> >changed in the past several years. Use with caution if at all.
33 >>>> >
34 >>>> >This is a little script, if you want to call it that, that I used
35 >>to do
36 >>>> >mine. It also lists the command to use to do a 32 bit chroot from
37 >>a 64
38 >>>> >bit rig. Here it is:
39 >>>> >
40 >>>> >root@fireball / # cat /root/xx.chroot-mount-32bit
41 >>>> >
42 >>>> >
43 >>>> >mount -o bind /dev /mnt/gentoo32/dev
44 >>>> >mount -o bind /dev/pts /mnt/gentoo32/dev/pts
45 >>>> >mount -o bind /dev/shm /mnt/gentoo32/dev/shm
46 >>>> >mount -o bind /proc /mnt/gentoo32/proc
47 >>>> >mount -o bind /proc/bus/usb /mnt/gentoo32/proc/bus/usb
48 >>>> >mount -o bind /sys /mnt/gentoo32/sys
49 >>>> >mkdir -p /mnt/gentoo32/usr/portage/
50 >>>> >mount -o bind /usr/portage /mnt/gentoo32/usr/portage/
51 >>>> >
52 >>>> >
53 >>>> >echo " mounting finished"
54 >>>> >
55 >>>> >echo "run linux32 chroot /mnt/gentoo32 /bin/bash next"
56 >>>> >root@fireball / #
57 >>>> >
58 >>>> >
59 >>>> >You may have different mount points at the very least so edit to
60 >>match
61 >>>> >what you have. Again, things could have changed and that no longer
62 >>>> >will
63 >>>> >work. It may not be a bad idea to let someone who has done this
64 >>more
65 >>>> >recently to give a thumbs up to that.
66 >>>> >
67 >>>> >That last command should be:
68 >>>> >
69 >>>> >linux32 chroot /mnt/gentoo32 /bin/bash
70 >>>> >
71 >>>> >Dale
72 >>>> >
73 >>>> >:-) :-)
74 >>>>
75 >>>> That script is too long :)
76 >>>>
77 >>>> cd /mnt/gentoo
78 >>>> mount -o rbind /dev dev
79 >>>> mount -o rbind /sys sys
80 >>>> mount -o rbind /proc proc
81 >>>> cp -L /etc/resolv.conf etc/resolv.conf
82 >>>> cd ..
83 >>>> chroot gentoo /bin/bash
84 >>>>
85 >>>> To undo:
86 >>>> cd /mnt/gentoo
87 >>>> umount -l proc sys dev
88 >>>
89 >>> That's still too long :)
90 >>>
91 >>> With systemd-nspawn, you only do:
92 >>>
93 >>> systemd-nspawn -D /mnt/gentoo
94 >>>
95 >>> Systemd takes care of /dev, /sys, etc. If the container has systemd
96 >>> installed, you can do
97 >>>
98 >>> systemd-nspawn -bD /mnt/gentoo
99 >>>
100 >>> and the services inside the container will be started like in a
101 >>regular boot
102 >>> (you'll need to set the root password for the container).
103 >>>
104 >>> Also, if you want to share the /usr/portage directory between host
105 >>and
106 >>> container, you only need to
107 >>>
108 >>> systemd-nspawn --bind=/usr/portage -bD /mnt/gentoo
109 >>
110 >>Oh, and I forgot: to stop the container, just log out if the container
111 >>runs OpenRC, or run systemctl poweroff if the container runs systemd.
112 >>
113 >>Regards.
114 >
115 > That script could easily be written in C and compiled and then called in a similar way as systemd-nspawn.
116
117 And yet nobody has done it and got it included in most distributions.
118
119 > What your command does is basically the same apart from doing something different from using chroots.
120
121 True, but still it's shorter ;)
122
123 > Converting a perfectly working and efficiently running system to use something like systemd just to have a chroot environment is overly complex and convoluted.
124
125 I agree; but as many of us are already using systemd, is good to know
126 that the possibility exists.
127
128 > These solutions often cause more issues then the problem it tried to solve.
129
130 I was only offering options. The OP will use whatever he decides to use.
131
132 Regards.
133 --
134 Canek Peláez Valdés
135 Profesor de asignatura, Facultad de Ciencias
136 Universidad Nacional Autónoma de México

Replies

Subject Author
Re: [gentoo-user] What to put in chroot mtab "Canek Peláez Valdés" <caneko@×××××.com>
Re: [gentoo-user] What to put in chroot mtab "J. Roeleveld" <joost@××××××××.org>
Re: [gentoo-user] What to put in chroot mtab Peter Humphrey <peter@××××××××××××.uk>