Wednesday, November 21, 2012

OpenWrt Attitude Adjustment (Trunk) Exrootfs (Jail Break)

First, plug your external drive to linux and follow this step. Update your packages database
$ opkg update
   Downloading http://192.168.77.246:8080/Packages.gz.
   Inflating http://192.168.77.246:8080/Packages.gz.
   Updated list of available packages in /var/opkg-lists/attitude_adjustment.
Install following package
$ opkg install kmod-usb-core # Kernel support for USB
$ opkg install kmod-usb2 # Kernel support for USB2 (EHCI) controllers
$ opkg install kmod-usb-ohci #Kernel support for USB OHCI controllers
$ opkg install kmod-usb-storage #Kernel support for USB Mass Storage devices
$ opkg install block-mount
$ opkg install kmod-fs-ext4 # Kernel module for the filesystem with which you formatted the partition you want to mount
$ opkg install fdisk # utility to create partitions table
To install package, you can always you this syntax
$ opkg install package_name
Before you step forward, you must prepare your disk partition, i choose fdisk for creating partition table, and i make 3 partition table, two partitions for my data and one for swap file. you can see here for instruction using fdisk. Now, it is time to create filesystem on it, i choose ext3.
$ mkfs.ext3 /dev/sda1 for my data
$ mkfs.ext3 /dev/sda2 for my openwrt rootfs
$ mkswap /dev/sda3 for swap
Next step is create mount point and edit /etc/config/fstab, so every time you restart router, everything back as before :D
$ mkdir -p /home --> mount point /dev/sda1
$ mkdir -p /mnt/rootfs --> mount point /dev/sda2
Editing /etc/config/fstab, my fstab file looks like this
$ vi /etc/config/fstab
config global 'automount'
        option from_fstab '1'
        option anon_mount '1'

config global 'autoswap'
        option from_fstab '1'
        option anon_swap '0'

config mount
        option target '/home'
        option device '/dev/sda1'
        option fstype 'ext3'
        option options 'rw,sync'
        option enabled '1'
        option enabled_fsck '0'
 
config mount
        option target '/mnt/rootfs'
        option device '/dev/sda2'
        option fstype 'ext3'
        option options 'rw,sync'
        option enabled '1'
        option enabled_fsck '0'

config swap
        option device '/dev/sda3'
        option enabled '1'
Reboot it, after reboot check your mount point
$ df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.1M    652.0K    436.0K  60% /
/dev/root                 2.0M      2.0M         0 100% /rom
tmpfs                    14.3M    148.0K     14.1M   1% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mtdblock3            1.1M    652.0K    436.0K  60% /overlay
overlayfs:/overlay        1.1M    652.0K    436.0K  60% /
/dev/sda1               916.5G    477.8G    392.2G  55% /home
/dev/sda2                97.3M      4.1M     88.1M   4% /mnt/rootfs
Check swap
$free
             total         used         free       shared      buffers
Mem:         29220        24864         4356            0         1660
-/+ buffers:              23204         6016
Swap:        98936          456        98480
Exrootfs - Whole external root (pivot root) Do this on openwrt console
$ tar -C /overlay -cvf - . | tar -C /mnt/rootfs -xf -
$ mkdir -p /tmp/cproot
$ mount --bind / /tmp/cproot
$ tar -C /tmp/cproot -cvf - . | tar -C /mnt/rootfs -xf -
$ umount /tmp/cproot
Reboot After Reboot, check your system mount point and swap memory Before
$ df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.1M    652.0K    436.0K  60% /
/dev/root                 2.0M      2.0M         0 100% /rom
tmpfs                    14.3M    148.0K     14.1M   1% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mtdblock3            1.1M    652.0K    436.0K  60% /overlay
overlayfs:/overlay        1.1M    652.0K    436.0K  60% /
/dev/sda1               916.5G    477.8G    392.2G  55% /home
/dev/sda2                97.3M      4.1M     88.1M   4% /mnt/rootfs
After
$ df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                  370.4M     15.4M    335.8M   4% /
/dev/root                 2.0M      2.0M         0 100% /rom
tmpfs                    14.3M     88.0K     14.2M   1% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda2               370.4M     15.4M    335.8M   4% /overlay
overlayfs:/overlay      370.4M     15.4M    335.8M   4% /
/dev/sda1               916.5G    477.8G    392.2G  55% /home
Now you have a lot of space to install any applications :D Enjoy it !!

4 comments:

FCG said...

Hello,

I am having an issue trying to merge /mnt/rootfs with /overlay any tips?

FCG said...

I found the solution:
You need to add option is_rootfs '1' to /mnt/rootfs

Anonymous said...

Om, kalau di windows gak bisa ya?

alvaro said...

hello, I cannot edit /etc/config/fstab, it it is in read only
What can be the problem?