1

I followed this thread and installed Ubuntu 16.04 alongside macOS. Now I have 8GM RAM and 8G swap space so I should reduce it. After searching from existing threads, I am aware there may be risk involved when dealing with partition on an active OS. Then, should I switch to macOS and resize the partition? Or using Gparted on Ubuntu will be the best practice?

This is the result after df:

Filesystem     1K-blocks    Used Available Use% Mounted on
udev             4016104       0   4016104   0% /dev
tmpfs             807456    9664    797792   2% /run
/dev/sda6       24339852 6650036  16430348  29% /
tmpfs            4037272   56160   3981112   2% /dev/shm
tmpfs               5120       4      5116   1% /run/lock
tmpfs            4037272       0   4037272   0% /sys/fs/cgroup
/dev/sda1         201633   27390    174244  14% /boot/efi
tmpfs             807456      76    807380   1% /run/user/1000

and free:

              total        used        free      shared  buff/cache   available
Mem:        8074548     1387972     4520412      535036     2166164     5800552
Swap:       7802784           0     7802784

This is my partition table:

flint1025@xiaofeng-MacBookPro:~$ sudo gdisk -l /dev/sda   
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: hybrid
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with hybrid MBR; using GPT.
Disk /dev/sda: 490234752 sectors, 233.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 215DBDCF-EC33-482E-AC7D-8526F063DBA7
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 490234718
Partitions will be aligned on 8-sector boundaries
Total free space is 981 sectors (490.5 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       422660167   201.3 GiB   AF05  Customer
   3       422660168       423929927   620.0 MiB   AB00  
   4       423929928       439535503   7.4 GiB     8200  
   5       489259008       490233855   476.0 MiB   EF00  
   6       439535616       489259007   23.7 GiB    8300  

Thanks for help in advance.

  • Why do you want to reduce swap? 8G is not horribly out of line with your config... although some might argue for a smaller swap... it all depends on your system usage. – heynnema May 06 '17 at 15:47
  • I agree with heynnema; however, if you really want to reallocate some or all of that swap space, we need to see your partition table, which you have not shown us. The output of sudo gdisk -l /dev/sda or sudo parted /dev/sda print is what we need to see, or a screen shot of GParted. Also, where you do want to reallocate the swap space? To macOS or to Ubuntu? – Rod Smith May 06 '17 at 22:30
  • @RodSmith The main reason is I want to give Ubuntu more disk space and I think 8G RAM should be enough for me at this moment. so maybe just need 2-4G for swap. So I want those space go to Ubuntu. Thanks. – Xiaofeng Fan May 06 '17 at 23:34

1 Answers1

1

Here are your Ubuntu partitions:

Number  Start (sector)    End (sector)  Size       Code  Name
   4       423929928       439535503   7.4 GiB     8200  
   5       489259008       490233855   476.0 MiB   EF00  
   6       439535616       489259007   23.7 GiB    8300 

Partition 4 is your swap space, followed by an ESP (more on that shortly) and finally your Ubuntu root (/) partition. Before you begin, you should consider a few points:

  • Your disk has two EFI System Partitions (ESPs). This is legal, but pointless. In fact, the df output you posted shows that /dev/sda5 is unused by Ubuntu; and macOS won't use it, either. Thus, if you decide to proceed with your plan, I recommend you delete /dev/sda5, along with resizing the swap partition. This will enable you to recover an extra 476 MiB of disk space.
  • Because your swap space precedes your Ubuntu root (/) partition and you want to add space to that installation, the usual way to do this involves moving the start of the root partition. Moving the start of a partition is more time-consuming and more dangerous than moving the end of a partition. If you decide to resize these partitions, you should be sure to back up your Ubuntu installation, or at least any personal data it holds, before proceeding.
  • As an alternative to resizing the root partition, you could shrink your swap space, delete the ESP, and create a new partition (presumably ~3-4 GiB in size). You could then use that partition for exchanging data between macOS and Linux or transfer the contents of some Ubuntu directory to that partition. OTOH, even 4 GiB is so small that it might not be worth bothering with this.

Overall, therefore, I don't think it's worth the bother or risk to do as you're suggesting; you'd only be gaining about 4 GiB (closer to 8 GiB if you completely deleted the swap space, which I do not recommend), which is smaller than most modern USB flash drives. OTOH, your Ubuntu installation is fairly small, at about 24 GiB, with about 16 GiB free, so that 4 GiB increase would be a significant increase in available disk space, percentage-wise. I guess the big question is whether you anticipate using more disk space -- probably for personal files, but conceivably for big programs. If not, then I wouldn't bother increasing the size of the Ubuntu partition; but if you do anticipate using more disk space, it might be better to increase that disk space sooner rather than later.

If you decide to proceed anyway, you should use GParted, not any macOS resizing tool; you won't be touching any macOS partitions, so a macOS tool would do nothing useful. You'll need to do the work from an emergency disk; GParted won't let you resize or move a partition that's currently mounted, which your Ubuntu root (/) partition must be when you've booted Ubuntu. There are several questions and answers on this site that cover how to do this, such as:

Finally, if you're running short of disk space, especially in macOS as well as Ubuntu, you might consider upgrading your disk. Your current disk is only 234 GiB, which is pretty small by modern standards. If you do such an upgrade, you can resize the partitions as part of the disk swap.

Rod Smith
  • 44,284
  • 7
  • 63
  • 105