Derek
Derek A site dedicated interesting things like Machine Learning and Mechatronics

Expanding rootfs with external storage

Expanding rootfs with external storage

Some embedded computers such as the Jetson TX2 have very little storage (eMMC) which makes it difficult to do anything productive such as running and plotting point clouds. The newest generation Xavier NX only has 8GB of internal storage! Using the external card simply as an external storage isn’t ideal either since your it doesn’t leave any room for you to install new programs.

This particular tutorial teaches how to build Autoware on a Jetson TX2 (with the latest Jetpack 4.4). This tutorial should be applicable to other arm based Nvidia products like the Xavier and Drive units (however, I cannot confirm this since I do not own one. I would not mind testing and deploying Autoware if someone is willing to send me one).

Solution

The best solution so far is to mount the external storage for your home and usr folder. By doing so, you will not touch anything “important” on the system such as the kernel or main OS files. With a larger home and usr folder, you will be able to use the computer as is but have much more storage to install new software and download files.

In order to increase the capacity of the home and usr folder, the following steps needs to be followed:

  1. Buy external storage and plug it in (can be SD card or SSD)

  2. Partition the drive

  3. Move the existing content to the external storage

  4. Update the fstab to permanently mount the external storage as home and usr

Buying an external storage and plug it in

The benefit with SSD drive is that it’s significantly faster and more reliable/durable (especially with the 3D NAND). The downside is cost and bulk unless you can get it in M.2 form factor. The benefit of SD card is that it’s low cost and integrates better in terms of hardware since most embedded computers have built-in SD card readers. I’ve only seen NVIDIA ones have SATA and PCI-e x4 ports since they’re geared towards ML and AV applications.

There is a chronic and systemic issue at Amazon with counterfeits so it’s very hard to choose a good SD card and get a genuine one. I decided to choose a Samsung EVO Select 128GB microSDXC UHS-I U3 since there is an agreement with Amazon and Samsung that this particular product is sold and shipped by Amazon exclusively so there risk of counterfeits are much lower.

Partition the drive

I prefer to partition my drives via GUI software such as the built-in disk utility (or gparted) in Ubuntu. However, you can search online how to partition your drives via fdisk. The SD card has to be split into 2 partitions in ext4 format as shown below. The size is extremely crucial so choose it carefully. I chose the particular size below because I am using my TX2 for AV application so the data files will consume most of the storage. I estimated I would need about 20-25 GB for my programs so 48GB is more than enough for my usr folder.

  1. home - ext4 - 75 GB
  2. usr - ext4 - 45 GB.

After you partition, it should pop up using the command shown below

1
2
3
4
5
sudo fdisk -l
# It will return somewhere in the list something like shown below
Device         Boot     Start       End   Sectors  Size Id Type
/dev/mmcblk2p1           2048 156344319 156342272 74.6G 83 Linux
/dev/mmcblk2p2      156344320 250347519  94003200 44.8G 83 Linux

Note the name and the corresponding partition name (/dev/mmcblk2p1 and /dev/mmcblk2p2 in my case)

Move the existing content to the external storage

Create a temporary folder so that the two new partitions on the SD card can be mounted somewhere to transfer the files from the current system in the eMMC into the external storage

1
2
3
4
mkdir /tmp/usr && mkdir /tmp/home
# Change the partition name accordingly below
sudo mount /dev/mmcblk2p1 /tmp/home
sudo mount /dev/mmcblk2p2 /tmp/usr

Use rsync to copy the files over to the mounted folders. rysnc is preferred over cp since it maintains relationships and permissions correctly. If you use cp, it will most likely cause some problems due to the nature of the home and usr folder structure.

1
2
3
4
5
# Install rsync
sudo apt-get install rsync
# Copy the files over. Changing the name of folders if you didn't name them the same way 
sudo rsync -ahv --progress /usr/ /tmp/usr/
sudo rsync -ahv --progress /home/ /tmp/home/ 

Update the fstab to permanently mount the external storage as home and usr

Copy and paste the following commands to get the lines you will need to add to the fstab

1
2
echo UUID=$(lsblk -no UUID /dev/mmcblk2p2) /usr ext4 defaults 0 1
echo UUID=$(lsblk -no UUID /dev/mmcblk2p1) /home ext4 defaults 0 1

Copy the output of both commands into /etc/fstab by using nano or gedit. Run the following commands for gedit:

1
2
sudo gedit /etc/fstab
sudo reboot

Use df to confirm that everything is working correctly

1
df -h

It should return something similar as shown below:

1
2
/dev/mmcblk2p1   73G  2.7G   67G   4% /home
/dev/mmcblk2p2   44G   12G   31G  27% /usr