Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:installation:openwrt_x86 [2023/03/26 08:59] – [Expanding root partition / filesystem] vgaeteradocs: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.  For many x86 machines, disk space is likely not a limiting factor.  Users coming from desktop distros where thousand of modules are provided in the default image, might be surprised to see that on OpenWrt, the default number of drivers is also minimal.  Therefore, it may be necessary to identify and obtain the needed modules for things like: storage controllers (SATA/USB etc.), sound module, crypto modules, video modules, etc.
 +
 +One strategy to identify needed modules is to boot into a live Linux distro (for example [[https://archlinux.org/download|Arch Linux]]) and inspect the output of ''lsmod'' or ''lspci -vvv | grep driver'' and then search for corresponding OpenWrt kmod packages.
 +
 +Another option if building your own image is to build all modules ''ALL_KMODS=y'' and see what works.  Newer hardware may not be supported out-of-the-box.
 +
 +Beyond the kmods, some common packages to consider installing on x86 are listed below:
 +  * For CPU/APU microcode updates for AMD processors, [[:packages:pkgdata:amd64-microcode]] and for Intel processors, [[:packages:pkgdata:intel-microcode]].
 +  * For disk monitoring, [[:packages:pkgdata_owrt21_2:smartmontools]], see: [[:docs:guide-user:additional-software:smartmontools]]
 +  * For hardware monitoring, [[:packages:pkgdata:lm-sensors]]
 +  * For hardware watchdog support, see: [[:docs:guide-user:hardware:watchdog]]
 +  * For kernel entropy, [[:packages:pkgdata:rng-tools]], see: [[:docs:guide-user:services:rng]]
  
 ===== Installation ===== ===== Installation =====
Line 118: Line 132:
 Any additional space in the device is unallocated. Any additional space in the device is unallocated.
  
-===== Expanding root partition =====+===== Expanding root partition and filesystem ===== 
 +See also: [[docs:guide-user:advanced:expand_root|Expanding root partition and filesystem: Automated]] 
 + 
 +==== Expanding root partition ====
 <WRAP important> <WRAP important>
-When installing OpenWRT on a VM, be sure to [[docs:guide-user:virtualization:qemu#preparation|expand the underlying disk image]] before expanding the root partition.+When installing OpenWrt on a VM, be sure to [[docs:guide-user:virtualization:qemu#preparation|expand the underlying disk image]] before expanding the partition.
 </WRAP> </WRAP>
  
-==== Expanding root partition with parted ==== 
 Use [[man>parted]] to fix the partition table, identify and expand the root partition. Use [[man>parted]] to fix the partition table, identify and expand the root partition.
  
Line 132: Line 148:
  
 # Identify disk name and partition number # Identify disk name and partition number
-echo -e "ok\nfix"parted -l ---pretend-input-tty+parted -l -s
  
 # Expand root partition # Expand root partition
-parted -s /dev/sda resizepart 2 100%+parted -f -s /dev/sda resizepart 2 100%
  
 # Apply changes # Apply changes
Line 141: Line 157:
 </code> </code>
  
-See also: [[docs:guide-user:installation:openwrt_x86#expanding_root_partitionfilesystem|Expanding root partition / Automated]]+==== Expanding root filesystem ==== 
 +<WRAP important> 
 +Be sure to [[docs:guide-user:installation:openwrt_x86#expanding_root_partition|expand the underlying partition]] before expanding the filesystem. 
 + 
 +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. 
 +</WRAP> 
 + 
 +Use [[man>losetup]] to map the root partition and [[man>resize2fs]] to expand the root filesystem. 
 + 
 +<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 /dev/loop0 
 + 
 +# Apply changes 
 +reboot 
 +</code>
  
 ==== Expanding root partition with fdisk ==== ==== Expanding root partition with fdisk ====
 +You can also use ''fdisk'' to expand the root partition if ''parted'' does not work for you.
 The easiest way to do this is from the machine booted with a "live CD" distro like [[https://www.finnix.org|Finnix]]. The easiest way to do this is from the machine booted with a "live CD" distro like [[https://www.finnix.org|Finnix]].
  
 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 /dev/nvme0n1p2).+  - Write down the starting sector address of the root partition (Usually ''/dev/sda2'' or ''/dev/nvme0n1p2'').
   - 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 201: Line 241:
 </code> </code>
  
-===== Updating GRUB configuration ===== +Be aware that deleting and recreating the root partition can change its UUID. 
-If you expand your root partition using a method which causes the partition to be deleted and recreated (such as when using ''fdisk''), you will need to update your GRUB configuration in order for your system to be bootable as the partition UUID which is used in the ''grub.cfg'' will refer to the old partition UUID. +Make sure to update the root partition UUID in your GRUB configuration ''/boot/grub/grub.cfg'' in order for the system to be bootable.
- +
-See also: [[docs:guide-user:installation:openwrt_x86#updating_grub_configuration1|Updating GRUB configuration / Automated]] +
- +
-===== Expanding root filesystem ===== +
-<WRAP important> +
-Before expanding the filesystem, be sure to [[docs:guide-user:installation:openwrt_x86#expanding_root_partition|expand the underlying partition]]. +
- +
-While it is possible to expand the rootfs online while OpenWrt is booted, you may want to perform this operation offline to reduce the chance of filesystem corruption. +
-</WRAP> +
- +
-Use [[man>losetup]] to map the root partition and [[man>resize2fs]] to expand the root filesystem.+
  
 <code bash> <code bash>
-Install packages +Update GRUB configuration 
-opkg update +ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e \ 
-opkg install losetup resize2fs +'$9=="/dev/root"{print $3}' /proc/self/mountinfo)")" 
- +ROOT_DISK="/dev/$(basename "${ROOT_BLK%/*}")" 
-# Map loop device to root partition +ROOT_DEV="/dev/${ROOT_BLK##*/}" 
-losetup /dev/loop1 /dev/sda2 +ROOT_UUID="$(partx -g -o UUID "${ROOT_DEV}" "${ROOT_DISK}")" 
- +sed -i -r -e "s|(PARTUUID=)\S+|\1${ROOT_UUID}|g" /boot/grub/grub.cfg
-# Expand root filesystem +
-resize2fs -f /dev/loop1 +
- +
-Apply changes +
-reboot+
 </code> </code>
- 
-See also: [[docs:guide-user:installation:openwrt_x86#expanding_root_partitionfilesystem|Expanding root filesystem / Automated]] 
  
 ===== Adding extra partitions ===== ===== Adding extra partitions =====
Line 338: Line 360:
 We can either edit ''.config'' file on building folder or pass them directly to ''make image''. We can either edit ''.config'' file on building folder or pass them directly to ''make image''.
 Example ''CONFIG_TARGET_KERNEL_PARTSIZE=128 CONFIG_TARGET_ROOTFS_PARTSIZE=512''. Example ''CONFIG_TARGET_KERNEL_PARTSIZE=128 CONFIG_TARGET_ROOTFS_PARTSIZE=512''.
- 
-===== Extras ===== 
-==== Expanding root partition / filesystem ==== 
-  * Automatically identify root partition/filesystem. 
-  * Expand root partition/filesystem allocating available free space. 
-  * Preserve the scripts through firmware upgrade. 
-  * Automatically run after firmware upgrade. 
- 
-<code bash> 
-# Install packages 
-opkg update 
-opkg install parted losetup resize2fs 
- 
-# Configure startup scripts 
-cat << "EOF" > /etc/uci-defaults/70-rootpt-resize 
-if [ ! -e /etc/rootpt-resize ] \ 
-&& type parted > /dev/null \ 
-&& lock -n /var/lock/rootpt-resize 
-then 
-BOOT_DEV="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)" 
-BOOT_PART="${BOOT_DEV##*[^0-9]}" 
-DISK_DEV="${BOOT_DEV%${BOOT_PART}}" 
-parted -l ---pretend-input-tty << EOI 
-ok 
-fix 
-EOI 
-parted -s "${DISK_DEV%p}" resizepart "$((BOOT_PART+1))" 100% 
-touch /etc/rootpt-resize 
-reboot 
-fi 
-exit 1 
-EOF 
-cat << "EOF" > /etc/uci-defaults/80-rootfs-resize 
-if [ ! -e /etc/rootfs-resize ] \ 
-&& [ -e /etc/rootpt-resize ] \ 
-&& type losetup > /dev/null \ 
-&& type resize2fs > /dev/null \ 
-&& lock -n /var/lock/rootpt-resize 
-then 
-BOOT_DEV="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)" 
-BOOT_PART="${BOOT_DEV##*[^0-9]}" 
-DISK_DEV="${BOOT_DEV%${BOOT_PART}}" 
-ROOT_DEV="${DISK_DEV}$((BOOT_PART+1))" 
-ROOT_TYPE="$(ubus call system board \ 
-| jsonfilter -e "$['rootfs_type']")" 
-case "${ROOT_TYPE}" in 
-(ext4) LOOP_DEV="$(losetup -f)" 
-losetup "${LOOP_DEV}" "${ROOT_DEV}" ;; 
-(squashfs) LOOP_DEV="$(losetup -n -l \ 
-| sed -n -e "\|\s.*\s${ROOT_DEV#/dev}\s.*$|{s///p;q}")" ;; 
-esac 
-resize2fs -f "${LOOP_DEV}" 
-touch /etc/rootfs-resize 
-reboot 
-fi 
-exit 1 
-EOF 
-cat << "EOF" >> /etc/sysupgrade.conf 
-/etc/uci-defaults/70-rootpt-resize 
-/etc/uci-defaults/80-rootfs-resize 
-EOF 
- 
-# Expand root partition/filesystem 
-sh /etc/uci-defaults/70-rootpt-resize 
-</code> 
- 
-==== Updating GRUB configuration ==== 
-<code bash> 
-# Install packages 
-opkg update 
-opkg install lsblk 
- 
-# Configure GRUB 
-BOOT_DEV="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)" 
-BOOT_PART="${BOOT_DEV##*[^0-9]}" 
-DISK_DEV="${BOOT_DEV%${BOOT_PART}}" 
-ROOT_DEV="${DISK_DEV}$((BOOT_PART+1))" 
-ROOT_UUID="$(lsblk -n -o PARTUUID ${ROOT_DEV})" 
-sed -i -r -e "s|(PARTUUID=)\S+|\1${ROOT_UUID}|g" /boot/grub/grub.cfg 
-</code> 
  
  • Last modified: 2024/12/11 21:31
  • by efahlgren