Mounting drives and boot options in Linux

Post date: 03-May-2010 06:29:27

Changing boot settings

The file that controls the boot process is called grub.conf, actually located at /etc/grub.conf on Fedora systems, and there are many options that can be added or removed to alter how your computer boots. On initial boot, if you have a dual boot setup, then the default OS you chose during the install process will be shown, and will be automatically selected after the default timeout ( usually 5 seconds ). If you only have Linux then your most recent kernel will be the default boot target. My grub.conf looks like this:

Grub.conf

# grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,2) # kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00 # initrd /initrd-version.img #boot=/dev/hda default=0 timeout=5 splashimage=(hd0,2)/grub/splash.xpm.gz hiddenmenu title Fedora Core (2.6.16-1.2080_FC5) root (hd0,2) kernel /vmlinuz-2.6.16-1.2080_FC5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet vga=834 initrd /initrd-2.6.16-1.2080_FC5.img title Fedora Core (2.6.15-1.2054_FC5) root (hd0,2) kernel /vmlinuz-2.6.15-1.2054_FC5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet vga=834 initrd /initrd-2.6.15-1.2054_FC5.img title Windows XP Pro rootnoverify (hd0,0) chainloader +1

Note that I have 3 possible options to boot into, 2 different Linux kernels and Windows XP Professional. The default line controls which option will be booted into after the timeout, which can be set to anything you like.

The hiddenmenu option means that initially I will only be given 1 option to boot into unless I press any key before the timeout, if you add # in front of the line to comment it out you will always be given the full menu. The rhgb option means Red Hat graphical boot, remove this to see the booting process display on screen.

Password protecting boot options

If you didn't set up a boot password for grub during the install process you can easily do this later. This boot password will only be required if you press a key on boot to boot into a different kernel and then try to modify the boot arguments, otherwise you will not be asked for the password and you can just boot normally. To give some added security it just stops anyone adding kernel arguments which could enable changing the root password for example.

To create the password we need to run grub and use the md5crypt function, open a terminal and type:

$ /sbin/grub GNU GRUB version 0.97 (640K lower / 3072K upper memory) [ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename.] grub> md5crypt Password: ********* Encrypted: $1$txhYN1$XJ5umyihXCpAqCQNq/Y6G1

Now copy this md5 hashed password and open up the grub.conf file as root and add the line below somewhere in the file:

password --md5 $1$txhYN1$XJ5umyihXCpAqCQNq/Y6G1

So now the start of my grub.conf file looks like this:

default=0 timeout=5 splashimage=(hd0,2)/grub/splash.xpm.gz hiddenmenu password --md5 $1$txhYN1$XJ5umyihXCpAqCQNq/Y6G1

Thats all there is to it, next time you boot press any key to see the hidden menu and you will see that to add any kernel arguments you need to press p first to enter your grub password.

If you want to completely prevent booting into one of your boot options (or all) then you need to add the word 'lock' to the required entry as shown below.

title Windows XP Pro lock rootnoverify (hd0,0) chainloader +1

Now if you boot and select Windows XP Pro from the menu you will be prevented from booting into it. To boot first press 'p' then enter your grub password, you should now be able to boot into the locked entry.

VGA boot options

Finally the vga=834 option controls the screen resolution and colour depth, in this case 834 being 1400 x 1050 ( this will also display Tux the penguin logo on the boot screen ). A list of possible vga options are listed below.

Cleaning up old kernels

Note that if you update kernels then your list may become very long, in this case it's very easy to remove old kernels using rpm. To find which kernels you have installed type:

$ rpm -qa|grep kernel

On my system this returns the following list.

kernel-module-ntfs-2.6.13-1.1532_FC4-2.1.23-0.rr.10.4 kernel-module-ntfs-2.6.13-1.1526_FC4-2.1.23-0.rr.9.4 kernel-module-fglrx-2.6.13-1.1532_FC4-8.18.6.1-0.lvn.1.4 kernel-devel-2.6.13-1.1526_FC4 kernel-devel-2.6.13-1.1532_FC4 kernel-2.6.13-1.1526_FC4 kernel-2.6.13-1.1532_FC4

The first 3 lines starting kernel-module are, as the name suggests, kernel modules, it's the last 2 lines that are of interest as these are the 2 kernels I have installed on my computer. To remove a kernel simply type as root:

