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
docs:guide-user:installation:installation_methods:sd_card [2024/05/28 23:56] – [Expanding the filesystem] wryundocs:guide-user:installation:installation_methods:sd_card [2024/12/13 16:42] (current) – [Expanding the filesystem] fix link for correct location palebloodsky
Line 1: Line 1:
 ====== SD card ====== ====== SD card ======
  
-This page provides an overview for OpenWrt installation via an SD card. Common devices that use this procedure include Raspberry Pi and NanoPi. +OpenWrt can be installed and run from devices that use an SD card. Common devices with this include Raspberry Pi and NanoPi.
  
 ==== Graphical Utilities ==== ==== Graphical Utilities ====
  
-Install [[https://www.balena.io/etcher/|Balena Etcher]], a free open source program to flash SD cards on Windows, Linux, or macOS. +Install [[https://etcher.balena.io/|Balena Etcher]], a free open source program to flash SD cards on Windows, Linux, or macOS. 
-  - Download the correct image for your device which will be named similar to ''openwrt-*-sysupgrade.img.gz''. +  - Download the image for your device which will be named similar to ''openwrt-*-sysupgrade.img.gz'' 
-  - Select the image. +  - Select the image 
-  - Select your SD card. +  - Select your SD card 
-  - Flash the image.+  - Flash the image
  
 ==== Command Line ==== ==== Command Line ====
-  - Download the image for your device which will be named similar to ''openwrt-*-sysupgrade.img.gz''.+  - Download the image for your device which will be named similar to ''openwrt-*-sysupgrade.img.gz''
   - Decompress it: <code>gzip -d openwrt-*-sysupgrade.img.gz</code>   - Decompress it: <code>gzip -d openwrt-*-sysupgrade.img.gz</code>
-  - Connect SD card to your computer and look at ''lsblk'' or ''dmesg'' to identify it. In most cases, it would be something like ''/dev/sdX''. ((You want to specify the device and not the partition, meaning, you have to use ''/dev/sdX'' and not ''/dev/sdX1'')) +  - Connect an SD card to your computer and look at ''lsblk'' or ''dmesg'' to identify it. In most cases, it would be something like ''/dev/sdX''. ((You want to specify the device and not the partition, meaning, you have to use ''/dev/sdX'' and not ''/dev/sdX1'')) 
-  - Double check that you have identified your sd card correctly. If the ''/dev/sdX'' you have chosencorresponds to your harddrive, the next step would destroy your system+  - Double check you identified your SD card correctly. If the ''/dev/sdX'' you have chosen corresponds to your hard drive, the next step would destroy your system.
   - Copy the image to the SD card with: <code>dd if=openwrt-*-sysupgrade.img of=/dev/sdX</code>   - Copy the image to the SD card with: <code>dd if=openwrt-*-sysupgrade.img of=/dev/sdX</code>
  
 ==== Which image to chose? ==== ==== Which image to chose? ====
-Often a device has multiple images available which differ in the [[:docs:guide-user:storage:filesystems-and-partitions|filesystem]] used.+Most SD card devices have multiple images available which differ in the [[:docs:guide-user:storage:filesystems-and-partitions|filesystem]] used.
  
 === ext4-sdcard.img.gz === === ext4-sdcard.img.gz ===
-  * not optimized for flash memory (journaling increases flash wear)+  * Not optimized for flash memory (journaling increases flash wear)
   * SD card can be easily mounted externally for modification   * SD card can be easily mounted externally for modification
-  * updates and changes can be made directly to the partition+  * Updates and changes can be made directly to the partition
   * Linux desktop standard   * Linux desktop standard
  
 === squashfs-sdcard.img.gz === === squashfs-sdcard.img.gz ===
-  * compressed +  * Compressed 
-  * newer images include a hidden f2fs filesystem, which is optimized for flash memory +  * Newer images include a hidden F2FS filesystem, which is optimized for flash memory 
-  * needs special mount procedure to externally modify +  * Needs special mount procedure to externally modify 
-  * all changes are done in an overlay partition +  * All changes are done in an overlay partition 
-  * due to overlay partition it is simple to reset system to defaults+  * Due to overlay partition it is simple to reset system to defaults
  
-== other images ==+=== Other images ===
   * ubifs-sdcard.img.gz   * ubifs-sdcard.img.gz
  
-==== Mounting a squashfs filesystem locally ====+==== Mounting a squashfs image locally ====
  
-If you insert your newly flashed SD card into a Linux machine, it will be easy to mount the read only squashfs partition but it won't know about the overlay, which is not even in the partition table but instead located immediately after the squashfs filesystem in the same partition. You therefore need to mount the overlay as a loopback device. You can discover the offset by running losetup on the device, or calculate the offset yourself by inspecting the filesystem.+If you insert your newly flashed SD card into a Linux computer it will be easy to mount the read only squashfs partition but it won't know about the overlay, which is not even in the partition table but instead located immediately after the squashfs filesystem in the same partition. In fact, before you've booted the SD card on your device, the overlay won't even exist. 
 + 
 +So, first you need to make sure you've booted your image. You then need to mount the overlay as a loopback device. You can discover the offset by running ''losetup'' on the device, or calculate the offset yourself by inspecting the filesystem.
  
 <code> <code>
Line 58: Line 59:
 </code> </code>
  
-This should leave you with a writable filesystem in /mnt/combined which will work as it does on OpenWRT.+This should leave you with a writable filesystem in /mnt/combined which will work as it does on OpenWrt.
  
 ==== Expanding the filesystem ==== ==== Expanding the filesystem ====
  
-To use the whole available space of your sdcard, you probably have to resize your partition. +To use the whole available space of your SD card, you may have to resize your partition.
  
 === squashfs image === === squashfs image ===
- 
-As with mounting the overlay above, to resize it you'll need the offset of the hidden f2fs or ext4 filesystem (depending on the size of your image, one or the other will be used). 
  
 First, make sure the partition is not mounted, then do something like: First, make sure the partition is not mounted, then do something like:
Line 74: Line 73:
 PARTITION="$DEVICE"2 PARTITION="$DEVICE"2
 sudo cfdisk "$DEVICE"  # select resize, then write sudo cfdisk "$DEVICE"  # select resize, then write
 +</code>
  
 +If you've never booted the image that's all there is to it. OpenWrt will create an overlay which uses the rest of this partition on the first boot.
 +
 +However, if you already booted the image OpenWrt will have created an overlay that is smaller, so you'll need to resize the filesystem. Expand the partition as above, then:
 +
 +<code>
 # Create a loop device pointing to the FS # Create a loop device pointing to the FS
 # See libfstools/rootdisk.c for source of partition offset logic. # See libfstools/rootdisk.c for source of partition offset logic.
Line 81: Line 86:
 LOOP_DEVICE="$(sudo losetup -f --show -o "$FS_OFFSET" "$PARTITION")" LOOP_DEVICE="$(sudo losetup -f --show -o "$FS_OFFSET" "$PARTITION")"
  
-# Nowresize... you may need to fsck firstthough.+# Now to resize... you may need to use fsck first though.
 sudo fsck "$LOOP_DEVICE" sudo fsck "$LOOP_DEVICE"
 sudo resize2fs "$LOOP_DEVICE" sudo resize2fs "$LOOP_DEVICE"
Line 87: Line 92:
 </code> </code>
  
-If you get an error from resize2fs about a bad superblock, you probably have an F2FS filesystem. Try using resize.f2fs instead of resize2fs.+If you get an error from resize2fs about a bad superblock, you probably have an F2FS filesystem. Use ''resize.f2fs'' instead of ''resize2fs''.
  
 === ext4 image === === ext4 image ===
  
-You can use gparted to resize and extend the partitions. +You can use ''gparted'' to resize and extend the partitions. 
-To do it online, follow the procedure in [[http://bugs.openwrt.org/index.php?do=details&task_id=2951|link]] or [[docs:guide-user:installation:openwrt_x86#resizing_filesystem|link]].+To do it online, follow the procedure described on [[http://bugs.openwrt.org/index.php?do=details&task_id=2951|github]] or [[:docs:guide-user:installation:openwrt_x86#expanding_root_partition_and_filesystem]].
  
 Example, to resize ''/dev/mmcblk0p2'' mounted on ''/'', install ''parted'', ''tune2fs'' and ''resize2fs'' then: Example, to resize ''/dev/mmcblk0p2'' mounted on ''/'', install ''parted'', ''tune2fs'' and ''resize2fs'' then:
  • Last modified: 2024/12/13 16:42
  • by palebloodsky