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/17 16:18] – [Resizing Ext4 root filesystem] 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}" /etc/mtab)" | + | '$9=="/dev/root"{print $3}' |
| - | PART="${BOOT## | + | ROOT_DISK="/dev/$(basename |
| - | DISK="${BOOT%${PART}}" | + | ROOT_DEV="/dev/${ROOT_BLK## |
| - | ROOT="${DISK}$((PART+1))" | + | ROOT_UUID="$(partx -g -o UUID "${ROOT_DEV}" " |
| - | UUID="$(lsblk -n -o PARTUUID | + | sed -i -r -e " |
| - | sed -i -r -e " | + | |
| </ | </ | ||
| - | |||
| - | ===== Resizing root filesystem ===== | ||
| - | <WRAP important> | ||
| - | Before resizing the filesystem, be sure to [[docs: | ||
| - | </ | ||
| - | |||
| - | ==== 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. | ||
| - | </ | ||
| - | |||
| - | 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 /dev/loop1 | ||
| - | 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=" | ||
| - | PART=" | ||
| - | DISK=" | ||
| - | ROOT=" | ||
| - | LOOP=" | ||
| - | losetup ${LOOP} ${ROOT} | ||
| - | resize2fs -f ${LOOP} | ||
| - | reboot | ||
| - | </ | ||
| - | |||
| - | Resize Ext4 rootfs for **squashfs-combined.img.gz**. | ||
| - | |||
| - | <code bash> | ||
| - | opkg update | ||
| - | opkg install losetup resize2fs | ||
| - | BOOT=" | ||
| - | PART=" | ||
| - | DISK=" | ||
| - | ROOT=" | ||
| - | LOOP=" | ||
| - | resize2fs -f ${LOOP} | ||
| - | reboot | ||
| - | </ | ||
| - | |||
| - | :!: OpenWrt 22.03 with squashfs requires the code including reboot to be run twice for it to actually take effect. | ||
| ===== Adding extra partitions ===== | ===== Adding extra partitions ===== | ||
| Line 284: | Line 268: | ||
| Fortunately, | Fortunately, | ||
| - | < | + | < |
| + | 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 on a virtual machine and execute the upgrade on the virtual machine prior to upgrading the real router. This can be an effective strategy for learning and experimenting the process without risking the real thing. | ||
| + | </ | ||
| 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/USB such as [[https:// | 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/USB such as [[https:// | ||
| Line 298: | Line 284: | ||
| FIXME Include instructions for EFI: '' | FIXME Include instructions for EFI: '' | ||
| + | |||
| ==== Extracting boot partition image ==== | ==== Extracting boot partition image ==== | ||
| The boot partition contains part of GRUB2 software, Linux kernel and '' | The boot partition contains part of GRUB2 software, Linux kernel and '' | ||
| Line 343: | 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 355: | 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. | ||