$ rpm -e kernel-2.6.13-1.1526_FC4

Of course you should replace the actual kernel name with your choice, you should also remove the corresponding kernel-devel package the same way. By doing this the entries in you grub.conf will also be deleted.

Mounting FAT partitions

If like me you created a FAT32 partition to share data between Windows and Linux then you need to be able to mount this partition before you can access the data. The easiest way to do this so that the partition gets mounted on boot up is to add a line to you fstab file which is located in /etc/fstab in Fedora systems. Note that Linux has built in support for FAT16 and FAT32 filesystems ( which Linux calls vfat ) so this step can be carried out right after install, NTFS support is not included with Fedora but is easily added as I will show later.

Create the mount point

First you need to create a folder that the filesystem will be mounted onto, normally this would be in the /mnt folder but you could mount the drive anywhere. In my case I created a folder called /mnt/fat to use as the mount point, as root type:

$ mkdir /mnt/fat

Using fdisk

Next you need to find the device name of you FAT filesystem. Open up a terminal and type as root:

$ /sbin/fdisk -l

On my system this returns the following entries:

$ /sbin/fdisk -l Disk /dev/hda: 40.0 GB, 40007761920 bytes 255 heads, 63 sectors/track, 4864 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes s Device Boot Start End Blocks Id System /dev/hda1 * 1 1567 12586896 7 HPFS/NTFS /dev/hda2 1568 2220 5245222+ c W95 FAT32 (LBA) /dev/hda3 2221 2233 104422+ 83 Linux /dev/hda4 2234 4864 21133507+ 5 Extended /dev/hda5 2234 4864 21133476 8e Linux LVM

Here we look for the line that has FAT32 as system, on my system this is on device /dev/hda2, we need this information to create the fstab entry.

Mounting from the command line

To test everything is working OK we should probably mount the filesystem from the command line first before we add the entry to the fstab file, in the terminal type:

$ mount -t vfat /dev/hda2 /mnt/fat

Of course replacing the device and mount point with your settings. If you now navigate to the /mnt/fat folder using nautilus you should see the filesystem from your fat partition, note that at this point as a regular user you have no access since we mounted the drive as root so only root has any permissions on the files. To unmount the filesystem simply type:

$ umount /mnt/fat

Editing your fstab file

Now that we see that things are working we can add an entry into the fstab file, doing so means that the filesystem will automatically be mounted on boot. Open the file /etc/fstab ( as root ) with your text editor and add the following line to the end of the file on a new line of it's own, also make sure it's all on one line.

/dev/hda2 /mnt/fat vfat auto,rw,uid=0,gid=500,showexec,quiet,fmask=117,dmask=007 0 0

fstab options

The fstab line can be summarised as follows:

  1. /dev/hda2 - This entry should be replaced by your device name from the fdisk output.

  2. /mnt/fat - This entry is the path to your desired mount point, /mnt/fat in my case.

  3. vfat - This is filesystem to mount, we could leave this as 'auto' for Linux to work it out for itself, but we know it's vfat so enter that.

  4. auto - This tells linux to mount the filesystem on boot.

  5. rw - Read/write access, could also be ro for read only

  6. uid=0 - User id of the owner of the filesystem mounted, uid=0 is roots uid, this is also the default

  7. gid=500 - Group id of the filesystem, you should add your normal logged in user here. To find the group id of your user open a terminal and type:

    1. $ id bobpeers

    2. Where username is replaced by your actual username. This returns something like:

      1. $ uid=500(bobpeers) gid=500(bobpeers) groups=500(bobpeers)

    3. This gives you your uid and gid. Note that by default Fedora adds new users to their own group starting at 500, hence uid and gid are both 500. If I add another user then the uid and gid for that user will be 501. If you wish to also own the filesystem then set uid to this number in place of uid=0 from above.

  8. showexec - All windows executables ( .exe .com etc ) files are made executable ( permissions 770 ).

  9. quiet - the system will not output errors when we try to change file settings not supported by fat filesystems

  10. fmask=117 - this sets permissions on files, works the opposite to normal, so 117 equates to 660. In practise the owner and group have read/write access ( with execute also on .exe and other windows executables ) while others have no access at all.

  11. dmask=007 - same as above but only for directories.

One other option that is useful is 'user', if you just add the word 'user' into the options line then this mount point can be mounted by any user but only that user can then unmount it, if you add the word 'users' then anybody can mount and unmount it.

