It is currently Thu Nov 26, 2020 10:00 am
All times are UTC + 8 hours

[SOLVED] [How-to] Chroot on asustor

Got a question about our NAS utilities? The answer lies within.

[SOLVED] [How-to] Chroot on asustor

Postby prokium » Tue Aug 04, 2020 5:36 pm

Hi all,
At the begining, i would like to install bind9 on my asustor nas.
I read that the "best"(?) solution is to make a chroot with an other distrib, so i am trying to doing that...
It needs sudo apkg --download perl in requirements to make debootstrap working.


So first :
Code: Select all
wget http://ftp.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.123.tar.gz
sudo ln -s /volume1/home/admin/debootstrap /usr/share/debootstrap


After that, i ve executed the following cmd to "create" the debian environement (correct me if i am wrong)
Code: Select all
sudo ./debootstrap --no-check-certificate --no-check-gpg --arch armhf buster asustordebian


So now, there is my state :
Code: Select all
ls -lah asustordebian/
total 24
drwsrwsrwt    6 root     root        4.0K Aug  4 11:25 ./
drwxr-xr-x    6 admin    administ    4.0K Aug  4 10:28 ../
lrwxrwxrwx    1 root     root           7 Aug  4 10:32 bin -> usr/bin/
drwsrwsrwt    2 root     root        4.0K Aug  4 11:25 debootstrap/
drwsrwsrwt    2 root     root        4.0K Aug  4 10:32 etc/
lrwxrwxrwx    1 root     root           7 Aug  4 10:32 lib -> usr/lib/
lrwxrwxrwx    1 root     root           8 Aug  4 10:32 sbin -> usr/sbin/
drwxr-sr-x    5 root     root        4.0K Aug  4 10:32 usr/
drwxr-sr-x    4 root     root        4.0K Aug  4 10:06 var/


If i try to chroot, that's not working:
Code: Select all
sudo chroot asustordebian/
chroot: can't execute '/bin/sh': No such file or directory



Could you give me some solutions/advices?
Thx

Ben
Last edited by prokium on Thu Aug 06, 2020 2:26 pm, edited 1 time in total.
prokium
 
Posts: 11
Joined: Wed Jul 29, 2020 2:30 pm

Re: [How-to] Chroot on asustor

Postby father.mande » Tue Aug 04, 2020 8:14 pm

Hi.
If you have a debootstrap folder ... Need a second-stage

From my zenfone on the road
Philippe
AS5202T /AS5002T / AS202TE / AS1002T
My Blog specific to my APKG : https://blog.father-mande.ovh/
User avatar
father.mande
 
Posts: 1047
Joined: Sat Sep 12, 2015 2:55 am

Re: [How-to] Chroot on asustor

Postby father.mande » Wed Aug 05, 2020 3:53 am

Hi,

I am now arrive ...
check in chroot /bin ... normally bash or ash must exist
... so search and change sh by bash or ash

so do the chroot then doing "debootstart --second-stage" ...

Philippe.
AS5202T /AS5002T / AS202TE / AS1002T
My Blog specific to my APKG : https://blog.father-mande.ovh/
User avatar
father.mande
 
Posts: 1047
Joined: Sat Sep 12, 2015 2:55 am

Re: [How-to] Chroot on asustor

Postby Nazar78 » Wed Aug 05, 2020 4:45 am

prokium wrote:If i try to chroot, that's not working:
Code: Select all
sudo chroot asustordebian/
chroot: can't execute '/bin/sh': No such file or directory

Try:
Code: Select all
sudo chroot asustordebian /bin/bash
AS5304T - 16GB DDR4 - [40TB N300 RAID10 + 5 Bay USB: 8TB RAID5 & 480GB SSD for Apps]
User avatar
Nazar78
 
Posts: 195
Joined: Wed Jul 17, 2019 10:21 pm
Location: Singapore

Re: [How-to] Chroot on asustor

Postby prokium » Thu Aug 06, 2020 12:13 am

Dear helpers,
First, thx for you replies.
I work on it a big part of the day...

Ok, so I get that i did a lot of mistakes...
So lets start again about what I did :

1) Get the arch of the nas to know witch architecture will be good for the installation:
Code: Select all
admin@nas:/volume1/home/admin $ uname -m
x86_64

That means that it's not an ARM

2) Install VM & Generate Debootstrap
As the nas is x86_64, lets generate it with this script
Code: Select all
ARCH=amd64
sudo debootstrap --arch=$ARCH --foreign buster debian_$ARCH
sudo tar -czvf debian_$ARCH.tar.gz debian_$ARCH/

