Skip to content

Commit 201bc33

Browse files
committed
Define the mountpoint on the golang side.
Then plumb that through to the script. This means that logic on the golang side owns the knowledge of the mountpoint, and doesn't need to assume that it knows what the mountpoint is from the shell script. For now, this is only done on the `gce_install_cuttlefish_packages` command.
1 parent d44ee71 commit 201bc33

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

tools/baseimage/cmd/gce_install_cuttlefish_packages/main.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
const (
3232
outImageName = "amended-image"
33+
mountpoint = "/mnt/image"
3334
)
3435

3536
type DebSrcsFlag struct {
@@ -90,11 +91,8 @@ func fillAvailableSpace(project, zone, insName string) error {
9091
return gce.RunCmd(project, zone, insName, "./fill_available_disk_space.sh")
9192
}
9293

93-
func mountAttachedDisk(project, zone, insName string) (string, error) {
94-
if err := gce.RunCmd(project, zone, insName, "./mount_attached_disk.sh"); err != nil {
95-
return "", err
96-
}
97-
return "/mnt/image/", nil
94+
func mountAttachedDisk(project, zone, insName, mountpoint string) error {
95+
return gce.RunCmd(project, zone, insName, "./mount_attached_disk.sh "+mountpoint)
9896
}
9997

10098
func installCuttlefishDebs(project, zone, insName string, debSrcs []string) error {
@@ -185,7 +183,7 @@ func amendImageMain(project, zone string, opts amendImageOpts) error {
185183
return fmt.Errorf("fillAvailableSpace error: %v", err)
186184
}
187185

188-
if _, err := mountAttachedDisk(project, zone, insName); err != nil {
186+
if err := mountAttachedDisk(project, zone, insName, mountpoint); err != nil {
189187
return fmt.Errorf("mountAttachedDisk error: %v", err)
190188
}
191189

tools/baseimage/pkg/gce/scripts/create_base_image_main.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sudo growpart /dev/sdb 1 || /bin/true
3030
sudo e2fsck -f -y /dev/sdb1 || /bin/true
3131
sudo resize2fs /dev/sdb1
3232

33-
./mount_attached_disk.sh
33+
./mount_attached_disk.sh /mnt/image
3434

3535
kmodver_begin=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
3636
cut -d: -f2 | cut -d" " -f2 | sed 's/linux-image-//')

tools/baseimage/pkg/gce/scripts/install_kernel_main.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ linux_image_deb=$1
2626
sudo apt-get update
2727
sudo apt-get upgrade -y
2828

29-
./mount_attached_disk.sh
29+
./mount_attached_disk.sh /mnt/image
3030

3131
version=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
3232
cut -d: -f2 | cut -d" " -f2 )

tools/baseimage/pkg/gce/scripts/mount_attached_disk.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# Mount attached disk `/dev/sdb1` at `/mnt/image`.
17+
# Mount attached disk `/dev/sdb1` at `/mnt/image` (the argument).
1818
set -o errexit -o nounset -o pipefail
1919

20-
sudo mkdir -p /mnt/image
21-
sudo mount /dev/sdb1 /mnt/image
22-
sudo mount -t sysfs none /mnt/image/sys
23-
sudo mount -t proc none /mnt/image/proc
24-
sudo mount --bind /boot/efi /mnt/image/boot/efi
25-
sudo mount --bind /dev/ /mnt/image/dev
26-
sudo mount --bind /dev/pts /mnt/image/dev/pts
27-
sudo mount --bind /run /mnt/image/run
20+
MOUNTPONT=$1
21+
22+
sudo mkdir -p ${MOUNTPOINT}
23+
sudo mount /dev/sdb1 ${MOUNTPOINT}
24+
sudo mount -t sysfs none ${MOUNTPOINT}/sys
25+
sudo mount -t proc none ${MOUNTPOINT}/proc
26+
sudo mount --bind /boot/efi ${MOUNTPOINT}/boot/efi
27+
sudo mount --bind /dev/ ${MOUNTPOINT}/dev
28+
sudo mount --bind /dev/pts ${MOUNTPOINT}/dev/pts
29+
sudo mount --bind /run ${MOUNTPOINT}/run
2830
# resolv.conf is needed on Debian but not Ubuntu
29-
if [ ! -f /mnt/image/etc/resolv.conf ]; then
30-
sudo cp /etc/resolv.conf /mnt/image/etc/
31+
if [ ! -f ${MOUNTPOINT}/etc/resolv.conf ]; then
32+
sudo cp /etc/resolv.conf ${MOUNTPOINT}/etc/
3133
fi
3234
`

0 commit comments

Comments
 (0)