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/08 03:26] – [Update Grub] updates wording for readability joshenders | 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 78: | Line 92: | ||
| </ | </ | ||
| - | ===== Installing OpenWrt | + | ===== Installing OpenWrt |
| If you want to write OpenWrt in SATA or IDE drives or CF Cards or SD cards, you can just remove them from the device and flash the image raw from your PC. | If you want to write OpenWrt in SATA or IDE drives or CF Cards or SD cards, you can just remove them from the device and flash the image raw from your PC. | ||
| Also sometimes eMMC is removable or can be put in "usb write mode" in some devices. | Also sometimes eMMC is removable or can be put in "usb write mode" in some devices. | ||
| Line 118: | Line 132: | ||
| Any additional space in the device is unallocated. | Any additional space in the device is unallocated. | ||
| - | ===== Resizing partitions | + | ===== Expanding root partition and filesystem |
| + | See also: [[docs: | ||
| + | |||
| + | ==== Expanding root partition | ||
| <WRAP important> | <WRAP important> | ||
| - | When installing | + | When installing |
| </ | </ | ||
| - | ==== How to manually resize the root partition with fdisk in a live environment | + | Use [[man> |
| + | |||
| + | <code bash> | ||
| + | # Install packages | ||
| + | opkg update | ||
| + | opkg install parted | ||
| + | |||
| + | # Identify disk name and partition number | ||
| + | parted -l -s | ||
| + | |||
| + | # Expand root partition | ||
| + | parted -f -s /dev/sda resizepart 2 100% | ||
| + | |||
| + | # Apply changes | ||
| + | reboot | ||
| + | </ | ||
| + | |||
| + | ==== Expanding | ||
| + | <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> | ||
| + | # Install packages | ||
| + | opkg update | ||
| + | opkg install losetup resize2fs | ||
| + | |||
| + | # Map loop device to root partition | ||
| + | losetup /dev/loop0 /dev/sda2 2> /dev/null | ||
| + | |||
| + | # Expand root filesystem | ||
| + | resize2fs -f / | ||
| + | |||
| + | # Apply changes | ||
| + | reboot | ||
| + | </ | ||
| + | ==== Expanding root partition with fdisk ==== | ||
| + | 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 136: | 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 182: | Line 241: | ||
| </ | </ | ||
| - | ===== Update Grub ===== | + | 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 filesystem ===== | + | |
| - | <WRAP important> | + | |
| - | Before resizing the filesystem, be sure to [[docs: | + | |
| - | </WRAP> | + | |
| - | + | ||
| - | ==== Resizing Ext4 rootfs ==== | + | |
| - | <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 257: | 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 294: | Line 301: | ||
| ==== Upgrading rootfs partition ==== | ==== Upgrading rootfs partition ==== | ||
| - | As said above, there are 2 options for upgrading rootfs partition, when we are using the ext4 file system | + | As said above, there are 2 options for upgrading rootfs partition, when we are using the ext4 filesystem |
| Writing **ext4-rootfs.img.gz** will delete any file on the partition. | Writing **ext4-rootfs.img.gz** will delete any file on the partition. | ||
| Line 323: | 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 335: | 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. | ||