Gentoo Archives: gentoo-user

From: Michael Mol <mikemol@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: Gentoo install script
Date: Wed, 04 Jul 2012 20:08:44
Message-Id: CA+czFiBCqMpdWa8RLNhG7vBebxXp1PXu25XoAbBnMwkC=kVWyQ@mail.gmail.com
In Reply to: Re: [gentoo-user] Re: Gentoo install script by Kaddeh
1 On Wed, Jul 4, 2012 at 1:20 AM, Kaddeh <kaddeh@×××××.com> wrote:
2 > Very well done, reminded me of some code that I wrote (poorly, I might add)
3 > but, I dug it up and found some changes that you might be able to implement
4 > instead of lines and lines of static configs. That being said, take some of
5 > these changes into consideration.
6 >
7 > Dynamic detection of drives and partitions:
8 >
9 > # Get Existing Drives
10 > existing_drives=$(fdisk -l | grep /dev | grep -i disk | cut -c11-13)
11 >
12 > # Set default drive
13 > default_drive=$(fdisk -l | grep --max-count=1 /dev | cut -c11-13)
14 >
15 > echo -e "What drive do you want to partition? [$existing_drives]: \c"
16 > read drive
17 >
18 > and then creating the partition table later:
19 >
20 > # Make Drive Selection
21 > if [ "$drive" == "" ]
22 > then
23 > selected_drive=$default_drive
24 > else
25 > # Verify Drive Exists
26 > does_exist=$(fdisk -l | grep --max-count=1 -ci $drive)
27 >
28 > if [ "$does_exist" == "1" ]
29 > then
30 > selected_drive=$drive
31 > else
32 > echo -e "The selected drive" $drive "does not exist. Using"
33 > $default_drive "instead."
34 > selected_drive=$default_drive
35 > fi
36 > fi
37 >
38 > num_partitions=$(fdisk -l | grep ^/dev | grep -ic $selected_drive)
39 >
40 > echo "There are" $num_partitions "partitions on" $selected_drive
41 >
42 > partitions=1
43 >
44 > # Clear existing partition file
45 > rm -rf partition_table
46 > touch partition_table
47 >
48 > while [ "$partitions" -le "$num_partitions" ]
49 > do
50 > # Find partition numbers
51 > edit_partitions=$(fdisk -l | grep ^/dev/$selected_drive | cut -c9)
52 >
53 > # Parse out extra partitons
54 > if [ "$partitions" == "1" ]
55 > then
56 > work_partition=$(echo -e $edit_partitions | cut -c$partitions)
57 > # Write to partition_table file
58 > echo -e "d\n$work_partition" >> partition_table
59 > else
60 > if [ "$partitions_cut" == "" ]
61 > then
62 > # If First Partition after partition 1, cut off $partitions + 1
63 > partitions_cut=$(($partitions+1))
64 > else
65 > partitions_cut=$(($partitions_cut+1))
66 > fi
67 > work_partition=$(echo -e $edit_partitions | cut -c$partitions_cut)
68 > # Write to partition_table file
69 > echo -e "d\n$work_partition" >> partition_table
70 > ((partitions_cut += 1))
71 > fi
72 > ((partitions += 1))
73 >
74 > done
75 >
76 > # build the rest of the table
77 > # Get Total System Memory
78 > total_mem=$(cat /proc/meminfo | grep -i memtotal | cut -c16- | sed s/\ // |
79 > sed s/kB//)
80 > swap_space=$(expr $(expr $total_mem + $total_mem) / 1024)
81 >
82 > # Write first partition to file
83 > echo -e "n\np\n1\n\n+100M\n" >> partition_table
84 >
85 > # Write Swap Space (double system memory)
86 > echo -e "n\np\n2\n\n+"$swap_space"M\n">> partition_table
87 >
88 > # Write / partition to file
89 > echo -e "n\np\n3\n\n\n" >> partition_table
90 >
91 > # Write partition setting to file and drive write
92 > echo -e "a\n1\nt\n2\n82\nw\n" >> partition_table
93 >
94 > # Set drive number variables
95 > boot_drive=$(echo $selected_drive"1")
96 > swap_drive=$(echo $selected_drive"2")
97 > root_drive=$(echo $selected_drive"3")
98 >
99 > # KEEP THIS COMMENTED OUT BELLOW HERE
100 > fdisk /dev/$selected_drive < partition_table
101 >
102 > Mainly due to the fact that you statically set the UUIDs of the drive that
103 > you want to use.
104 >
105 > Cheers,
106 > Kad
107
108 Thank you very much.
109
110 I'd gladly entertain a pull request if you'd like to integrate it. I'm
111 not doing much in the way of active development on the script until I
112 have either (or both) of my machines operational again; they're almost
113 there, but I'm a sticking point with the 3.3.8 kernel, got past that,
114 and have now discovered that stable genkernel and stable
115 gentoo-sources don't play well together. (Because stable genkernel is
116 using a slightly older version of busybox which doesn't know about
117 some moved kernel header files). That stuff is slowly moving on b.g.o,
118 and I'm slowly working around at home. It's only a matter of time, of
119 which nobody seems to have enough...
120
121 --
122 :wq