1 |
Very well done, reminded me of some code that I wrote (poorly, I might add) |
2 |
but, I dug it up and found some changes that you might be able to implement |
3 |
instead of lines and lines of static configs. That being said, take some |
4 |
of these changes into consideration. |
5 |
|
6 |
Dynamic detection of drives and partitions: |
7 |
|
8 |
# Get Existing Drives |
9 |
existing_drives=$(fdisk -l | grep /dev | grep -i disk | cut -c11-13) |
10 |
|
11 |
# Set default drive |
12 |
default_drive=$(fdisk -l | grep --max-count=1 /dev | cut -c11-13) |
13 |
|
14 |
echo -e "What drive do you want to partition? [$existing_drives]: \c" |
15 |
read drive |
16 |
|
17 |
and then creating the partition table later: |
18 |
|
19 |
# Make Drive Selection |
20 |
if [ "$drive" == "" ] |
21 |
then |
22 |
selected_drive=$default_drive |
23 |
else |
24 |
# Verify Drive Exists |
25 |
does_exist=$(fdisk -l | grep --max-count=1 -ci $drive) |
26 |
|
27 |
if [ "$does_exist" == "1" ] |
28 |
then |
29 |
selected_drive=$drive |
30 |
else |
31 |
echo -e "The selected drive" $drive "does not exist. Using" |
32 |
$default_drive "instead." |
33 |
selected_drive=$default_drive |
34 |
fi |
35 |
fi |
36 |
|
37 |
num_partitions=$(fdisk -l | grep ^/dev | grep -ic $selected_drive) |
38 |
|
39 |
echo "There are" $num_partitions "partitions on" $selected_drive |
40 |
|
41 |
partitions=1 |
42 |
|
43 |
# Clear existing partition file |
44 |
rm -rf partition_table |
45 |
touch partition_table |
46 |
|
47 |
while [ "$partitions" -le "$num_partitions" ] |
48 |
do |
49 |
# Find partition numbers |
50 |
edit_partitions=$(fdisk -l | grep ^/dev/$selected_drive | cut -c9) |
51 |
|
52 |
# Parse out extra partitons |
53 |
if [ "$partitions" == "1" ] |
54 |
then |
55 |
work_partition=$(echo -e $edit_partitions | cut -c$partitions) |
56 |
# Write to partition_table file |
57 |
echo -e "d\n$work_partition" >> partition_table |
58 |
else |
59 |
if [ "$partitions_cut" == "" ] |
60 |
then |
61 |
# If First Partition after partition 1, cut off $partitions + 1 |
62 |
partitions_cut=$(($partitions+1)) |
63 |
else |
64 |
partitions_cut=$(($partitions_cut+1)) |
65 |
fi |
66 |
work_partition=$(echo -e $edit_partitions | cut -c$partitions_cut) |
67 |
# Write to partition_table file |
68 |
echo -e "d\n$work_partition" >> partition_table |
69 |
((partitions_cut += 1)) |
70 |
fi |
71 |
((partitions += 1)) |
72 |
|
73 |
done |
74 |
|
75 |
# build the rest of the table |
76 |
# Get Total System Memory |
77 |
total_mem=$(cat /proc/meminfo | grep -i memtotal | cut -c16- | sed s/\ |
78 |
// | sed s/kB//) |
79 |
swap_space=$(expr $(expr $total_mem + $total_mem) / 1024) |
80 |
|
81 |
# Write first partition to file |
82 |
echo -e "n\np\n1\n\n+100M\n" >> partition_table |
83 |
|
84 |
# Write Swap Space (double system memory) |
85 |
echo -e "n\np\n2\n\n+"$swap_space"M\n">> partition_table |
86 |
|
87 |
# Write / partition to file |
88 |
echo -e "n\np\n3\n\n\n" >> partition_table |
89 |
|
90 |
# Write partition setting to file and drive write |
91 |
echo -e "a\n1\nt\n2\n82\nw\n" >> partition_table |
92 |
|
93 |
# Set drive number variables |
94 |
boot_drive=$(echo $selected_drive"1") |
95 |
swap_drive=$(echo $selected_drive"2") |
96 |
root_drive=$(echo $selected_drive"3") |
97 |
|
98 |
# KEEP THIS COMMENTED OUT BELLOW HERE |
99 |
fdisk /dev/$selected_drive < partition_table |
100 |
|
101 |
Mainly due to the fact that you statically set the UUIDs of the drive that |
102 |
you want to use. |
103 |
|
104 |
Cheers, |
105 |
Kad |
106 |
|
107 |
On Sun, Jul 1, 2012 at 5:28 PM, Michael Mol <mikemol@×××××.com> wrote: |
108 |
|
109 |
> On Wed, Jun 27, 2012 at 10:13 PM, Michael Mol <mikemol@×××××.com> wrote: |
110 |
> > Very rough, and very much a works-for-me thing, but I thought I'd share. |
111 |
> > |
112 |
> > https://github.com/mikemol/gentoo-install |
113 |
> > |
114 |
> > I wrote it to ease the pain of the "install-configure-build" cycle I |
115 |
> > was going through to figure out what was breaking glibc. |
116 |
> |
117 |
> Just a bit of a followup. I've got most of the bugs worked out, and |
118 |
> I'm very pleased with it. I've used it to get through most of the |
119 |
> install sequence for inara, and it's currently on package 113/158 of |
120 |
> its second pass of 'emerge -e @world'. |
121 |
> |
122 |
> If anyone else gets around to trying it, let me know. :) |
123 |
> |
124 |
> -- |
125 |
> :wq |
126 |
> |
127 |
> |