Q: How do I mount a hard drive in Solaris?
A:
Summary:
1) Make sure the drive is visible to the operating system.
2) Partition the disk as needed.
3) Write a new file system to the new slice (aka "partition.")
4) Create a mount point (aka "directory") where you will mount the slice.
5) Mount the slice to that mount point.
Detailed:
1) Make sure the drive is visible to the operating system.
At a command prompt, type:
format
You should get output similar to the following:
------- SCREENSHOT BEGIN -------
Searching for disks...done
AVAILABLE DISK SELECTIONS:
0. c0t0d0 <SUN18G cyl 7506 alt 2 hd 19 sec 248>
/pci@1f,4000/scsi@3/sd@0,0
1. c0t1d0 <SUN18G cyl 7506 alt 2 hd 19 sec 248>
/pci@1f,4000/scsi@3/sd@1,0
Specify disk (enter its number):
------- SCREENSHOT END -------
At this point you, can see that you have two drives. Let's assume that the
first drive is your root drive with the necessary slices mounted to run your
operating system and that you would like to mount the second disk for extra
storage. Since you can see the second drive it in this menu, you know that
the operating system is recognizing it.
=====
NOTE:
If the drive does not show up in this menu, it is possible that it was added
after the operating system was installed. At a command prompt, simply type:
devfsadm
The system will search for new devices. Wait for it to return you to a command
prompt and then repeat Step 1, at which point the disk should show up.
=====
Take note of the controller/target/disk number. For disk 1, the disk we will
be working with, it is the number/letter combination that looks like this:
c0t1d0
You will need this later on. Write it down or just remember it.
2) Partition the disk as needed.
Select option 1 and press ENTER.
At the "format>" menu, type:
partition
At the "partition>" menu, type:
modify
For simplicity's sake, let's make slice 0 the size of the full drive.
Select the option for "All Free Hog", which should be option 1, and press
ENTER.
Answer "yes" when asked if you want to continue creating a new parition table.
It will ask you which slice you wan to be the Free Hog partition. Type 0,
then press ENTER.
It will then ask you for the size of the rest of the slices, starting with
1 and working to 7. Hit ENTER for each of these. It will automatically set
each one to a size of 0, meaning that it is not given any space. Since we
set slice 0 to the be "Free Hog" partition, this ensures that slice 0 takes
up the entire space of the drive.
You are then shown the partition table as you have just created it. Note
that slice 0 contains the full size of the drive, but so does slice 2. The
reason for this is that slice 2 is representative of the entire drive. You
should never change it -- it is for the computer's use only.
Answer "yes" when asked if it is ok to make this the current partition table.
It will then ask you for a table name. This is completely up to you. I like
to just call it "disk1" or something simple like that. Press ENTER. You will
then be asked if you are ready to label the disk. Answer "yes" to this question.
At the "partition>" menu, type:
quit
At the "format>" menu, type:
save
You will be asked to enter a file name. This is the name of the file where
it will save the partition information you have just created. The system
reads this information from a file called /etc/format.dat However, if you
notice, the line reads:
Enter file name["./format.dat"]:
If you just hit ENTER, you will be saving the partition information to a
file called format.dat IN THE CURRENT DIRECTORY! This means that if
you are not currently in the /etc directory, you will be saving the partition
information to the wrong file. VERY IMPORTANT: When it asks you to enter
the filename, ALWAYS type the entire pathname:
/etc/format.dat
At the "format>" prompt, type:
quit
3) Write a new file system to the slice (aka "partition.")
Remember the controller/target number that we wrote down (or comitted to
memory) in step 1? Well, this is where you are going to need it.
newfs /dev/rdsk/{controller/target/disk number}
In keeping with the example we've been using, to write a new filesystem to
the slice we just created, type the following:
newfs /dev/rdsk/c0t1d0s0
If you're observant, you noticed that there is an "s0" at the end of the
line that was not there when we wrote it down before. The reason we need
to add this is that the c0t1d0 number only goes as far as describing which
disk we are writing the new file system to. In order to actually write the
new filesystem, we need to tell the computer which slice on that disk we
want to write it to. That's where the "s0" comes in. It stands for
for "slice 0." After hitting ENTER, you will be asked if you want to construct
a new file system on the device you just specified. Answer "yes" and press
ENTER.
4) Create a mount point (aka "directory") where you will mount the slice.
Now you need to create the mount point where this newly created slice will
be mounted. The mount point can be named anything you want. To keep it simple,
I will just call it disk1. To create the mount point, type:
mkdir /disk1
5) Mount the slice to that mount point.
Once the mount point has been created, you can manually mount the slice to
the mount point by typing:
mount /dev/rdsk/c0t1d0s0 /disk1
This will mount slice 0 (s0) of the second disk (t1) on the mount point,
or directory, known as /disk1. Since we have put the entire drive space of
the second disk onto slice 0 of the second disk, consequently, the entire
second disk has now been mounted (and therefore is accesible) at /disk1.
If you are familiar with DOS, /disk1 is now basically equivalent to a D:
drive. As a matter of fact, if you wanted, you could have changed the name
of the directory in step 4 to /d: or whatever pleases you. However, if you
do that, you would have to change the line in step 5 to mount the disk to
/d: instead of /disk1.
One important thing to note is that when you manually mount things with the
mount command, as we did above, it is only 'temporarily' mounted. By this,
I mean that the next time you reboot the machine, it will no longer be mounted.
In order to automatically mount /dev/rdsk/c0t1d0s0 to /disk1 every time the
machine is rebooted, you need to edit a file called /etc/vfstab. This is
the file that the computer reads in order to find out what drives/slices
to mount at boot time. Please see our tutorial
on vfstab for more information.