mercredi 31 décembre 2014

CentOS 6.5 and Ubuntu 14.04 Vagrant VMs getting assigned domain name


I'm provisioning a CentOS 6.5 and Ubuntu 14.04.1 LTS VM with Vagrant running under VirtualBox. I'm using Vagrantfiles to set the hostnames and IPs, but when I boot them, for example, instead of server1 the FQDN becomes server1.domain.com. The host machine is a Windows Machine on an Active Directory domain (domain.com). I just want the FQDN to be server1 with no domain name. How can I achieve this, preferably using just the Vagrantfiles?


Here is one of the Vagrantfiles



Installing Arch on RAID, LUKS, LVM, Btrfs?


I am struggling with setting up an encrypted NAS for some days now. The basic plan is to have btrfs on lvm on luks on raid1 with lvmcache in writeback mode thrown in for the root partition to reduce disk access.


TL;DR:


After setting up the partitions and filesystems GRUB fails to install with:



grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet..
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.




Partitions


Following the Arch Wiki I start by setting up the partitions:


gdisk output for /dev/sda and /dev/sdb:



Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9EFA6587-E34F-4AC1-8B56-5262480A6C6A
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02 BIOS boot partition
2 4096 976773134 465.8 GiB 8300 Linux filesystem


Note the BIOS boot partition that is apparently required by GRUB when installing in BIOS/GPT mode.


MDADM


As I have two disk I want them in a RAID1 array:



mdadm --create --level=1 --raid-devices=2 /dev/md0 /dev/sda2 /dev/sdb2

root@archiso ~ # mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=archiso:0 UUID=bdfc3fea:f4a0ee6d:6ac08012:59ea384b

root@archiso ~ # cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb2[1] sda2[0]
488253440 blocks super 1.2 [2/2] [UU]
[>....................] resync = 2.0% (9832384/488253440) finish=96.6min speed=82460K/sec
bitmap: 4/4 pages [16KB], 65536KB chunk

unused devices: <none>


LUKS


Next I setup a LUKS volume on top of the RAID:



root@archiso ~ # cryptsetup luksFormat /dev/md0

WARNING!
========
This will overwrite data on /dev/md0 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:


root@archiso ~ # cryptsetup luksOpen /dev/md0 md0-crypt
Enter passphrase for /dev/md0:


LVM


Btrfs snapshots could be used instead of LVM, but as of writing this there is no way to add a SSD caching device to Btrfs. So I opted to use LVM and add the SSD via lvmcache later:


(Creating the volume group in one step:)



root@archiso ~ # vgcreate vg0 /dev/mapper/md0-crypt
Physical volume "/dev/mapper/md0-crypt" successfully created
Volume group "vg0" successfully created

root@archiso ~ # lvcreate -L 100M -C y vg0 -n boot
Logical volume "boot" created.
root@archiso ~ # lvcreate -L 20G vg0 -n root
Logical volume "root" created.
root@archiso ~ # lvcreate -L 10G vg0 -n var
Logical volume "var" created.
root@archiso ~ # lvcreate -L 6G -C y vg0 -n swap
Logical volume "swap" created.
root@archiso ~ # lvcreate -l +100%FREE vg0 -n home
Logical volume "home" created


Resulting in the following layout:



root@archiso ~ # lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
boot vg0 -wc-a----- 100.00m
home vg0 -wi-a----- 429.53g
root vg0 -wi-a----- 20.00g
swap vg0 -wc-a----- 6.00g
var vg0 -wi-a----- 10.00g


Btrfs/Filesystems


Creating the filesystems:



root@archiso ~ # mkfs.ext4 /dev/vg0/boot
root@archiso ~ # mkfs.btrfs /dev/vg0/home
root@archiso ~ # mkfs.btrfs /dev/vg0/root
root@archiso ~ # mkfs.btrfs /dev/vg0/var


(ext4 was chosen for boot because btrfs complains about the small partition size.)


Mounting the filesystems:



