Tricks

Set a Python script as the default program to open .pcd files

With this setup, you can open/view any .pcd point cloud file by just double clicking the mouse.

  1. Prepare a script that takes filename as the first argument.

    • for example, running command pcd_viewer.py example.pcd can open the pcd file.

    • remember to add executable permission sudo chmod +x pcd_viewer.py .

  2. Create a MIME type for .pcd files.

    • open the file /etc/mime.types and add a line application/x-pcd pcd,

    • such that files with extension .pcd can be recognized as the MIME type application/x-pcd.

  3. Create a pcd-viewer.desktop file to link/associate the program to the designated MIME type.

    • set the execution path to the prepared python script, and add %u to help pass the argument

    • add a line MimeType=application/x-pcd to declare that this app can handle this MIME type

    • place this file in /usr/share/applications if you plan to make it work for all users

    • place this file in ~/.local/share/applications for only the current user

    • with this file set properly, you can see it in the "Open with" menu after right click (please verify this before moving forward; it would not show up if %u is not added or the path is not valid)

  4. Set this application as the default program for .pcd files.

    • option one: right click an.pcd file and select PCD Viewer; it will remember the last program as the default one to open it in the future.

    • option two: open the file /usr/share/applications/defaults.list and add a line application/x-pcd=pcd-viewer.desktop ; this will force it to use PCD Viewer at all time.

    • note: creating a defaults.list at ~/.local/share/applications would not work.

    • To make it work immediately you can run sudo update-desktop-database after the changes.

# file: pcd_viewer.py
#!/usr/bin/env python3
import sys
import os
import open3d as o3d
if __name__ == "__main__":
    if 'SVGA_VGPU10' in os.environ:
        del os.environ['SVGA_VGPU10']
    pcd = o3d.io.read_point_cloud(sys.argv[1])
    o3d.visualization.draw_geometries([pcd])
# file: open3d_pcdviewer.desktop
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=PCD Viewer
Icon=python3.8  # full path is /usr/share/pixmaps/python3.8.xpm
Terminal=false
Exec=/opt/pcd_viewer.py %u 
MimeType=application/x-pcd

Reference: Ubuntu – Make shell script default to run file extension

Set Snap Store applications as the default program

The same approach can be applied to applications installed from Snap Store.

  • Run snap list to see all applications installed from Snap Store.

  • Run echo $XDG_DATA_DIRS to check the env path for all installed applications.

  • Their .desktop files are placed at /var/lib/snapd/desktop/applications/ .

Just two steps needed:

  1. Register .pcd as the MIME type if not done yet. (Similar to the Step 2 to set up a python script as the default program.)

  2. Place the following .desktop file under ~/.local/share/applications.

# file: cloudcompare_pcdviewer.desktop
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=CloudCompare PCDViewer
Icon=/snap/cloudcompare/208/meta/gui/cloudcompare.png
Terminal=false
Exec=/snap/bin/cloudcompare.CloudCompare %u
MimeType=application/x-pcd

Reference: Launchers for installed snap applications

Auto start a program/script when the system boots

If sudo privilege is required, we will need three files; otherwise two files. The usage is the following.

  1. Prepare the script you plan to run as the system starts, named launch.sh for example.

  2. If root privilege is needed, prepare a file named root.sh to run the launch.sh file.

  3. Prepare a launch.desktop file to run launch.sh or root.sh script. Place this file in ~/.config/autostart/ folder.

  4. Reboot the computer and you will see the program running automatically as the system starts.

# file: launch.sh
#!/bin/bash
source /opt/ros/indigo/setup.bash
source /home/ubuntu/catkin_ws/devel/setup.bash
roslaunch cruiser cruiser_manifold.launch

# file: root.sh
echo "password" | sudo -S /home/ubuntu/Desktop/launch.sh

# file: launch.desktop
[Desktop Entry]
Encoding=UTF-8
Name=LaunchROS
Type=Application
Exec=/home/ubuntu/Desktop/root.sh
Terminal=true
Categories=Application;

Reference: Cruiser-OnboardROS autostart