And after that, let's send the archive from the VM to the nas :
Code: Select all
scp debian_amd64.tar.gz  admin@ip-nas-asustor:./


3) Untar, prepare and chroot
Code: Select all
sudo tar xzvf debian_amd64.tar.gz


Lets make a script to prepare the chroot env :
Code: Select all
cat > ./chrootDebian.sh << EOF
CHROOT=/volume1/home/admin/debian_amd64
mount -o bind /dev \$CHROOT/dev
mount -o bind /proc \$CHROOT/proc
mount -o bind /dev/pts \$CHROOT/dev/pts
mount -o bind /sys \$CHROOT/sys
cp /etc/resolv.conf \$CHROOT/etc/resolv.conf
cp /etc/hosts \$CHROOT/etc/hosts
EOF

and :
Code: Select all
sudo  sh ./chrootDebian.sh


Lets chroot !
Code: Select all
sudo chroot debian_amd64 /bin/bash


Code: Select all
admin@nas:/volume1/home/admin $ sudo chroot debian_amd64 /bin/bash
Password:
root@nas:/#


Ok, so now, it sounds quiet good, but not enough...

As you said, i need ton finish the installation with debootstrap --second-stage, lets try :
Code: Select all
root@nas:/# /debootstrap/debootstrap --second-stage
I: Installing core packages...
W: Failure trying to run:  dpkg --force-depends --install /var/cache/apt/archives/base-passwd_3.5.43_amd64.deb
W: See //debootstrap/debootstrap.log for details (possibly the package /var/cache/apt/archives/libc6_2.24-11+deb9u4_amd64.deb is at fault)


In the debootstrap.log:
Code: Select all
2020-08-05 15:55:07 URL:http://deb.debian.org/debian/pool/main/x/xapian-core/libxapian30_1.4.3-2+deb9u3_amd64.deb [1068326/1068326] -> "/home/superman/debian_64//var/cache/apt/archives/partial/libxapian30_1.4.3-2+deb9u3_amd64.deb" [1]
2020-08-05 15:55:07 URL:http://deb.debian.org/debian/pool/main/x/xz-utils/liblzma5_5.2.2-1.2+b1_amd64.deb [234010/234010] -> "/home/superman/debian_64//var/cache/apt/archives/partial/liblzma5_5.2.2-1.2+b1_amd64.deb" [1]
2020-08-05 15:55:08 URL:http://deb.debian.org/debian/pool/main/z/zlib/zlib1g_1.2.8.dfsg-5_amd64.deb [87522/87522] -> "/home/superman/debian_64//var/cache/apt/archives/partial/zlib1g_1%3a1.2.8.dfsg-5_amd64.deb" [1]
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':
 missing description
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':
 missing architecture
Selecting previously unselected package base-passwd.
(Reading database ... 0 files and directories currently installed.)
Preparing to unpack .../base-passwd_3.5.43_amd64.deb ...
Unpacking base-passwd (3.5.43) ...
dpkg: base-passwd: dependency problems, but configuring anyway as you requested:
 base-passwd depends on libc6 (>= 2.8); however:
  Package libc6 is not installed.
 base-passwd depends on libdebconfclient0 (>= 0.145); however:
  Package libdebconfclient0 is not installed.

Setting up base-passwd (3.5.43) ...
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 24 package 'dpkg':
 missing description
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 24 package 'dpkg':
 missing architecture
Selecting previously unselected package base-files.
dpkg: regarding .../base-files_9.9+deb9u13_amd64.deb containing base-files, pre-dependency problem:
 base-files pre-depends on awk
  awk is not installed.

dpkg: warning: ignoring pre-dependency problem!
(Reading database ... 41 files and directories currently installed.)
Preparing to unpack .../base-files_9.9+deb9u13_amd64.deb ...
Unpacking base-files (9.9+deb9u13) ...
dpkg: base-files: dependency problems, but configuring anyway as you requested:
 base-files depends on awk; however:
  Package awk is not installed.

Setting up base-files (9.9+deb9u13) ...
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 51 package 'dpkg':
 missing description
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 51 package 'dpkg':
 missing architecture
dpkg: regarding .../dpkg_1.18.25_amd64.deb containing dpkg, pre-dependency problem:
 dpkg pre-depends on libbz2-1.0
  libbz2-1.0 is not installed.

dpkg: warning: ignoring pre-dependency problem!
dpkg: regarding .../dpkg_1.18.25_amd64.deb containing dpkg, pre-dependency problem:
 dpkg pre-depends on libc6 (>= 2.14)
  libc6 is not installed.