root@archiso ~ # swapon /dev/vg0/swap
root@archiso ~ # mount /dev/vg0/root /mnt/arch -o compress=lzo
root@archiso ~ # mount /dev/vg0/home /mnt/arch/home -o compress=lzo
root@archiso ~ # mount /dev/vg0/var /mnt/arch/var -o compress=lzo
root@archiso ~ # mount /dev/vg0/boot /mnt/arch/boot


Installing Arch


Actually I just copy the system from a previous backup:



root@archiso ~ # rsync -Pa /mnt/bkp/sda/* /mnt/arch


(coffee break)


Setting up mdadm.conf and fstab



root@archiso ~ # genfstab -U /mnt/arch > /mnt/arch/etc/fstab
root@archiso ~ # cat /mnt/arch/etc/fstab
# /dev/mapper/vg0-root
UUID=62ebf0c9-bb37-4b4e-87dd-eb8a4ace6a69 / btrfs rw,relatime,compress=lzo,space_cache 0 0

# /dev/mapper/vg0-home
UUID=53113e11-b663-452f-b4da-1443e470b065 /home btrfs rw,relatime,compress=lzo,space_cache 0 0

# /dev/mapper/vg0-var
UUID=869ffe10-7a1c-4254-9612-25633c7ae619 /var btrfs rw,relatime,compress=lzo,space_cache 0 0

# /dev/mapper/vg0-boot
UUID=d121a9df-8c03-4ad9-a6e0-b68739b1a358 /boot ext4 rw,relatime,data=ordered 0 2

# /dev/mapper/vg0-swap
UUID=29035eeb-540d-4437-861b-c30597bb7c16 none swap defaults 0 0

root@archiso ~ # mdadm --detail --scan >> /mnt/arch/etc/mdadm.conf
root@archiso ~ # cat /mnt/arch/etc/mdadm.conf
[...]
ARRAY /dev/md0 metadata=1.2 name=archiso:0 UUID=bdfc3fea:f4a0ee6d:6ac08012:59ea384b


Chrooting into the system



root@archiso ~ # arch-chroot /mnt/arch /bin/bash
[root@archiso /]#


mkinitcpio.conf


These hooks were added: mdadm_udev encrypt lvm2 btrfs



[root@archiso /]# mkinitcpio -p linux


Configuring GRUB


Now for the interesting (and failing) part, I chose GRUB as my bootloader as it should support all of the contraptions that I use.


References: * http://ift.tt/1uTkZon * http://ift.tt/1Bjoqpx


Changed parts in /etc/default/grub:



GRUB_CMDLINE_LINUX="cryptdevice=/dev/md0:vg0"
GRUB_ENABLE_CRYPTODISK=y


Installing grub:



[root@archiso /]# grub-install --target=i386-pc --recheck /dev/sda
Installing for i386-pc platform.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet..
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.


(--debug output available here)


Frankly ... I have no idea what's the problem here. In BIOS/GPT mode GRUB should embed it's core.img into the ef02/BIOS boot partition shouldn't it?


Edit


http://ift.tt/13SQkx6 doesn't apply here:



[root@archiso /]# btrfs fi show --all-devices
Label: none uuid: 62ebf0c9-bb37-4b4e-87dd-eb8a4ace6a69
Total devices 1 FS bytes used 965.77MiB
devid 1 size 20.00GiB used 3.04GiB path /dev/mapper/vg0-root

Label: none uuid: 869ffe10-7a1c-4254-9612-25633c7ae619
Total devices 1 FS bytes used 339.15MiB
devid 1 size 10.00GiB used 3.04GiB path /dev/mapper/vg0-var

Label: none uuid: 53113e11-b663-452f-b4da-1443e470b065
Total devices 1 FS bytes used 384.00KiB
devid 1 size 429.53GiB used 2.04GiB path /dev/mapper/vg0-home

Btrfs v3.17.3


How to install ALX drivers for an AR8171 network adaptor in OMV


