EXT4 disk formatting options on the router

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

WET

Regular Contributor
If you already made an ext4 partition and you want to remove the journaling without wiping the data, i believe the
Code:
tune2fs -O ^has_journal /dev/sda1
command should work ( adjusted for your particular device of course)

Can journaling be added back (if so, what is command) to an EXT4 which journaling was removed on without wiping data?
 

WET

Regular Contributor
tune2fs -O has_journal /dev/sda1

You should have tried searching.
The above is the turn journaling 'off' command, I wish to know if there is a turn journaling 'on' command. I apologize up front if I am miss understanding and the same command is just a toggle command for off & on which I need confirmed.

Nevermind I see the difference in the two commands. Thank you!
 

Huib

Occasional Visitor
The above is the turn journaling 'off' command, I wish to know if there is a turn journaling 'on' command. I apologize up front if I am miss understanding and the same command is just a toggle command for off & on which I need confirmed.
Take a close look at the command: it doesn't have the ^, which is used to negate the option. So with a ^ it turns off the journaling, without it it turns it on.
 

Zonkd

Very Senior Member
Guide to disk formatting with ASUS-WRT Merlin

AMTM now includes an automatic disk formatting feature!
https://www.snbforums.com/threads/a...erlin-terminal-menu.42415/page-20#post-460843

Go to the Merlin Wiki for the latest version of this guide.
https://github.com/RMerl/asuswrt-merlin/wiki/Disk-formatting

~~

Summary: Learn to manage attached USB disks (under 2TB) directly on router; create new partition tables, format ext2/3/4, adjust features like disk labels and journaling.

Prerequisites:
  1. SSH client and basic CLI skills
  2. Plugging in USB disk requires physical access
Contents:
  1. Readying USB disk
  2. Plug USB disk into router
  3. SSH into router (Enable SSH for LAN Only)
  4. View disk details, with fdisk and df
  5. Unmount disk, with umount
  6. Repartition disk, with fdisk
  7. Format and adjust disk filesystem, with mke2fs and tune2fs (eg. journaling on/off)
  8. Reboot to remount disk

1. Readying USB disk

All data will be erased. Backup data. Start with disk formatted FAT32.

2. Plug USB disk into router

Plug into either USB2.0 or USB3.0 ports.
  • USB 3.0 : use high speed port for large capacity disks, for network file sharing.
  • USB 2.0 : use low speed port for small capacity disks, adequate for router scripts and packages like Diversion/Skynet.
Note: insufficient shielding on USB port for some router models may cause WiFi interference on 2.4ghz band. You may choose to enable Reduce USB Interference option in router web ui.


3. SSH into router (Enable SSH for LAN Only)

Goto Administration / System in router web UI typically at URL
http://router.asus.com/Advanced_System_Content.asp

Enable SSH for LAN ONLY (you will get hacked if you select WAN)

Login to router with your preferred SSH client.

4. View disk details

We'll use 2 commands to view disk info. Search online for manuals.

fdisk -- DOS partition maintenance program
Show the partition table for every disk. Include -l option:
Code:
fdisk -l

My example below shows fdisk output:
Code:
[email protected]:/# fdisk -l

Disk /dev/sda: 15.3 GB, 15376318464 bytes
255 heads, 63 sectors/track, 1869 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sda1               1        1870    15014912   b Win95 FAT32
From my output we can see:
1. The USB disk is sda (with an impressive 15.3GB storage capacity!)
2. The disk has 1 partition mounted as device sda1

TAKE NOTE OF YOUR DEVICE DETAILS.

df -- display free disk space
Show human-readable filesystem usage statistics for all mounted disks:
Code:
df -h

My example below shows df output:
Code:
[email protected]:/# df -h
Filesystem                Size      Used Available Use% Mounted on
ubi:rootfs_ubifs         77.2M     63.9M     13.2M  83% /
mtd:bootfs                4.4M      3.3M      1.1M  75% /bootfs
mtd:data                  8.0M    576.0K      7.4M   7% /data
/dev/mtdblock8           48.0M      1.6M     46.4M   3% /jffs
/dev/sda1                14.3G      2.3M     14.3G   0% /tmp/mnt/SANDISK
From my output we can see:
1. Device sda1 is mounted at /tmp/mnt/
2. sda1 currently has the label SANDISK (we can change this later with tune2fs)


5. Unmount disk

We MUST unmount device before repartitioning and formatting.

mount command lists mounted devices:
Code:
mount

