14

A very basic query which requires your kind guidance. If I am at command prompt in either DOS or Windows, I would use, (if I am in C: drive) d: to go to drive D. What is the equivalent in Ubuntu Terminal if I want to move around between partitions, from sda1 to sda2 for example?

15

Ok, this is one of the fundamental differences between windows and linux. The Windows file system uses devices as starting points for each section of the file system. So you have:

c:\  
d:\
e:\

Linux/Unix systems use the concept of a unified file system. Everything is under the root folder, and can be arbitrarily mixed together. The user and programs do not know about devices because they have been abstracted away. So, all linux systems will have the same general hierarchy.

A linux system will look something like this:

/
|---var
|---lib
|---home
|---mnt

But these folder could be on the same hard drive, or separate hard drives. They can even be network folders! There is a special folder called /dev for if a program actually needs to talk to the physical device. So, anywhere that you want to go on a linux system will never require switching devices like on windows.

However, sometimes a device is not added to the filesytem! It will be plugged in, the OS can see it as a device, but it has not been mounted. Modern linux systems will try and do this for you as necessary. Sometimes it doesn't work, and you have to do it your self. That is what the mount command is for. It is also the original purpose of the /mnt folder, so you can have an obvious place to mount new sections of the file system.

Before mounting a drive:

|---mnt
    |---temp

After mounting drive to /mnt/temp:

|---mnt
    |---temp
        |---docs
        |---programs
        |---tmp
        |---extra
        |---backups
        |---other stuff

So you can mount a drive, then use cd to move into it, or anywhere else in the file system. This allows for neat things, like having your /home directory on a separate hard drive, in case you want to switch linux distros later, or so you can back it up. The /tmp folder is often not on an actual device at all! It's could be some ram treated as a folder. That makes it easy to put stuff there, then have it cleaned up when you reboot.

| improve this answer | |
  • the best answer! – Aerin Aug 7 '18 at 20:42
11

Partitions that are mounted are found in the filesystem. They are usually mounted to the folders /mnt/ or /media/.

type df in the terminal to display all mounted partitions and where they are mounted . You can also use the Disk Utility application to see where each partition is mounted.

then cd into your partition using. For example if the partition mount is called data:

cd /media/data

| improve this answer | |
  • 2
    @Achu. As far as I understand it /dev/ contains device files for all devices but the mount points are generally /media/ for removable media and /mnt/ for manual mounts. – benj Dec 7 '11 at 9:13
  • 1
    um, just a small comment: windows partition isn't mounted by default. There's only cdrom/ in 'mnt/' – Sergiy Kolodyazhnyy Mar 3 '15 at 22:44
5

This is my process. Adapt the numbers as needed

  1. execute lsblk first.
 NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sda      8:0    0 232.9G  0 disk 
    ├─sda1   8:1    0   1.5G  0 part 
    ├─sda2   8:2    0 138.6G  0 part 
    ├─sda3   8:3    0   8.1G  0 part 
    ├─sda4   8:4    0     1K  0 part 
    ├─sda5   8:5    0  68.5G  0 part /
    └─sda6   8:6    0   5.8G  0 part 
    sdb      8:16   0  14.9G  0 disk 
    └─sdb1   8:17   0  14.9G  0 part /media/SergKolo/SERG
    sr0     11:0    1  1024M  0 rom
  1. Identify which partition is what, e.g, by size, i know /dev/sda2 is my Windows 7 partition.

  2. execute sudo mount /dev/sda2 /media/SergKolo/

  3. If step 3 successful , you now have folder in /media/SergKolo which will correspond to windows partition. Navigate there and enjoy
| improve this answer | |
  • If you like this answer, rate, comment and subscripe ! Oh, wait, wrong site ^_^ But simple upvote will do,too – Sergiy Kolodyazhnyy Mar 3 '15 at 22:38
0

Ok here is how you do it.

Log into ssh as the root user.

