Commit ecce23e2 authored by Natanael Copa's avatar Natanael Copa

setup-disk: fix mbr when creating partitions

We only want fiddle with MBR if we use new disks and not if we install
on a mounted root
parent f500a80b
...@@ -152,7 +152,7 @@ find_pvs_in_vg() { ...@@ -152,7 +152,7 @@ find_pvs_in_vg() {
install_mounted_root() { install_mounted_root() {
local mnt="$1" mnt_boot="$1" boot_fs= root_fs= local mnt="$1" mnt_boot="$1" boot_fs= root_fs=
local initfs_features="ata base ide scsi usb virtio" local initfs_features="ata base ide scsi usb virtio"
local pvs= dev= local pvs= dev= rootdev= bootdev= raidopt=
rootdev=$(find_mount_dev "$mnt") rootdev=$(find_mount_dev "$mnt")
if [ -z "$rootdev" ]; then if [ -z "$rootdev" ]; then
...@@ -179,7 +179,9 @@ install_mounted_root() { ...@@ -179,7 +179,9 @@ install_mounted_root() {
boot_fs=$(find_mount_fs "$mnt_boot") boot_fs=$(find_mount_fs "$mnt_boot")
supported_boot_fs "$boot_fs" || return 1 supported_boot_fs "$boot_fs" || return 1
mbrdisk=$(disk_from_part $bootdev) if [ -e "/sys/block/${bootdev#/dev/}/md" ]; then
raidopt="--raid"
fi
for dev in $rootdev $pvs; do for dev in $rootdev $pvs; do
[ -e "/sys/block/${dev#/dev/}/md" ] || continue [ -e "/sys/block/${dev#/dev/}/md" ] || continue
...@@ -191,23 +193,12 @@ install_mounted_root() { ...@@ -191,23 +193,12 @@ install_mounted_root() {
raid1) raidmod="$raidmod,$level";; raid1) raidmod="$raidmod,$level";;
raid[456]) raidmod="$raidmod,raid456";; raid[456]) raidmod="$raidmod,raid456";;
esac esac
raidopt="-r"
# get a list of slaves
mbrdisk=
for i in /sys/block/$md/slaves/*; do
j=${i##*/}
i=${j%[0-9]*}
if [ -b "/dev/$i" ]; then
mbrdisk="$mbrdisk /dev/${i}"
fi
done
done done
if [ -n "$VERBOSE" ]; then if [ -n "$VERBOSE" ]; then
echo "Root device: $rootdev" echo "Root device: $rootdev"
echo "Root filesystem: $root_fs" echo "Root filesystem: $root_fs"
echo "Boot device: $bootdev" echo "Boot device: $bootdev"
echo "Boot filesystem: $boot_fs" echo "Boot filesystem: $boot_fs"
echo "MBR disk(s): $mbrdisk"
fi fi
if [ -z "$APKOVL" ]; then if [ -z "$APKOVL" ]; then
...@@ -287,9 +278,7 @@ label $KERNEL_FLAVOR ...@@ -287,9 +278,7 @@ label $KERNEL_FLAVOR
EOF EOF
fi fi
# install extlinux is_xen || extlinux $raidopt --install "$mnt"/boot
apk add -q syslinux
is_xen || extlinux -i $raidopt "$mnt"/boot/
} }
unmount_partitions() { unmount_partitions() {
...@@ -299,16 +288,6 @@ unmount_partitions() { ...@@ -299,16 +288,6 @@ unmount_partitions() {
umount $(awk '{print $2}' /proc/mounts | grep ^"$mnt" | sort -r) umount $(awk '{print $2}' /proc/mounts | grep ^"$mnt" | sort -r)
} }
fix_mbr_all_disks() {
# fix mbr for all disk devices
for i in $mbrdisk; do
local errmsg
echo "Writing MBR to $i"
errmsg=$(dd if="$MBR" of=$i 2>&1) \
|| echo "$errmsg"
done
}
# figure out decent default swap size in mega bytes # figure out decent default swap size in mega bytes
find_swap_size() { find_swap_size() {
if [ -n "$SWAP_SIZE" ]; then if [ -n "$SWAP_SIZE" ]; then
...@@ -417,6 +396,9 @@ setup_partitions() { ...@@ -417,6 +396,9 @@ setup_partitions() {
# http://bugs.alpinelinux.org/issues/show/145 # http://bugs.alpinelinux.org/issues/show/145
echo "w" | fdisk $diskdev >/dev/null echo "w" | fdisk $diskdev >/dev/null
# fix the MBR while here so extlinux can boot
cat "$MBR" > $diskdev
local start=0 local start=0
local line= local line=
# create new partitions # create new partitions
...@@ -450,6 +432,7 @@ setup_boot_dev() { ...@@ -450,6 +432,7 @@ setup_boot_dev() {
set -- $part set -- $part
bootdev=$1 bootdev=$1
[ -z "$bootdev" ] && return 1 [ -z "$bootdev" ] && return 1
echo "Creating file systems..."
if [ -n "$USE_RAID" ]; then if [ -n "$USE_RAID" ]; then
local missing= local missing=
local num=$# local num=$#
...@@ -555,6 +538,7 @@ reset_var() { ...@@ -555,6 +538,7 @@ reset_var() {
setup_var() { setup_var() {
local var_dev="$1" local var_dev="$1"
local varfs=ext4 local varfs=ext4
echo "Creating file systems..."
mkfs.$varfs -q $var_dev >/dev/null || return 1 mkfs.$varfs -q $var_dev >/dev/null || return 1
sed -i -e '/[[:space:]]\/var[[:space:]]/d' /etc/fstab sed -i -e '/[[:space:]]\/var[[:space:]]/d' /etc/fstab
echo -e "${var_dev}\t/var\t\t${varfs}\tdefaults 1 2" >> /etc/fstab echo -e "${var_dev}\t/var\t\t${varfs}\tdefaults 1 2" >> /etc/fstab
...@@ -654,7 +638,6 @@ setup_root() { ...@@ -654,7 +638,6 @@ setup_root() {
install_mounted_root /mnt || return 1 install_mounted_root /mnt || return 1
unmount_partitions /mnt unmount_partitions /mnt
swapoff -a swapoff -a
fix_mbr_all_disks
echo "" echo ""
echo "Installation is done. Please reboot." echo "Installation is done. Please reboot."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment