LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Pkgtool and chroot directory. (http://www.linuxquestions.org/questions/slackware-14/pkgtool-and-chroot-directory-4175433466/)

basil_brush 10-22-2012 05:59 AM

Pkgtool and chroot directory.
 
Can you use pkgtool to install packages from the installation disc to a chroot directory? Or do you have to manually use installpkg -root /chroot package.t?z.

ponce 10-22-2012 06:14 AM

from "man pkgtool"
Quote:

--target_dir directory
The directory where the target root directory is located. This is '/' when installing on the hard drive, or typically '/mnt' when installing from an install disk.

basil_brush 10-22-2012 07:32 AM

I've tried that ponce, but using this command...

pkgtool --source_dir /cdrom/slackware/a/ --target_dir /mnt/chroot


chmod: cannot access '/mnt/chroot//var': No such file or directory
chmod: cannot access '/mnt/chroot//usr': No such file or directory
chmod: cannot access '/mnt/chroot//tmp': No such file or directory

I created those directories manually, when I issued the command again nothing happened?
I was thinking this would bring up Dialog to let me choose which packages I wanted to install in the chroot directory. Or am I doing something wrong?

damgar 10-22-2012 08:37 AM

I believe it would just be /mnt since that is the mountpoint of / when using the install disk. In other words no /chroot. I honestly can't say for sure since I usually only have a few packages to install from /extra after a full install or I just use slackpkg with a local mirror for updates. From a working system to install a whole series I just mount the slackware disk and cd to the slackware directory and use something like
Code:

upgradepkg -install-new -reinstall x/*.t?Z

basil_brush 10-22-2012 09:55 AM

@damgar, my idea was to use pkgtool dialog for selecting which packages to install in /chroot without using upgradepkg or installpkg commands. Basically like the dialog when you're selecting which packages you want on a fresh install.

xflow7 10-22-2012 12:08 PM

Disclaimer: I don't really know what I'm talking about. ;)

Just a thought....

Is your intention to do this to a mounted partition with nothing on it yet? If so, I wonder if perhaps before you use pkgtool you need to use installpkg to install aaa_base. I believe aaa_base is what sets up the root directory tree, so it kind of stands to reason that if that is not installed, other things may have a hard time doing what they are supposed to.

Dave

ponce 10-22-2012 12:35 PM

you can try changing two lines of /sbin/pkgtool, like below
Code:

--- pkgtool.orig        2012-08-09 20:38:10.000000000 +0200
+++ pkgtool        2012-10-22 15:47:03.360638344 +0200
@@ -94,8 +94,8 @@
  exit
  fi
 else
- TARGET_DIR=/
- TMP=/var/log/setup/tmp
+ TARGET_DIR=${ROOT:-/}
+ TMP=$ROOT/var/log/setup/tmp
 fi
 if [ ! -d $TMP ]; then
  mkdir -p $TMP

this way it should honor the $ROOT environment variable (like installpkg already does) and you can use it to install in the chroot, exporting first ROOT=/chroot (no need for --target_dir, that seems used only in the O.S. install phase).

basil_brush 10-22-2012 12:53 PM

Thanks ponce, that is exactly what I was looking for. Previously I was using installpkg for individual packages, when I only wanted to miss a couple of packages out.

ponce 10-22-2012 01:20 PM

Maybe slackpkg is a better choice for this kind of tasks, it even supports templates: that's what I use to create my lxc containers.
I had to modify it just a little too to let it honor the $ROOT environment variable and to have the possibility of specifying an alternate configuration folder (in alternative to /etc/slackpkg) with a $CONF variable, to not being tied to the contents of that folder and choose to install, for example, 32bit packages in the container from a slackware64 host, use a custom blacklist and so on.
If you want to try it, it's here

http://ponce.cc/slackware/utilities/...0-noarch-9.tgz

these are the modified bits
Code:

diff -Naur slackpkg/usr/libexec/slackpkg/core-functions.sh slackpkg.new/usr/libexec/slackpkg/core-functions.sh
--- slackpkg/usr/libexec/slackpkg/core-functions.sh        2011-04-05 07:54:23.000000000 +0200
+++ slackpkg.new/usr/libexec/slackpkg/core-functions.sh        2012-10-21 09:09:45.000000000 +0200
@@ -549,9 +549,9 @@
 
        grep -vE "(^#|^[[:blank:]]*$)" ${CONF}/blacklist > ${TMPDIR}/blacklist
        if echo $CMD | grep -q install ; then
-                ls -1 /var/log/packages/* | awk -f /usr/libexec/slackpkg/pkglist.awk > ${TMPDIR}/tmplist
+                ls -1 $ROOT/var/log/packages/* | awk -f /usr/libexec/slackpkg/pkglist.awk > ${TMPDIR}/tmplist
        else
-                ls -1 /var/log/packages/* | awk -f /usr/libexec/slackpkg/pkglist.awk | applyblacklist > ${TMPDIR}/tmplist
+                ls -1 $ROOT/var/log/packages/* | awk -f /usr/libexec/slackpkg/pkglist.awk | applyblacklist > ${TMPDIR}/tmplist
        fi
        cat ${WORKDIR}/pkglist | applyblacklist > ${TMPDIR}/pkglist
 
@@ -763,7 +763,7 @@
            # First is the package already installed?
            # Amazing what a little sleep will do
            # exclusion is so much nicer :)
-            INSTPKG=$(ls -1 /var/log/packages | \
+            INSTPKG=$(ls -1 $ROOT/var/log/packages | \
                grep -e "^${BASENAME}-[^-]\+-\(${ARCH}\|fw\|noarch\)-[^-]\+")
 
                # INSTPKG is local version
@@ -1130,14 +1130,14 @@
 
        [ "$SPINNING" = "off" ] || spinning ${TMPDIR}/waiting &
 
-        for i in $(ls -1 /var/log/packages | \
+        for i in $(ls -1 $ROOT/var/log/packages | \
                egrep -- "^.*-(${ARCH}|fw|noarch)-[^-]+-upgraded"); do
                REVNAME=$(echo ${i} | awk -F'-upgraded' '{ print $1 }')
-                mv /var/log/packages/${i} /var/log/packages/${REVNAME}
-                mv /var/log/scripts/${i} /var/log/scripts/${REVNAME}
+                mv $ROOT/var/log/packages/${i} $ROOT/var/log/packages/${REVNAME}
+                mv $ROOT/var/log/scripts/${i} $ROOT/var/log/scripts/${REVNAME}
        done
       
-        ls -1 /var/log/packages | egrep "^.*-(${ARCH}|fw|noarch)-[^-]+$" | \
+        ls -1 $ROOT/var/log/packages | egrep "^.*-(${ARCH}|fw|noarch)-[^-]+$" | \
                                  batchcutpkg | sort > $TMPDIR/list1
        cat $TMPDIR/list1 | uniq > $TMPDIR/list2
        FILES="$(diff $TMPDIR/list1 $TMPDIR/list2 | grep '<' | cut -f2 -d\ )"
@@ -1159,7 +1159,7 @@
 worry about this list - when you select your action, slackpkg will show a\n\
 better list:\n"
                for i in $DOUBLEFILES ; do
-                        ls -1 /var/log/packages |\
+                        ls -1 $ROOT/var/log/packages |\
                                egrep -i -- "^${i}-[^-]+-(${ARCH}|fw|noarch)-"
                done
                echo -ne "\n\
@@ -1174,7 +1174,7 @@
                        ;;
                        R|r)
                                for i in $DOUBLEFILES ; do
-                                        FILE=$(ls -1 /var/log/packages |\
+                                        FILE=$(ls -1 $ROOT/var/log/packages |\
                                                egrep -i -- "^${i}-[^-]+-(${ARCH}|fw|noarch)-")
                                        FILES="$FILES $FILE"
                                done
@@ -1294,7 +1294,7 @@
        touch $TMPDIR/waiting
        echo -e "\tGenerating slackware installed package list (this may take a while) \c"
        [ "$SPINNING" = "off" ] || spinning ${TMPDIR}/waiting &
-        for i in /var/log/packages/* ; do
+        for i in $ROOT/var/log/packages/* ; do
                PKGNAME=$( cutpkg $(basename $i))
                grep -q " $PKGNAME " ${WORKDIR}/pkglist && \
                        echo $PKGNAME >> $TMPDIR/$TEMPLATE.work
diff -Naur slackpkg/usr/libexec/slackpkg/functions.d/dialog-functions.sh slackpkg.new/usr/libexec/slackpkg/functions.d/dialog-functions.sh
--- slackpkg/usr/libexec/slackpkg/functions.d/dialog-functions.sh        2010-05-02 01:10:33.000000000 +0200
+++ slackpkg.new/usr/libexec/slackpkg/functions.d/dialog-functions.sh        2012-10-21 09:11:36.000000000 +0200
@@ -20,7 +20,7 @@
                rm -f $TMPDIR/dialog.tmp
               
                if [ "$2" = "upgrade" ]; then
-                        ls -1 /var/log/packages > $TMPDIR/tmplist
+                        ls -1 $ROOT/var/log/packages > $TMPDIR/tmplist
                        for i in $1; do
                                BASENAME=$(cutpkg $i)
                                PKGFOUND=$(grep -m1 -e "^${BASENAME}-[^-]\+-\(noarch\|fw\|${ARCH}\)" $TMPDIR/tmplist)
diff -Naur slackpkg/usr/sbin/slackpkg slackpkg.new/usr/sbin/slackpkg
--- slackpkg/usr/sbin/slackpkg        2011-03-25 03:42:10.000000000 +0100
+++ slackpkg.new/usr/sbin/slackpkg        2012-10-21 09:05:56.000000000 +0200
@@ -35,7 +35,7 @@
 VERSION=2.81.1
 PATH=/bin:/usr/bin:/sbin:/usr/sbin
 SLACKWARE_VERSION=$(cat /etc/slackware-version | cut -f2 -d\ )
-CONF=/etc/slackpkg
+CONF=${CONF:-/etc/slackpkg}
 SOURCE=$(sed -e 's/^[[:blank:]]*//' $CONF/mirrors | grep -m1 -e "^\([a-z]\)")
 . $CONF/slackpkg.conf
 ERROR=""

I'm going to send this to Pat too soon, hoping that he likes the thing ;)

basil_brush 10-22-2012 01:27 PM

I was looking at your lxc-container blog before your pkgtool reply. I'll try that too, see which is best for me. I've used lxc-containers in the past and your blog was very helpful.

Thanks once again :)


All times are GMT -5. The time now is 12:17 PM.