dpkg: warning: ignoring pre-dependency problem!
dpkg: regarding .../dpkg_1.18.25_amd64.deb containing dpkg, pre-dependency problem:
 dpkg pre-depends on liblzma5 (>= 5.2.2)
  liblzma5 is not installed.

dpkg: warning: ignoring pre-dependency problem!
dpkg: regarding .../dpkg_1.18.25_amd64.deb containing dpkg, pre-dependency problem:
 dpkg pre-depends on libselinux1 (>= 2.3)
  libselinux1 is not installed.

dpkg: warning: ignoring pre-dependency problem!
dpkg: regarding .../dpkg_1.18.25_amd64.deb containing dpkg, pre-dependency problem:
 dpkg pre-depends on zlib1g (>= 1:1.1.4)
  zlib1g is not installed.

dpkg: warning: ignoring pre-dependency problem!
(Reading database ... 120 files and directories currently installed.)
Preparing to unpack .../dpkg_1.18.25_amd64.deb ...
Unpacking dpkg (1.18.25) over (1.18.25) ...
dpkg: dpkg: dependency problems, but configuring anyway as you requested:
 dpkg depends on libbz2-1.0; however:
  Package libbz2-1.0 is not installed.
 dpkg depends on libc6 (>= 2.14); however:
  Package libc6 is not installed.
 dpkg depends on liblzma5 (>= 5.2.2); however:
  Package liblzma5 is not installed.
 dpkg depends on libselinux1 (>= 2.3); however:
  Package libselinux1 is not installed.
 dpkg depends on zlib1g (>= 1:1.1.4); however:
  Package zlib1g is not installed.
 dpkg depends on tar (>= 1.28-1); however:
  Package tar is not installed.

