User Tools

Site Tools


howto:mountdrives

Mount Drives at Bootup of EeePC Linux

How does EeePC Linux Mount System Drives?

EeePC Linux has its unique way to mount system drives which is completely different to standard Linux distributions (not even Xandros). In particular, /etc/fstab is ignored. Therefore, the usual Linux way of adding entries to /etc/fstab will not get any drive mounted automatically by the system.

[NB. If you want to use /etc/fstab to mount drives at bootup, you will need to add a “mount -a” command somewhere. However, since many system files are called by /sbin/fastinit, the only practical solution is to hexedit /sbin/fastinit as described in Option 2 below to add this “mount -a” command. Otherwise, you may run into a situation where a system file is called by /sbin/fastinit but it is still in a not yet mounted partition, and the system will hang up.]

To understand how we can mount drives at bootup, the following is a summary of the sequence and steps (commands) how drives are mounted during the boot process of EeePC Linux:

1) By initramfs

#mount /dev/sda1 as the SYSTEM partition
mount -t ext2 -o ro $ROOT /mnt-system
#mount /dev/sda2 as the USER partition
mount -t ext3 -o rw /dev/sda2 /mnt-user
#mount the SYSTEM and USER partitions together as the union filesystem,
#or aufs (another union filesystem) for 900 and later models
#for 701 model
mount -t unionfs -o dirs=/mnt-user=rw:/mnt-system=ro unionfs /mnt
#for 900 and later models
mount -t aufs -o br:/mnt-user:/mnt-system none /mnt

2) By /sbin/fastinit

/bin/mount -n -o remount,ro /
#for 900 and later models with 2 SSD
#mount partition with Linux volume label "HOME" in /home
/bin/mount -onoatime -L HOME /home > /dev/null 2>&1
#for 901 model
/bin/mount -oremount,ro,noxino,del:/.rw /

3) By /usr/sbin/services.sh

#for 701 model
#mount 2nd SSD (ATA disk), if any, to "My Documents 2" in $HOME
if [ `cat /sys/block/sdb/device/vendor` = "ATA" ]; then
mount /dev/sdb1 "/home/user/My Documents 2"
#for 1000h model
mount /dev/sda1 /ro -o ro

Options for Mounting Drives during Bootup of EeePC Linux

During the boot process of EeePC Linux, X Window is started by /sbin/fastinit (after mounting $HOME). So partitions containing any system file have to be mounted before X starts, i.e. either by /sbin/fastinit or by initramfs.

Depending on what folders you want to move to another partition, we have a few options:

  1. Rebuild initramfs as described in this wikipage: Rebuilding initramfs (Initial RAM filesystem) of EeePC
    • With this method, it is possible to mount any folder, even your root partition, i.e. union filesystem of the SYSTEM (/dev/sda1) and USER (/dev/sda2) partition elsewhere
      • e.g. instead of /dev/sda2, you can mount a bigger partition in the 2nd SSD (e.g. /dev/sdb2) as the USER partition
      • You can also add another partition to the union filesystem, e.g. overlay /dev/sdb2 on top of the original union filesystem of sda1 and sda2. (See Common Mount Command Examples - union filesystem below)
    • Or for 2G Surf users, you can mount your USER partition in a SDHC to get more disk space available to the root filesystem as per this thread: Mount SD as part of the unionfs
    • You can even boot the whole OS with the root partition residing in an USB device as per this wiki: Boot Xandros from USB
    • Disadvantage of this method is that initramfs resides in the SYSTEM partition which is mounted READ ONLY. So it is a bit complicated to implement the change.
  2. Hexedit /sbin/fastinit as described in this thread: Mount SD partition as /usr/local
    • Warning: You should be very careful doing hexedit of binaries. Always back up first before you make any change. Do not delete any strings, replace them with spaces. The file size must remain the same after your modification.
    • Basically what you need to do is to modify /sbin/fastinit to run a script /sbin/mountdrv.sh (where you will place the mount drives command) before it runs anything
      • If you put the “mount -a” command in the script /sbin/mountdrv.sh, then you can mount drives by specifying them in /etc/fstab just like other Linux distributions
    • In this way, it is possible to mount /home, /lib, /opt, /root /usr, /var elsewhere
      • However, /home and /var cannot be placed in USB partitions. This is because at shutdown of EeePC Linux, it will try to umount USB drives first. So the system cannot shutdown because /home and /var is always busy and cannot be umounted.
      • Also, /bin, /boot, /dev, /etc, /initrd, /mnt, /proc, /sbin, /sys have to reside in the root partition and cannot be mounted elsewhere
      • /tmp is already in tmpfs (i.e. in RAM), so no need to mount it elsewhere
    • Finally, please note that filesystems mounted in this way will NOT be part of the union filesystem. You cannot do a F9 Restore on them
  3. Edit /usr/sbin/services.sh to add mount drives command
    • With the following options 3-5, you can only mount partitions containing non-system folders, e.g. man pages, /usr/share/doc, and folders for your documents, media files, etc.
  4. Edit /etc/fastservices (which is called by /usr/sbin/services.sh) and add mount drives command
    • Use this option if you don't feel comfortable editing /usr/sbin/services.sh
  5. Edit /home/user/.icewm/startup to add mount drives command as per this wiki: Running a script at startup [NB. Add sudo before every mount command]
    • An example is described in this wiki: Script to mount USB devices in old style
    • Also, this method can be used to mount partitions in your SSDs. For example, if you have installed winxp in /dev/sdb1 and you want your default Xandros to mount the winxp partition at bootup. See common examples below for details of the mount command to use.

Linux Command to Mount Partitions

Mount Command Syntax

The Linux command to mount partition is mount. The syntax of this command is:

mount -t [filesystem type] -o [options] [device] [mount point]
#e.g. 
mount -t ext3 -o rw,user /dev/sdb1 /home/user/temp

If there is an entry in /etc/fstab giving details of how to mount this drive, then the filesystem type, options, etc. can be omitted in the mount command. For example, if you put this line into /etc/fstab:

#<device>   <mountpoint>    <fstype>  <options>  <dbg> <pass>
/dev/sdb1   /home/user/temp   ext3    rw,user      0    0

Then you can simply mount with these commands:

mount /home/user/temp
mount /dev/sdb1
mount -a     #mount all partitions specified in /etc/fstab

[NB. Please note that mounting drives require root privilege. So you should either su to change to a root terminal first, or add sudo before your mount command.]

Mount by Volume Label or UUID

Besides specifying [device] in terms of device name, e.g. /dev/sdb1, it is also possible to specify device according to their volume label, serial number or UUID. The mount command can then be specified like this:

mount -t [fstype] -o [options] -L [label] [mount point]
mount -t [fstype] -o [options] -U [uuid] [mount point]

Notes:

  • Mount by UUID and Volume Label is not supported by the default initramfs
  • To find out the UUID of your device, you can run the blkid command as root. This is unique for every device (drive/partition)
  • Volume label of Linux partitions can be changed by the e2label command, e.g.
e2label /dev/sdb1 [new label]

Common Mount Command Examples

Below are some common examples of the mount command for some frequently used filesystem types. Please note that mount options will vary depending on fstype:

  • Linux ext2/ext3 partitions
mount -o rw /dev/sda2 /mnt/sda2

[NB. For ext2/ext3 Linux partitions, you can simply omit the [fstype] in the mount command. However, if you specify fstype of ext3 while mounting an ext2 partition, the system will return an error]

  • Windows FAT32 partition
mount -t vfat -o sync,gid=user,uid=user /dev/sdb1 /home/user/Windows

[NB. These options will give ordinary user privilege to write to the FAT32 partition]

  • Windows NTFS partition
mount -t ufsd -o iocharset=utf8,showmeta,uid=user,gid=user,fmask=0777,dmask=0777 /dev/sdb1 /home/user/Windows

[NB. These options will give ordinary user read/write/exec privilege to the NTFS partition and support for unicode characters]

  • CD iso image
#loop mount an iso9660 CD image
mount -t iso9660 -o loop XXX.iso /home/user/CD

[NB. unionfs is not compatible with losetup. So you cannot place your iso image somewhere in the root filesystem that is mounted by unionfs. In 70x models, it means you have to place it in an USB device. For 900 and later models with 2 SSDs, you can place it in HOME.]

mount -t ext2 -o ro /dev/sda1 /mnt-system
mount -t ext3 -o rw /dev/sda2 /mnt-user
mount -t ext3 -o rw /dev/sdb2 /mnt-user2
#for 701 model with unionfs
mount -t unionfs -o dirs=/mnt-user2=rw:/mnt-user=rw:/mnt-system=ro unionfs /mnt
#for 900 and later models with aufs (another union filesystem)
mount -t aufs -o br:/mnt-user2=rw:/mnt-user=rw:/mnt-system none /mnt

[NB. This example mounts /dev/sdb2 on top of the original union filesystem of /dev/sda1 and /dev/sda2 with both sda2 and sdb2 mounted read/write. To be able to do this, you will also need to mknod to create /dev/sdb2 in /module and mkdir to create the mounting point /mnt-user2 in initramfs]



Reference:
Auto-Mount USB Storage Devices
mount manpage
aufs manpage

Mount a bigger partition in 2nd SSD as part of the Union Filesystem

For those who have an EeePC with 2 SSDs (e.g. 4G + 16G), yet run out of disk space in the 4G SSD and cannot install new softwares, there is really a cure to this stupid mistake of Asus: You can re-partition your 2nd SSD to create another Linux partition and mount it as part of the root filesystem by rebuilding the initramfs image.



The steps are as follows:

[NB. Steps 2-6 below are in fact quite similiar to step 3 of Part A onwards in this post: http://forum.eeeuser.com/viewtopic.php?pid=138554#p138554, except that the init script is more simple because we don't need to load USB drivers. So you can refer to that thread for more details.]

1) Repartition your 2nd SSD to create another Linux partition (e.g. /dev/sdb2) and format it to ext3

You will need to boot from another OS, e.g. Puppy Linux from CD or USB, to do this. Puppy Linux is bundled with the GUI GParted partition manager which is very user-friendly and is suitable for this job.

What you'll need to do is:

  1. Select /dev/sdb (from the top right)
  2. Highlight /dev/sdb1 and Resize it, say leave 4 GB “Free Space Following (MB)” [NB. Do not move the beginning of /dev/sdb1 to create “Free Space Preceding (MB)” or you may lost data]

gparted.sourceforge.net_screens_gparted_5_big.jpg

  1. Highlight the free space and create a new Linux ext3 partition [Partition > New]
  2. Format it to ext3 [Partition > Format to > ext3]
  3. Apply changes


2) Rebuild initramfs with these CHANGES:

[NB. For details on how to rebuild the initramfs image, please refer to this wiki: Rebuilding initramfs (Initial RAM filesystem) of EeePC. Here I will only briefly cover the CHANGES you need to make.]

  1. Edit /init, find and replace all “sda2” with “sdb2”
  2. Create device /dev/sdb2
mknod -m 644 dev/sdb2 b 8 18

3) Edit /sbin/formatuser.sh and /sbin/scanuser.sh, find and replace all “sda2” with “sdb2”

For example, to edit the script /sbin/formatuser.sh in the default text editor, you can run this command in a terminal:

sudo kwrite /sbin/formatuser.sh

[NB. Verify the files still have exec permission after the modification. Otherwise, it can't run]

4) Copy everything from /dev/sda2 to /dev/sdb2 (If you do not want to configure your system from the beginning again)

#mount /dev/sda2 in /mnt/sda2
sudo mkdir /mnt/sda2
sudo mount /dev/sda2 /mnt/sda2
#mount /dev/sdb2 in /mnt/sdb2
sudo mkdir /mnt/sdb2
sudo mount /dev/sdb2 /mnt/sdb2
#copy files recursively from /mnt/sda2 to /mnt/sdb2, preserving all file attributes
cd /mnt/sda2
cp -ax * /mnt/sdb2

5) Boot into rescue mode to implement the changes

You will need to move the modified /sbin/formatuser.sh, /sbin/scanuser.sh, initramfs image (and GRUB menu.lst if the modified initramfs image has a new name) from /dev/sda2 to the read only SYSTEM partition (/dev/sda1) as described in Steps to modify initramfs.

6) Reboot

Now you can check in “Disk Utility” to see how much disk space you have on your system. It should be 2.7 GB (/dev/sda1) + say 4G (/dev/sdb2) = say 6.7 GB total.



Alternately, you can overlay the new partition /dev/sdb2 on top of the union filesystem of /dev/sda1 + /dev/sda2, then you can skip step 4, but there will be more changes you need to apply to the initramfs image, /sbin/formatuser.sh and /sbin/scanuser.sh for a complete solution.

howto/mountdrives.txt · Last modified: 2009/03/15 02:10 by albkwan