This is a comprehensive Tutorial on how to make a Ram Drive for Ubuntu.
Unfortunately.. the screenshots do not show up in this via cut and paste..
Later I will add them, but they are not needed.
The first thing you need to do is create space for your ram drive.
I have a dual boot system with only a 32gb hard drive. My Ubuntu is actually installed on an SD card (yes, a real install and not a Live Casper thing). My swap was also on the SD and might get worn out quickly. I looked up how to change the swap and found this article and did not like the answers so I made a tutorial while I made the change.
If you simply wish to increase or decrease your Swap partition, you only need to increase or decrease the partition through your favorite partition manager. Ubuntu already knows where to go and it is size independent.
If you want to change the location or make a new Swap, then read on.
The first thing you will need to do is Shrink your hard drive to provide space for a swap. If you are shrinking a disk with the Windows system on it, then you'd better use Windows to shrink the disk (It knows its own stuff). If you are on a pure ubuntu, try resizing using a live Ubuntu USB.
Windows Resize Instructions:
- Backup your system, and defrag your drive.
- Right Click on the start bar.
- Select Disk management
- Right click ON THE CORRECT DRIVE
- Select Shrink.
- Type in the correct amount.
If you are in Ubuntu. Make sure you use Ubuntu tools.
To finish the allocation, I will use a bootable Live USB of Ubuntu which includes GParted. A Live USB is the best way to use Gparted for any reason, and you should have a USB from your first install or make one to keep handy.
Typing in 2000 was not allowed because there was not enough room to do that even though I had “defragmented” the drive (I do not believe Windows really defragged it). With some experimentation, I was allowed 1000. Then I tried 1000 again and it worked. I should thank my primary school math teacher for that one more than the MS Windows programmers. That left me with 1.95gb which is close enough for my primary school math.
Format the partition
Now I am ready for gparted to format that space as a proper swap drive.
If you are in Windows and switching back and forth between Ubuntu and Windows, MAKE SURE YOU HOLD THE SHIFT KEY when clicking "Power" and "Shut down." This is very important, especially when you are messing with the "C" drive particulars in another operating system. If you are dual booting, you should know already that Windows does a fake shut down under normal circumstances. Some people have disabled "Fast Boot". I do not have that choice on my system (Windows 10) and must use the shift key thanks to my friend Google. If you boot with a live USB and you cannot mount the "C" drive (by clicking on it), then you did not fully shut down properly. Reload windows and shut down again using the shift key.
Now you are in Ubuntu Live Mode and read below:
If you are a pure Ubuntu and did not shrink in Windows. You will use the Resize option in gParted. If you already shrank your drive, do not do the resize step. You can type GParted in the Dash bar and get the application quite quickly. Right click on the drive you want to resize.
Now we will format the unallocated space as a partitioned drive:
Before:
I did not know what to do, so I looked at my previous Ram Drive on the SD. It is formatted as Linux Swap. So I formatted my new allocation that I recently shrank as Linux Swap too.
I said OK to the Primary Partition and the warning notice and it worked!
Formatting the partition
After the format and new partition
It is a coincidence that the old swap partition on the sd
was called mmblk1p5
and new one is also p5
with mmblk0
in front. Yours could be p6 or p7. Don't worry.
The mmblk0
is the physical disk and p is the partition on that physical disk. And mmblk01
is another physical disk, etc. (That is my SD)
Before I did any more work, I opened Windows again to make sure Windows still booted. You do not need to do this step if you are lazy or on a pure ubuntu machine. If it broke Windows, I would likely wipe Windows do a fresh install of Ubuntu on that disk (with a swap too). If I broke my system, I would not need to follow any more steps because I can allocate the swap on the new install. All went well and Windows booted. Now you can see the new partition in the Windows disk manager: (Right click on the start bar to get disk management)
Now attach the Swap to the boot routine
Previous answers to this question actually had swapon/off commands which are not needed and can be complex. All one needs to do is find the right file, and point the swap to the new partition.
Again, if you only resized the partition, you do not need to do anything. It is already setup to find the partition. The size gets done automatically.
If you changed the partition or are making a first ever swap, then read below:
Let me tell you that, this is the first time I am doing this. I am not a UNIX geek and I prefer GUI tools. I am learning and crossing my fingers as I make this tutorial. All has gone well so far.
At the root of your system is a directory called etc. Inside that directory is a file called fstab
(no extension). You will need to edit this file with super user "su" rights. Before we do that, we need the UUID of the new Swap Partition you made with the Live USB.
Type sudo su
Now you are in Super User mode. You can do anything (including wipe your own existence).
Type blkid
and look for the uuid of the new swap partition. I saw mine below and highlighted it:
Pay no attention to PartUID's.
Now, the other people will say type:
sudo gedit /etc/fstab
However, I tried that and it did not find the right file (comments please).
So I just typed gedit and open it the whimpy GUI way (Success!). Since, I was already in Super User mode (sudo su) I have root permission to do ANYTHING in Gedit, including saving the file after I change it. Wonderful! Before you change or corrupt anything, save the fstab as backup called... fstab.bak
.
Make the backup by using the whimpy GUI way and choose the familiar “Save As” and add "bak" to the file fstab.bak
. Check to see it is there with a .bak extension. Geeks will tell you to use the terminal cp command, but we novices cannot find the file in terminal to get this far in the first place. Just like any word processor, after the “save as” command, your current file is now the fstab.bak
. Open the real one you had before, and then close the backup file.
Double check to see you are editing the real fstab
with no extension. If you edit the backup file, nothing will happen when you reboot, plus your backup copy will not be a real backup of the original.
My original fstab
file looks like this:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/mmcblk1p6 during installation
UUID=a611601a-6ea8-4e34-9859-42a2470cac29 / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/mmcblk0p1 during installation
UUID=00F2-C0CE /boot/efi vfat umask=0077 0 1
# swap was on /dev/mmcblk1p5 during installation
UUID=8fb20159-62e4-41a3-8550-791c7a66c328 none swap sw 0 0
The last line (I made red for you), has the original swap info that is used probably on boot up time. From the previous blkid command, I could see my new drive UUID. Copy that phrase by highlighting the text in the terminal and then right clicking and choosing copy. Paste that phrase into another separate editor without su
rights as a scratch pad (you can use Libre Office, and geeks can use nano
). This step helps you get the right text easily without the quotes so you can paste easily into the fstab
file. You want to change this file as little as possible.
New UUID
UUID="709ea197-e6fb-428b-9c1f-4b258452b10c"
So, my new UUID is listed in red above. All I need to do is change the uuid for the swap. If you have no swap drive, then copy my line in the above fstab file and then add the proper uuid from the previous blkid command. (choose the right uuid please!)
If this is your first Swap line, make sure you includes the complete line with the extra stuff
none swap sw 0 0
Do not worry about the exact spacing so much.
My new file looks like this: Notice I added a comment above my change too
The #
character means it is a comment.
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/mmcblk1p6 during installation
UUID=a611601a-6ea8-4e34-9859-42a2470cac29 / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/mmcblk0p1 during installation
UUID=00F2-C0CE /boot/efi vfat umask=0077 0 1
# swap was on /dev/mmcblk1p5 during installation NOW changed to mmcblk0p5
UUID= 709ea197-e6fb-428b-9c1f-4b258452b10c none swap sw 0 0
Do not paste the quotes. Do not have spaces after the =
sign.
Save your file.
Open it again, just to be sure your changes saved.
Close the gedit and terminal with dangerous su
rights that geeks will scold you for doing (because it is easy work with... and easy to destroy things too).
REBOOT and and cross your fingers!
I rebooted and then I checked to see if my swap was working by looking at system performance app.
I still had a Swap drive! But was it the new one or the old one? I could not verify my new drive was actually loaded because the new one is the same size as the old drive. Therefore, I typed: swapon
(DO NOT TYPE ANYTHING MORE THAN SWAPON and it will only list the swap for you: safe). Now I see my new drive on mmblk0p5
which matches the UUID work I did on fstab
. My slim 32gb main drive took effect:
This concludes this tutorial from a novice user who has never done this before. Half of the reason I made this tutorial was so the Geeks who help us (and thank you) can see how to help novice users. I suspected the previous answers were misleading and decided to make a tutorial as I did my work... By guessing from the other answers which were useful, I concluded that all I needed to do was edit the fstab
flle and reboot. All worked well and I still have windows 10 and have not wiped my system yet. If anyone knows how to share a Windows pagefile.sys
as a Linux swap file, I would be interested since 2 gb is taken for that in Windows and hd space is very pricy on my 32 GB machine.