Last active
April 13, 2018 14:06
-
-
Save anonymouse64/e0af4aa3f4c53e41c3c3558529da3826 to your computer and use it in GitHub Desktop.
How to add usb drive as swap on Ubuntu Core using systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the usb device's id/info (for me this was /dev/sda1) | |
sudo blkid | |
# unmount it if it's currently mounted | |
sudo umount /dev/sda1 | |
# make the device into swap space | |
################################################################################## | |
#### CAUTION THIS WILL ERASE EVERYTHING ON THE DRIVE ####################### | |
#### PLEASE ENSURE THIS IS THE CORRECT DRIVE AND THERE'S ####################### | |
#### NOTHING OF VALUE ON THE USB DRIVE ####################### | |
################################################################################## | |
sudo mkswap /dev/sda1 | |
# the device id will have likely changed - so find the new id by inspecting the current disks, looking for something like USB | |
ls /dev/disk/by-id | |
# using the name of the device make the systemd unit for the swap | |
export USBDRIVESWAP=dev/disk/by-id/usb-USB_DISK_2.0_064BFA242910DCE92D9F007D-0:0-part1.swap | |
tee /etc/systemd/system/$(systemd-escape -p $USBDRIVESWAP) > /dev/null << EOF | |
[Unit] | |
Description=Swap unit for USB flash drive | |
[Swap] | |
What=/$USBDRIVESWAP | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
# enable the unit | |
sudo systemctl enable $(systemd-escape -p $USBDRIVESWAP) | |
# start the unit to enable the swap | |
sudo systemctl start $(systemd-escape -p $USBDRIVESWAP) | |
# see the new memory available | |
cat /proc/meminfo | grep Swap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment