Difference between revisions of "Debian10 rootfs"

From ESS-WIKI
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:How to build one Debian 10 SDcard image for i.MX8}} {| align="right" |- | __TOC__ |} <!-- --> = Host Prerequisites = == required packages == <syntaxhighligh...")
 
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:How to build one Debian 10 SDcard image for i.MX8}}
+
{{DISPLAYTITLE:How to create Debian 10 rootfs base for iMX6/iMX8}}
  
 
{| align="right"
 
{| align="right"
Line 9: Line 9:
 
= Host Prerequisites =
 
= Host Prerequisites =
  
== required packages ==
+
== install required packages ==
  
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo apt-get install binfmt-support qemu-user-static wget
 
sudo apt-get install binfmt-support qemu-user-static wget
modinfo binfmt_misc
+
sudo modprobe binfmt_misc
 
</syntaxhighlight>
 
</syntaxhighlight>
== pre-built Yocto SD card image ==
+
= Building Procedures =
 
 
:e.g. 5720A1AIM20LIV90100_iMX8M_2020-04-03.img.gz
 
  
=== uncompress the image ===
+
== set ARM architecture ==
  
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
SDIMAGE=5720A1AIM20LIV90100_iMX8M_2020-04-03.img
+
export ARCH=arm64 # for i.MX8
zcat $SDIMAGE.gz > $SDIMAGE
+
export ARCH=armhf # for i.MX6
 
</syntaxhighlight>
 
</syntaxhighlight>
=== backup modules and firmware ===
 
 
  
<syntaxhighlight lang="bash">
 
BACKUPDIR=~/${SDIMAGE%%_*}
 
mkdir $BACKUPDIR
 
MNT=~/mnt
 
mkdir -p $MNT
 
PL=`fdisk -lu $SDIMAGE | grep "83 Linux" | awk '{print $2}'`
 
sudo mount -o offset=$((PL*512)) $SDIMAGE $MNT
 
sudo tar zcvf $BACKUPDIR/lib_modules.tgz -C $MNT lib/modules
 
sudo tar zcvf $BACKUPDIR/lib_firmware.tgz -C $MNT lib/firmware
 
sudo umount $MNT
 
</syntaxhighlight>
 
= Building Procedures =
 
  
== getting Debian 10 (Buster) base rootfs ==
+
== get the basic rootfs ==
  
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
export ROOTFS=~/rootfs_arm64-deb10
+
export ROOTFS=~/rootfs_${ARCH}-deb10
 
sudo apt -y install debian-archive-keyring
 
sudo apt -y install debian-archive-keyring
 
sudo apt-key add /usr/share/keyrings/debian-archive-keyring.gpg
 
sudo apt-key add /usr/share/keyrings/debian-archive-keyring.gpg
sudo qemu-debootstrap --arch=arm64 \
+
sudo qemu-debootstrap --arch=${ARCH} \
 
--keyring /usr/share/keyrings/debian-archive-keyring.gpg \
 
--keyring /usr/share/keyrings/debian-archive-keyring.gpg \
 
--variant=buildd \
 
--variant=buildd \
 
--exclude=debfoster buster $ROOTFS http://ftp.debian.org/debian
 
--exclude=debfoster buster $ROOTFS http://ftp.debian.org/debian
 
</syntaxhighlight>
 
</syntaxhighlight>
== chroot environment ==
+
== go on in chroot ==
  
=== before entering a chroot ===
+
=== set the mount point ===
  
  
Line 68: Line 52:
  
  
=== entering a chroot ===
+
=== enter the chroot ===
  
  
Line 104: Line 88:
 
sed -i "s|^adv:[^:]\+:|adv:$CRYPT:|" /etc/shadow
 
sed -i "s|^adv:[^:]\+:|adv:$CRYPT:|" /etc/shadow
 
sed -i "s/^root:[^:]\+:/root::/" /etc/shadow
 
sed -i "s/^root:[^:]\+:/root::/" /etc/shadow
echo "iMX8" > /etc/hostname
+
echo "unknown" > /etc/hostname
echo -e "127.0.0.1    localhost \n127.0.1.1    `cat /etc/hostname`\n" > /etc/hosts
+
echo -e "127.0.0.1    localhost \n127.0.1.1    unknown\n" > /etc/hosts
  
 
ln -sf ../run/resolvconf/resolv.conf /etc/resolv.conf
 
ln -sf ../run/resolvconf/resolv.conf /etc/resolv.conf
 
apt-get clean
 
apt-get clean
mkdir /lib/modules
+
history -c
mkdir /lib/firmware
 
history -c && rm ~/.bash_history
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
=== leaving the chroot ===
+
=== leave the chroot ===
  
  
Line 123: Line 105:
  
  
=== after leaving the chroot ===
+
=== clear the mount point ===
  
  
Line 132: Line 114:
 
sudo umount $ROOTFS/proc
 
sudo umount $ROOTFS/proc
 
</syntaxhighlight>
 
</syntaxhighlight>
== Creating Debian 10 SDcard image ==
+
= Basic rootfs is ready =
 
 
=== duplicate from Yocto SDcard image ===
 
  
 
+
go on to create SD card image if needed
<syntaxhighlight lang="bash">
 
DEBIMAGE=`sed "s/AIM20.*LIV/DIV/" <<< ${SDIMAGE%%_*}`_Debian10_base.img
 
cp $SDIMAGE $DEBIMAGE
 
mkfs.ext4 -F -E offset=$((PL*512)) $DEBIMAGE
 
 
 
</syntaxhighlight>
 
=== restore modules & firmware ===
 
 
 
 
 
<syntaxhighlight lang="bash">
 
sudo mount -o offset=$((PL*512)) $DEBIMAGE $MNT
 
sudo rsync -av $ROOTFS/ $MNT/
 
sudo tar zxvf $BACKUPDIR/lib_modules.tgz -C $MNT
 
sudo tar zxvf $BACKUPDIR/lib_firmware.tgz -C $MNT
 
sudo umount $MNT
 
</syntaxhighlight>
 
== SDcard image is ready ==
 

Latest revision as of 03:43, 17 April 2020


Host Prerequisites

install required packages

sudo apt-get install binfmt-support qemu-user-static wget
sudo modprobe binfmt_misc

Building Procedures

set ARM architecture

export ARCH=arm64 # for i.MX8
export ARCH=armhf # for i.MX6


get the basic rootfs

export ROOTFS=~/rootfs_${ARCH}-deb10
sudo apt -y install debian-archive-keyring
sudo apt-key add /usr/share/keyrings/debian-archive-keyring.gpg
sudo qemu-debootstrap --arch=${ARCH} \
--keyring /usr/share/keyrings/debian-archive-keyring.gpg \
--variant=buildd \
--exclude=debfoster buster $ROOTFS http://ftp.debian.org/debian

go on in chroot

set the mount point

sudo mount -t proc proc $ROOTFS/proc
sudo mount -t sysfs sysfs $ROOTFS/sys
sudo mount --bind /dev $ROOTFS/dev
sudo mount --bind /dev/pts $ROOTFS/dev/pts


enter the chroot

HOME=/root sudo chroot $ROOTFS /bin/bash --login -i


installation

cd ~
apt-get update
apt -y install iputils-ping iproute2 lsb-release vim
apt -y install python2.7-minimal
ln -s python2.7 /usr/bin/python
ln -sf bash /bin/sh
ln -sf bash.1.gz /usr/share/man/man1/sh.1.gz

apt -y install sudo
apt -y install systemd systemd-sysv kmod
apt -y install network-manager
apt -y install parted


configuration

groupadd -g 1000 adv
useradd -u 1000 -d /home/adv -m -g adv -G adm,sudo,audio adv
CRYPT=$(python -c 'import crypt; print crypt.crypt("'adv'", "$6$fWqaDxsq")')
sed -i "s|^adv:[^:]\+:|adv:$CRYPT:|" /etc/shadow
sed -i "s/^root:[^:]\+:/root::/" /etc/shadow
echo "unknown" > /etc/hostname
echo -e "127.0.0.1    localhost \n127.0.1.1    unknown\n" > /etc/hosts

ln -sf ../run/resolvconf/resolv.conf /etc/resolv.conf
apt-get clean
history -c


leave the chroot

logout


clear the mount point

sudo umount -lf $ROOTFS/dev/pts
sudo umount -lf $ROOTFS/dev
sudo umount $ROOTFS/sys
sudo umount $ROOTFS/proc

Basic rootfs is ready

go on to create SD card image if needed