|
1 | 1 | # -*- shell-script -*-
|
2 | 2 |
|
| 3 | + |
| 4 | +NBD_CLIENT=/usr/sbin/@xnbd-client |
| 5 | + |
| 6 | + |
| 7 | +setup_nbd_device() { |
| 8 | + local device="$1" # ie: 0 |
| 9 | + local retries=900 |
| 10 | + |
| 11 | + |
| 12 | + # Fetching metadatas |
| 13 | + local export_uri=$(oc-metadata VOLUMES_${device}_EXPORT_URI) |
| 14 | + [ "$export_uri" = "" ] && log_fatal_msg "Unable to load metadatas..." |
| 15 | + |
| 16 | + local nbd_host=$(echo $export_uri | sed -n 's#nbd://\(.*\):.*$#\1#p') |
| 17 | + local nbd_port=$(echo $export_uri | sed -n 's#nbd://.*:\(.*\)$#\1#p') |
| 18 | + [ "$nbd_host" = "" -o "$nbd_port" = "" ] && log_fatal_msg "Parse error of $export_uri" |
| 19 | + |
| 20 | + |
| 21 | + # Checking if device is already attached |
| 22 | + $NBD_CLIENT -c /dev/nbd${device} >/dev/null 2>/dev/null |
| 23 | + if [ $? -eq 0 ]; then |
| 24 | + return |
| 25 | + fi |
| 26 | + |
| 27 | + # Connecting the device |
| 28 | + $NBD_CLIENT --blocksize 4096 --retry=$retries $nbd_host $nbd_port /dev/nbd${device} 2>/dev/null |
| 29 | + |
| 30 | + # Checking if device is already attached |
| 31 | + $NBD_CLIENT -c /dev/nbd${device} >/dev/null 2>/dev/null || \ |
| 32 | + log_fatal_msg "Device connection failed." |
| 33 | + |
| 34 | + # Fixing IO scheduler |
| 35 | + if grep -q '\[cfq\]' /sys/block/nbd${device}/queue/scheduler |
| 36 | + then |
| 37 | + echo deadline > /sys/block/nbd${device}/queue/scheduler |
| 38 | + fi |
| 39 | +} |
| 40 | + |
| 41 | + |
3 | 42 | mountroot() {
|
4 |
| - echo "boot-nbd.mountroot(): TODO" |
5 |
| - # /scripts/local-top/ocs-nbd |
6 |
| - # mkdir -p /mnt/root |
7 |
| - # mount /dev/mapper/nbd0 |
8 |
| - # echo 0x0100 > /proc/sys/kernel/real-root-dev |
9 |
| - # mount -o move /dev /mnt/dev |
10 |
| - # mount -o move /dev/pts /mnt/dev/pts |
11 |
| - # mount -o move /sys /mnt/sys |
12 |
| - # mount -o move /proc /mnt/proc |
13 |
| - # mount -o move /run /mnt/run |
14 |
| - # sync |
15 |
| - # echo "Let's play" |
16 |
| - # export PS1="# " |
17 |
| - # /bin/sh |
18 |
| - # exec switch_root /mnt/root /init |
| 43 | + log_begin_msg "Mounting NBD root" |
| 44 | + |
| 45 | + # Attaching NBD |
| 46 | + setup_nbd_device 0 # nbd0 |
| 47 | + |
| 48 | + # Prepare switch_root |
| 49 | + mount /dev/nbd0 ${rootmnt} |
| 50 | + echo 0x0100 > /proc/sys/kernel/real-root-dev |
| 51 | + mount -o move /dev ${rootmnt}/dev |
| 52 | + mount -o move /dev/pts ${rootmnt}/dev/pts |
| 53 | + mount -o move /sys ${rootmnt}/sys |
| 54 | + mount -o move /proc ${rootmnt}/proc |
| 55 | + mount -o move /run ${rootmnt}/run |
| 56 | + sync |
| 57 | + #exec switch_root ${rootmnt}/root /init |
| 58 | + |
| 59 | + log_end_msg |
19 | 60 | }
|
0 commit comments