Changes between Version 30 and Version 31 of newport/ubuntu


Ignore:
Timestamp:
10/17/2023 10:45:54 PM (9 months ago)
Author:
Tim Harvey
Comment:

moved ubuntu rootfs to generic ubuntu page

Legend:

Unmodified
Added
Removed
Modified
  • newport/ubuntu

    v30 v31  
    4646To build a complete Ubuntu image, including all the boot firmware, start with the [wiki:newport/bsp Newport BSP] page as the easiest option.
    4747
    48 
    49 [=#debootstrap]
    50 == Root filesystem ==
    51 This is to build the rootfs ONLY. To easily build an entire system image, including the boot firmware and Ubuntu, consider the [wiki:newport/bsp Newport BSP] page.
    52 
    53 A popular way to create an Ubuntu root filesystem is to use the {{{deboostrap}}} utility on a Debian or Ubuntu host. This tool provides a 2-stage install where the second stage is within a chroot environment using qemu.
    54 
    55 Gateworks uses a script to do this which you may find at http://github.com/Gateworks/ubuntu-rootfs
    56 
    57 Requirements:
    58 - Linux Ubuntu or Debian System with network connection and sudo permissions
    59 
    60 Important notes:
    61  * We set and use '''target''' and '''distro''' env variables in step 2 and use those env variables in the remaining steps to make this tutorial more version-agnostic. Please be aware of this and do not deviate from the steps unless or until you completely understand what you are doing.
    62  * These steps are not always exactly what we do in our script but give you an idea of how you would go about doing it yourself if you wanted to customize something
    63 
    64 Steps:
    65 1. Install pre-requisites:
    66 {{{
    67 #!bash
    68 sudo apt-get install qemu-user-static debootstrap binfmt-support
    69 }}}
    70 
    71 2. Perform first stage install of minimal filesystem for {{{arm64}}} architecture:
    72 {{{#!bash
    73 distro=focal
    74 arch=arm64
    75 target=${distro}-${arch}
    76 qemu_arch=aarch64
    77 sudo debootstrap --arch=$arch --foreign $distro $target
    78 # copy qemu binary for the binfmt packages to find it and copy in resolv.conf from host
    79 sudo cp /usr/bin/qemu-${qemu_arch}-static $target/usr/bin
    80 }}}
    81  * See http://ports.ubuntu.com/ubuntu-ports/dists/ for a list of current Ubuntu releases: oe 20.04=focal (latest LTS)
    82  * this minimal rootfs is still missing some core packages and configuration before it can be booted. These steps are taken care of in a 2nd stage install within a chroot shell
    83  * the chroot shell below will provide network support (inherited from the host)
    84 
    85 3. We now have a minimal Ubuntu rootfs - chroot to it and perform the 2nd stage install:
    86 {{{
    87 #!bash
    88 sudo chroot $target
    89 # now we are in the chroot - setup env matching the distro above
    90 distro=focal
    91 export LANG=C
    92 # setup second stage
    93 /debootstrap/debootstrap --second-stage
    94 }}}
    95  * this is the most minimal rootfs we would recommend
    96 
    97 4. (optional) add additional apt package repos:
    98 {{{
    99 #!bash
    100 cat <<EOT > /etc/apt/sources.list
    101 deb http://ports.ubuntu.com/ubuntu-ports $distro main restricted universe multiverse
    102 deb http://ports.ubuntu.com/ubuntu-ports $distro-updates main restricted universe multiverse
    103 deb http://ports.ubuntu.com/ubuntu-ports $distro-security main restricted universe multiverse
    104 EOT
    105 }}}
    106  * you may want to customize the above list, depending on your needs. See [#packages below] for more detail on Ubuntu package feeds
    107 
    108 5. (optional) update package database and setup locales (do not skip this step if you are needing to install any packages for the steps below or otherwise)
    109 {{{
    110 #!bash
    111 apt-get update
    112 apt-get -f install # fixup missing package dependencies
    113 apt-get install locales dialog
    114 dpkg-reconfigure locales
    115 }}}
    116 
    117 6. Set hostname:
    118 {{{
    119 #!bash
    120 echo ${distro}-$(uname -m) > /etc/hostname
    121 }}}
    122 
    123 7. set a root passwd so you can login
    124 {{{
    125 #!bash
    126 passwd
    127 }}}
    128  - or consider adding a user via {{{adduser}}}:
    129 {{{
    130 #!bash
    131 adduser myuser
    132 usermod -a -G tty myuser # add to tty group for tty access
    133 usermod -a -G dialout myuser # add to dialout group for UART access
    134 usermod -a -G sudo myuser # add to sudo group for root access
    135 }}}
    136 
    137 8. (optional) configure networking:
    138  - wired ethernet with DHCP on eth0
    139 {{{#!bash
    140 apt-get install net-tools ifupdown
    141 cat <<EOF >> /etc/network/interfaces
    142 allow-hotplug eth0
    143 auto eth0
    144 iface eth0 inet dhcp
    145 
    146 EOF
    147 }}}
    148  - or static IP:
    149 {{{#!bash
    150 apt-get install net-tools ifupdown
    151 cat <<EOF >> /etc/network/interfaces
    152 allow-hotplug eth0
    153 auto eth0
    154 iface eth0 inet static
    155 address 192.168.1.1
    156 netmask 255.255.255.0
    157 gateway 192.168.1.254
    158 
    159 EOF
    160 }}}
    161  - or wireless (requires ~3MB of additional packages):
    162 {{{
    163 #!bash
    164 apt-get install wpasupplicant iw
    165 cat << EOF >> /etc/network/interfaces
    166 # Wireless interface
    167 auto wlan0
    168 iface wlan0 inet dhcp
    169         wireless_mode managed
    170         wireless_essid any
    171         wpa-driver nl80211
    172         wpa-conf /etc/wpa_supplicant.conf
    173 
    174 EOF
    175 wpa_passphrase <myssid> <mypass> >> /etc/wpa_supplicant.conf
    176 }}}
    177 
    178 9. (optional) install some useful packages
    179 {{{
    180 #!bash
    181 apt-get install openssh-server # ssh server for remote access
    182 apt-get install can-utils i2c-tools usbutils pciutils # cmdline tools for various hardware support
    183 }}}
    184  * Note that by default root ssh access is disabled for security. See [wiki:/ubuntu#SSHServer This link] for info on enabling it
    185 
    186 10. Exit the chroot shell and remove files we no longer need
    187 {{{
    188 #!bash
    189 exit
    190 sudo rm $target/usr/bin/qemu-$qemu_arch-static
    191 }}}
    192 
    193 At this point you have a directory containing a root filesystem (without kernel) and likely want to install it onto removable storage or the on-board FLASH of a target board. Some intermediate formats that are useful to keep around would be a tarball, perhaps an ext4 filesystem image, or a compressed disk image suitable for flashing in the U-Boot bootloader.
    194 
    195 To create a tarball which is the most flexible storage format and can be used for a variety of future installation uses:
    196 {{{#!bash
    197 sudo tar --keep-directory-symlink -cvJf focal-newport.tar.xz -C rootfs/ .
    198 }}}
    199  * '--numeric-owner' is required to store user/group as a number instead of a name, your specific use case may require this switch.
    200  * the '-C rootfs/' is required to eliminate the rootfs directory prefix
    201  * the sudo is needed to be able to read the root owned files
    202  * '--keep-directory-symlink' will preserve symbolic links
    203 
    204 
    205 === Compressed Disk Image (for flashing onto a board)
    206 To create a 'Compressed Disk Image' using this tarball see [wiki:newport/boot#disk-images newport/boot#disk-images] and to install this onto a board's embedded FLASH see [wiki:newport#serial-ethernet here].
    207 
    208 
    209 === ext4 filesystem ===
    210 If desired you can create an ext4 filesystem from the directory or tarball. This requires you choose a size for the filesystem. This size can be increased at runtime using {{{resize2fs}}} as long as the partition table has room for it to grow. The advantage of using an as small as possible size is that the time necessary to flash it onto storage is reduced to a minimum (when flashing you have to write the entire ext4 fs but when formatting or resizing it only has to write periodic markers to FLASH).
    211 
    212 For a given size (see SIZEMB variable below) you can create a rootfs with:
    213 {{{#!bash
    214 SIZEMB=1536 # 1.5GB - expandable later with resize2fs
    215 OUT=rootfs.ext4
    216 # create a file of specific size
    217 truncate -s ${SIZEMB}M ${OUT}
    218 # format it as an ext4 filesystem
    219 mkfs.ext4 -q -F -L rootfs ${OUT}
    220 # mount it to a temporary mount point
    221 tmp_mnt=$(mktemp -d -p/tmp)
    222 mount ${OUT} ${tmp_mnt}
    223 # copy files to it
    224 cp -rup rootfs/* ${tmp_mnt}
    225 # and/or extract files from a tarball
    226 tar -C ${tmp_mnt} -xf linux-newport.tar.xz
    227 # unmount temporary mount point
    228 umount ${tmp_mnt}
    229 sync
    230 # compress it
    231 gzip -k -f ${OUT}
    232 }}}
    233 
    234 Note that the pre-built Gateworks images create a minimal root filesystem as well as a partition table that assumes a specific size (matching the smallest eMMC device used on our boards). There is a script similar to the one above that runs on first-boot which expands the last partition to the extents of the device and grows the partition to fill it. See https://github.com/Gateworks/ubuntu-rootfs/blob/master/ubuntu-rootfs.sh and look for 'growpart' for details.
     48== Root Filesystem
     49see [wiki:ubuntu]
    23550
    23651[=#disk-images]