1 |
While installing Gentoo recently, I managed to pull off a cute stunt |
2 |
that... |
3 |
a) minimizes wasted disk space |
4 |
b) retains the ability to wipe and re-install the OS, without wiping |
5 |
user data |
6 |
|
7 |
I'm considering doing a Gentoo Wiki entry, if one hasn't already been |
8 |
done. First, I'll run it past the list for comments and any problems |
9 |
you may find. (Update: after a read-through, it occurs to me that I |
10 |
should probably bindmount /opt similarly to /tmp, /usr, and /var). |
11 |
|
12 |
The example below uses /dev/sda. Substitute as appropriate for your |
13 |
system (hda or wharever) |
14 |
|
15 |
Step 1) Partition a blank hard drive. |
16 |
|
17 |
- partition the entire hard drive (500 gigabytes in my case) as one |
18 |
gigantic extended partition (partition 1) |
19 |
|
20 |
- create a 500 megabyte logical linux (type 83) partition of at the |
21 |
beginning of the extended partition (partition 5). This will be the |
22 |
/ partition |
23 |
|
24 |
- next, create a logical linux swap (type 82) partition approx twice |
25 |
the size of your ram (partition 6). |
26 |
|
27 |
- next, create a logical linux (type 83) partition using the remainder |
28 |
of the drive (partition 7). This will be mounted as /home. Here's |
29 |
what my drive looks like, according to "fdisk -l" |
30 |
|
31 |
Disk /dev/sda: 500.1 GB, 500107862016 bytes |
32 |
255 heads, 63 sectors/track, 60801 cylinders |
33 |
Units = cylinders of 16065 * 512 = 8225280 bytes |
34 |
|
35 |
Device Boot Start End Blocks Id System |
36 |
/dev/sda1 1 60801 488384001 5 Extended |
37 |
/dev/sda5 1 62 497952 83 Linux |
38 |
/dev/sda6 63 549 3911796 82 Linux swap / Solaris |
39 |
/dev/sda7 550 60801 483974158+ 83 Linux |
40 |
|
41 |
Step 2) File system creation... *WARNING* the following script wipes |
42 |
all data on partitions 5, 6, and 7. Use this only when you want to wipe |
43 |
everything, *INCLUDING ALL YOUR DATA*, and start fresh. For mounting |
44 |
the drive after a reboot during install (or booting off the install CD |
45 |
for rescue work) use the script in step 3. |
46 |
|
47 |
#!/bin/bash |
48 |
mke2fs /dev/sda5 |
49 |
mkswap /dev/sda6 |
50 |
mkreiserfs /dev/sda7 |
51 |
swapon /dev/sda6 |
52 |
mount /dev/sda5 /mnt/gentoo -o noatime |
53 |
mkdir /mnt/gentoo/home |
54 |
mount /dev/sda7 /mnt/gentoo/home -o noatime,notail |
55 |
mkdir /mnt/gentoo/tmp |
56 |
chmod 1777 /mnt/gentoo/tmp |
57 |
mkdir /mnt/gentoo/usr |
58 |
chmod 755 /mnt/gentoo/usr |
59 |
mkdir /mnt/gentoo/var |
60 |
chmod 755 /mnt/gentoo/var |
61 |
mkdir /mnt/gentoo/home/bindmounts |
62 |
mkdir /mnt/gentoo/home/bindmounts/tmp |
63 |
chmod 1777 /mnt/gentoo/home/bindmounts/tmp |
64 |
mkdir /mnt/gentoo/home/bindmounts/usr |
65 |
chmod 755 /mnt/gentoo/home/bindmounts/usr |
66 |
mkdir /mnt/gentoo/home/bindmounts/var |
67 |
chmod 755 /mnt/gentoo/home/bindmounts/var |
68 |
mount --bind /mnt/gentoo/home/bindmounts/tmp /mnt/gentoo/tmp |
69 |
mount --bind /mnt/gentoo/home/bindmounts/usr /mnt/gentoo/usr |
70 |
mount --bind /mnt/gentoo/home/bindmounts/var /mnt/gentoo/var |
71 |
|
72 |
Again, substitute as appropriate if your harddrive is not /dev/sda. |
73 |
Let's examine the script in detail... |
74 |
|
75 |
mke2fs /dev/sda5 |
76 |
mkswap /dev/sda6 |
77 |
mkreiserfs /dev/sda7 |
78 |
swapon /dev/sda6 |
79 |
|
80 |
The first 4 commands format the partitions and activate the swapdrive. |
81 |
Partition 5 really should be ext2fs for a few reasons... |
82 |
|
83 |
- Partition 5 will rarely be written to during normal operation; only |
84 |
when you are installing/updating programs/scripts that reside in |
85 |
/bin or /sbin so journalling isn't that important. |
86 |
|
87 |
- Journalling requires disk space, which we're trying to conserve. |
88 |
|
89 |
- Given the small size of the / partition, ext2fs is sufficient |
90 |
|
91 |
- ext2fs is the easiest filesystem to shrink/grow. If you ever need |
92 |
to grow the / partition in future, you can take space from the swap |
93 |
partition. Unless you're doing a suspend-to-swap, you can screw |
94 |
around with the swap partition with impunity. |
95 |
|
96 |
- partition 7 will require a (preferably journalling) filesystem that |
97 |
can handle a large partition. I currently use reiserfs. There are |
98 |
several competent filesystems. The choice is yours. |
99 |
|
100 |
mount /dev/sda5 /mnt/gentoo -o noatime |
101 |
mkdir /mnt/gentoo/home |
102 |
mount /dev/sda7 /mnt/gentoo/home -o noatime,notail |
103 |
|
104 |
The next 3 statements |
105 |
|
106 |
- mount partition 5 as / |
107 |
|
108 |
- create directory /home on partition 5 |
109 |
|
110 |
- mount partition 7 as /home. All physical partitions are now mounted. |
111 |
|
112 |
mkdir /mnt/gentoo/tmp |
113 |
chmod 1777 /mnt/gentoo/tmp |
114 |
mkdir /mnt/gentoo/usr |
115 |
chmod 755 /mnt/gentoo/usr |
116 |
mkdir /mnt/gentoo/var |
117 |
chmod 755 /mnt/gentoo/var |
118 |
|
119 |
The next 6 statements create /tmp, /usr, and /var, and set permissions. |
120 |
|
121 |
mkdir /mnt/gentoo/home/bindmounts |
122 |
mkdir /mnt/gentoo/home/bindmounts/tmp |
123 |
chmod 1777 /mnt/gentoo/home/bindmounts/tmp |
124 |
mkdir /mnt/gentoo/home/bindmounts/usr |
125 |
chmod 755 /mnt/gentoo/home/bindmounts/usr |
126 |
mkdir /mnt/gentoo/home/bindmounts/var |
127 |
chmod 755 /mnt/gentoo/home/bindmounts/var |
128 |
|
129 |
The next 7 statements create /home/bindmounts/ on partition 7, and |
130 |
then create mirrors of /tmp, /usr, and /var in /home/bindmounts, and set |
131 |
permissions. |
132 |
|
133 |
mount --bind /mnt/gentoo/home/bindmounts/tmp /mnt/gentoo/tmp |
134 |
mount --bind /mnt/gentoo/home/bindmounts/usr /mnt/gentoo/usr |
135 |
mount --bind /mnt/gentoo/home/bindmounts/var /mnt/gentoo/var |
136 |
|
137 |
And now, the connection between the directories in /home/bindmounts and |
138 |
their equivalents on /, which makes the whole thing work. If you ever |
139 |
need to re-install Gentoo, or another linux distro, you can wipe the |
140 |
contents of (*DO NOT* rmdir)... |
141 |
/tmp |
142 |
/usr |
143 |
/var |
144 |
|
145 |
And then wipe everything in / except the 4 directories... |
146 |
/home |
147 |
/tmp |
148 |
/usr |
149 |
/var |
150 |
|
151 |
Step 3) |
152 |
|
153 |
OK, so you've set up the partitions and subdirectories. There are |
154 |
re-boots during the linux install process. Ditto for installing a new |
155 |
distro, or for doing rescue work. Use the following script to mount the |
156 |
directories... |
157 |
|
158 |
#!/bin/bash |
159 |
swapon /dev/sda6 |
160 |
mount /dev/sda5 /mnt/gentoo -o noatime |
161 |
mount /dev/sda7 /mnt/gentoo/home -o noatime,notail |
162 |
mount --bind /mnt/gentoo/home/bindmounts/tmp /mnt/gentoo/tmp |
163 |
mount --bind /mnt/gentoo/home/bindmounts/usr /mnt/gentoo/usr |
164 |
mount --bind /mnt/gentoo/home/bindmounts/var /mnt/gentoo/var |
165 |
|
166 |
|
167 |
|
168 |
The advantages of my setup... |
169 |
- a minimum of wasted disk space |
170 |
- you can create lots of files, and use almost the entire hard drive |
171 |
flexibly, because all the really variable stuff goes on the big |
172 |
partition |
173 |
- with a little care, you can wipe the OS files and keep your data, |
174 |
and re-install the same or another linux distro. |
175 |
|
176 |
Disadvantages... |
177 |
- "find" will show duplicate results if the target file physically |
178 |
exists in /home/bindmounts |
179 |
- in Gentoo, /etc/localtime is a physical file, not a symlink into |
180 |
/usr/share/zoneinfo. If it is a symlink in your distro, scripts |
181 |
that execute early in the boot process might get confused about what |
182 |
time it is. |
183 |
|
184 |
-- |
185 |
Walter Dnes <waltdnes@××××××××.org> In linux /sbin/init is Job #1 |
186 |
Q. Mr. Ghandi, what do you think of Microsoft security? |
187 |
A. I think it would be a good idea. |
188 |
-- |
189 |
gentoo-user@g.o mailing list |