Skip to content

Instantly share code, notes, and snippets.

@shivai
Last active July 4, 2019 15:04
Show Gist options
  • Save shivai/6dc19e768a67ec280b82239e2462adc6 to your computer and use it in GitHub Desktop.
Save shivai/6dc19e768a67ec280b82239e2462adc6 to your computer and use it in GitHub Desktop.

Ho to mount a disk to a directory:

fdisk -l 

Disk /dev/sdc: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

fdisk /dev/sdc
root@debian:~# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x055c06f2.

Command (m for help): n   
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-167772159, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-167772159, default 167772159): 

Created a new partition 1 of type 'Linux' and of size 80 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Now:

fdisk -l

Disk /dev/sdc: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd33eed63

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdc1        2048 419430399 419428352  200G 83 Linux

now copy the all data of your directory to another place :

cp /var/lib/postgres/ /home

now:

blkid /dev/sdc1

copy the UUID and add the following line in it:

nano /etc/fstab
UUID=358e0fcd-cb80-497e-bab6-62e11253966e       /var/lib/postgresql     ext4    defaults,noatime        0       0

save it and run this command:

mount -a

df -h 
/dev/sda1                922M   37M  822M   5% /boot
tmpfs                    2.4G     0  2.4G   0% /run/user/0
/dev/sdc1                196G  100M  186G   1% /var/lib/postgresql

finally copy the files to your directory:

cp /home/* /var/lib/postgres/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment