Пример #1
0
def test_format_and_mount():
    """
    Format, mount and unmount a block device
    """

    from fabtools.disk import ismounted, mkfs, mount

    assert not ismounted('/dev/loop0')

    try:
        # Make a loopback block device
        sudo('dd if=/dev/zero of=bigfile bs=1024 count=30720')
        sudo('losetup /dev/loop0 bigfile')

        # Format the block device
        mkfs('/dev/loop0', 'ext3')

        # Mount the block device
        require_directory('/mnt/loop', use_sudo=True)
        mount('/dev/loop0', '/mnt/loop')
        assert ismounted('/dev/loop0')

        # Unmount the block device
        sudo('umount /dev/loop0')
        assert not ismounted('/dev/loop0')

    finally:
        sudo('umount /dev/loop0', quiet=True)
        sudo('losetup -d /dev/loop0', quiet=True)
        sudo('rm -f bigfile', quiet=True)
Пример #2
0
def mount_device(device="/dev/datavg01/datavol01",
                 mountpoint="/data/brick1",
                 fstype="ext4"):
    directory(mountpoint, use_sudo=True)
    append("/etc/fstab",
           "{0}    {1}    {2}    defaults,nosuid,nodev    1 2".format(
               device, mountpoint, fstype),
           use_sudo=True)
    mount(device, mountpoint)
    sudo("mount")
Пример #3
0
def install():
    """
    If you have a USB router, you can move data to USB stick for free RAM
    This USB stick must have 3 partitions
      cfdisk /dev/usbdisk
      mkfs.ext4 /dev/usbdisk1
      mkfs.ext4 /dev/usbdisk2
      mkswap /dev/usbdisk3
    """

    # Set Shell environment
    env.shell = "/bin/ash -l -c"

    # Install USB required packages
    openwrt.update_index()
    openwrt.install([
        'openssh-sftp-server',
        'kmod-usb-storage',
        'block-mount',
        'kmod-fs-ext4',
    ])

    # Prepare system
    require.files.directory('/mnt/tmp')
    require.files.directory('/mnt/var')

    # Refresh file system
    with settings(hide('running', 'warnings', 'stdout'), warn_only=True):
        run('ls -alh /mnt')

    # Mount partitions
    disk.mount('/dev/sda1', '/mnt/tmp')
    disk.mount('/dev/sda2', '/mnt/var')
    disk.swapon('/dev/sda3')

    # Copy /etc/config/fstab
    lpath = os.path.join(os.path.dirname(__file__), 'fstab')
    put(lpath, '/etc/config/fstab')
    run('/etc/init.d/fstab enable')

    # Copy /etc/init.d/data2usb
    lpath = os.path.join(os.path.dirname(__file__), 'data2usb')
    put(lpath, '/etc/init.d/data2usb')
    run('chmod +x /etc/init.d/data2usb')
    run('/etc/init.d/data2usb enable')
    run('/etc/init.d/data2usb start')
Пример #4
0
def install():
    """
    If you have a USB router, you can move data to USB stick for free RAM
    This USB stick must have 3 partitions
      cfdisk /dev/usbdisk
      mkfs.ext4 /dev/usbdisk1
      mkfs.ext4 /dev/usbdisk2
      mkswap /dev/usbdisk3
    """

    # Set Shell environment
    env.shell = "/bin/ash -l -c"

    # Install USB required packages
    openwrt.update_index()
    openwrt.install([
        'openssh-sftp-server',
        'kmod-usb-storage',
        'block-mount',
        'kmod-fs-ext4',
    ])

    # Prepare system
    require.files.directory('/mnt/tmp')
    require.files.directory('/mnt/var')

    # Refresh file system
    with settings(hide('running', 'warnings', 'stdout'), warn_only=True):
        run('ls -alh /mnt')

    # Mount partitions
    disk.mount('/dev/sda1', '/mnt/tmp')
    disk.mount('/dev/sda2', '/mnt/var')
    disk.swapon('/dev/sda3')

    # Copy /etc/config/fstab
    lpath = os.path.join(os.path.dirname(__file__), 'fstab')
    put(lpath, '/etc/config/fstab')
    run('/etc/init.d/fstab enable')

    # Copy /etc/init.d/data2usb
    lpath = os.path.join(os.path.dirname(__file__), 'data2usb')
    put(lpath, '/etc/init.d/data2usb')
    run('chmod +x /etc/init.d/data2usb')
    run('/etc/init.d/data2usb enable')
    run('/etc/init.d/data2usb start')
Пример #5
0
def mount_partitions():
    """
    mount all paritions
    """
    disk.mount(env.part['/']['device'], "/mnt/")
    if not is_dir('/mnt/boot'):
        run_as_root('mkdir /mnt/boot')

    if not is_dir('/mnt/home'):
        run_as_root('mkdir /mnt/home')

    disk.mount(env.part['/boot']['device'], "/mnt/boot")
    disk.mount('/dev/mapper/home', "/mnt/home")
    disk.swapon(env.part['swap']['device'])
Пример #6
0
def mount_partitions():
    """
    mount all paritions
    """
    disk.mount(env.part['/']['device'], "/mnt/")
    if not is_dir('/mnt/boot'):
        run_as_root('mkdir /mnt/boot')

    if not is_dir('/mnt/home'):
        run_as_root('mkdir /mnt/home')

    disk.mount(env.part['/boot']['device'], "/mnt/boot")
    disk.mount('/dev/mapper/home', "/mnt/home")
    disk.swapon(env.part['swap']['device'])