How to go between partitions in terminal
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?
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.
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
This is my process. Adapt the numbers as needed
- 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
Identify which partition is what, e.g, by size, i know /dev/sda2 is my Windows 7 partition.
execute
sudo mount /dev/sda2 /media/SergKolo/
- If step 3 successful , you now have folder in
/media/SergKolo
which will correspond to windows partition. Navigate there and enjoy