How to mount a disk with symbolic links

De GIGAS DOCS
Saltar a: navegación, buscar

First of all, we have to add a SATA disk to our server. Once this is done, we will have something similar to the following.

Check system disks

[root@disk ~]# fdisk -l

The command "fdisk -l" shows storage devices directly connected to our system:

Disk /dev/vda: 41.9 GB, 41875931136 bytes
13 heads, 48 sectors/track, 131072 cylinders
Units = cilindros of 624 * 512 = 319488 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8f0a35c1

Device      Boot        Start  End       Blocks     Id  System
/dev/vda1   *           4      131072    40893440   83  Linux

Disk /dev/vdb: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders
Units = cilindros of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/vdc: 53.7 GB, 53687091200 bytes
21 heads, 12 sectors/track, 416101 cylinders
Units = cilindros of 252 * 512 = 129024 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xecfb8b84

Device      Boot        Start  End       Blocks     Id  System
/dev/vdc1   *           9      416102    52427776   83  Linux

You have to check which device has the size of the assigned disk. We will note down the path of the device. In this example, we want to mount the device with this path: "/dev/vdc". We will mount the partition "/dev/vdc1".

Disk /dev/vda: 41.9 GB, 41875931136 bytes

Disk /dev/vdb: 1073 MB, 1073741824 bytes

Disk /dev/vdc: 53.7 GB, 53687091200 bytes

Check if the partition is mounted

Once you have located the device, you have to check if it is mounted in the sustem by using the command "mount":

[root@disk ~]# mount

/dev/vda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

As you can see, the partition with path "/dev/vdc1" does not appear as mounted, so you can proceed with the mount.

Mounting the partition

In first place, you have to create the mount point (create the directory):

[root@disk ~]# mkdir /media/newPartition

Once you have created the mount point, you have to mount the partition of the aforementioned device:

[root@disk ~]# mount /dev/vdc1 /media/newPartition

Checking if the partition has been successfully mounted

[root@disk ~]# mount

/dev/vda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/vdc1 on /media/newPartition type ext3 (rw)

Setting up a mount point for the partition in /etc/fstab

You have to set up your system so mounting takes place each time a reboot occurs:

[root@disk ~]# echo "/dev/vdc1 /media/newPartition ext3 defaults  1 1" >> /etc/fstab

You have to check if the changes to "/etc/fstab" are correct using the command "cat /etc/fstab":

[root@disk ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jul 12 03:55:42 2011
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/vda1               /                       ext3    defaults        1 1
/dev/vdb                swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/vdc1                /media/newPartition    ext3    defaults        1 1

Recreate in the new partition the directories you want to mount

Now you have to begin to recreate the directories that you want to mount in the new disk (in this example, only /var):

[root@disk ~]# cp -fr --preserve /var /media/newPartition/

Change in the original disk the name of the directory you want to migrate:

[root@disk ~]# mv /var/ /var.old

Create a symbolic link

After this, you have to create a symbolic link pointing from the new directory path (in the new partition) to the original path (in the old disk):

[root@disco ~]# ln -sf /media/newPartition/var/ /var

Everything done!

[root@disco ~]# ls -al /|grep var
lrwxrwxrwx   1 root root    22 nov  7 17:26 var -> /media/newPartition/var/
drwxr-xr-x  17 root root  4096 feb  8  2012 var.old


Rebooting

Now you have to reboot to check that everything is ok.


Check that the partition is correctly mounted

[root@disk ~]# df -h

Filesystem            Size  Used Avail Use% Mounted in
/dev/vda1              39G  1,1G   36G   3% /
tmpfs                 1,5G     0  1,5G   0% /dev/shm
/dev/vdc1              50G  247M   47G   1% /media/newPartition
If you have doubts or need further information remember we are available 24x7, 365 days chat, phone and ticket.