My example below, mount shows my USB device sda1 is currently mounted (see last line):
Code:
[email protected]:/# mount
ubi:rootfs_ubifs on / type ubifs (ro,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,mode=0755)
proc on /proc type proc (rw,relatime)
tmpfs on /var type tmpfs (rw,noexec,relatime,size=420k)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mtd:bootfs on /bootfs type jffs2 (ro,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
mtd:data on /data type jffs2 (rw,relatime)
tmpfs on /tmp type tmpfs (rw,relatime)
/dev/mtdblock8 on /jffs type jffs2 (rw,noatime)
/dev/sda1 on /tmp/mnt/SANDISK type ext4 (rw,nodev,relatime)

umount command unmounts filesystems. Include -f option to forcibly unmount:

For my example the command would be:
Code:
umount -f /tmp/mnt/SANDISK

Check disk was unmounted with mount or df.

Remember...
df will NOT show unmounted disks.
fdisk will show both mounted and unmounted disks.

5.1 Optional: zero disk

This step is OPTIONAL and carries risk. Don't do unless necessary.

A user reportedly fixed problems with their USB disk by using the dd data duplicator utility to zero it. I think it's worth mentioning here.

dd is affectionately nicknamed DISK DESTROYER because people can accidentally erase the wrong disk by mistyping the command (reversing the source/target disk).

Don't dd while tired or drunk.

In my example my USB disk is sda therefore my command would be:
WARNING: RISK OF ACCIDENTAL DATA LOSS
Code:
dd if=/dev/zero of=/dev/sda count=16065 bs=512 && sync

Thanks @loveleeyoungae and @ColinTaylor for posting info here and here.

References:
[1] snbforums.com - EXT4 disk formatting options on the router post-447604
[2] superuser.com - How to format a usb stick flash drive with fat32 for use on linux and windows
[3] ss64.com - dd man page
[4] linuxnix.com - 12 Linux dd comands
[5] snbforums.com - amtm v1.6_beta, now with Disk formatting automated post-459430


6. Repartition disk

fdisk command allows managing partitions. We’ll use it to make a new empty MDOS MBR partition table only supported on disks under 2TB. Larger disks should be formatted on PC.

My example USB disk is sda so my command would be:
Code:
fdisk /dev/sda

From interactive menu, do these commands in order:

m (or help) to see options
Code:
m

p to see all existing partitions on disk (take note)
Code:
p

o to erase and create new disk partition table of type mdos MBR Master Boot Record.
This step is important to ensure compatibility with router. Existing partition table could cause problems. For example, GPT GUID Partition Tables will appear as locked and an error will display "Found valid GPT with protective MBR; using GPT" and no menu options would be available.
Code:
o

p to see all partitions on disk (now we should see none)
Code:
p

n to begin making new partition
Code:
n

...then p to make it a primary partition
Code:
p

...then 1 (one) for its partition number
Code:
1

...then accept default values for first and last cylinder

p to see all partitions on disk (now we should see 1 created of type ID 83 Linux)
Code:
p

w to write changes to disk
Code:
w
7. Format and adjust disk filesystem

mke2fs command is to create an ext2/ext3/ext4 filesystem, usually in a disk partition, where device is the special file corresponding to the device (e.g /dev/sdXX ).

A few command options:
-t : set file system type
-L : set a new volume label
-O : specify a feature to use

My example USB device is sda1 but yours may differ...

To format as ext2 filesystem:
Code:
mke2fs -t ext2 /dev/sda1
or use the alias asus built-in
Code:
mkfs.ext2 /dev/sda1

To format as ext3 filesystem:
Code:
mke2fs -t ext3 /dev/sda1
or use the alias asus built-in
Code:
mkfs.ext3 /dev/sda1

To format as ext4 with journaling off:
Code:
mke2fs -t ext4 -O ^has_journal /dev/sda1

To format as ext4 with journaling on:
Code:
mke2fs -t ext4 -O has_journal /dev/sda1

tune2fs command allows to adjust various filesystem parameters on ext2/ext3/ext4 filesystems.

To add or change disk label:
Code:
tune2fs -L "yourDiskLabel" /dev/sda1

To disable journaling on ext4:
Code:
tune2fs -O ^has_journal /dev/sda1

To enable journaling on ext4 omit the ^:
Code:
tune2fs -O has_journal /dev/sda1

To disable 64bit filesystem compatibility:
Code:
tune2fs -O ^64bit /dev/sda1

To enable 64bit filesystem compatibility omit the ^:
Code:
tune2fs -O 64bit /dev/sda1

8. Reboot to remount disk

Asus-wrt often has trouble remounting disks. It is best to reboot to remount.

Reboot router:
Code:
/sbin/reboot

See a problem?

Let me know if you see a mistake in these instructions and I'll correct it.
 
Last edited:

Marin

Very Senior Member
How-to: Managing USB disks on the router

Summary: Learn how to manage USB disks directly on the router. Follow a guide to erase the disk, create a new partition table, create a new partition, format as ext2/3/4, and adjust features like disk labels and journaling.

Prerequisites:
  1. SSH client and basic command line interface skills
  2. Plugging USB disk into router requires physical access
Contents:
  1. Readying USB disk
  2. Plug USB disk into router
  3. SSH into router (Enable SSH for LAN Only)
  4. View disk details, with fdisk and df
  5. Unmount disk, with umount
  6. Repartition disk, with fdisk
  7. Format and adjust disk filesystem, with mke2fs and tune2fs (eg. journaling on/off)
  8. Reboot to remount disk

1. Readying USB disk

All data will be erased from your USB disk in following steps. Backup any existing data, then use computer to format USB disk as FAT32 before plugging into router.


2. Plug USB disk into router

Plug into either USB2.0 or USB3.0 ports.
  • USB 3.0 : use this high speed port for large capacity disks requiring performance for file sharing and media streaming.
  • USB 2.0 : use this low speed port for small capacity disks, adequate for router scripts and packages like Diversion and Skynet.
Note: insufficient shielding on USB port on some router models has been known to cause WiFi interference on 2.4ghz band. You may choose to enable the Reduce USB Interference option in router web ui.


3. SSH into router (Enable SSH for LAN Only)

Goto Administration / System in router web UI typically at URL
http://router.asus.com/Advanced_System_Content.asp

Enable SSH for LAN ONLY (you will get hacked if you select WAN)

Login to router with your preferred SSH client.


4. View disk details

We have 2 commands available to view disks. Search online for their man pages.

fdisk -- DOS partition maintenance program
It shows partition tables for all disks:
Code:
fdisk -l

Take note of the details for your target disk.

df -- display free disk space
Show human readable filesystem usage statistics for all mounted disks (unmounted disks will not be shown):
Code:
df -h

My example below shows output from fdisk...
Code:
[email protected]:/# fdisk -l

Disk /dev/sda: 15.3 GB, 15376318464 bytes
255 heads, 63 sectors/track, 1869 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sda1               1        1870    15014912   b Win95 FAT32

From the output we take note my USB disk is /dev/sda and has 1 partition at /dev/sda1

Continuing my example, we can see output from df...
Code:
[email protected]:/# df -h
Filesystem                Size      Used Available Use% Mounted on
ubi:rootfs_ubifs         77.2M     63.9M     13.2M  83% /
mtd:bootfs                4.4M      3.3M      1.1M  75% /bootfs
mtd:data                  8.0M    576.0K      7.4M   7% /data
/dev/mtdblock8           48.0M      1.6M     46.4M   3% /jffs
/dev/sda1                14.3G      2.3M     14.3G   0% /tmp/mnt/SANDISK

This output shows our target USB disk partition /dev/sda1 is mounted at /tmp/mnt with label SANDISK.

df will only show statistics for mounted disks. It will not show unmounted disks. fdisk will show both mounted and unmounted disks.


5. Unmount disk

We MUST unmount the disk before repartitioning and formatting.
Code:
umount /tmp/mnt/mydisklabel

In my example my target disk has the label SANDISK, so my command would be:
Code:
umount /tmp/mnt/SANDISK

You may use df to check if the disk was unmounted:
Code:
df -h

6. Repartition disk

Use fdisk on your target disk to manage its partition table (replace the * with your own):
Code:
fdisk /dev/sd*

In my example my target disk was /dev/sda, so my command would be:
Code:
fdisk /dev/sda

From interactive menu, do these commands in order:

m (or help) to see options
Code:
m

p to see all existing partitions on disk (take note)
Code:
p

o to erase and create new disk partition table of type mdos MBR Master Boot Record.
This step is important to ensure compatibility with router. Existing partition table could cause problems. For example, GPT GUID Partition Tables will appear as locked and an error will display "Found valid GPT with protective MBR; using GPT" and no menu options would be available.
Code:
o

p to see all partitions on disk (now we should see none)
Code:
p

n to begin making new partition
Code:
n

...then p to make it a primary partition
Code:
p

...then one (1) for its partition number
Code:
1

...then accept default values for first and last cylinder

p to see all partitions on disk (now we should see 1 created of type ID 83 Linux)
Code:
p

w to write changes to disk
Code:
w


7. Format and adjust disk filesystem

In my example the target disk was /dev/sda1, and the commands below reflect that. Your target disk may be different. Be sure to check with fdisk.

mke2fs command is to create an ext2/ext3/ext4 filesystem, usually in a disk partition, where device is the special file corresponding to the device (e.g /dev/sdXX ).

A few command options:
-t : set file system type
-L : set a new volume label
-O : specify a feature to use

To format as ext2 filesystem:
Code:
mke2fs -t ext2 /dev/sda1
or use the alias asus built-in
Code:
mkfs.ext2 /dev/sda1

To format as ext3 filesystem:
Code:
mke2fs -t ext3 /dev/sda1
or use the alias asus built-in
Code:
mkfs.ext3 /dev/sda1

To format as ext4 with journaling off (RECOMMENDED):
Code:
mke2fs -t ext4 -O ^has_journal /dev/sda1

To format as ext4 with journaling on:
Code:
mke2fs -t ext4 -O has_journal /dev/sda1

tune2fs command allows to adjust various filesystem parameters on ext2/ext3/ext4 filesystems.

To change disk label:
Code:
tune2fs -L "MYUSB" /dev/sda1

To disable journaling on ext4:
Code:
tune2fs -O ^has_journal /dev/sda1

To enable journaling on ext4 you must exclude the ^:
Code:
tune2fs -O has_journal /dev/sda1

To disable 64bit filesystem compatibility:
Code:
tune2fs -O ^64bit /dev/sda1

To enable 64bit filesystem compatibility exclude the ^:
Code:
tune2fs -O 64bit /dev/sda1

8. Reboot to remount disk

Asus-wrt often has trouble remounting disks. It is best to reboot to remount.

DONT unplug the USB disk. Reboot the router.
Code:
/sbin/reboot

If you're unable to reboot you can try the mount command.

To force remount the disk...
Code:
mount /dev/sda /tmp/mnt/disklabelhere

In my example the disk label was SANDISK, so my command would be:
Code:
mount /dev/sda /tmp/mnt/SANDISK

See a problem?

Let me know if you see a mistake in these instructions and I'll correct it.

Nice work @Zonkd! Will give it a try! Thanks for putting this guide together!


Sent from my iPhone using Tapatalk
 

thelonelycoder

Part of the Furniture
Let me know if you see a mistake in these instructions and I'll correct it.
Not reporting a problem.
Following this instruction created a proper Linux type filesystem out of a FAT disk. Thanks for the instructions.
Now, if it only were a semi or fully automated script.
 

Zonkd

Very Senior Member
Not reporting a problem.
Following this instruction created a proper Linux type filesystem out of a FAT disk. Thanks for the instructions.
Now, if it only were a semi or fully automated script.

Glad it worked. I hit the 1000 word limit on the post so hopefully i covered everything. Saves people time reanswering the same questions. A script may be good but beyond my ability. Feel welcome! Thanks for feedback.
 

ColinTaylor

Part of the Furniture
6. Repartition disk

o to erase and create new disk partition table of type mdos MBR Master Boot Record.
This step is important to ensure compatibility with router. Existing partition table could cause problems. For example, GPT GUID Partition Tables will appear as locked and an error will display "Found valid GPT with protective MBR; using GPT" and no menu options would be available.
This is potentially a problem. The MBR partition table limits the maximum size of the entire disk (not just a partition) to 2TB. If you have a disk larger than this you need to use a GUID partition table (GPT).

Whilst personally I always use MBR if possible for compatibility reasons, we know that Asus officially supports disks of at least 4TB, ergo they must also support GPT.

But here's the rub, the router's version of fdisk doesn't support editing GPT partition tables or have the option to create them. So owners of such devices, when they get to Step 6, will have to partition them with GPT on another device and then skip the whole of that step, continuing from Step 7.

8. Reboot to remount disk

If you cannot reboot you can try mount command. For my example the disk label is SANDISK so my command would be:
Code:
mount /dev/sda /tmp/mnt/SANDISK
Typo - Should be /dev/sda1, not /dev/sda.
 
Last edited:

Zonkd

Very Senior Member
This is potentially a problem. The MBR partition table limits the maximum size of the entire disk (not just a partition) to 2TB. If you have a disk larger than this you need to use a GUID partition table (GPT).

Whilst personally I always use MBR if possible for compatibility reasons, we know that Asus officially supports disks of at least 4TB, ergo they must also support GPT.

But here's the rub, the router's version of fdisk doesn't support GTP partition tables let alone have the option to create them. So owners of such devices, when they get to Step 6, will have to partition them with GTP on another device and then skip the whole of that step, continuing from Step 7.


Typo - Should be /dev/sda1, not /dev/sda.

I’ll take some time to expand on the guide to address all these issues. Due to word limit I’ll need to post it to the GitHub instead. Once finished I’ll edit the post on SNB with a link to the github page.

We’re seeing this is a surprisingly complex topic with so many factors to consider before selecting the best method for your particular disk and use case scenario. I’ll accept all the help I can get in explaining why things go wrong when someone selects the wrong method. Thanks.
 

ColinTaylor

Part of the Furniture
To format as ext4 with journaling off (RECOMMENDED):
Code:
mke2fs -t ext4 -O ^has_journal /dev/sda1
A recent discussion in this thread reminded me of this. Personally I would never make a blanket recommendation to use a non-journaling filesystem. You're trading data integrity for performance, and the performance gains are probably negligible.

The argument goes that devices like USB flash drives are so slow that you need to squeeze every last bit of speed out of them. They also tend to contain relatively small amounts of data that can be recreated if the device becomes corrupted.

Larger HDD or SSD storage devices can be many terabytes in size and can contain thousands of files. Things like media collections or backups. These devices are fast and there is no excuse not to use a journaling filesystem (assuming the router supports it). These devices also tend to contain data that would be difficult to identify (let alone restore) due to the shear volume of it.
 

Zonkd

Very Senior Member
A recent discussion in this thread reminded me of this. Personally I would never make a blanket recommendation to use a non-journaling filesystem. You're trading data integrity for performance, and the performance gains are probably negligible.

The argument goes that devices like USB flash drives are so slow that you need to squeeze every last bit of speed out of them. They also tend to contain relatively small amounts of data that can be recreated if the device becomes corrupted.

Larger HDD or SSD storage devices can be many terabytes in size and can contain thousands of files. Things like media collections or backups. These devices are fast and there is no excuse not to use a journaling filesystem (assuming the router supports it). These devices also tend to contain data that would be difficult to identify (let alone restore) due to the shear volume of it.

Good points, edits made. Future rewrite will have no word limit and i can cover when it’s best to enable journaling.
 

ColinTaylor

Part of the Furniture
@Zonkd As per the discussion in the amtm beta thread, I suggest you amend your dd command as follows. This wipes out not only the MBR but the beginning of partition 1, which prevents all sorts of issues when there is a preexisting filesystem ;).

