Running Apt-Get for Another Partition/Directory

Running apt-get for another partition/directory?

chroot /mnt/partition1

If your system uses several disk partitions you may have to mount some of them in order to get the package system working (I stopped setting up multiple partitions 10 years ago when hard disks started to get too large for raw physical backup).

This wouldn't work if you don't already have a usable debian system in that location. – akostadinov

If you can't get the package system working when chrooting, perhaps it is too messed up to ever be trusted again - in my experience the effort to bring it back to life rarely pays. If that happens, be happy you can still access your HD, backup your data and perform a clean reinstall.

Some relevant comments from other answer:

apt-get -o RootDir=/tmp/test_apt sets (almost) all paths to be in the different root. btw on a running system, if you copy /etc/apt, /usr/lib/apt, and mkdir -p usr/lib etc var/cache var/lib/dpkg var/lib/apt/lists/partial var/cache/apt/archives/partial and finally touch var/lib/dpkg/status, then apt is going to work in that root. It can even work as a non-root user if you add the option -o Debug::NoLocking=1. The nolock option is necessary because I couldn't find a way to set the lock file inside the different root directory. – akostadinov

Work means using search and downloading packages and such operations. Actually installing is not possible if some essential packages are not already there. debootstrap can help if the goal is actually installing packages in a new root for whatever reason. – akostadinov

Access another partition using terminal in ubuntu

Unescaped exclamation marks do history substitution. Turn off history expansion or quote the directory name (or rename it so you don't have to).

How can I change the apt-get install directory

Best way I can think of is to use a symbolic link

note that not all programmes are installed to the same directory and /opt may not be the best thing to move. (see end for example of moving only one folder/program)

This is what I did with EasyPeasy (Ubuntu 10.04)

Follow this code carefully some of the commands can delete important files if used incorrectly.

First you need to make sure /opt (or your distros default apt-get install directory) is empty. If you have data in the opt folder, which you most likely do, you can move it to somewhere else first for safe keeping:

sudo mkdir /New_Location/newtmp                                      # Generates Temporary Folder for Programs 
sudo cp -a /opt/* /New_Location/newtmp # Moves Programs to Temp folder

Once backed up you can remove the original directory:

sudo rm -rf /opt/                                                    # Removes opt directory

You can then create your new Program Files folder in a drive with lots of space and create a symbolic link:

sudo mkdir /New_Location/Program-Files                               # Generates New Program Directory
sudo ln -s /New_Location/Program-Files /opt # Creates Symbolic Link

Finally move all your old program files to your new folder and clean up the temporary data:

sudo cp -a /New_Location/newtmp/* /New_Location/Program-Files        # Moves Programs to Program Files Folder 
sudo rm -rf /New_Location/newtmp/ # Removes Temp folder

If you only wanted to move a single program which is taking up a hunk of your space you could use the same process.

eg:
to move Java (JVM approx 300MB) do the following.
check directory of java using disk usage analyser.
mine is /usr/lib/jvm

sudo mkdir /New_Location/Program-Files/Java                          # Generates New Program Directory
sudo cp -a /usr/lib/jvm/* /New_Location/Program-Files/Java # Moves Program to new folder
sudo rm -rf /usr/lib/jvm # Removes opt directory
sudo ln -s /New_Location/Program-Files/Java /usr/lib/jvm # Creates Symbolic Link

Its best at this point to do a restart which should clear the cache.

How to install a package in user defined directory using apt-get?

It is generally discouraged as you'll run into many complications like dependencies and where they're all located and linked at, but if you still want it to give it a shot, you could either do 2 of the following:

1. Compile from source

This would allow you to modify where you want each package to go and their contents, however this will require more work than the next option.

2. Chroot

Chroot is basically a 'jail' for anything you run inside it. What it does is create a special directory and sets that as root for anything you run inside it. It's been used to test applications or even test upgrade/downgrade systems. However, note that it is not a security feature as an executable can still possibly break out of the 'jail' and affect the main system. For your purposes this might be what you want to look at.
Here's how to use Chroot and also why it isn't a security feature.

These 2 are discussed in detail in this AskUbuntu link. In fact your question would be more suited there if those answers from that question do not give you the answer you seek.

Other than that I suppose packages that are Dockerized allow for a different path to deployment tutorial here or a VM, which isn't your question but just an alternative which might be acceptable to you.

How to fix error with SHFileOperationA when I am trying to copy a directory from a remote drive to a new directory on that same drive. WinSysErr 183

I receive an error code from SHFileOperationA( &directory ); Specifically 183, which looking at Windows System Errors I find this: ERROR_ALREADY_EXISTS 183 (0xB7) Cannot create a file when that file already exists.

That is not what error code 183 means in this situation. The SHFileOperation() documentation has the following to say about error 183 (hex 0xB7):

Return value

Type: int

Returns zero if successful; otherwise nonzero. Applications normally should simply check for zero or nonzero.

...

Do not use GetLastError with the return values of this function.

To examine the nonzero values for troubleshooting purposes, they largely map to those defined in Winerror.h. However, several of its possible return values are based on pre-Win32 error codes, which in some cases overlap the later Winerror.h values without matching their meaning. Those particular values are detailed here, and for these specific values only these meanings should be accepted over the Winerror.h codes. However, these values are provided with these warnings:

These are pre-Win32 error codes and are no longer supported or defined in any public header file. To use them, you must either define them yourself or compare against the numerical value.

These error codes are subject to change and have historically done so.

These values are provided only as an aid in debugging. They should not be regarded as definitive.



























Error CodeValueMeaning
.........
DE_ERROR_MAX0xB7MAX_PATH was exceeded during the operation.
.........

How do I install a library permanently in Colab?

If you want a no-authorization solution. You can use mounting with gcsfuse + service-account key embedded in your notebook. Like this:

# first install gcsfuse
%%capture
!echo "deb http://packages.cloud.google.com/apt gcsfuse-bionic main" > /etc/apt/sources.list.d/gcsfuse.list
!curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
!apt update
!apt install gcsfuse

Then get your service account credential from google cloud console and embed it in the notebook

%%writefile /key.json
{
"type": "service_account",
"project_id": "kora-id",
"private_key_id": "xxxxxxx",
"private_key": "-----BEGIN PRIVATE KEY-----\nxxxxxxx==\n-----END PRIVATE KEY-----\n",
"client_email": "colab-7@kora-id.iam.gserviceaccount.com",
"client_id": "100380920993833371482",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/colab-7%40kora-id.iam.gserviceaccount.com"
}

Then set environment to look for this credential file

%env GOOGLE_APPLICATION_CREDENTIALS=/key.json

You must then create (or have it already) a gcs bucket. And mount it to a made-up directory.

!mkdir /content/my-bucket
!gcsfuse my-bucket /content/my-bucket

Then finally, install the library there. Like my above answer.

import sys
nb_path = '/content/my-bucket'
sys.path.insert(0, nb_path)
# Do this just once
!pip install --target=$nb_path jdc

You can now import jdc without !pip install it next time.



Related Topics



Leave a reply



Submit