Recently I’ve ran into problems when I am using a 32-bit OS and dealing with 64-bit files. In my case, I have a layout like this:
The main system I have is 32-bit and I untar a 64-bit root file system to the folder /tmp/64-bit-files-here. At this point, I want to chroot and run a shell script but I’m unable to. Since I would be chroot-ed, the binaries that would be used are coming from /tmp/64-bit-files-here/bin and /tmp/64-bit-files-here/sbin and they are 64-bit and won’t run.
Symlinks won’t work because as soon as you chroot, that path is invalid. I had to read some man pages and do some searching, but I found a solution. The way I got around this is by using mount. I made the appropriate folders in my 64-bit file system folder:
#create other directories here
cp /tmp/MyShellScript.sh /tmp/64-bit-files-here/tmp-root
Then I used mount to provide a link-like functionality. I mount the 32-bit executable directories but I load the 64-bit file directories such as etc. Note the –bind argument:
mount --bind /bin /tmp/64-bit-files-here/tmp-root/bin
mount --bind /tmp/64-bit-files-here/etc /tmp/64-bit-files-here/tmp-root/etc
mount --bind /lib /tmp/64-bit-files-here/tmp-root/lib
mount --bind /sbin /tmp/64-bit-files-here/tmp-root/sbin
#mount other directories here
chroot /tmp/64-bit-files-here/tmp-root /MyShellScript.sh
When you do chroot, you’ll have access to run the 32-bit executables but modify your 64-bit file system. This specific example might only be useful if you’re doing imaging but the chroot / mount example should be useful for any kind of scripting.