Updating Debian under a chroot
Debian's Unstable ("Sid") distribution has been terrible lately. They're switching to a version of X that doesn't require root, and apparently the X transition has broken all sorts of things in ways that are hard to fix and there's no ETA for when things might get any better.
And, being Debian, there's no real bug system so you can't just CC yourself on the bug to see when new fixes might be available to try. You just have to wait, try every few days and see if the system
That's hard when the system doesn't work at all. Last week, I was booting into a shell but X wouldn't run, so at least I could pull updates. This week, X starts but the keyboard and mouse don't work at all, making it hard to run an upgrade. has been fixed.
Fortunately, I have an install of Debian stable ("Jessie") on this system as well. When I partition a large disk I always reserve several root partitions so I can try out other Linux distros, and when running the more experimental versions, like Sid, sometimes that's a life saver. So I've been running Jessie while I wait for Sid to get fixed. The only trick is: how can I upgrade my Sid partition while running Jessie, since Sid isn't usable at all?
I have an entry in /etc/fstab that lets me mount my Sid partition easily:
/dev/sda6 /sid ext4 defaults,user,noauto,exec 0 0So I can type
mount /sid
as myself, without even needing
to be root.
But Debian's apt upgrade tools assume everything will be on /,
not on /sid. So I'll need to use chroot /sid
(as root)
to change the root of the filesystem to /sid. That only affects
the shell where I type that command; the rest of my system will still be
happily running Jessie.
Mount the special filesystems
That mostly works, but not quite, because I get a lot of errors like
permission denied: /dev/null
.
/dev/null is a device: you can write to it and the bytes disappear, as if into a black hole except without Hawking radiation. Since /dev is implemented by the kernel and udev, in the chroot it's just an empty directory. And if a program opens /dev/null in the chroot, it might create a regular file there and actually write to it. You wouldn't want that: it eats up disk space and can slow things down a lot.
The way to fix that is before you chroot:
mount --bind /dev /sid/dev
which will make /sid/dev a mirror of the real /dev.
It has to be done before the chroot because inside the chroot,
you no longer have access to the running system's /dev.
But there is a different syntax you can use after chrooting:
mount -t proc proc proc/ mount --rbind /sys sys/ mount --rbind /dev dev/
It's a good idea to do this for /proc and /sys as well, and Debian recommends adding /dev/pts (which must be done after you've mounted /dev), even though most of these probably won't come into play during your upgrade.
Mount /boot
Finally, on my multi-boot system, I have one shared /boot
partition with kernels for Jessie, Sid and any other distros I have
installed on this system. (That's
somewhat
hard to do using grub2
but easy on Debian
though you may need to
turn
off auto-update and
Debian
is making it harder to use extlinux now.)
Anyway, if you have a separate /boot partition, you'll want it mounted
in the chroot, in case the update needs to add a new kernel.
Since you presumably already have the same /boot mounted on the
running system, use mount --bind
for that as well.
So here's the final set of commands to run, as root:
mount /sid mount --bind /proc /sid/proc mount --bind /sys /sid/sys mount --bind /dev /sid/dev mount --bind /dev/pts /sid/dev/pts mount --bind /boot /sid/boot chroot /sid
And then you can proceed with your apt-get update
,
apt-get dist-upgrade
etc.
When you're finished, you can unmount everything with one command:
umount --recursive /sid
Some helpful background reading:
- Change root on the Arch Linux wiki: thorough and readable, like most Arch Wiki pages, and applicable to any distro, not just Arch
- chroot on the Debian wiki: A good discussion of using debootstrap to install a new version of Debian, but less good as an explanation of chroot
- mount dev, proc, sys in a chroot environment? discussion on SuperUser
[ 11:43 Feb 05, 2016 More linux/install | permalink to this entry | ]