Add new hard drive as swap

11 篇文章 0 订阅

Identify hard disk

First you need to identified the new hard disk.

press CTRL+ALT+T to open a console then type :

lsblk

You will see something similar with this:

loop0    7:0    0 86.6M  1 loop /snap/core/4486
sda      8:0    0    5G  0 disk 
├─sda1   8:1    0  512M  0 part /boot/efi
└─sda2   8:2    0  4.5G  0 part /
sdb      8:16   0   10G  0 disk
sr0     11:0    1 1024M  0 rom 

For example the sdb it’s the new hard disk that you want to add.

Format hard disk

If the sdb it’s a new hard disk , you need to format to ext3 or ext4

sudo mkfs.ext4 -j -L NewHDD /dev/sdb

Keep in mind, command above will delete everything on target hard disk. You can skip this step if there are any data on the hard disk and you want to not lose them.

Now you need the UUID of the new hard disk.

sudo blkid /dev/sdb

You will see something similar with this:

/dev/sdb: LABEL="NewHDD" UUID="5d6c8f68-dcc8-4a91-a510-9bca2aa71521" TYPE="ext4"

Swap on a different disk

You can create a swap partition on a separate drive by using mkswap and swapon.

Eg - To to migrate swap from /dev/sda3 to /dev/sdb1

swapoff /dev/sda3

mkswap /dev/sdb

swapon /dev/sdb

Now chen what we have:

lsblk

and found:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 447.1G  0 disk 
├─sda1   8:1    0 431.2G  0 part /
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0    16G  0 part 
sdb      8:16   0 447.1G  0 disk [SWAP]
sr0     11:0    1  1024M  0 rom

Then edit swap entry in /etc/fstab.

UUID=2b593f65-8f50-4317-8e0a-c649d5d8ba68 none            swap    sw              0       0

Or auto mount after reset

next step it’s to add the new hard disk in fstab for auto mount after reset:

sudo vim /etc/fstab

And add new line on bottom, with follow content:

/dev/disk/by-uuid/5d6c8f68-dcc8-4a91-a510-9bca2aa71521 /mnt/NewHDD auto nosuid,nodev,nofail,x-gvfs-show,x-gvfs-name=NewHDD 0 0

Remeber to replace the 5d6c8f68-dcc8-4a91-a510-9bca2aa71521 and /mnt/NewHDD whit your own UUID and path where will be mounted. Save then exit.

To mount it use: sudo mount -a , if the result will be:

mount: /mnt/NewHDD: mount point does not exist.

You must create mount point sudo mkdir /mnt/NewHDD then use again: sudo mount -a

Also you need to change owner and group of the new hard disk using next command:

sudo chown user:user -R /mnt/NewHDD

Replace the: user:user with your own user and group that you need it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值