Difference between revisions of "Create Debian sysroots"

From Aram's Wiki
Jump to: navigation, search
(Run debootstrap)
(Prerequisites)
 
(21 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
We'll create Debian sysroots suitable for a [[Linux/amd64 GCC 8.3.0 cross-compiler instructions | GCC cross compiler]].
 
We'll create Debian sysroots suitable for a [[Linux/amd64 GCC 8.3.0 cross-compiler instructions | GCC cross compiler]].
  
== Prerequisites ==
+
== Debootstrap machine ==
  
[[Debian Linux Post Install Steps| Debian]] or [[Ubuntu Linux Post Install Steps | Ubuntu]] or any system that can run [https://wiki.debian.org/Debootstrap debootstrap].
+
Everything below runs on the '''debootstrap machine''' as root:
  
Everything below runs as root:
+
sudo -i
  
sudo -i
+
=== Prerequisites ===
 +
 
 +
[[Debian Linux Post Install Steps| Debian]] or [[Ubuntu Linux Post Install Steps | Ubuntu]] or any system that can run [https://wiki.debian.org/Debootstrap debootstrap], with a configured QEMU user emulator. In practice only Debian and Ubuntu will work.
  
== Install debootstrap ==
+
=== Install debootstrap and associated tools ===
  
  apt install -y debootstrap
+
  apt install -y binfmt-support qemu qemu-user-static debootstrap
  
== Run debootstrap ==
+
=== Run debootstrap ===
  
 
  <nowiki>mkdir -p /tmp/sysroots
 
  <nowiki>mkdir -p /tmp/sysroots
 
cd /tmp/sysroots
 
cd /tmp/sysroots
 
arches="amd64,x86_64-linux-gnu arm64,aarch64-linux-gnu mips,mips-linux-gnu mips64el,mips64el-linux-gnuabi64 ppc64el,powerpc64le-linux-gnu"
 
arches="amd64,x86_64-linux-gnu arm64,aarch64-linux-gnu mips,mips-linux-gnu mips64el,mips64el-linux-gnuabi64 ppc64el,powerpc64le-linux-gnu"
for arch in $arches; do IFS=","; debootstrap --arch $1 --variant=buildd stable $2 http://deb.debian.org/debian; unset IFS; done</nowiki>
+
for arch in $arches; do IFS=","; set $arch; qemu-debootstrap --arch "$1" --variant=buildd stable "$2" http://deb.debian.org/debian; unset IFS; done</nowiki>
  
== Fix symlinks ==
+
=== Fix symlinks ===
  
 
Debootstrap will create absolute symlinks, fix absolute symlinks to refer to the sysroot dir by changing them into relative symlinks.
 
Debootstrap will create absolute symlinks, fix absolute symlinks to refer to the sysroot dir by changing them into relative symlinks.
  
  for arch in amd64 arm64 mips mips64el ppc64el; do find debian-$arch -type l -lname '/*' -exec sh -c 'file="$0"; dir=$(dirname "$file"); target=$(readlink "$0"); prefix=$(dirname "$dir" | sed 's@[^/]*@\.\.@g'); newtarget="$prefix$target"; ln -snf $newtarget $file' {} \; ; done
+
  for arch in $arches; do IFS=","; set $arch; find "$2" -type l -lname '/*' -exec sh -c 'file="$0"; dir=$(dirname "$file"); target=$(readlink "$0"); prefix=$(dirname "$dir" | sed 's@[^/]*@\.\.@g'); newtarget="$prefix$target"; ln -snf $newtarget $file' {} \; ; unset IFS; done
 +
 
 +
== Host machine ==
 +
 
 +
=== Create directories ===
 +
 
 +
cd $HOME
 +
arches="x86_64-linux-gnu aarch64-linux-gnu mips-linux-gnu mips64el-linux-gnuabi64 powerpc64le-linux-gnu"
 +
for arch in $arches; do mkdir -p $HOME/cross/sysroot/$arch/{lib,usr/{include,lib}}; done
 +
 
 +
=== Copy sysroots ===
 +
 
 +
for arch in $arches; do for dir in /lib/ /usr/{include,lib}; do rsync -a ubuntu.local:/tmp/sysroots/$arch/$dir/ $HOME/cross/sysroot/$arch$dir; done; done
 +
 
 +
== Debootstrap machine (again) ==
 +
 
 +
=== Cleanup ===
 +
 
 +
Still as root:
 +
 
 +
rm -rf /tmp/sysroots
  
 
== See also ==
 
== See also ==
  
 
* [https://wiki.debian.org/Debootstrap debootstrap]
 
* [https://wiki.debian.org/Debootstrap debootstrap]
 +
* [https://www.debian.org/ports Debian ports]

Latest revision as of 14:55, 24 November 2019


Introduction

We'll create Debian sysroots suitable for a GCC cross compiler.

Debootstrap machine

Everything below runs on the debootstrap machine as root:

sudo -i

Prerequisites

Debian or Ubuntu or any system that can run debootstrap, with a configured QEMU user emulator. In practice only Debian and Ubuntu will work.

Install debootstrap and associated tools

apt install -y binfmt-support qemu qemu-user-static debootstrap

Run debootstrap

mkdir -p /tmp/sysroots
cd /tmp/sysroots
arches="amd64,x86_64-linux-gnu arm64,aarch64-linux-gnu mips,mips-linux-gnu mips64el,mips64el-linux-gnuabi64 ppc64el,powerpc64le-linux-gnu"
for arch in $arches; do IFS=","; set $arch; qemu-debootstrap --arch "$1" --variant=buildd stable "$2" http://deb.debian.org/debian; unset IFS; done

Fix symlinks

Debootstrap will create absolute symlinks, fix absolute symlinks to refer to the sysroot dir by changing them into relative symlinks.

for arch in $arches; do IFS=","; set $arch; find "$2" -type l -lname '/*' -exec sh -c 'file="$0"; dir=$(dirname "$file"); target=$(readlink "$0"); prefix=$(dirname "$dir" | sed 's@[^/]*@\.\.@g'); newtarget="$prefix$target"; ln -snf $newtarget $file' {} \; ; unset IFS; done

Host machine

Create directories

cd $HOME
arches="x86_64-linux-gnu aarch64-linux-gnu mips-linux-gnu mips64el-linux-gnuabi64 powerpc64le-linux-gnu"
for arch in $arches; do mkdir -p $HOME/cross/sysroot/$arch/{lib,usr/{include,lib}}; done

Copy sysroots

for arch in $arches; do for dir in /lib/ /usr/{include,lib}; do rsync -a ubuntu.local:/tmp/sysroots/$arch/$dir/ $HOME/cross/sysroot/$arch$dir; done; done

Debootstrap machine (again)

Cleanup

Still as root:

rm -rf /tmp/sysroots

See also