You'll see this:

root@yourserver [~]#

Ok so if you saw that [~] then you are root. But it also means /root.
In other words, [~] = [/root]. †

Now to get to the other partitions, such as a second hard drive, first you need to find out what partitions you have. Find this by putting lsblk

root@yourserver [~]# lsblk

For me, it game something like this:

sda                  8:0    0 931.5G  0 disk
├─sda1               8:1    0   250M  0 part /boot
└─sda2               8:2    0 931.3G  0 part
  ├─vg-root (dm-0) 253:0    0 915.5G  0 lvm  /
  ├─vg-swap (dm-1) 253:1    0  11.8G  0 lvm  [SWAP]
  └─vg-tmp (dm-2)  253:2    0     4G  0 lvm  /tmp
sdb                  8:16   0 931.5G  0 disk
└─sdb1               8:33   0 931.5G  0 part /mnt/home2

Ok, so here in this setup which I simplified above, all you need to be concerned about is the sdb1 which is the second partition (I have more drives but I removed them from the output above for this answer).

For me, sdb is a second hard drive, but you can do the same thing if sdb is a second partition. It essentially functions the same.

Next, you need to get out of the root folder. Do this by doing the following:

root@yourserver [~]# ../

Now you will be here:

root@yourserver [/]#

Notice that [~] became [/]

Next, you need to enter your mounts folder. You can know what this is because if you look at the lsblk above, you can see at the bottom left that sdb1 is located in the /mnt/ folder. This folder might be different for you. If so just put whatever name is there.

Finally you are ready to enter the new hard drive or new partition. cd enters a folder.

root@yourserver [/]# cd mnt

Now you are here:

root@yourserver [/mnt]#

Make sure you're in the right place. Enter the following:

root@yourserver [/mnt]# ls

Now your output might look like this.

./  ../  home2/  secondary/

If you see the directory on the new drive or partition, you're in! Now just cd to the right place. Example (-lh flag means human readable):

root@yourserver [/mnt]# cd home2

Great! Now you're rolling! Now you can display the contents of your desired folder like this:

root@yourserver [/mnt/home2]# ls -lh

You might get an output like this:

total 32K
drwxr-xr-x   5 root      root      4.0K Mar 12 14:09 ./
drwxr-xr-x.  4 root      root      4.0K Mar 12 14:00 ../
drwx------   2 root      root       16K Mar 12 13:58 lost+found/
drwx--x--x  12 myfolder1 myfolder1 4.0K Mar 12 11:33 myfolder1/
drwx------  11 root      root      4.0K Mar 12 14:09 myfolder2/

Okay, I think that covers the scope of this question, you can take it from there! Good luck! :)

Side note: (proof of this is to [~]# cd ../ and then [/]# cd root and now you are back in [~]#)

Debug info:
These instructions were written for a CentOS 6.5 system which is using cPanel/WHM and has a second hard drive.

| improve this answer | |
0

Ok, this is the way I use to go to other partition where I have saved all my data...

   cd ..

This goes to the previous directory.

After this, I am on the home folder, so I execute once again cd .. to go to the / directory, once I'm here I execute

cd media

Here you have all your mounted partitions, just execute:

ls

and choose which partition you want to get in, and:

cd partitionYouChoose

you may see here the name of a partition with many characteres like 997ac596-09ce-453b-8ccd-2120839ba825 or something like that.

I hope to help you.

| improve this answer | |
  • Your first command is invalid since it has an open backquote with no command and no end backquote. It does not take you to your home directory. To do that it is simply cd with no arguments. From there cd .. takes you to /home, not /. If your goal is to get to /media, then you can skip all of that rigamarole and just cd /media. – psusi Mar 3 '15 at 21:47
  • Just a suggestion to improve your answer: the partition actually has to be mounted in order to navigate to /media folder. – Sergiy Kolodyazhnyy Mar 3 '15 at 22:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.