How to Manage USB Devices and Configure Swap Space on Linux
This guide explains how to detect and mount USB storage devices on Linux, install NTFS support, view system logs, and set up swap space—either as a dedicated partition or a swap file—while covering swappiness tuning and enabling or disabling swap.
Mobile Device Management
Removable storage (USB flash drives, external hard disks) must be mounted before use and unmounted before removal to avoid data loss.
Detecting a USB storage device
When a USB device is plugged in, the kernel creates a SCSI device node under /dev, typically named /dev/sdX. Verify the detection with:
lsusbViewing kernel logs
Real‑time kernel messages show the device discovery process. Use the appropriate log file for your distribution:
# Ubuntu
tail -f /var/log/syslog
# CentOS
tail -f /var/log/messagesNTFS file‑system support
Linux cannot write to NTFS partitions without the ntfs-3g driver. Install it from the package manager:
# Ubuntu
apt install ntfs-3g
# CentOS
yum install ntfs-3gSwap Space Management
Swap is a special area on disk used to store pages that are not actively used in RAM. The kernel parameter /proc/sys/vm/swappiness controls how aggressively the system uses swap.
Default swappiness = 60 (swap starts when RAM usage reaches ~40%).
Swappiness = 0 – swap is used only when RAM is almost exhausted.
Swappiness = 100 – the kernel uses swap aggressively.
Creating a swap partition
Create a new partition with fdisk or gdisk (e.g., /dev/sdb1).
Mark the partition type as Linux swap (type 82) and write the table.
Initialize the partition as swap: sudo mkswap /dev/sdb1 Activate the swap partition immediately: sudo swapon /dev/sdb1 Verify activation: swapon -s Add a persistent entry to /etc/fstab so the swap is enabled at boot:
/dev/sdb1 none swap sw 0 0Creating a swap file
If there is no free partition space, a swap file can be created on an existing filesystem.
Create a file of the desired size (example: 1 GiB): dd if=/dev/zero of=/swapfile bs=1G count=1 Restrict permissions so only root can read/write: sudo chmod 600 /swapfile Mark the file as swap space: sudo mkswap /swapfile Enable the swap file immediately: sudo swapon /swapfile Verify that it is active: swapon -s Persist the swap file across reboots by adding to /etc/fstab:
/swapfile none swap sw 0 0Disabling swap
To turn off all swap devices and files (useful for testing or when swap is no longer needed):
swapoff -aSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
