How to Manage Mobile Devices and Swap Space on Linux Systems
This guide explains mounting USB storage, checking device status, configuring NTFS support, and creating, enabling, and disabling swap partitions or swap files on Linux, including practical commands and configuration steps for Ubuntu and CentOS.
Managing USB and External Storage Devices
When a USB flash drive or external hard drive is connected to a Linux system, it appears as a block device such as /dev/sdX. The device must be mounted before use and unmounted before removal to avoid data loss.
Verify detection with lsusb or by monitoring system logs ( tail -f /var/log/syslog on Ubuntu, tail -f /var/log/messages on CentOS). If the device uses the NTFS filesystem, install the ntfs-3g package ( apt install ntfs-3g on Ubuntu, yum install ntfs-3g on CentOS) to enable read/write support.
Swap Space Overview
Swap is a special filesystem that moves inactive memory pages to disk, freeing RAM. It is slower than RAM, so it is optional on systems with sufficient memory. The kernel parameter /proc/sys/vm/swappiness controls swap aggressiveness; the default value 60 starts swapping when memory usage reaches roughly 40%.
Swappiness 0 – use swap only when memory is almost full.
Swappiness 100 – aggressively use swap.
Creating Swap Using a Dedicated Partition
Create a new partition with fdisk or gdisk.
Format the partition as swap: sudo mkswap /dev/sdb1.
Activate the swap partition: sudo swapon /dev/sdb1.
Verify activation: swapon -s.
Add a persistent entry to /etc/fstab:
/dev/sdb1 none swap sw 0 0Creating Swap Using a Swap File
Create a zero‑filled file of the desired size: dd if=/dev/zero of=swapfile bs=1G count=1 Restrict permissions: chmod 600 swapfile.
Initialize the file as swap: sudo mkswap swapfile.
Enable the swap file: sudo swapon swapfile and verify with swapon -s.
Persist across reboots by adding to /etc/fstab: /home/ehigh/swapfile none swap sw 0 0 Swap files work because the OS treats any properly marked disk area as swap, regardless of whether it is a partition or a regular file. Using /dev/zero ensures the file is contiguous and contains no residual data.
Disabling Swap
To deactivate all swap devices, run swapoff -a.
Signed-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.
