본문 바로가기

컴퓨터

OpenWrt SD 카드 커스텀 파티셔닝 하기

SD 카드가 보통 16기가는 되는데 openWRT 를 설치 후  기껏해봤자1기가도 안쓴다.

이 경우 남는 15기가는 그대로 처박혀서 보이지도 않고, 

순정 OPENWRT 에서는 읽어들일 방법도 없더라.

 

그런데 역시 길은 있음.. 우분투 기반이라 그런가

Fdisk 를 실행 가능하게 모드가 있음.

 

 

출처 : forum.openwrt.org/t/expanding-openwrt-squashfs-image-sdcard/60606/5

 

Expanding OpenWrt squashfs image? (SDcard)

I managed to resize the overlay. The tricky (nasty) part is that there's two filesystems in the second partition. There's a squashfs and right after the squashfs a hidden f2fs. A loopmount with an offset is needed. One needs to install losetup and use it t

forum.openwrt.org

  1. Install required PKGs

opkg update && opkg install block-mount kmod-fs-ext4 kmod-usb-storage kmod-usb-ohci kmod-usb-uhci e2fsprogs fdisk

 

   2. Create new partition, /dev/mmcblk0p3, and reboot

 

root@Rpi3:~# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 14.43 GiB, 15485370368 bytes, 30244864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f

Device         Boot Start    End Sectors  Size Id Type
/dev/mmcblk0p1 *     8192  49151   40960   20M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      57344 581631  524288  256M 83 Linux

Command (m for help): n 
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 
First sector (2048-30244863, default 2048): 5811632
Last sector, +/-sectors or +/-size{K,M,G,T,P} (5811632-30244863, default 30244863): 

Created a new partition 3 of type 'Linux' and of size 11.7 GiB.

Command (m for help): p
Disk /dev/mmcblk0: 14.43 GiB, 15485370368 bytes, 30244864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f

Device         Boot   Start      End  Sectors  Size Id Type
/dev/mmcblk0p1 *       8192    49151    40960   20M  c W95 FAT32 (LBA)
/dev/mmcblk0p2        57344   581631   524288  256M 83 Linux
/dev/mmcblk0p3      5811632 30244863 24433232 11.7G 83 Linux

Command (m for help): w
The partition table has been altered.
Syncing disks.

root@Rpi3:~# reboot

 

 

 

3. Format new partition

 

root@Rpi3:~# mkfs.ext4 /dev/mmcblk0p3 
mke2fs 1.44.5 (15-Dec-2018)
Discarding device blocks: done                            
Creating filesystem with 3054154 4k blocks and 764032 inodes
Filesystem UUID: 8f3f385e-2ee5-4618-b2e2-e5be282acef9
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

 

4. Configuring rootfs_data, extroot, transferring the data and reboot

 

root@Rpi3:~# DEVICE="/dev/mmcblk0p3"

root@Rpi3:~# eval $(block info "${DEVICE}" | grep -o -e "UUID=\S*")

root@Rpi3:~# uci -q delete fstab.overlay

root@Rpi3:~# uci set fstab.overlay="mount"

root@Rpi3:~# uci set fstab.overlay.uuid="${UUID}"

root@Rpi3:~# uci set fstab.overlay.target="/overlay"

root@Rpi3:~# uci commit fstab

root@Rpi3:~#

root@Rpi3:~# mount /dev/mmcblk0p3 /mnt

root@Rpi3:~# cp -a -f /overlay/. /mnt

root@Rpi3:~# umount /mnt

root@Rpi3:~# reboot

 

5.Preserving software package lists across boots

Or, modify /etc/opkg.conf in Web interface

root@Rpi3:~# sed -i -r -e "s/^(lists_dir\sext\s).*/\1\/usr\/lib\/opkg\/lists/" /etc/opkg.conf

root@Rpi3:~# opkg update