I bought a shiny new ASRock FM2A88X Extreme4+ motherboard (which I chose specifically for the plentiful expansion slots) to run my shiny new file server. During the installation of Open Media Vault, the installer failed to identify the network adaptor (according to the ASRock website, a Qualcomm Atheros AR8171 ). Googling lead me to believe it uses the ALX driver. I selected the entry in the installer, however it failed to initialise. I decided to try a manual install of an updated driver, so downloaded the latest Backports Driver Pack for the ALX driver (via my desktop mackine onto a USB stick). However when I went to compile it on the OMV server, it complained saying MAKE isn't installed. To add salt to injury, when I tried to download MAKE, the installation instructions give direction to make MAKE (which I cannot do without MAKE installed).


For the life of me I cannot find a stand-alone installer (such as a .deb file) for the ALX driver. All other instructions I've found online need an internet connection to do (adding sources etc) which I cannot do without a working network adaptor!


Does anyone out there know how to fix this??



mardi 30 décembre 2014

Use curl to send binary file through POST with content-type multipart/form-data;


A post request is made to:



http://www.example.com/example/


and the post data is as follows:



------WebKitFormBoundaryB8NNdk2kNdndnnn
Content-Disposition: form-data; name="picture[uploaded_data]"; filename="picture.jpg"
Content-Type: image/jpeg

binarydatagoeshere
------WebKitFormBoundaryB8NNdk2kNdndnnn--


So my question is, how can i use curl to do this exact same thing with the binary data of picture.jpg? I know of --data-binary @myfile.bin, but this is completely different and in this case the string after Boundary e.g B8NNdk2kNdndnnn in this case needs to be valid for the request to go through. So how do i do all this using curl?



What is the /boot partition really for?


I'm reading a relatively old text on Linux partitions and file systems (the LPIC 1 Certification Bible). It says:



Some versions of the Linux boot loaders cannot access a kernel that is outside the first 1024 cylinders on a disk. By putting the /boot partition at the beginning of the drive you can be assured of not having a problem when accessing the kernel at boot. This problem shows itself most often in cases of dual booting Linux along with another operating system that is on the first partition.



Why would a Linux distribution have "no access to the kernel outside the first 1024 cylinders on a disk"?


Also, what does "putting the /boot partition at the beginning of the drive" mean?



What are the implications of using an inode_ratio of 16384 in terms of storage use on ext4?


I'm assuming that this means that if the average file stored (including directories etc) is less than 16384 bytes, it may be possible to run out of inodes before using the full storage capacity of the filesystem. However, should the files being stored consume over 16384 bytes, on average, a physical space storage limit should be reached before one would run out of inodes.



npm style OS package manager. Packages local to a directory


Is there any distro or package manager with the following npm-like characteristics?:




  • Packages are installed to their own directory, chosen by the user at install time. As opposed to packages spilling their stuff all over different directories (/bin /usr/bin /etc/ ...)




  • Dependencies are contained in the local environment of a package. Clearly this is strongly coupled with the resolution of resources at runtime, which in unix is given by $PATH and conventions. In node dependencies are contained in nested subdirectories under $PKGDIR/node_module/$DEPPKG. This is only sustainable because the packages are very small, but there is a feature to link packages to other places in the filesystem. This could be the default.




What attracts me most about npm's system is that everything is local, so it is easy to reason about in isolation. There is no implicit global environment to worry about. You get user level installations and multiple versions of the same package for free. It is interesting (and in my opinion a pitty) how the idea of encapsulation has clearly impacted programming practices, but not the environments in which applications will ultimately be run.


I realize this goes against half of what unix is currently: The FSH, $PATH and other enviroment variables as a way of setting the environment, etc. However, I would argue that it is closest to the Unix filosophy, in the sense that (in my opinion) it is simpler.


Note: I'm closer to the noob side in the noob->beard spectrum. This is based more on more speculation than experience. If you think the whole idea is stupid, or you see some fundamental problem with it, please tell me why. Thanks.


Edit: Sorry to broaden an already broad question, ignore this if you like: I know little about compilation, shared libraries, etc. Is this only possible for npm because javascript is interpreted? Are there any issues with compiled languages (C, most importantly) that would make this impossible or very hard?