Create a server and mount a block storage device. - ebsarr/packet GitHub Wiki
Goals
- Create a server on packet.net
- Create a block storage volume
- Attach the volume to the server with the packet API and tools
- Create a partion and filesystem on the volume
- Mount the volume to the server
This article assumes that you have installed the packet CLI and set a default profile. Refer to this page to see how to do it.
Create the server
Ubuntu running on a Type 0 server
$ packet baremetal create-device --facility ewr1 --hostname ebsarrtest01 --os-type ubuntu_16_04_image
Provisioning of device successfully started...
[ 2016-11-23T15:46:22Z ] "%device%" (Type 0) was deployed to project "%project%" by %user%
[ 2016-11-23T15:47:11Z ] Network configured with addresses 147.75.197.69, 2604:1380:1:da00::3, and 10.99.176.3
[ 2016-11-23T15:47:22Z ] Configuration written, restarting device
[ 2016-11-23T15:47:56Z ] Device connected to DHCP system
[ 2016-11-23T15:48:49Z ] Server partitions created
[ 2016-11-23T15:49:10Z ] Operating system packages installed
[ 2016-11-23T15:49:17Z ] Installation finished, rebooting server
[ 2016-11-23T15:50:21Z ] Provision complete! Your device is ready to go.
{
"id": "058df2b4-a050-4a5d-89c0-e9d704c9a6de",
"href": "/devices/058df2b4-a050-4a5d-89c0-e9d704c9a6de",
"hostname": "ebsarrtest01",
"state": "active",
"created_at": "2016-11-23T15:46:20Z",
"updated_at": "2016-11-23T15:50:21Z",
"billing_cycle": "hourly",
...
First login
$ ssh -i ~/.ssh/packet_rsa root@ebsarrtest01
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.2.0-36-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
root@ebsarrtest01:~# uname -n
ebsarrtest01.local.lan
root@ebsarrtest01:~#
Create the block storage volume
$ packet storage create-volume --facility ewr1 size 80
{
"id": "cbb23532-430b-4bf2-b475-a59c5a8aa4be",
"name": "volume-cbb23532",
"description": "",
"size": 120,
"locked": false,
"billing_cycle": "hourly",
"state": "queued",
"created_at": "2016-11-23T15:56:58Z",
"updated_at": "2016-11-23T15:56:58Z",
...
Attach the volume to the server
$ packet storage attach-volume --volume-id cbb23532-430b-4bf2-b475-a59c5a8aa4be --device-id 058df2b4-a050-4a5d-89c0-e9d704c9a6de
No error.
Mounting our volume
All remaining commands executed in the server.
The first step is to attach the volume with the packet-block-storage-attach
tool. This tool is installed by default on all packet server.
# packet-block-storage-attach
If the volume was successfully attached, you should see the following message before the command ends
Block device /dev/mapper/volume-cbb23532 is available for use
We can now make a partition, build the filesystem and mount it.
# fdisk /dev/mapper/volume-cbb23532
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xd4612f60.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-251658239, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-251658239, default 251658239):
Created a new partition 1 of type 'Linux' and of size 120 GiB.
Command (m for help): w
The partition table
# fdisk /dev/mapper/volume-cbb23532
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/mapper/volume-cbb23532: 120 GiB, 128849018880 bytes, 251658240 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 1048576 bytes
I/O size (minimum/optimal): 1048576 bytes / 1048576 bytes
Disklabel type: dos
Disk identifier: 0xd4612f60
Device Boot Start End Sectors Size Id Type
/dev/mapper/volume-cbb23532-part1 2048 251658239 251656192 120G 83 Linux
Command (m for help): q
Create the filesytem
# mkfs -t ext4 /dev/mapper/volume-cbb23532-part1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 31457024 4k blocks and 7864320 inodes
Filesystem UUID: 31159988-5527-4322-b339-1e2a55e313d1
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Let's mount it now
# mkdir /data1
# mount /dev/mapper/volume-cbb23532-part1 /data1
# df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 4070200 0 4070200 0% /dev
tmpfs 816264 8804 807460 2% /run
/dev/sda3 113278624 873340 106627928 1% /
tmpfs 4081312 0 4081312 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
tmpfs 4081312 0 4081312 0% /sys/fs/cgroup
/dev/mapper/volume-cbb23532-part1 123722724 60984 117353952 1% /data1
Simple write test
# cd /data1
# pwd
/data1
# cat >first_file
this is a test
# ls -l first_file
-rw-r--r-- 1 root root 15 Nov 23 16:23 first_file
# cat first_file
this is a test
Looks alright
Extra: commands to detach the volume and destroy everything.
On the server side
# umount /data1
# packet-block-storage-detach
# exit
Go back to packet CLI
Delete the volume
$ packet storage detach-volume --attachement-id=b4e80fe0-d46d-4da5-9bc7-a1fec1069cc3
$ packet storage delete-volume --volume-id=cbb23532-430b-4bf2-b475-a59c5a8aa4be
$ packet storage list-volume --volume-id=cbb23532-430b-4bf2-b475-a59c5a8aa4be
Error: GET https://api.packet.net/storage/cbb23532-430b-4bf2-b475-a59c5a8aa4be: 404 Not found
Delete the server
$ packet baremetal delete-device --device-id=058df2b4-a050-4a5d-89c0-e9d704c9a6de
$ packet baremetal list-device --device-id=058df2b4-a050-4a5d-89c0-e9d704c9a6de
Error: GET https://api.packet.net/devices/058df2b4-a050-4a5d-89c0-e9d704c9a6de?include=facility: 404 Not found