LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [chroot] What happens when upgrading? (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bchroot%5D-what-happens-when-upgrading-830514/)

littlebigman 09-05-2010 06:25 PM

[chroot] What happens when upgrading?
 
Hello

While learning about customizing a live ISO file, there's something I'd like to understand about chrooting and then, upgrading the kernel + applications:

1. It appears that (Ubuntu's) "apt-get upgrade" will not only upgrade applications but will also upgrade the kernel. Is this correct? Can I tell "apt-get upgrade" to upgrade applications and leave the kernel alone, so that "chroot" really means local files only?

2. After chrooting to a directory and running the command above, I'm seeing some discrepancy between the kernel files:

Code:

# chroot /mnt/squashfs

# apt-get update
# apt-get upgrade

//This is the host kernel?
# uname -a
Linux ubuntu 2.6.31-22-generic #63-Ubuntu SMP Wed Aug 18 22:54:26 UTC 2010 i686 GNU/Linux

//This is the packages installed in the chroot?
# dpkg-query -W | grep -i linux
linux-headers-2.6.31-22-generic 2.6.31-22.63
linux-headers-generic  2.6.31.22.35

linux-image-2.6.31-20-generic  2.6.31-20.58
linux-image-generic    2.6.31.20.33
linux-generic  2.6.31.20.33

How come the version of the linux-headers and linux-image don't match?

Thank you.

xeleema 09-06-2010 01:29 AM

Greetingz!

1) Yes, you are correct. Minor updates (and sometimes major ones) are done to the kernel (2.6.31-22.61, 2.6.31-22.62, 2.6.31-22.63, etc) when you run "apt-get upgrade"

From the apt-get man page;
Quote:

update
update is used to resynchronize the package index files from their sources. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list. For example, when using a Debian archive, this command retrieves and scans the Packages.gz files, so that information about new and updated packages is available. An update should always be performed before an upgrade or dist-upgrade. Please be aware that the overall progress meter will be incorrect as the size of the package files cannot be known in advance.

upgrade
upgrade is used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list. Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. An update must be performed first so that apt-get knows that new versions of packages are available.
2) The reason why is because "2.6.31-22-generic" is the kernel you booted off of, and "2.6.31-22.63" is the newly installed kernel & headers (that were installed with "apt-get update" & "apt-get upgrade").

Basically, there's nothing wrong with doing a full "apt-get upgrade" from within a chrooted environment. As long as your chrooted environment happens to be the hard drive you're installing the OS into.

Quote:

Can I tell "apt-get upgrade" to upgrade applications and leave the kernel alone, so that "chroot" really means local files only?
I wouldn't recommend that if I were you. The official repositories are updated and certain applications, scripts, sources, etc, may expect a given kernel version.
(Translation: That's usually a lot more trouble than you'd think.)

Hope this helps!

P.S: "so that "chroot" really means local files only?" Um, I think you would benefit from reading the chroot man page ("man chroot" at the command prompt). The "chroot" command always uses local files...but that doesn't upgraded anything, it just "changes your root".

littlebigman 09-06-2010 03:29 AM

Thanks for the information.

The problem I'm trying to solve, is that I need to update the kernel + applications contained in a live ISO file. This is done by mounting the ISO file, extract its files (squashfs) in a directory, chroot to it, update the applications, and save the files in a new ISO file.

According to documents like LiveCDCustomization, we just need to chroot to the directory where the squashfs file (ie. the tree that will be used as the live root filesystem) was extracted, and then run "apt-get" to add/remove applications.

So apparently, "apt-get" while in chroot actually updates the underlying host instead of restricting itself to the chroot filesystem?

Thank you.

littlebigman 09-06-2010 04:12 AM

I noticed something, though: To avoid typing "sudo" every time, I simply ran the whole thing as root. Maybe this is not right when using chroot?

I also notice something in the document: In Advanced Customizations > Live CD Kernel:

Code:

sudo cp edit/boot/vmlinuz-2.6.15-26-k7 extract-cd/casper/vmlinuz
sudo cp edit/boot/initrd.img-2.6.15-26-k7 extract-cd/casper/initrd.gz

(Note: "edit" = squashfs unpacked from ISO, while "extract-cd" is the ISO minus squashfs)