Mounting NTFS partitions

Fedora Core 6

There is now support for mounting NTFS partitions read/write in Fedora Core 6 using a driver found in Fedora Extras called ntfs-3g.

To install (assuming Fedora Extras is enabled in your yum profile), simply use as root:

$ yum install ntfs-3g

To mount the partition listed above as read/write (add -ro for read only) for the listed user and group uids we now use:

$ mount /dev/hda1 /mnt/windows -t ntfs-3g -o uid=0,gid=500,umask=0007

To add this to your fstab file to be mounted at boot we now use:

/dev/hda1 /mnt/windows ntfs-3g auto,uid=0,gid=500,umask=007 0 0

IMPORTANT NOTE- there is currently a problem with fuse and SELinux whereby the mount point will not be mounted at boot time (see the RedHat Bugzilla report), however you are able to later mount the partiton using the mount command. Just add the noauto option to the line in fstab until this problem is fixed or follow the instructions on the ntfs-3g.org site.

To enable NTFS support we need to install a kernel module, this is very easy to do but if you change kernels then you will have to install a new kernel module as well. For this reason it may be easier to install it using yum, but it's very easy to do manually so I'll include that method as well.

Fedora Core 5 and older

Getting the kernel module manually

Mounting NTFS partitions is a bit more difficult with Fedora Core due to the fact support for this filesystem is not built in. To enable support we need to download the correct kernel module depending on which kernel you are currently running. To find this information just open a terminal and type:

$ uname -rm

For me this returns 2.6.16-1.2080_FC5 i686, my kernel version and processor. Now open a web browser and navigate to the Linux NTFS project page for Fedora Core 5 ( although there are kernel modules for nearly all version of Fedora and Red Hat ) and just select the download that matches your kernel. In my case I would download 2.6.16-1.2080_FC5 for i686, most people will require the i686 download. Save this file into your home folder, then open a terminal and type as root:

$ rpm -ivh kernel-module-ntfs-2.6.16-1.2080_FC5-2.1.26-0.rr.10.5.i686.rpm

The easy way to do this is to start typing the name and then use bash autocompletion of filenames by pressing the tab key, assuming there is only 1 file in your home folder starting with 'kernel' then it will complete the whole filename for you. If not you just need to type more of the name and press tab again until it becomes the only possible choice in the folder. You could also type rpm -ivh *.rpm if this is the only rpm file in the folder. After it installs you can just delete the rpm if you wish.

Getting the kernel module using yum

The NTFS kernel module is not available in any of the Fedora repositories set up on a fresh Fedora install so we need to enable the Livna.org repository to have access to it. To do this for Fedora Core 5 simply type as root:

$ rpm -ivh http://rpm.livna.org/livna-release-5.rpm

Now the repository is enabled we can use yum to get and install the correct kernel module, now type:

$ yum install kmod-ntfs-$(uname -r)

You should now have NTFS support, to check this is the case type:

$ cat /proc/filesystems|grep ntfs

If you see 'ntfs' then the kernel has support, if not then try the above steps again or reboot and then try again.

Mounting the NTFS filesystem

The next steps are similar to above with FAT filesystems. First create a mount point, I'll choose /mnt/windows, as root type:

$ mkdir /mnt/windows

Next we again need to find the device name of the NTFS filesystem by using fdisk as above, on my system this shows dev\hda1. Now we need to add a line to our fstab file as with FAT drives so that the filesystem will be mounted at boot. As root open /etc/fstab with a text editor and add the line.

/dev/hda1 /mnt/windows ntfs auto,ro,uid=0,gid=500,umask=0007 0 0

Save and close this file, open a terminal and as root type:

$ mount -a /dev/hda1 /mnt/windows

This command should mount the NTFS filesystem located at /dev/hda1 on /mnt/windows using the settings in the fstab file we just edited, of course replace the entries with those valid for your system, to see what the options mean see theFAT entry above. To check all is OK open nautilus and navigate to your /mnt/windows folder to see your NTFS filesystem. Note that the filesystem is mounted as read only, you can read about this on the webpage for the project and enable write support if you wish, but it's not recommended unless you know the risks involved.

Remember that the kernel module is specific to the kernel you are running so if you update kernels then you will need to install a new kernel module to match the new kernel. Once the mount point is ready and the fstab file is edited this is a very trivial process and only takes a few minutes.

