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/01/05 02:42] – [Update Grub] support block devices such as /dev/nvme0n1p2, /dev/mmcblk0p1 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 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 |
| </ | </ | ||
| - | 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% | ||
| - | </ | ||
| - | This process can also be automated. | + | # Identify disk name and partition number |
| + | parted -l -s | ||
| - | <code bash> | + | # Expand root partition |
| - | opkg update | + | parted -f -s /dev/sda resizepart |
| - | opkg install | + | |
| - | BOOT=" | + | |
| - | DISK=" | + | |
| - | PART=" | + | |
| - | echo fix | parted -l ---pretend-input-tty | + | |
| - | parted -s ${DISK} | + | |
| - | </ | + | |
| - | ===== Update Grub ===== | + | # Apply changes |
| - | If your GPT partition UUID has changed, be sure to update the GPT partition UUID in the GRUB configuration to ensure you will still have a bootable system when using ***efi.img.gz**. | + | reboot |
| - | + | ||
| - | <code bash> | + | |
| - | opkg update | + | |
| - | opkg install lsblk | + | |
| - | BOOT=" | + | |
| - | DISK=" | + | |
| - | PART=" | + | |
| - | ROOT=" | + | |
| - | UUID=" | + | |
| - | sed -i -r -e " | + | |
| </ | </ | ||
| - | ===== Resizing | + | ==== Expanding root filesystem ==== |
| <WRAP important> | <WRAP important> | ||
| - | Before resizing the filesystem, be sure to [[docs: | + | Be sure to [[docs: |
| - | </ | + | |
| - | ==== Resizing Ext4 rootfs ==== | + | It is possible to expand |
| - | <WRAP important> | + | You can also perform this operation |
| - | While it is technically | + | |
| </ | </ | ||
| - | In order to resize the filesystem, we're essentially mounting | + | Use [[man> |
| <code bash> | <code bash> | ||
| - | losetup /dev/loop1 /dev/sda2 | + | # Install packages |
| - | resize2fs -f /dev/loop1 | + | opkg update |
| + | opkg install losetup resize2fs | ||
| + | |||
| + | # Map loop device to root partition | ||
| + | losetup /dev/loop0 / | ||
| + | |||
| + | # Expand root filesystem | ||
| + | resize2fs -f /dev/loop0 | ||
| + | |||
| + | # Apply changes | ||
| reboot | reboot | ||
| </ | </ | ||
| - | This can be automated | + | ==== Expanding root partition |
| + | You can also use '' | ||
| + | The easiest way to do this is from the machine booted with a "live CD" distro like [[https:// | ||
| - | Resize Ext4 rootfs for **ext4-combined.img.gz**. | + | Here's an overview of the steps: |
| + | | ||
| + | - 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 create a new partition 2. | ||
| + | - choose/type the starting sector address you wrote down earlier (as by default it will try to place it somewhere else). | ||
| + | - leave the default end sector address (this will mean the partition will now use all available space). | ||
| + | - 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. | ||
| + | - Proceed with updating ''/ | ||
| - | < | + | Example output: |
| - | opkg update | + | |
| - | opkg install losetup resize2fs | + | < |
| - | BOOT=" | + | Welcome to fdisk (util-linux 2.32). |
| - | DISK=" | + | Changes will remain in memory only, until you decide to write them. |
| - | PART=" | + | Be careful before using the write command. |
| - | ROOT=" | + | |
| - | LOOP=" | + | Command |
| - | losetup ${LOOP} ${ROOT} | + | Disk /dev/sda: 7.2 GiB, 7751073792 bytes, 15138816 sectors |
| - | resize2fs | + | Units: sectors of 1 * 512 = 512 bytes |
| - | reboot | + | Sector size (logical/physical): 512 bytes / 512 bytes |
| + | I/O size (minimum/optimal): 512 bytes / 512 bytes | ||
| + | Disklabel type: dos | ||
| + | Disk identifier: 0xcbad8a62 | ||
| + | |||
| + | Device | ||
| + | /dev/ | ||
| + | /dev/sda2 33792 246783 | ||
| + | |||
| + | Command (m for help): d | ||
| + | Partition number | ||
| + | |||
| + | Partition 2 has been deleted. | ||
| + | |||
| + | Command (m for help): n | ||
| + | Partition type | ||
| + | | ||
| + | | ||
| + | Select (default p): | ||
| + | Partition number | ||
| + | First sector (33280-15138815, default 34816): 33792 | ||
| + | Last sector, +sectors or +size{K,M,G,T,P} (33792-15138815, | ||
| + | |||
| + | Created a new partition 2 of type ' | ||
| + | Partition #2 contains a ext4 signature. | ||
| + | |||
| + | Do you want to remove the signature? [Y]es/[N]o: n | ||
| + | |||
| + | Command (m for help): w | ||
| + | |||
| + | The partition table has been altered. | ||
| + | Syncing disks. | ||
| </ | </ | ||
| - | Resize Ext4 rootfs for **squashfs-combined.img.gz**. | + | Be aware that deleting and recreating the root partition can change its UUID. |
| + | Make sure to update the root partition UUID in your GRUB configuration ''/ | ||
| <code bash> | <code bash> | ||
| - | opkg update | + | # Update GRUB configuration |
| - | opkg install losetup resize2fs | + | ROOT_BLK="$(readlink |
| - | BOOT="$(sed -n -e "\|\s/ | + | '$9=="/dev/root" |
| - | DISK="$(echo "${BOOT}" | sed -e "s/[0-9]*$//" | + | ROOT_DISK="/dev/$(basename |
| - | PART="$((${BOOT##*[^0-9]}+1))" | + | ROOT_DEV="/dev/${ROOT_BLK##*/}" |
| - | ROOT="${DISK}${PART}" | + | ROOT_UUID=" |
| - | LOOP="$(losetup -n -l | sed -n -e "\|\s.*\s${ROOT#/dev}\s.*$|{s///p; | + | sed -i -r -e "s|(PARTUUID=)\S+|\1${ROOT_UUID}|g" |
| - | resize2fs -f ${LOOP} | + | |
| - | reboot | + | |
| </ | </ | ||
| Line 217: | 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 on this section, we must either connect | + | <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 | ||
| + | </ | ||
| - | If you had used a **ext4-combined.img.gz** type of image to install, there are 4 options for upgrading: | + | 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:// |
| - | - Write a new **ext4-combined.img.gz** image: this is the simplest option and is identical | + | If your installation used the '' |
| - | - Use **sysupgrade**: | + | |
| - | - Extracting boot partition image from **ext4-combined.img.gz** and writing it and **ext4-rootfs.img.gz**, | + | |
| - | - Extracting boot partition image from **ext4-combined.img.gz** and writing it, then uncompressing **rootfs.tar.gz** to existing rootfs partition. | + | |
| - | The 2 last options require more steps to execute, but have the advantage of leaving | + | - Write a new '' |
| - | At this time they are the most recommended methods of upgrading. | + | - Use '' |
| - | The only exception | + | - Extract the boot partition image from '' |
| - | Part of GRUB2 is stored close to MBR and outside of partitions area, so we need to write a full ext4-combined.img.gz to update it. | + | - Extract the boot partition image from '' |
| + | |||
| + | The last two options require more steps to execute but have the advantage of leaving | ||
| + | |||
| + | FIXME Include instructions for EFI: '' | ||
| ==== Extracting boot partition image ==== | ==== Extracting boot partition image ==== | ||
| Line 254: | 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 283: | 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 295: | 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. | ||