Setting up dpkg (1.18.25) ...
Selecting previously unselected package libc6:amd64.
(Reading database ... 365 files and directories currently installed.)
Preparing to unpack .../libc6_2.24-11+deb9u4_amd64.deb ...
/var/lib/dpkg/tmp.ci/preinst: 132: [: Illegal number:
/var/lib/dpkg/tmp.ci/preinst: 9: /var/lib/dpkg/tmp.ci/preinst: arithmetic expression: expecting primary: "4 * 10000 + 14 * 100 + "
dpkg: error processing archive /var/cache/apt/archives/libc6_2.24-11+deb9u4_amd64.deb (--install):
 subprocess new pre-installation script returned error exit status 2
Errors were encountered while processing:
 /var/cache/apt/archives/libc6_2.24-11+deb9u4_amd64.deb
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 87 package 'dpkg':
 missing description
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 87 package 'dpkg':
 missing architecture
dpkg: error: parsing file '/var/lib/dpkg/status' near line 87 package 'dpkg':
 multiple non-coinstallable package instances present; most probably due to an upgrade from an unofficial dpkg
dpkg: error: parsing file '/var/lib/dpkg/status' near line 87 package 'dpkg':
 duplicate value for 'Package' field



I tried to re-generate my boostrap on my VM with the --include dpkg but that doesnt change the result

Thx & Cheers
Ben
Last edited by prokium on Thu Aug 06, 2020 2:35 pm, edited 1 time in total.
prokium
 
Posts: 11
Joined: Wed Jul 29, 2020 2:30 pm

Re: [How-to] Chroot on asustor

Postby Nazar78 » Thu Aug 06, 2020 12:44 am

You don't actually need to perform the second stage unless you're doing CrossDebootstrap e.g. from a x86 VM creating for an ARM client NAS chroot. Hence, you also don't need the "--foreign" switch.

Check your VM "dpkg --print-architecture", if it's amd64 which matches your NAS x86_64 (they are the same), then you don't need second stage nor foreign switch to begin with.
AS5304T - 16GB DDR4 - [40TB N300 RAID10 + 5 Bay USB: 8TB RAID5 & 480GB SSD for Apps]
User avatar
Nazar78
 
Posts: 195
Joined: Wed Jul 17, 2019 10:21 pm
Location: Singapore

Re: [How-to] Chroot on asustor

Postby prokium » Thu Aug 06, 2020 2:25 pm

The VM architecture is the amd64, as you thought.

So, as you said, it seems to work more or less.
After the chroot, i am able to ls / cd / apt-get update, but nothing else.

Edit :
Code: Select all
ARCH=amd64
sudo debootstrap --variant=minbase --include=linux-image-amd64,systemd-sysv,perl,build-essential,libc6 --arch=$ARCH buster debian_$ARCH
sudo tar -czvf debian_$ARCH.tar.gz debian_$ARCH/


It looks like to work good now with this debootstrap.. Dont know witch part is mandatory or not. I will dig in it to understand what is working and what is not.

I think the main issue was about the libc6 that was "missing" in the deboostrap generated...
prokium
 
Posts: 11
Joined: Wed Jul 29, 2020 2:30 pm

Re: [SOLVED] [How-to] Chroot on asustor

Postby Nazar78 » Thu Aug 06, 2020 3:37 pm

In chroot, check the libc6 it should be there else your debootstrap is not done correctly:
Code: Select all
(Chroot)root@Nimbustor4:/# dpkg -l|grep libc6
ii  libc6:amd64           2.28-10    amd64    GNU C Library: Shared libraries
ii  libc6-dev:amd64       2.28-10    amd64    GNU C Library: Development Libraries and Header Files
Just do a simple debootstrap on your VM, don't include switches such as variant/include.

prokium wrote:After the chroot, i am able to ls / cd / apt-get update, but nothing else.

Define "but nothing else"? I have been running chroot with a simple debootstrap then later updated with build-essential and other apps I require like git, nginx, mysql, php7, perl, python, jre, ffmpeg etc. even with drivers such as i965-va-driver-shaders, intel-media-va-driver, mesa-va-drivers etc.

You didn't include your NAS details, most probably the culprit is "x" this which breaks some deb installation:
Code: Select all
(Chroot)root@Nimbustor4:/# uname -r
4.14.x

Quick one time work around to fix the issue created by Asustor (you can recompile the kernel if you wish), do this in chroot:
Code: Select all
(Chroot)root@Nimbustor4:~# mv /bin/uname /bin/uname.asustor
(Chroot)root@Nimbustor4:~# echo -e '#!/bin/sh\n\n/bin/uname.asustor "$@"'"|sed 's/\\.x/\\.0/g'">/bin/uname
(Chroot)root@Nimbustor4:~# chmod +x /bin/uname
Then run your stuffs like "apt update && apt -y upgrade".
AS5304T - 16GB DDR4 - [40TB N300 RAID10 + 5 Bay USB: 8TB RAID5 & 480GB SSD for Apps]
User avatar
Nazar78
 
Posts: 195
Joined: Wed Jul 17, 2019 10:21 pm
Location: Singapore

Re: [SOLVED] [How-to] Chroot on asustor

Postby father.mande » Thu Aug 06, 2020 3:38 pm

Hi,

Strange ... I can't reproduce the previous problem (now I am in my lab ... not on the road)
Normally :
If you create a chroot on a machine with the same architecture ... the second stage is not necessary ... and debootstrap folder don't exist anymore (the second stage is run during the debootstrap) ...
on the same architecture ... arch= is not mandatory (get the same)

One possibility is that debootstrap was not at last version and generate somethings wrong or don't manage arch correctly ??? but why ? ... so a debootstrap folder exist and second stage is not done.

Last : when updating libc in chroot on Asustor ... error can occur in post-install script ... due to the malformed kernel version 4.14.x (x generate the error in a calculation) ... so think to create (in chroot) a fake uname to have response like 4.14.187 (last 4.14 version) to uname -r ... to bypass the problem.

Philippe.
[EDIT] send at the same time that nazar78 response ... sorry (so not need I search my small uname modified ... )
AS5202T /AS5002T / AS202TE / AS1002T
My Blog specific to my APKG : https://blog.father-mande.ovh/
User avatar
father.mande
 
Posts: 1047
Joined: Sat Sep 12, 2015 2:55 am

Re: [SOLVED] [How-to] Chroot on asustor

Postby prokium » Tue Aug 18, 2020 4:41 pm

Nazar78 wrote:
prokium wrote:After the chroot, i am able to ls / cd / apt-get update, but nothing else.

Define "but nothing else"? I have been running chroot with a simple debootstrap then later updated with build-essential and other apps I require like git, nginx, mysql, php7, perl, python, jre, ffmpeg etc. even with drivers such as i965-va-driver-shaders, intel-media-va-driver, mesa-va-drivers etc.

When I was writing that, I was able to do apt-get update but not the install...
I get an error, and it was because of the libc6...

Your explenation about the "culprit" sounds good.
I stay with my solution that's is working for the moment, but i keep in mind your information.
Thx
prokium
 
Posts: 11
Joined: Wed Jul 29, 2020 2:30 pm

Return to NAS Utilities

  • You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot post attachments in this forum
  • Who is online

    Users browsing this forum: No registered users and 5 guests