kusnier / vagrant-persistent-storage

A Vagrant plugin that creates a persistent storage and attaches it to guest machine.
MIT License
292 stars 68 forks source link

boot2docker: no bash available, /etc/fstab not writable #27

Open rsenden opened 10 years ago

rsenden commented 10 years ago

I'm trying to set up some persistent storage with the dduportal/boot2docker vagrant box, but mounting the volume fails. The /tmp/disk_operations_boot2docker-data.sh script fails to execute, as bash is not available in boot2docker. Also, /etc/fstab is not writable (as boot2docker runs from an iso).

Changing the disk_operations script to use /bin/sh fails with the following errors: sh: LABEL="boot2docker-data": unknown operand mke2fs 1.42.7 (21-Jan-2013) mkfs.ext4: No such device or address while trying to determine filesystem size mkdir: can't create directory '/data': Permission denied /tmp/disk_operations_boot2docker-data.sh: line 16: can't create /etc/fstab: Permission denied mount: can't find /data in /etc/fstab

Any suggestions on how to make this work with boot2docker?

rsenden commented 10 years ago

I have now updated my copy of manage_storage.rb as follows. This uses /bin/sh instead of /bin/bash, fdisk instead sfdisk, and an approach similar to boot2docker to create the filesystem if it does not yet exist. I removed all the lvm stuff for now, as this is not supported on boot2docker. I also do not check the format flag; I format unconditionally if the filesystem does not yet exist.

        disk_operations_template = ERB.new <<-EOF
#!/bin/sh
# fdisk the disk if it's not a block device already:
PERSISTENT_DATA=`blkid -o device -l -t LABEL=#{mnt_name}`
if [ ! -n "$PERSISTENT_DATA" ]; then
    echo "Unformatted persistent data disk found; creating partition" >> /tmp/disk_operation_log.txt 2>&1
    (echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk #{disk_dev} >> /tmp/disk_operation_log.txt 2>&1
    echo "Running modprobe" >> /tmp/disk_operation_log.txt 2>&1
    modprobe >> /tmp/disk_operation_log.txt 2>&1
    echo "Creating filesystem" >> /tmp/disk_operation_log.txt 2>&1
    mkfs.#{fs_type} #{disk_dev}1 -L #{mnt_name} >> /tmp/disk_operation_log.txt 2>&1
fi
<% if mount == true %>
echo "Creating mount point" >> /tmp/disk_operation_log.txt 2>&1
[ -d #{mnt_point} ] || mkdir -p #{mnt_point} >> /tmp/disk_operation_log.txt 2>&1
#echo "Updating fstab" >> /tmp/disk_operation_log.txt 2>&1
#[ "`grep -i #{disk_dev}1 /etc/fstab`" ] || echo #{disk_dev}1 #{mnt_point} #{fs_type} #{mnt_options.join(',')} 0 0 >> /etc/fstab
echo "Mounting #{mnt_point}" >> /tmp/disk_operation_log.txt 2>&1
echo "mount -t #{fs_type} -o #{mnt_options.join(',')} #{disk_dev}1 #{mnt_point}" >> /tmp/disk_operation_log.txt 2>&1
[ "`mount | grep #{mnt_point}`" ] || mount -t #{fs_type} -o #{mnt_options.join(',')} #{disk_dev}1 #{mnt_point} >> /tmp/disk_operation_log.txt 2>&1
echo "#{mnt_point} mounting returned:  $?" >> /tmp/disk_operation_log.txt 2>&1
<% end %>
exit $?
        EOF
mritalian commented 6 years ago

Is there any intention to merge above change (or rather an updated version of that) into the codebase? Are so few people using boot2docker that this doesn't matter? I don't know Ruby or I'd work on this myself.