Commit 734d0bed by John Lane Committed by Stéphane Graber

lxc-archlinux: support different architectures

parent d8c77af0
...@@ -166,10 +166,32 @@ EOF ...@@ -166,10 +166,32 @@ EOF
# install packages within container chroot # install packages within container chroot
install_arch() { install_arch() {
[ "${arch}" != "$(uname -m)" ] && different_arch=true
if [ "${different_arch}" = "true" ]; then
container_pacman_config=$(mktemp)
container_mirrorlist=$(mktemp)
sed -e "s:Architecture =.*:Architecture = ${arch}:g" \
-e "s:/etc/pacman.d/mirrorlist:${container_mirrorlist}:g" \
"${pacman_config}" > "${container_pacman_config}"
sed -e "s:\(x86_64\|\$arch\):${arch}:g" \
/etc/pacman.d/mirrorlist > "${container_mirrorlist}"
pacman_config="${container_pacman_config}"
fi
if ! pacstrap -dcC "${pacman_config}" "${rootfs_path}" ${base_packages[@]}; then if ! pacstrap -dcC "${pacman_config}" "${rootfs_path}" ${base_packages[@]}; then
echo "Failed to install container packages" echo "Failed to install container packages"
return 1 return 1
fi fi
if [ "${different_arch}" = "true" ]; then
sed -i -e "s:Architecture =.*:Architecture = ${arch}:g" \
"${rootfs_path}"/etc/pacman.conf
cp "${container_mirrorlist}" "${rootfs_path}"/etc/pacman.d/mirrorlist
rm "${container_pacman_config}" "${container_mirrorlist}"
fi
[ -d "${rootfs_path}/lib/modules" ] && ldconfig -r "${rootfs_path}" [ -d "${rootfs_path}/lib/modules" ] && ldconfig -r "${rootfs_path}"
return 0 return 0
} }
...@@ -185,6 +207,7 @@ Optional args: ...@@ -185,6 +207,7 @@ Optional args:
-p,--path path to where the container rootfs will be created, defaults to ${default_path}/rootfs. The container config will go under ${default_path} in that case -p,--path path to where the container rootfs will be created, defaults to ${default_path}/rootfs. The container config will go under ${default_path} in that case
-P,--packages preinstall additional packages, comma-separated list -P,--packages preinstall additional packages, comma-separated list
-c,--config use specified pacman config when installing container packages -c,--config use specified pacman config when installing container packages
-a,--arch use specified architecture instead of host's architecture
-t,--network_type set container network interface type (${lxc_network_type}) -t,--network_type set container network interface type (${lxc_network_type})
-l,--network_link set network link device (${lxc_network_link}) -l,--network_link set network link device (${lxc_network_link})
-h,--help print this help -h,--help print this help
...@@ -192,7 +215,7 @@ EOF ...@@ -192,7 +215,7 @@ EOF
return 0 return 0
} }
options=$(getopt -o hp:P:n:c:l:t: -l help,rootfs:,path:,packages:,name:,config:,network_type:,network_link: -- "${@}") options=$(getopt -o hp:P:n:c:a:l:t: -l help,rootfs:,path:,packages:,name:,config:,arch:,network_type:,network_link: -- "${@}")
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
usage $(basename ${0}) usage $(basename ${0})
exit 1 exit 1
...@@ -208,6 +231,7 @@ do ...@@ -208,6 +231,7 @@ do
--rootfs) rootfs_path=${2}; shift 2;; --rootfs) rootfs_path=${2}; shift 2;;
-P|--packages) additional_packages=${2}; shift 2;; -P|--packages) additional_packages=${2}; shift 2;;
-c|--config) pacman_config=${2}; shift 2;; -c|--config) pacman_config=${2}; shift 2;;
-a|--arch) arch=${2}; shift 2;;
-t|--network_type) lxc_network_type=${2}; shift 2;; -t|--network_type) lxc_network_type=${2}; shift 2;;
-l|--network_link) lxc_network_link=${2}; shift 2;; -l|--network_link) lxc_network_link=${2}; shift 2;;
--) shift 1; break ;; --) shift 1; break ;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment