On Wed, Mar 03, 2010 at 05:34:34PM +0100, Alex Schuster wrote
> I had this once on a smaller machine, but now I'd prefer it the other way
> around, there's plenty of space available. I have 15G for distfiles and
> pkgdir, so I don't worry about some 100MB for the portage tree.
I managed to pull off a cute stunt that...
a) minimizes wasted disk space
b) retains the ability to wipe and re-install the OS, without wiping
user data
The example below uses /dev/sda and a 500 megabyte / partition. I
think I could get away with 300. Substitute as appropriate for your
system (hda or wharever)
Step 1) Partition a blank hard drive.
- partition the entire hard drive (500 gigabytes in my case) as one
gigantic extended partition (partition 1)
- create a 500 megabyte logical linux (type 83) partition of at the
beginning of the extended partition (partition 5). This will be the
/ partition
- next, create a logical linux swap (type 82) partition approx twice
the size of your ram (partition 6).
- next, create a logical linux (type 83) partition using the remainder
of the drive (partition 7). This will be mounted as /home. Here's
what my drive looks like, according to "fdisk -l"
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 60801 488384001 5 Extended
/dev/sda5 1 62 497952 83 Linux
/dev/sda6 63 549 3911796 82 Linux swap / Solaris
/dev/sda7 550 60801 483974158+ 83 Linux
Step 2) File system creation... *WARNING* the following script wipes
all data on partitions 5, 6, and 7. Use this only when you want to wipe
everything, *INCLUDING ALL YOUR DATA*, and start fresh. For mounting
the drive after a reboot during install (or booting off the install CD
for rescue work) use the script in step 3.
#!/bin/bash
mke2fs /dev/sda5
mkswap /dev/sda6
mkreiserfs /dev/sda7
swapon /dev/sda6
mount /dev/sda5 /mnt/gentoo -o noatime
mkdir /mnt/gentoo/home
mount /dev/sda7 /mnt/gentoo/home -o noatime,notail
mkdir /mnt/gentoo/opt
chmod 1777 /mnt/gentoo/opt
mkdir /mnt/gentoo/tmp
chmod 1777 /mnt/gentoo/tmp
mkdir /mnt/gentoo/usr
chmod 755 /mnt/gentoo/usr
mkdir /mnt/gentoo/var
chmod 755 /mnt/gentoo/var
mkdir /mnt/gentoo/home/bindmounts
mkdir /mnt/gentoo/home/bindmounts/opt
chmod 755 /mnt/gentoo/home/bindmounts/opt
mkdir /mnt/gentoo/home/bindmounts/tmp
chmod 1777 /mnt/gentoo/home/bindmounts/tmp
mkdir /mnt/gentoo/home/bindmounts/usr
chmod 755 /mnt/gentoo/home/bindmounts/usr
mkdir /mnt/gentoo/home/bindmounts/var
chmod 755 /mnt/gentoo/home/bindmounts/var
mount --bind /mnt/gentoo/home/bindmounts/opt /mnt/gentoo/opt
mount --bind /mnt/gentoo/home/bindmounts/tmp /mnt/gentoo/tmp
mount --bind /mnt/gentoo/home/bindmounts/usr /mnt/gentoo/usr
mount --bind /mnt/gentoo/home/bindmounts/var /mnt/gentoo/var
Again, substitute as appropriate if your harddrive is not /dev/sda.
Let's examine the script in detail...
mke2fs /dev/sda5
mkswap /dev/sda6
mkreiserfs /dev/sda7
swapon /dev/sda6
The first 4 commands format the partitions and activate the swapdrive.
Partition 5 really should be ext2fs for a few reasons...
- Partition 5 will rarely be written to during normal operation; only
when you are installing/updating programs/scripts that reside in
/bin or /sbin so journalling isn't that important.
- Journalling requires disk space, which we're trying to conserve.
- Given the small size of the / partition, ext2fs is sufficient
- ext2fs is the easiest filesystem to shrink/grow. If you ever need
to grow the / partition in future, you can take space from the swap
partition. Unless you're doing a suspend-to-swap, you can screw
around with the swap partition with impunity.
- partition 7 will require a (preferably journalling) filesystem that
can handle a large partition. I currently use reiserfs. There are
several competent filesystems. The choice is yours.
mount /dev/sda5 /mnt/gentoo -o noatime
mkdir /mnt/gentoo/home
mount /dev/sda7 /mnt/gentoo/home -o noatime,notail
The next 3 statements
- mount partition 5 as /
- create directory /home on partition 5
- mount partition 7 as /home. All physical partitions are now mounted.
mkdir /mnt/gentoo/opt
chmod 1777 /mnt/gentoo/opt
mkdir /mnt/gentoo/tmp
chmod 1777 /mnt/gentoo/tmp
mkdir /mnt/gentoo/usr
chmod 755 /mnt/gentoo/usr
mkdir /mnt/gentoo/var
chmod 755 /mnt/gentoo/var
The next 6 statements create /opt, /tmp, /usr, and /var, and set permissions.
mkdir /mnt/gentoo/home/bindmounts
mkdir /mnt/gentoo/home/bindmounts/opt
chmod 755 /mnt/gentoo/home/bindmounts/opt
mkdir /mnt/gentoo/home/bindmounts/tmp
chmod 1777 /mnt/gentoo/home/bindmounts/tmp
mkdir /mnt/gentoo/home/bindmounts/usr
chmod 755 /mnt/gentoo/home/bindmounts/usr
mkdir /mnt/gentoo/home/bindmounts/var
chmod 755 /mnt/gentoo/home/bindmounts/var
The next 9 statements create /home/bindmounts/ on partition 7, and
then create mirrors of /opt, /tmp, /usr, and /var in /home/bindmounts,
and set permissions.
mount --bind /mnt/gentoo/home/bindmounts/opt /mnt/gentoo/opt
mount --bind /mnt/gentoo/home/bindmounts/tmp /mnt/gentoo/tmp
mount --bind /mnt/gentoo/home/bindmounts/usr /mnt/gentoo/usr
mount --bind /mnt/gentoo/home/bindmounts/var /mnt/gentoo/var
And now, the connection between the directories in /home/bindmounts and
their equivalents on /, which makes the whole thing work. If you ever
need to re-install Gentoo, or another linux distro, you can wipe the
contents of (*DO NOT* rmdir)...
/opt
/tmp
/usr
/var
And then wipe everything in / except the 4 directories...
/home
/opt
/tmp
/usr
/var
Step 3)
OK, so you've set up the partitions and subdirectories. There are
re-boots during the linux install process. Ditto for installing a new
distro, or for doing rescue work. Use the following script to mount the
directories...
#!/bin/bash
swapon /dev/sda6
mount /dev/sda5 /mnt/gentoo -o noatime
mount /dev/sda7 /mnt/gentoo/home -o noatime,notail
mount --bind /mnt/gentoo/home/bindmounts/opt /mnt/gentoo/opt
mount --bind /mnt/gentoo/home/bindmounts/tmp /mnt/gentoo/tmp
mount --bind /mnt/gentoo/home/bindmounts/usr /mnt/gentoo/usr
mount --bind /mnt/gentoo/home/bindmounts/var /mnt/gentoo/var
The advantages of my setup...
- a minimum of wasted disk space
- you can create lots of files, and use almost the entire hard drive
flexibly, because all the really variable stuff goes on the big
partition
- with a little care, you can wipe the OS files and keep your data,
and re-install the same or another linux distro.
Disadvantages...
- "find" will show duplicate results if the target file physically
exists in /home/bindmounts
- in Gentoo, /etc/localtime is a physical file, not a symlink into
/usr/share/zoneinfo. If it is a symlink in your distro, scripts
that execute early in the boot process might get confused about what
time it is.
My /etc/fstab looks like so.
# <fs> <mountpoint> <type> <opts>
<dump/pass>
/dev/hda1 / ext3 noatime 0 1
/dev/hda5 none swap sw 0 0
/dev/hda6 /home ext3 noatime 0 0
/home/bindmounts/opt /opt auto bind,noatime 0 0
/home/bindmounts/var /var auto bind,noatime 0 0
/home/bindmounts/usr /usr auto bind,noatime 0 0
/home/bindmounts/tmp /tmp auto bind,noatime 0 0
/dev/hdd /mnt/cdrom iso9660 noauto,ro 0 0
/dev/hdc /mnt/dvd auto noauto,ro 0 0
/dev/fd0 /mnt/floppy auto noauto 0 0
/dev/SDReader /mnt/sdcard msdos noauto,user,noatime,async 0 0
/dev/mp3player_1 /mnt/mp3player1 vfat noauto,user,noatime,async 0 0
/dev/Cruzer1 /mnt/flashdrive1 vfat noauto,user,noatime,async 0 0
/dev/bigUSBdrive /mnt/bigdrive reiserfs noauto,user,noatime,async,notail 0 0
/dev/PocketDrive1 /mnt/pocket1 reiserfs noauto,user,noatime,async,notail 0 0
/dev/PocketDrive2 /mnt/pocket2 reiserfs noauto,user,noatime,async,notail 0 0
# NOTE: The next line is critical for boot!
proc /proc proc defaults 0 0
# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
# POSIX shared memory (shm_open, shm_unlink).
# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will
# use almost no memory if not populated with files)
shm /dev/shm tmpfs nodev,nosuid,noexec 0 0
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda1 1208692 212956 946580 19% /
udev 62464 2660 59804 5% /dev
/dev/hda6 37815936 24949736 11329424 69% /home
shm 62464 0 62464 0% /dev/shm
--
Walter Dnes <[email protected]>