Mount USB Drive in Remote Sessions without Root Privilege

  • When working on GUI desktop (with monitor, mouse and keyboard), if you plug in a USB flash drive or SD card, it will get mounted automatically and file manager will prompt out. The mounting point is at /media/<username>/<usb-drive-id>.

  • In remote login sessions (where you only have ssh terminals), if you plug in a USB flash drive, nothing happens. You have to mount it manually by the mountcommand with sudo.

sudo mkdir /mnt/ssd
sudo mount /dev/sda1 /mnt/ssd
sudo umount /mnt/ssd
  • The drawback of this operation is that, you have to use sudofor all write operations in this directory later on, because the owner is root rather than the current user. The solution is to mount it by udiskscommand instead. (Actually in GUI desktop, nautilus file manager does this for you.)

udisks --mount /dev/sdb1

Reference: CLI mounting vs. GUI mounting

Secure Erase a Portable SSD

  • For SanDisk SSD, there is an official software: SanDisk SSD Dashboard

    • This software installer requires network connection to install. (~100MB)

    • "Secure Erase is different from Sanitize because it only deletes the mapping table but will not erase all blocks that have been written to. Sanitize will delete the mapping table and will erase all blocks that have been written to. Therefore, Secure Erase is faster to complete than Sanitize."

    • There may not be a secure erase option available for some models of SSD. (e.g., not available for my Extreme PRO 4TB)

  • Secure Erase under Windows

    • For HDD

      • DBAN: Short for Darik’s Boot and Nuke, DBAN has been around for years and is a well-known and trusted drive wipe utility for HDDs. It does multiple pass rewrites (binary ones and zeros) on the disk. You’ll need to download it to a USB drive and run it from there.

      • Disk Wipe: Disk Wipe is another free utility that does multiple rewrites of binary data. You can choose from a number of different methods for overwriting your disk. Disk Wipe is also portable, so you don’t need to install it to use it.

      • Eraser: Eraser is also free to use. It gives you the most control over how you erase your disk. Like Disk Wipe, you can choose from different methods that include varying numbers of rewrites, or you can define your own.

    • For SSD

      • Parted Magic: Parted Magic is the most regularly recommended third-party erase tool for SSDs, but it does cost $13. It’s a bootable tool like some of the HDD erase tools—you have to download it to a USB drive and run it from there. (Note: there might be some executable available for download at 3rd party websites.)

      • ATA Secure Erase: ATA Secure Erase is a command that basically shocks your SSD. It uses a voltage spike to flush stored electrons. While this sounds damaging (and it does cause some wear), it’s perfectly safe. It doesn’t overwrite the data like other secure erase tools, so there’s actually less damage done to the SSD.

  • Secure Erase under Linux

    • Option One: Using Parted Magic

      • Download a ISO image from some 3rd party software website for free.

      • Create a new VM in VMware using this image.

      • Forward SSD to this Parted Magic VM and perform secure erase.

    • Option Two: Command-line Simple Secure Erase

      • sudo hdparm -I /dev/sdX Displays all information about a drive.

      • sudo hdparm ––security-erase PASS /dev/sdX Simple command to secure erase a drive with no hassle.

      • sudo hdparm ––user-master u ––security-set-pass PASS /dev/sdX Sets a password.

      • sudo hdparm ––user-master u ––security-erase PASS /dev/sdX Securely erases the SSD.

    • More information for Option Two: check this article.

References: SanDisk Dashboard Support Information; Getting Rid of Your PC? Here’s How to Wipe a Windows SSD or Hard Drive; Securely Erasing Your SSD with Linux: A How-To; Perform a SSD Secure Erase

Increase Swap Space

Normally, it is safe to increase your swap size to match the RAM size. For example, if you RAM size is 16GB, you can increase the swap size to be 16GB as well.

# Turn swap off
# This moves stuff in swap to the main memory and might take several minutes
sudo swapoff -a

# Create an empty swapfile
# Note that "1G" is basically just the unit and count is an integer.
# Together, they define the size. In this case 16GB.
sudo dd if=/dev/zero of=/swapfile bs=1G count=16

# Set the correct permissions
sudo chmod 0600 /swapfile

sudo mkswap /swapfile  # Set up a Linux swap area
sudo swapon /swapfile  # Turn the swap on

References: AskUbuntu: How to increase swap space?; How To Add Swap Space on Ubuntu 20.04

Last updated