dd if=/dev/zero of=/dev/sda count=16065 bs=512 && sync
 

heysoundude

Very Senior Member
@Zonkd - assuming I did everything correctly when I set up my drive on my old (n66u) router, is it as simple as connecting it to my new one (ac86)? I'm also not sure it was correctly unmounted; will there be problems (ie data loss) when I reconnect it?
 

Zonkd

Very Senior Member
@Zonkd - assuming I did everything correctly when I set up my drive on my old (n66u) router, is it as simple as connecting it to my new one (ac86)? I'm also not sure it was correctly unmounted; will there be problems (ie data loss) when I reconnect it?

What device did you use to format it? What are you using the drive for? Multimedia network file sharing (movies/music)? Scripts?

What is the filesystem type? Read the top of this section 5 of the guide on using mount command to check.
 

heysoundude

Very Senior Member
What device did you use to format it? What are you using the drive for? Multimedia network file sharing (movies/music)? Scripts?

What is the filesystem type? Read the top of this section 5 of the guide on using mount command to check.

Using it for network file sharing/backup(personal cloud).
fdisk -l shows HPFS/NTFS...so I guess it came formatted/was never formatted according to this (uh-oh...there's stuff on there - can it be saved?)
 

martinr

Part of the Furniture
What device did you use to format it? What are you using the drive for? Multimedia network file sharing (movies/music)? Scripts?

What is the filesystem type? Read the top of this section 5 of the guide on using mount command to check.

Reading thiat section, I saw:

“Stop any processes/scripts that may be utilizing the disk before continuing.”

How would one go about that, ie what would be the command to list which scripts/processes are using the disk, and, then, what would the command be to stop a typical script/process?

Would it be a better use of your time if your answer was added to that page and just linked to here, to save you getting the same question in the future?
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top