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 [2021/12/19 15:22] – [SD card] remove fixme mercygroundabyssdocs: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 ======
  
-Installation can be done via SD card.+OpenWrt can be installed and run from devices that use an SD card. Common devices with this include Raspberry Pi and NanoPi.
  
 +==== Graphical Utilities ====
  
-===== Prebuilt disk images =====+Install [[https://etcher.balena.io/|Balena Etcher]], a free open source program to flash SD cards on Windows, Linux, or macOS. 
 +  - Download the image for your device which will be named similar to ''openwrt-*-sysupgrade.img.gz'' 
 +  - Select the image 
 +  - Select your SD card 
 +  - Flash the image
  
- +==== Command Line ==== 
- +  - Download the image for your device which will be named similar to ''openwrt-*-sysupgrade.img.gz''
-==== General procedure: ==== +
-**Linux :** +
-  - Download the correct image for your device. Probably 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 sdcard 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 sdcard 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 sdcard 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>
- +
-**Other OS :** \\  +
- +
-https://www.balena.io/etcher/ - Can flash SDCards on Windows and MacOs (also has a linux install) +
-  - Download the correct image for your device. Probably named similar to ''openwrt-*-sysupgrade.img.gz''+
-  - Select the image. +
-  - Select your SDCard. +
-  - Flash the image. +
- +
-Examples: +
-  * [[toh:pcengines:apu#installation1|APU]] +
-  * [[toh:raspberry_pi_foundation:raspberry_pi#how_to_flash_openwrt_to_an_sd_card|RPi]] +
-  * [[docs:techref:hardware:soc:soc.allwinner.sunxi#trunk_-_pre-built_sd_card_images|Sunxi]]+
  
 ==== Which image to chose? ==== ==== Which image to chose? ====
-Often, different images are available for a device. The differ in the 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 speed up flash wear) +  * Not optimized for flash memory (journaling increases flash wear) 
-  * sdcard can be easyly mounted externally for modification +  * SD card can be easily mounted externally for modification 
-  * desktop linux standard +  * Updates and changes can be made directly to the partition 
-  * +  * Linux desktop standard
  
 === squashfs-sdcard.img.gz === === squashfs-sdcard.img.gz ===
-  * newer images include a hidden f2fs filesystem, which is optimized for flash memory +  * Compressed 
-  * compressed +  * Newer images include a hidden F2FS filesystem, which is optimized for flash memory 
-  * needs special mount procedureto externally modify it +  * 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
  
-== other images ==+=== Other images ===
   * ubifs-sdcard.img.gz   * ubifs-sdcard.img.gz
-  * ... 
  
-== see also ==+==== Mounting a squashfs image locally ====
  
 +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>
 +# Setup the loop back device.
 +# See libfstools/rootdisk.c for source of partition offset logic.
 +DEVICE= ### Set this appropriately - e.g. /dev/sda
 +PARTITION="$DEVICE"2
 +FS_SIZE="$(sudo unsquashfs -s "$PARTITION" | grep -o 'Filesystem size [0-9]* bytes' | grep -o '[0-9][0-9]*')"
 +FS_OFFSET="$(expr '(' "$FS_SIZE" + 65535 ')' / 65536 '*' 65536)" 
 +LOOP_DEVICE="$(sudo losetup -f --show -o "$FS_OFFSET" "$PARTITION")"
 +
 +# Now mount both partitions (remember, you may need to unmount any automatic mounts)
 +mkdir -p /mnt/base /mnt/overlay /mnt/combined
 +sudo mount "$PARTITION" /mnt/base            
 +sudo mount "$LOOP_DEVICE" /mnt/overlay
 +sudo mount -o noatime,lowerdir=/mnt/base,upperdir=/mnt/overlay/upper,workdir=/mnt/overlay/work -t overlay overlayfs /mnt/combined
 +</code>
 +
 +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 ===
-To resize the squashfs-image one has to know the offset of the hidden f2fs filesystem.  + 
-In this example, the squashfs partiton is ''/dev/sde2''. +Firstmake sure the partition is not mounted, then do something like: 
-  - You can find the offsetby running ''losetup'' on your openwrt device+ 
-  - On your computer, resize the squashfs partition, for example with ''cfdisk''. +<code> 
-  - Loop mount the underlying f2fs partition (( If you are already using a loop device, you may have to use another number that loop0 )) <code>losetup --o <offset> /dev/loop0 /dev/sde2</code> +DEVICE= ### Set this appropriately - e.g. /dev/sda 
-  - Run filesystem checks <code>fsck.f2fs /dev/loop0</code> +PARTITION="$DEVICE"
-  - Resize f2fs filesystem <code>resize.f2fs /dev/loop0</code> +sudo cfdisk "$DEVICE"  # select resizethen write 
-Now your filesystem should be recognized with the correct size.+</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
 + 
 +Howeverif 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 abovethen: 
 + 
 +<code> 
 +# Create a loop device pointing to the FS 
 +# See libfstools/rootdisk.c for source of partition offset logic. 
 +FS_SIZE="$(sudo unsquashfs -s "$PARTITION" | grep -o 'Filesystem size [0-9]* bytes| grep -o '[0-9][0-9]*')" 
 +FS_OFFSET="$(expr '(' "$FS_SIZE" + 65535 ')' / 65536 '*' 65536)"  
 +LOOP_DEVICE="$(sudo losetup -f --show -o "$FS_OFFSET" "$PARTITION")" 
 + 
 +# Now to resize... you may need to use fsck first though. 
 +sudo fsck "$LOOP_DEVICE" 
 +sudo resize2fs "$LOOP_DEVICE" 
 +sudo fsck "$LOOP_DEVICE" 
 +</code> 
 + 
 +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 us 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]]. 
  
 +You can use ''gparted'' to resize and extend the partitions.
 +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:
 +<code>
 +parted
 +p
 +resizepart 2 32GB
 +q
 +</code>
 +Next, you may need to repair your device (perhaps say yes to all interactive queries):
 <code> <code>
 mount -o remount,ro /                  #Remount root as Read Only mount -o remount,ro /                  #Remount root as Read Only
-tune2fs -O^resize_inode /dev/device    #Remove reserved GDT blocks +tune2fs -O^resize_inode /dev/mmcblk0p2    #Remove reserved GDT blocks 
-fsck.ext4 /dev/device                  #Fix part, answer yes to remove GDT blocks remnants +fsck.ext4 /dev/mmcblk0p2                  #Fix part, answer yes to remove GDT blocks remnants 
- +</code> 
-#reboot +Now, ''reboot'' and then resize the partition: 
-resize2fs /dev/device+<code> 
 +resize2fs /dev/mmcblk0p2
 </code> </code>
  
Line 85: Line 126:
   - Copy bootloader, kernel, rootfs (and if necessary other data) to SD card. Details devicespecific? -> Devicepage   - Copy bootloader, kernel, rootfs (and if necessary other data) to SD card. Details devicespecific? -> Devicepage
   - Possibly resize filesystem in order to use the complete available space on the SD card   - Possibly resize filesystem in order to use the complete available space on the SD card
-  - ... 
  
-===== Devices with this installation method ===== 
----- datatable ---- 
-cols       : Brand, Model, Versions, Supported Current Rel_releasecurrent, Installation method(s)_method-installations, Comment installation, Device Page_page, Device Techdata_pageid 
-dynfilters : 1 
-filter     : Model!=@@Model@@ 
-filter     : installation method(s)=SD card 
-sort       : Brand 
-limit      : 25 
----- 
  • Last modified: 2024/12/13 16:42
  • by palebloodsky