When chrooted in the extracted squashfs, there is no boot/ since the kernel + initrd are at the root of the ISO image, ie. in extract-cd/.

So what's the right way to update a kernel within an ISO image? I was thinking of downloading a .deb image, extract vmlinuz from its data.tar.bz2, and somehow recompile a initrd.gz (or .lz, rather). I suspect there are dependencies (configuration files, libraries) that make this a bit less straightforward.

Thank you.

xeleema 09-06-2010 05:26 AM

Quote:

Originally Posted by littlebigman (Post 4089273)
So apparently, "apt-get" while in chroot actually updates the underlying host instead of restricting itself to the chroot filesystem?

Um, no. if you're in the 'chrooted environment' then an apt-get upgrade is going to upgrade *that* environment.

Quote:

Originally Posted by littlebigman (Post 4089273)
I need to update the kernel + applications contained in a live ISO file.

Ah, okay, that makes more sense. However, my advice regarding the updating of both applications+kernel still stands.

Here's a nice trick;
1) jump into your chrooted environment
NOTE: should be something like "chroot /mnt/sysimage /bin/bash"
2) Type "touch OMGlolWTF" (or some other filename that isn't going to exist elswhere)
3) "Exit" the chrooted environment.
4) Run "updatedb && locate OMGlolWTF"

The file OMGlolWTF should pop up in "/mnt/sysimage", and not just plain "/". If for some reason the file DOES pop-up in just plain "/", then you're skipping a step somewhere...

littlebigman 09-06-2010 05:43 AM

Thanks for the tip. Sorry for the error: "apt-get ugrade" in chroot does update the chroot, not the underlying host (I added a new driver just to check, and it's not listed when I exit chroot and run "dpkg -l").

I'm taking a further look at updating an ISO file, and I suspect it's going to take a while ;-)

I haven't found information on replacing the kernel within the ISO file, though. I doubt it's just a matter of replacing vmlinuz with the one found in the latest kernel .deb package. Most likely, I need to generate a new initrd.gz based on what's living in /lib/modules after the upgrade, update configuration files, etc.

Has someone successfully updated the kernel of an existing ISO file and could tell me how it's done?

Thank you.

littlebigman 09-09-2010 07:26 AM

After further investigation, here's what I see when I mount the live ISO file and chroot to it:

BEFORE apt-get upgrade
0. # uname -r
2.6.31-22-generic
(this is the kernel used by the host)

Ob. # lsb_release -a
Description: Ubuntu 9.10
Codename: karmic

1. No /boot

2. # dpkg-query -W | grep -i linux-
linux-generic 2.6.31.20.33
linux-image-2.6.31-20-generic 2.6.31-20.57
linux-image-generic 2.6.31.20.33
(this is data from the local database of installed applications)

AFTER apt-get upgrade
1. /boot:
System.map-2.6.31-20-generic
abi-2.6.31-20-generic
config-2.6.31-20-generic
initrd.img-2.6.31-20-generic
vmcoreinfo-2.6.31-20-generic
vmlinuz-2.6.31-20-generic
(why no 2.6.31-22?)

2. # dpkg-query -W | grep -i linux-
linux-firmware 1.26
linux-generic 2.6.31.20.33
linux-image-2.6.31-20-generic 2.6.31-20.58
linux-image-generic 2.6.31.20.33

3. # apt-cache search linux-image
linux-image-2.6.31-22-generic

Why doesn't /boot contain the latest kernel image from the Ubuntu repository (2.6.31-22)?

Thank you.

littlebigman 09-09-2010 07:45 AM

Here's the possible answer:
Code:

# apt-get upgrade
[...]
The following packages have been kept back:
  firefox firefox-3.5 firefox-3.5-branding linux-generic linux-image-generic

I was about to run "apt-get dist-upgrade", but the Knoppix Remastering Howto says:
Quote:

"Warning: apt-get upgrade is a BAD IDEA. It will, quite probably, render your KNOPPIX remaster unbootable, or broken in some way. A far safer method is to only upgrade packages as necessary."
So it looks like the right way is to upgrade required packages individually by running "apt-get install some.already.installed.package" (install will actually upgrade a package if it's already installed).


All times are GMT -5. The time now is 01:57 PM.