Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:installation:openwrt_x86 [2023/03/11 15:59] – update headers vgaetera | docs:guide-user:installation:openwrt_x86 [2023/12/12 11:24] – [Expanding root partition] optimize code vgaetera | ||
|---|---|---|---|
| Line 38: | Line 38: | ||
| NVMe SSD support is available since OpenWrt 21.02. | NVMe SSD support is available since OpenWrt 21.02. | ||
| + | |||
| + | ===== Packages to consider on x86 ===== | ||
| + | OpenWrt has a minimalist philosophy regarding packaging strategy due to limited space on embedded devices. | ||
| + | |||
| + | One strategy to identify needed modules is to boot into a live Linux distro (for example [[https:// | ||
| + | |||
| + | Another option if building your own image is to build all modules '' | ||
| + | |||
| + | Beyond the kmods, some common packages to consider installing on x86 are listed below: | ||
| + | * For CPU/APU microcode updates for AMD processors, [[: | ||
| + | * For disk monitoring, [[: | ||
| + | * For hardware monitoring, [[: | ||
| + | * For hardware watchdog support, see: [[: | ||
| + | * For kernel entropy, [[: | ||
| ===== Installation ===== | ===== Installation ===== | ||
| Line 118: | Line 132: | ||
| Any additional space in the device is unallocated. | Any additional space in the device is unallocated. | ||
| - | ===== Resizing | + | ===== Expanding |
| + | See also: [[docs: | ||
| + | |||
| + | ==== Expanding root partition | ||
| <WRAP important> | <WRAP important> | ||
| - | When installing | + | When installing |
| </ | </ | ||
| - | ==== Resizing root partition with parted ==== | + | Use [[man> |
| - | Use [[man> | + | |
| <code bash> | <code bash> | ||
| + | # Install packages | ||
| opkg update | opkg update | ||
| opkg install parted | opkg install parted | ||
| - | echo fix | parted -l ---pretend-input-tty | + | |
| - | parted -s /dev/sda resizepart 2 100% | + | # Identify disk name and partition number |
| + | parted -l -s | ||
| + | |||
| + | # Expand root partition | ||
| + | parted | ||
| + | |||
| + | # Apply changes | ||
| + | reboot | ||
| </ | </ | ||
| - | This process | + | ==== Expanding root filesystem ==== |
| + | <WRAP important> | ||
| + | Be sure to [[docs: | ||
| + | |||
| + | It is possible to expand the root filesystem online while OpenWrt is booted. | ||
| + | You can also perform this operation offline to reduce the chance of filesystem corruption. | ||
| + | </ | ||
| + | |||
| + | Use [[man> | ||
| <code bash> | <code bash> | ||
| + | # Install packages | ||
| opkg update | opkg update | ||
| - | opkg install | + | opkg install |
| - | BOOT=" | + | |
| - | PART=" | + | # Map loop device to root partition |
| - | DISK=" | + | losetup |
| - | echo fix | parted -l ---pretend-input-tty | + | |
| - | parted -s ${DISK%p} resizepart $((PART+1)) 100% | + | # Expand root filesystem |
| + | resize2fs | ||
| + | |||
| + | # Apply changes | ||
| + | reboot | ||
| </ | </ | ||
| - | ==== Resizing | + | ==== Expanding |
| + | You can also use '' | ||
| The easiest way to do this is from the machine booted with a "live CD" distro like [[https:// | The easiest way to do this is from the machine booted with a "live CD" distro like [[https:// | ||
| Here's an overview of the steps: | Here's an overview of the steps: | ||
| - Use fdisk to display the partition table. Notice the ~100MB root partition. | - Use fdisk to display the partition table. Notice the ~100MB root partition. | ||
| - | - Write down the starting sector address of the root partition (Usually /dev/sda2 or / | + | - Write down the starting sector address of the root partition (Usually |
| - Use fdisk to delete partition 2 but don't write the changes to disk yet. | - Use fdisk to delete partition 2 but don't write the changes to disk yet. | ||
| - Use fdisk to create a new partition 2. | - Use fdisk to create a new partition 2. | ||
| Line 157: | Line 195: | ||
| - Write the partition table changes to disk. | - Write the partition table changes to disk. | ||
| - When it warns about partition signatures being present, type **n** to NOT remove the partition signature to proceed. | - When it warns about partition signatures being present, type **n** to NOT remove the partition signature to proceed. | ||
| - | - Proceed with updating | + | - Proceed with updating |
| Example output: | Example output: | ||
| Line 203: | Line 241: | ||
| </ | </ | ||
| - | ===== Updating GRUB configuration ===== | + | Be aware that deleting and recreating the root partition |
| - | If you resize your root partition | + | Make sure to update the root partition UUID in your GRUB configuration |
| - | + | ||
| - | Here's an automated way of doing this: | + | |
| <code bash> | <code bash> | ||
| - | opkg update | + | # Update GRUB configuration |
| - | opkg install lsblk | + | ROOT_BLK="$(readlink |
| - | BOOT="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" / | + | '$9=="/dev/root"{print |
| - | PART=" | + | ROOT_DISK="/dev/$(basename |
| - | DISK=" | + | ROOT_DEV="/dev/${ROOT_BLK##*/}" |
| - | ROOT=" | + | ROOT_UUID="$(partx -g -o UUID "${ROOT_DEV}" "${ROOT_DISK}")" |
| - | UUID="$(lsblk -n -o PARTUUID ${ROOT})" | + | sed -i -r -e "s|(PARTUUID=)\S+|\1${ROOT_UUID}|g" |
| - | sed -i -r -e " | + | |
| - | </ | + | |
| - | + | ||
| - | ===== Resizing root filesystem ===== | + | |
| - | <WRAP important> | + | |
| - | Before resizing the filesystem, be sure to [[docs: | + | |
| - | </WRAP> | + | |
| - | + | ||
| - | ==== Resizing Ext4 root filesystem ==== | + | |
| - | <WRAP important> | + | |
| - | While it is technically possible to resize the rootfs online while OpenWrt is booted, it is highly recommended to resize the rootfs offline to reduce the chance of filesystem corruption. | + | |
| - | </WRAP> | + | |
| - | + | ||
| - | In order to resize the filesystem, we're essentially mounting the root filesystem on a loopback device and then running resize2fs against the loopback device: | + | |
| - | + | ||
| - | <code bash> | + | |
| - | losetup /dev/loop1 /dev/sda2 | + | |
| - | resize2fs -f / | + | |
| - | reboot | + | |
| - | </ | + | |
| - | + | ||
| - | This can be automated with the following commands for each installation type: | + | |
| - | + | ||
| - | Resize Ext4 rootfs for **ext4-combined.img.gz**. | + | |
| - | + | ||
| - | <code bash> | + | |
| - | opkg update | + | |
| - | opkg install losetup resize2fs | + | |
| - | BOOT="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)" | + | |
| - | PART=" | + | |
| - | DISK=" | + | |
| - | ROOT=" | + | |
| - | LOOP="$(losetup -f)" | + | |
| - | losetup | + | |
| - | resize2fs -f ${LOOP} | + | |
| - | reboot | + | |
| - | </code> | + | |
| - | + | ||
| - | Resize Ext4 rootfs for **squashfs-combined.img.gz**. | + | |
| - | + | ||
| - | <code bash> | + | |
| - | opkg update | + | |
| - | opkg install losetup resize2fs | + | |
| - | BOOT=" | + | |
| - | PART="${BOOT##*[^0-9]}" | + | |
| - | DISK="${BOOT%${PART}}" | + | |
| - | ROOT="${DISK}$((PART+1))" | + | |
| - | LOOP=" | + | |
| - | resize2fs -f ${LOOP} | + | |
| - | reboot | + | |
| </ | </ | ||
| Line 278: | Line 264: | ||
| ===== Upgrading ===== | ===== Upgrading ===== | ||
| - | On most embedded devices, upgrading | + | On most embedded devices |
| - | On x86 machines, | + | |
| - | One of the advantages of x86 is the easiness to backup and restore drives, | + | Fortunately, |
| - | Always make a proper backup | + | |
| - | It's also recommended to restore the backup on a virtual machine and execute the upgrade on it prior to upgrading the real router, to learn and experiment the procedures without risking the real thing. | + | |
| - | On all procedures | + | <WRAP important> |
| + | Always make a proper backup of the whole drive and test a restoration before any upgrade procedure. It's also recommended to restore the backup | ||
| + | </ | ||
| + | |||
| + | With most procedures in this section, we must either connect the drive on a secondary PC running Linux, or boot the router with a Linux Live CD/ | ||
| + | |||
| + | If your installation used the '' | ||
| - | If you had used a **ext4-combined.img.gz** type of image to install, there are 4 options for upgrading: | + | - Write a new '' |
| + | - Use '' | ||
| + | - Extract the boot partition image from '' | ||
| + | - Extract the boot partition image from '' | ||
| - | - Write a new **ext4-combined.img.gz** image: this is the simplest option and is identical to first installation: | + | The last two options require more steps to execute but have the advantage of leaving the Master Boot Record and partition table intact. This preserves |
| - | - Use **sysupgrade**: | + | |
| - | - Extracting boot partition image from **ext4-combined.img.gz** | + | |
| - | - Extracting boot partition | + | |
| - | The 2 last options require more steps to execute, but have the advantage of leaving MBR partition intact, therefore keeping boot and rootfs partitions sizes (in case of having resized them) and any extra partitions. | + | FIXME Include instructions for EFI: '' |
| - | At this time they are the most recommended methods of upgrading. | + | |
| - | The only exception is when new OpenWrt image brings a newer version of GRUB2. | + | |
| - | Part of GRUB2 is stored close to MBR and outside of partitions area, so we need to write a full ext4-combined.img.gz | + | |
| ==== Extracting boot partition image ==== | ==== Extracting boot partition image ==== | ||
| Line 344: | Line 330: | ||
| rm openwrt-19.07.8-x86-64-generic-rootfs.tar.gz | rm openwrt-19.07.8-x86-64-generic-rootfs.tar.gz | ||
| </ | </ | ||
| + | |||
| ===== Building your own image with larger partition size ===== | ===== Building your own image with larger partition size ===== | ||
| Anyone can compile OpenWrt from source, but it's a complex procedure with many options which require some experience, specially for using it on a production router. | Anyone can compile OpenWrt from source, but it's a complex procedure with many options which require some experience, specially for using it on a production router. | ||
| Line 356: | Line 343: | ||
| In many cases, OpenWrt will be back fully working on first boot after upgrading. | In many cases, OpenWrt will be back fully working on first boot after upgrading. | ||
| - | Another advantage for building a custom image is when the default rootfs partition size is too small to store all packages and we need to resize | + | Another advantage for building a custom image is when the default rootfs partition size is too small to store all packages and we need to expand |
| - | Note that, when following above procedures of installing then resizing | + | Note that, when following above procedures of installing then expanding |
| Doing so would result in the too large image file and would require enough RAM to store the whole file during building. | Doing so would result in the too large image file and would require enough RAM to store the whole file during building. | ||
| It's recommended to use on the image just enough size to store all packages plus a small amount of free space. | It's recommended to use on the image just enough size to store all packages plus a small amount of free space. | ||