Mounting Network filesystems (using cifs)

Mount using the command line

If you have a home network and want to mount a Windows share on your network this can be done using the mount.cifs command that is part of the Samba installation. To mount a share from the command line you need to be root using the syntax shown below.

$ mount -t cifs //servername/sharename /mnt/foldername -o username=***,password=***,rw

In a home network you will need to replace servername with the IP address of the computer with the folder to be shared. This command will mount the share for as long as you leave the computer switched on, but it's probably easier to add a new line to the fstab file so you can either mount the share at boot time or to make the mounting easier since most of the information will be saved in the file saving retyping whenever you wish to mount the share.

Mount using an fstab entry

Note that if you wish to add a line to fstab it's probably also a good idea to give your computer that has the share a static IP address, otherwise the IP address will possibly change every time you turn it on. In my network I've given the computer an IP address of 192.168.1.109 and a hostname of bergnet, so then I add this computer to my hosts file by adding this line to my /etc/hosts as root:

192.168.1.109 bergnet

This means that any requests for a computer named bergnet will be sent to 192.168.1.109 and so this allows me to use //bergnet/sharename when I mount the network share instead of using //192.168.1.109/sharename. Then in future if I change the IP address I can just edit the hosts file again.

To add the share to your fstab file add a line to it like the following while logged in as root:

//servername/sharename /mnt/foldername cifs noauto,username=******,password=******,uid=0,gid=500 0 0

In my case I use noauto since I do not want the share to mount at boot since the other computer is not always turned on, if you want it to mount at boot just put auto instead. To test the set up type as root:

$ mount /mnt/foldername

You should now see the shared folder mounted under /mnt/foldername.

Using a credentials file

If you do not want to put the username and password into the fstab file you can direct it to look into another file by using the credentials command. First create a file in your home directory called .smbdata, the name can be anything and the . will make the file hidden. In this file you can add the username and password, here is an example:

$ cd $ echo username=shareusername > .smbdata $ echo password=sharepassword >> .smbdata $ chmod 600 .smbdata

Now you can change the fstab file to refer to this credentials file:

//servername/sharename /mnt/foldername cifs noauto,credentials=/home/user/.smbdata,uid=0,gid=500 0 0

Note that unlike the mounting of FAT and NTFS partitions mount.cifs does not accept the 'user' or 'users' options, this means that you will need to be root to mount and unmount the partition.

As a final note you can no longer use mount -t smbfs in Fedora Core 5 as support for this has been dropped in favour of cifs. It seems as a result of this you can no longer mount network shares hosted on Windows 98 or Windows ME computers as the cifs command fails to connect for reasons that I do not fully understand.

Mounting WebDAV filesystems (using wdfs)

If you have an online file storage area accessible using WebDAV then you can mount them just like any other filesystem. This allows you to work with online files just as though they are on your local computer. All the packages are available from the Fedora repositories.

All the steps must be done as root.

Firstly make sure you have the FUSE (Filesystem in Userspace) files installed, this is simple using yum:

# yum install fuse

Next we need to install the wdfs rpm package:

# yum install wdfs

Next create the mount point:

# mkdir /mnt/webdav

Mounting from the command line

From the README file the usage is very simple:

usage: $ mkdir ~/mountpoint $ wdfs http[s]://server[:port][/directory/] ~/mountpoint [options] $ wdfs -h # prints wdfs and fuse options

So following this the following command mounts the file system:

# wdfs http[s]://path_to_your_host/ /mnt/webdav -o username=******,password=******,allow_other

The allow_other option is very important as without it only root can view the mounted files. You can leave the username and/or password out if you wish so you will be prompted for them when you mount the file system.

The remote file system is now mounted, to unmount just do umount /mnt/webdav as you would with any mounted file system.

Mounting using an fstab entry

This is achieved by adding the following line to your /etc/fstab file as root (all on one line):

wdfs#http[s]://path_to_your_host/ /mnt/webdav fuse allow_other,uid=0,gid=500,nonempty,username=******,umask=007,locking=simple,noauto

Notice here I have not added the password, this is because the fstab file is world readable so anyone could see your password. This way you will be prompted for it when you mount the file system. Also as explained above the noauto command prevents this being mounted at boot (prevents hanging if I'm not connected to the Internet).

To mount the system is now just like any other.

# mount /mnt/webdav