Changes between Version 7 and Version 8 of venice/ubuntu


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

moved ubuntu rootfs to generic ubuntu page

Legend:

Unmodified
Added
Removed
Modified
  • venice/ubuntu

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